From 59530984616e32fb2d0deaba4d2a0c2aa4322420 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Mon, 4 Jan 2021 09:29:58 -0500 Subject: [PATCH] Implement render bundle freeing --- wgpu-core/src/command/draw.rs | 2 ++ wgpu-core/src/command/render.rs | 3 ++- wgpu-core/src/device/queue.rs | 7 +++++++ 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/wgpu-core/src/command/draw.rs b/wgpu-core/src/command/draw.rs index c589d55d89..87ac116e85 100644 --- a/wgpu-core/src/command/draw.rs +++ b/wgpu-core/src/command/draw.rs @@ -65,6 +65,8 @@ pub enum DrawError { pub enum RenderCommandError { #[error("bind group {0:?} is invalid")] InvalidBindGroup(id::BindGroupId), + #[error("render bundle {0:?} is invalid")] + InvalidRenderBundle(id::RenderBundleId), #[error("bind group index {index} is greater than the device's requested `max_bind_group` limit {max}")] BindGroupIndexOutOfRange { index: u8, max: u32 }, #[error("dynamic buffer offset {0} does not respect `BIND_BUFFER_ALIGNMENT`")] diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 2a1b2bbbc2..cc53d21fe0 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1778,7 +1778,8 @@ impl Global { .trackers .bundles .use_extend(&*bundle_guard, bundle_id, (), ()) - .unwrap(); + .map_err(|_| RenderCommandError::InvalidRenderBundle(bundle_id)) + .map_pass_err(scope)?; info.context .check_compatible(&bundle.context) diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index d6c2ca2298..56def4f192 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -484,6 +484,8 @@ impl Global { let (mut command_buffer_guard, mut token) = hub.command_buffers.write(&mut token); if !command_buffer_ids.is_empty() { + let (render_bundle_guard, mut token) = hub.render_bundles.read(&mut token); + let (_, mut token) = hub.pipeline_layouts.read(&mut token); let (bind_group_guard, mut token) = hub.bind_groups.read(&mut token); let (compute_pipe_guard, mut token) = hub.compute_pipelines.read(&mut token); let (render_pipe_guard, mut token) = hub.render_pipelines.read(&mut token); @@ -583,6 +585,11 @@ impl Global { device.temp_suspected.render_pipelines.push(id); } } + for id in cmdbuf.trackers.bundles.used() { + if !render_bundle_guard[id].life_guard.use_at(submit_index) { + device.temp_suspected.render_bundles.push(id); + } + } // execute resource transitions let mut transit = device.cmd_allocator.extend(cmdbuf);