mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-12-08 21:26:17 +00:00
Cache framebuffers by the Device
This commit is contained in:
parent
d206de2049
commit
4f07ce8248
@ -14,7 +14,7 @@ use {
|
|||||||
BufferId, CommandBufferId, ComputePassId, DeviceId, RenderPassId, TextureId, TextureViewId,
|
BufferId, CommandBufferId, ComputePassId, DeviceId, RenderPassId, TextureId, TextureViewId,
|
||||||
};
|
};
|
||||||
use conv;
|
use conv;
|
||||||
use device::RenderPassKey;
|
use device::{FramebufferKey, RenderPassKey};
|
||||||
use registry::{HUB, Items, Registry};
|
use registry::{HUB, Items, Registry};
|
||||||
use track::{BufferTracker, TextureTracker};
|
use track::{BufferTracker, TextureTracker};
|
||||||
|
|
||||||
@ -230,16 +230,31 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let framebuffer = {
|
let mut framebuffer_cache = device.framebuffers.lock().unwrap();
|
||||||
let attachments = desc.color_attachments
|
let fb_key = FramebufferKey {
|
||||||
|
attachments: desc.color_attachments
|
||||||
.iter()
|
.iter()
|
||||||
.map(|at| at.attachment)
|
.map(|at| Stored(at.attachment))
|
||||||
.chain(desc.depth_stencil_attachment.as_ref().map(|at| at.attachment))
|
.chain(desc.depth_stencil_attachment.as_ref().map(|at| Stored(at.attachment)))
|
||||||
.map(|id| &view_guard.get(id).raw);
|
.collect(),
|
||||||
|
};
|
||||||
|
let framebuffer = match framebuffer_cache.entry(fb_key) {
|
||||||
|
Entry::Occupied(e) => e.into_mut(),
|
||||||
|
Entry::Vacant(e) => {
|
||||||
|
let fb = {
|
||||||
|
let attachments = e
|
||||||
|
.key()
|
||||||
|
.attachments
|
||||||
|
.iter()
|
||||||
|
.map(|&Stored(id)| &view_guard.get(id).raw);
|
||||||
|
|
||||||
device.raw
|
device.raw
|
||||||
.create_framebuffer(&render_pass, attachments, extent.unwrap())
|
.create_framebuffer(&render_pass, attachments, extent.unwrap())
|
||||||
.unwrap()
|
.unwrap()
|
||||||
};
|
};
|
||||||
|
e.insert(fb)
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
let rect = {
|
let rect = {
|
||||||
let ex = extent.unwrap();
|
let ex = extent.unwrap();
|
||||||
@ -263,8 +278,8 @@ pub extern "C" fn wgpu_command_buffer_begin_render_pass(
|
|||||||
}));
|
}));
|
||||||
|
|
||||||
current_comb.begin_render_pass(
|
current_comb.begin_render_pass(
|
||||||
&render_pass,
|
render_pass,
|
||||||
&framebuffer,
|
framebuffer,
|
||||||
rect,
|
rect,
|
||||||
clear_values,
|
clear_values,
|
||||||
hal::command::SubpassContents::Inline,
|
hal::command::SubpassContents::Inline,
|
||||||
|
|||||||
@ -24,6 +24,12 @@ pub(crate) struct RenderPassKey {
|
|||||||
}
|
}
|
||||||
impl Eq for RenderPassKey {}
|
impl Eq for RenderPassKey {}
|
||||||
|
|
||||||
|
#[derive(Hash, PartialEq)]
|
||||||
|
pub(crate) struct FramebufferKey {
|
||||||
|
pub attachments: Vec<Stored<TextureViewId>>,
|
||||||
|
}
|
||||||
|
impl Eq for FramebufferKey {}
|
||||||
|
|
||||||
|
|
||||||
pub struct Device<B: hal::Backend> {
|
pub struct Device<B: hal::Backend> {
|
||||||
pub(crate) raw: B::Device,
|
pub(crate) raw: B::Device,
|
||||||
@ -34,6 +40,7 @@ pub struct Device<B: hal::Backend> {
|
|||||||
texture_tracker: Mutex<TextureTracker>,
|
texture_tracker: Mutex<TextureTracker>,
|
||||||
mem_props: hal::MemoryProperties,
|
mem_props: hal::MemoryProperties,
|
||||||
pub(crate) render_passes: Mutex<HashMap<RenderPassKey, B::RenderPass>>,
|
pub(crate) render_passes: Mutex<HashMap<RenderPassKey, B::RenderPass>>,
|
||||||
|
pub(crate) framebuffers: Mutex<HashMap<FramebufferKey, B::Framebuffer>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<B: hal::Backend> Device<B> {
|
impl<B: hal::Backend> Device<B> {
|
||||||
@ -72,6 +79,7 @@ impl<B: hal::Backend> Device<B> {
|
|||||||
texture_tracker: Mutex::new(TextureTracker::new()),
|
texture_tracker: Mutex::new(TextureTracker::new()),
|
||||||
mem_props,
|
mem_props,
|
||||||
render_passes: Mutex::new(HashMap::new()),
|
render_passes: Mutex::new(HashMap::new()),
|
||||||
|
framebuffers: Mutex::new(HashMap::new()),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user