v26: Re-use memory in render pass encoding

This commit is contained in:
Connor Fitzgerald committed 2025-11-10 09:15:46 -05:00
1 parent 6f8edda9b1
commit 5203e4386e
6 files changed
+24 -7

No files matched your search

+2 -2
View File
@@ -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 {
+1 -1
View File
@@ -69,7 +69,7 @@ impl ComputePass {
} = desc;
Self {
base: BasePass::new(&label),
base: BasePass::new(Vec::new(), &label),
parent: Some(parent),
timestamp_writes,
+3 -2
View File
@@ -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<C, E> {
}
impl<C: Clone, E: Clone> BasePass<C, E> {
fn new(label: &Label) -> Self {
fn new(commands: Vec<C>, 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(),
+14 -2
View File
@@ -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(())
})
}
+3
View File
@@ -88,6 +88,8 @@ pub struct Device {
pub(crate) command_indices: RwLock<CommandIndices>,
pub(crate) render_pass_command_pool: Mutex<Vec<Vec<command::ArcRenderCommand>>>,
/// 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) },
+1
View File
@@ -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 { }