diff --git a/CHANGELOG.md b/CHANGELOG.md index 545536479..99d3a0767 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -182,6 +182,7 @@ By @sagudev in [#10109](https://github.com/gfx-rs/wgpu/pull/10109). #### Vulkan - Sub-allocate `wgpu_hal::MemoryFlags::TRANSIENT` buffers and acceleration structure build scratch from a separate Vulkan memory pool, so short-lived allocations no longer pin memory blocks shared with long-lived resources. By @stuartparmenter in [#10232](https://github.com/gfx-rs/wgpu/pull/10232). +- Allocate acceleration structures created with `AccelerationStructureFlags::ALLOW_COMPACTION` from the transient Vulkan memory pool, since they are usually replaced by their compacted copies. By @stuartparmenter in [#10233](https://github.com/gfx-rs/wgpu/pull/10233). ### Bug Fixes diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 9ab1ae303..a080285ef 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -3048,6 +3048,8 @@ pub struct AccelerationStructureDescriptor<'a> { pub label: Label<'a>, pub size: wgt::BufferAddress, pub format: AccelerationStructureFormat, + /// Backends may allocate the structure as a short-lived resource, since it is + /// usually replaced by its compacted copy. pub allow_compaction: bool, } diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index e2fa95831..5e1a79bc1 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -2908,10 +2908,15 @@ impl crate::Device for super::Device { .label .unwrap_or("Unlabeled acceleration structure buffer"); + let pool = if desc.allow_compaction { + super::MemoryPool::Transient + } else { + super::MemoryPool::General + }; let allocation = self .mem_allocator .allocate( - super::MemoryPool::General, + pool, &gpu_allocator::vulkan::AllocationCreateDesc { name, requirements, diff --git a/wgpu-types/src/ray_tracing.rs b/wgpu-types/src/ray_tracing.rs index c946cd566..147c5ccb7 100644 --- a/wgpu-types/src/ray_tracing.rs +++ b/wgpu-types/src/ray_tracing.rs @@ -133,6 +133,9 @@ bitflags::bitflags!( const ALLOW_UPDATE = 1 << 0; /// Allow the acceleration structure to be compacted in a copy operation /// (`Blas::prepare_for_compaction`, `CommandEncoder::compact_blas`). + /// + /// Some backends allocate structures with this flag from memory meant for + /// short-lived resources. Only set it on structures you compact soon after building. const ALLOW_COMPACTION = 1 << 1; /// Optimize for fast ray tracing performance, recommended if the geometry is unlikely /// to change (e.g. in a game: non-interactive scene geometry)