diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 743865bb6..80d2366eb 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -196,7 +196,7 @@ impl RenderBundleEncoder { //TODO: validate that attachment formats are renderable, // have expected aspects, support multisampling. Ok(Self { - base: base.unwrap_or_else(|| BasePass::new(&desc.label)), + base: base.unwrap_or_else(|| BasePass::new(Vec::new(), &desc.label)), parent_id, context: RenderPassContext { attachments: AttachmentData { @@ -232,7 +232,7 @@ impl RenderBundleEncoder { pub fn dummy(parent_id: id::DeviceId) -> Self { Self { - base: BasePass::new(&None), + base: BasePass::new(Vec::new(), &None), parent_id, context: RenderPassContext { attachments: AttachmentData { diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index e6793a32d..d113cc6cd 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -69,7 +69,7 @@ impl ComputePass { } = desc; Self { - base: BasePass::new(&label), + base: BasePass::new(Vec::new(), &label), parent: Some(parent), timestamp_writes, diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 80133c5b8..755e3b618 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -26,6 +26,7 @@ pub use self::{ }; pub(crate) use allocator::CommandAllocator; +pub(crate) use render_command::ArcRenderCommand; pub(crate) use timestamp_writes::ArcPassTimestampWrites; pub use timestamp_writes::PassTimestampWrites; @@ -877,11 +878,11 @@ pub struct BasePass { } impl BasePass { - fn new(label: &Label) -> Self { + fn new(commands: Vec, label: &Label) -> Self { Self { label: label.as_deref().map(str::to_owned), error: None, - commands: Vec::new(), + commands, dynamic_offsets: Vec::new(), string_data: Vec::new(), push_constant_data: Vec::new(), diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 18cf03db7..2415008b4 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -1,5 +1,5 @@ use alloc::{borrow::Cow, sync::Arc, vec::Vec}; -use core::{fmt, num::NonZeroU32, ops::Range, str}; +use core::{fmt, mem, num::NonZeroU32, ops::Range, str}; use arrayvec::ArrayVec; use thiserror::Error; @@ -287,8 +287,15 @@ impl RenderPass { occlusion_query_set, } = desc; + let render_commands = parent + .device + .render_pass_command_pool + .lock() + .pop() + .unwrap_or_else(|| Vec::with_capacity(1 << 14)); + Self { - base: BasePass::new(label), + base: BasePass::new(render_commands, label), parent: Some(parent), color_attachments, depth_stencil_attachment, @@ -2252,6 +2259,11 @@ impl Global { encoder.close_and_swap().map_pass_err(pass_scope)?; + device + .render_pass_command_pool + .lock() + .push(mem::take(&mut base.commands)); + Ok(()) }) } diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index ce7187ef5..74c9d6cab 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -88,6 +88,8 @@ pub struct Device { pub(crate) command_indices: RwLock, + pub(crate) render_pass_command_pool: Mutex>>, + /// The index of the last successful submission to this device's /// [`hal::Queue`]. /// @@ -289,6 +291,7 @@ impl Device { next_acceleration_structure_build_command_index: 1, }, ), + render_pass_command_pool: Mutex::new(rank::DEVICE_RENDER_PASS_COMMAND_POOL, Vec::new()), last_successful_submission_index: AtomicU64::new(0), fence: RwLock::new(rank::DEVICE_FENCE, ManuallyDrop::new(fence)), snatchable_lock: unsafe { SnatchLock::new(rank::DEVICE_SNATCHABLE_LOCK) }, diff --git a/wgpu-core/src/lock/rank.rs b/wgpu-core/src/lock/rank.rs index 34d70a14e..ca1cb3569 100644 --- a/wgpu-core/src/lock/rank.rs +++ b/wgpu-core/src/lock/rank.rs @@ -138,6 +138,7 @@ define_lock_ranks! { rank DEVICE_TRACKERS "Device::trackers" followed by { } rank DEVICE_LOST_CLOSURE "Device::device_lost_closure" followed by { } rank DEVICE_USAGE_SCOPES "Device::usage_scopes" followed by { } + rank DEVICE_RENDER_PASS_COMMAND_POOL "Device::render_pass_command_pool" followed by { } rank IDENTITY_MANAGER_VALUES "IdentityManager::values" followed by { } rank REGISTRY_STORAGE "Registry::storage" followed by { } rank RESOURCE_POOL_INNER "ResourcePool::inner" followed by { }