From 5bf61ebaea9e3ffe3f9b6234a51097184b5376b0 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Wed, 11 Dec 2024 05:12:55 -0500 Subject: [PATCH 1/5] Replace Range with StateTransition in wgpu_hal --- wgpu-core/src/command/compute.rs | 10 ++++-- wgpu-core/src/command/ray_tracing.rs | 50 ++++++++++++++++++++-------- wgpu-core/src/device/queue.rs | 20 ++++++++--- wgpu-core/src/resource.rs | 10 ++++-- wgpu-core/src/track/buffer.rs | 5 ++- wgpu-core/src/track/mod.rs | 2 +- wgpu-core/src/track/texture.rs | 20 ++++++++--- wgpu-hal/src/lib.rs | 12 +++++-- 8 files changed, 98 insertions(+), 31 deletions(-) diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 84fcfb5874..232c3088ff 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -946,7 +946,10 @@ fn dispatch_indirect( unsafe { state.raw_encoder.transition_buffers(&[hal::BufferBarrier { buffer: params.dst_buffer, - usage: hal::BufferUses::INDIRECT..hal::BufferUses::STORAGE_READ_WRITE, + usage: hal::StateTransition { + start: hal::BufferUses::INDIRECT, + end: hal::BufferUses::STORAGE_READ_WRITE, + }, }]); } @@ -990,7 +993,10 @@ fn dispatch_indirect( unsafe { state.raw_encoder.transition_buffers(&[hal::BufferBarrier { buffer: params.dst_buffer, - usage: hal::BufferUses::STORAGE_READ_WRITE..hal::BufferUses::INDIRECT, + usage: hal::StateTransition { + start: hal::BufferUses::STORAGE_READ_WRITE, + end: hal::BufferUses::INDIRECT, + }, }]); } diff --git a/wgpu-core/src/command/ray_tracing.rs b/wgpu-core/src/command/ray_tracing.rs index 8732377560..8d964c4ce4 100644 --- a/wgpu-core/src/command/ray_tracing.rs +++ b/wgpu-core/src/command/ray_tracing.rs @@ -289,8 +289,10 @@ impl Global { let scratch_buffer_barrier = hal::BufferBarrier:: { buffer: scratch_buffer.raw(), - usage: BufferUses::ACCELERATION_STRUCTURE_SCRATCH - ..BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + usage: hal::StateTransition { + start: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + end: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + }, }; let mut tlas_descriptors = Vec::new(); @@ -343,8 +345,10 @@ impl Global { cmd_buf_raw.place_acceleration_structure_barrier( hal::AccelerationStructureBarrier { - usage: hal::AccelerationStructureUses::BUILD_OUTPUT - ..hal::AccelerationStructureUses::SHADER_INPUT, + usage: hal::StateTransition { + start: hal::AccelerationStructureUses::BUILD_OUTPUT, + end: hal::AccelerationStructureUses::SHADER_INPUT, + }, }, ); } @@ -629,8 +633,10 @@ impl Global { let scratch_buffer_barrier = hal::BufferBarrier:: { buffer: scratch_buffer.raw(), - usage: BufferUses::ACCELERATION_STRUCTURE_SCRATCH - ..BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + usage: hal::StateTransition { + start: BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + end: BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + }, }; let mut tlas_descriptors = Vec::with_capacity(tlas_storage.len()); @@ -703,7 +709,10 @@ impl Global { if let Some(ref staging_buffer) = staging_buffer { cmd_buf_raw.transition_buffers(&[hal::BufferBarrier:: { buffer: staging_buffer.raw(), - usage: BufferUses::MAP_WRITE..BufferUses::COPY_SRC, + usage: hal::StateTransition { + start: BufferUses::MAP_WRITE, + end: BufferUses::COPY_SRC, + }, }]); } } @@ -720,12 +729,18 @@ impl Global { }; instance_buffer_barriers.push(hal::BufferBarrier:: { buffer: tlas.instance_buffer.as_ref(), - usage: BufferUses::COPY_DST..BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + usage: hal::StateTransition { + start: BufferUses::COPY_DST, + end: BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + }, }); unsafe { cmd_buf_raw.transition_buffers(&[hal::BufferBarrier:: { buffer: tlas.instance_buffer.as_ref(), - usage: BufferUses::MAP_READ..BufferUses::COPY_DST, + usage: hal::StateTransition { + start: BufferUses::MAP_READ, + end: BufferUses::COPY_DST, + }, }]); let temp = hal::BufferCopy { src_offset: range.start as u64, @@ -749,8 +764,10 @@ impl Global { cmd_buf_raw.place_acceleration_structure_barrier( hal::AccelerationStructureBarrier { - usage: hal::AccelerationStructureUses::BUILD_OUTPUT - ..hal::AccelerationStructureUses::SHADER_INPUT, + usage: hal::StateTransition { + start: hal::AccelerationStructureUses::BUILD_OUTPUT, + end: hal::AccelerationStructureUses::SHADER_INPUT, + }, }, ); } @@ -1275,8 +1292,10 @@ fn build_blas<'a>( if blas_present { unsafe { cmd_buf_raw.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { - usage: hal::AccelerationStructureUses::BUILD_INPUT - ..hal::AccelerationStructureUses::BUILD_OUTPUT, + usage: hal::StateTransition { + start: hal::AccelerationStructureUses::BUILD_INPUT, + end: hal::AccelerationStructureUses::BUILD_OUTPUT, + }, }); cmd_buf_raw.build_acceleration_structures(blas_descriptors); @@ -1301,7 +1320,10 @@ fn build_blas<'a>( } unsafe { cmd_buf_raw.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { - usage: source_usage..destination_usage, + usage: hal::StateTransition { + start: source_usage, + end: destination_usage, + }, }); } } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 3fbfeeb38c..1bc783ebe5 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -74,7 +74,10 @@ impl Queue { .command_encoder .transition_buffers(&[hal::BufferBarrier { buffer: zero_buffer, - usage: hal::BufferUses::empty()..hal::BufferUses::COPY_DST, + usage: hal::StateTransition { + start: hal::BufferUses::empty(), + end: hal::BufferUses::COPY_DST, + }, }]); pending_writes .command_encoder @@ -83,7 +86,10 @@ impl Queue { .command_encoder .transition_buffers(&[hal::BufferBarrier { buffer: zero_buffer, - usage: hal::BufferUses::COPY_DST..hal::BufferUses::COPY_SRC, + usage: hal::StateTransition { + start: hal::BufferUses::COPY_DST, + end: hal::BufferUses::COPY_SRC, + }, }]); } @@ -628,7 +634,10 @@ impl Queue { }; let barriers = iter::once(hal::BufferBarrier { buffer: staging_buffer.raw(), - usage: hal::BufferUses::MAP_WRITE..hal::BufferUses::COPY_SRC, + usage: hal::StateTransition { + start: hal::BufferUses::MAP_WRITE, + end: hal::BufferUses::COPY_SRC, + }, }) .chain(transition.map(|pending| pending.into_hal(&buffer, &snatch_guard))) .collect::>(); @@ -847,7 +856,10 @@ impl Queue { { let buffer_barrier = hal::BufferBarrier { buffer: staging_buffer.raw(), - usage: hal::BufferUses::MAP_WRITE..hal::BufferUses::COPY_SRC, + usage: hal::StateTransition { + start: hal::BufferUses::MAP_WRITE, + end: hal::BufferUses::COPY_SRC, + }, }; let mut trackers = self.device.trackers.lock(); diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index f0afab14c0..5462614b8c 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -636,11 +636,17 @@ impl Buffer { }); let transition_src = hal::BufferBarrier { buffer: staging_buffer.raw(), - usage: hal::BufferUses::MAP_WRITE..hal::BufferUses::COPY_SRC, + usage: hal::StateTransition { + start: hal::BufferUses::MAP_WRITE, + end: hal::BufferUses::COPY_SRC, + }, }; let transition_dst = hal::BufferBarrier:: { buffer: raw_buf, - usage: hal::BufferUses::empty()..hal::BufferUses::COPY_DST, + usage: hal::StateTransition { + start: hal::BufferUses::empty(), + end: hal::BufferUses::COPY_SRC, + }, }; let mut pending_writes = queue.pending_writes.lock(); let encoder = pending_writes.activate(); diff --git a/wgpu-core/src/track/buffer.rs b/wgpu-core/src/track/buffer.rs index ce3fdb1147..817745a26f 100644 --- a/wgpu-core/src/track/buffer.rs +++ b/wgpu-core/src/track/buffer.rs @@ -753,7 +753,10 @@ unsafe fn barrier( barriers.push(PendingTransition { id: index as _, selector: (), - usage: current_state..new_state, + usage: hal::StateTransition { + start: current_state, + end: new_state, + }, }); } diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index 9a66b5f903..d7a2ceab37 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -255,7 +255,7 @@ impl TrackerIndexAllocators { pub(crate) struct PendingTransition { pub id: u32, pub selector: S::Selector, - pub usage: ops::Range, + pub usage: hal::StateTransition, } pub(crate) type PendingTransitionList = Vec>; diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index f3b4c76176..c374d0f0e1 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -1304,7 +1304,10 @@ unsafe fn barrier( barriers.push(PendingTransition { id: index as _, selector: texture_selector.clone(), - usage: current_simple..new_simple, + usage: hal::StateTransition { + start: current_simple, + end: new_simple, + }, }); } (SingleOrManyStates::Single(current_simple), SingleOrManyStates::Many(new_many)) => { @@ -1320,7 +1323,10 @@ unsafe fn barrier( barriers.push(PendingTransition { id: index as _, selector, - usage: current_simple..new_state, + usage: hal::StateTransition { + start: current_simple, + end: new_state, + }, }); } } @@ -1343,7 +1349,10 @@ unsafe fn barrier( mips: mip_id..mip_id + 1, layers: layers.clone(), }, - usage: current_layer_state..new_simple, + usage: hal::StateTransition { + start: current_layer_state, + end: new_simple, + }, }); } } @@ -1372,7 +1381,10 @@ unsafe fn barrier( mips: mip_id..mip_id + 1, layers, }, - usage: *current_layer_state..new_state, + usage: hal::StateTransition { + start: *current_layer_state, + end: new_state, + }, }); } } diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 2de9d3e71c..28779ba66f 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -2251,17 +2251,23 @@ pub struct Rect { pub h: T, } +#[derive(Debug, Clone, PartialEq)] +pub struct StateTransition { + pub start: T, + pub end: T, +} + #[derive(Debug, Clone)] pub struct BufferBarrier<'a, B: DynBuffer + ?Sized> { pub buffer: &'a B, - pub usage: Range, + pub usage: StateTransition, } #[derive(Debug, Clone)] pub struct TextureBarrier<'a, T: DynTexture + ?Sized> { pub texture: &'a T, pub range: wgt::ImageSubresourceRange, - pub usage: Range, + pub usage: StateTransition, } #[derive(Clone, Copy, Debug)] @@ -2525,7 +2531,7 @@ bitflags::bitflags! { #[derive(Debug, Clone)] pub struct AccelerationStructureBarrier { - pub usage: Range, + pub usage: StateTransition, } #[derive(Debug, Copy, Clone)] From a1a94dad4cf7c7dedb1661eb624727fc5359c6d5 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Wed, 11 Dec 2024 05:14:30 -0500 Subject: [PATCH 2/5] Use from and to instead of start and end --- wgpu-core/src/command/compute.rs | 8 +++---- wgpu-core/src/command/ray_tracing.rs | 36 ++++++++++++++-------------- wgpu-core/src/device/queue.rs | 16 ++++++------- wgpu-core/src/resource.rs | 8 +++---- wgpu-core/src/track/buffer.rs | 4 ++-- wgpu-core/src/track/mod.rs | 4 ++-- wgpu-core/src/track/texture.rs | 16 ++++++------- wgpu-hal/src/dx12/command.rs | 12 +++++----- wgpu-hal/src/gles/command.rs | 8 +++---- wgpu-hal/src/lib.rs | 4 ++-- wgpu-hal/src/vulkan/command.rs | 16 ++++++------- 11 files changed, 66 insertions(+), 66 deletions(-) diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 232c3088ff..44b65b6d6e 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -947,8 +947,8 @@ fn dispatch_indirect( state.raw_encoder.transition_buffers(&[hal::BufferBarrier { buffer: params.dst_buffer, usage: hal::StateTransition { - start: hal::BufferUses::INDIRECT, - end: hal::BufferUses::STORAGE_READ_WRITE, + from: hal::BufferUses::INDIRECT, + to: hal::BufferUses::STORAGE_READ_WRITE, }, }]); } @@ -994,8 +994,8 @@ fn dispatch_indirect( state.raw_encoder.transition_buffers(&[hal::BufferBarrier { buffer: params.dst_buffer, usage: hal::StateTransition { - start: hal::BufferUses::STORAGE_READ_WRITE, - end: hal::BufferUses::INDIRECT, + from: hal::BufferUses::STORAGE_READ_WRITE, + to: hal::BufferUses::INDIRECT, }, }]); } diff --git a/wgpu-core/src/command/ray_tracing.rs b/wgpu-core/src/command/ray_tracing.rs index 8d964c4ce4..35fc581127 100644 --- a/wgpu-core/src/command/ray_tracing.rs +++ b/wgpu-core/src/command/ray_tracing.rs @@ -290,8 +290,8 @@ impl Global { let scratch_buffer_barrier = hal::BufferBarrier:: { buffer: scratch_buffer.raw(), usage: hal::StateTransition { - start: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, - end: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + from: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + to: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, }, }; @@ -346,8 +346,8 @@ impl Global { cmd_buf_raw.place_acceleration_structure_barrier( hal::AccelerationStructureBarrier { usage: hal::StateTransition { - start: hal::AccelerationStructureUses::BUILD_OUTPUT, - end: hal::AccelerationStructureUses::SHADER_INPUT, + from: hal::AccelerationStructureUses::BUILD_OUTPUT, + to: hal::AccelerationStructureUses::SHADER_INPUT, }, }, ); @@ -634,8 +634,8 @@ impl Global { let scratch_buffer_barrier = hal::BufferBarrier:: { buffer: scratch_buffer.raw(), usage: hal::StateTransition { - start: BufferUses::ACCELERATION_STRUCTURE_SCRATCH, - end: BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + from: BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + to: BufferUses::ACCELERATION_STRUCTURE_SCRATCH, }, }; @@ -710,8 +710,8 @@ impl Global { cmd_buf_raw.transition_buffers(&[hal::BufferBarrier:: { buffer: staging_buffer.raw(), usage: hal::StateTransition { - start: BufferUses::MAP_WRITE, - end: BufferUses::COPY_SRC, + from: BufferUses::MAP_WRITE, + to: BufferUses::COPY_SRC, }, }]); } @@ -730,16 +730,16 @@ impl Global { instance_buffer_barriers.push(hal::BufferBarrier:: { buffer: tlas.instance_buffer.as_ref(), usage: hal::StateTransition { - start: BufferUses::COPY_DST, - end: BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + from: BufferUses::COPY_DST, + to: BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, }, }); unsafe { cmd_buf_raw.transition_buffers(&[hal::BufferBarrier:: { buffer: tlas.instance_buffer.as_ref(), usage: hal::StateTransition { - start: BufferUses::MAP_READ, - end: BufferUses::COPY_DST, + from: BufferUses::MAP_READ, + to: BufferUses::COPY_DST, }, }]); let temp = hal::BufferCopy { @@ -765,8 +765,8 @@ impl Global { cmd_buf_raw.place_acceleration_structure_barrier( hal::AccelerationStructureBarrier { usage: hal::StateTransition { - start: hal::AccelerationStructureUses::BUILD_OUTPUT, - end: hal::AccelerationStructureUses::SHADER_INPUT, + from: hal::AccelerationStructureUses::BUILD_OUTPUT, + to: hal::AccelerationStructureUses::SHADER_INPUT, }, }, ); @@ -1293,8 +1293,8 @@ fn build_blas<'a>( unsafe { cmd_buf_raw.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { usage: hal::StateTransition { - start: hal::AccelerationStructureUses::BUILD_INPUT, - end: hal::AccelerationStructureUses::BUILD_OUTPUT, + from: hal::AccelerationStructureUses::BUILD_INPUT, + to: hal::AccelerationStructureUses::BUILD_OUTPUT, }, }); @@ -1321,8 +1321,8 @@ fn build_blas<'a>( unsafe { cmd_buf_raw.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { usage: hal::StateTransition { - start: source_usage, - end: destination_usage, + from: source_usage, + to: destination_usage, }, }); } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 1bc783ebe5..6ba9728e9e 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -75,8 +75,8 @@ impl Queue { .transition_buffers(&[hal::BufferBarrier { buffer: zero_buffer, usage: hal::StateTransition { - start: hal::BufferUses::empty(), - end: hal::BufferUses::COPY_DST, + from: hal::BufferUses::empty(), + to: hal::BufferUses::COPY_DST, }, }]); pending_writes @@ -87,8 +87,8 @@ impl Queue { .transition_buffers(&[hal::BufferBarrier { buffer: zero_buffer, usage: hal::StateTransition { - start: hal::BufferUses::COPY_DST, - end: hal::BufferUses::COPY_SRC, + from: hal::BufferUses::COPY_DST, + to: hal::BufferUses::COPY_SRC, }, }]); } @@ -635,8 +635,8 @@ impl Queue { let barriers = iter::once(hal::BufferBarrier { buffer: staging_buffer.raw(), usage: hal::StateTransition { - start: hal::BufferUses::MAP_WRITE, - end: hal::BufferUses::COPY_SRC, + from: hal::BufferUses::MAP_WRITE, + to: hal::BufferUses::COPY_SRC, }, }) .chain(transition.map(|pending| pending.into_hal(&buffer, &snatch_guard))) @@ -857,8 +857,8 @@ impl Queue { let buffer_barrier = hal::BufferBarrier { buffer: staging_buffer.raw(), usage: hal::StateTransition { - start: hal::BufferUses::MAP_WRITE, - end: hal::BufferUses::COPY_SRC, + from: hal::BufferUses::MAP_WRITE, + to: hal::BufferUses::COPY_SRC, }, }; diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 5462614b8c..466eded9e4 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -637,15 +637,15 @@ impl Buffer { let transition_src = hal::BufferBarrier { buffer: staging_buffer.raw(), usage: hal::StateTransition { - start: hal::BufferUses::MAP_WRITE, - end: hal::BufferUses::COPY_SRC, + from: hal::BufferUses::MAP_WRITE, + to: hal::BufferUses::COPY_SRC, }, }; let transition_dst = hal::BufferBarrier:: { buffer: raw_buf, usage: hal::StateTransition { - start: hal::BufferUses::empty(), - end: hal::BufferUses::COPY_SRC, + from: hal::BufferUses::empty(), + to: hal::BufferUses::COPY_SRC, }, }; let mut pending_writes = queue.pending_writes.lock(); diff --git a/wgpu-core/src/track/buffer.rs b/wgpu-core/src/track/buffer.rs index 817745a26f..0cdc9dc966 100644 --- a/wgpu-core/src/track/buffer.rs +++ b/wgpu-core/src/track/buffer.rs @@ -754,8 +754,8 @@ unsafe fn barrier( id: index as _, selector: (), usage: hal::StateTransition { - start: current_state, - end: new_state, + from: current_state, + to: new_state, }, }); } diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index d7a2ceab37..261bb0458e 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -282,8 +282,8 @@ impl PendingTransition { texture: &dyn hal::DynTexture, ) -> hal::TextureBarrier<'_, dyn hal::DynTexture> { // These showing up in a barrier is always a bug - strict_assert_ne!(self.usage.start, hal::TextureUses::UNKNOWN); - strict_assert_ne!(self.usage.end, hal::TextureUses::UNKNOWN); + strict_assert_ne!(self.usage.from, hal::TextureUses::UNKNOWN); + strict_assert_ne!(self.usage.to, hal::TextureUses::UNKNOWN); let mip_count = self.selector.mips.end - self.selector.mips.start; strict_assert_ne!(mip_count, 0); diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index c374d0f0e1..8ea1e04cd1 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -1305,8 +1305,8 @@ unsafe fn barrier( id: index as _, selector: texture_selector.clone(), usage: hal::StateTransition { - start: current_simple, - end: new_simple, + from: current_simple, + to: new_simple, }, }); } @@ -1324,8 +1324,8 @@ unsafe fn barrier( id: index as _, selector, usage: hal::StateTransition { - start: current_simple, - end: new_state, + from: current_simple, + to: new_state, }, }); } @@ -1350,8 +1350,8 @@ unsafe fn barrier( layers: layers.clone(), }, usage: hal::StateTransition { - start: current_layer_state, - end: new_simple, + from: current_layer_state, + to: new_simple, }, }); } @@ -1382,8 +1382,8 @@ unsafe fn barrier( layers, }, usage: hal::StateTransition { - start: *current_layer_state, - end: new_state, + from: *current_layer_state, + to: new_state, }, }); } diff --git a/wgpu-hal/src/dx12/command.rs b/wgpu-hal/src/dx12/command.rs index 00bb41cae5..d4c60aa528 100644 --- a/wgpu-hal/src/dx12/command.rs +++ b/wgpu-hal/src/dx12/command.rs @@ -339,8 +339,8 @@ impl crate::CommandEncoder for super::CommandEncoder { self.temp.barriers.clear(); for barrier in barriers { - let s0 = conv::map_buffer_usage_to_state(barrier.usage.start); - let s1 = conv::map_buffer_usage_to_state(barrier.usage.end); + let s0 = conv::map_buffer_usage_to_state(barrier.usage.from); + let s1 = conv::map_buffer_usage_to_state(barrier.usage.to); if s0 != s1 { let raw = Direct3D12::D3D12_RESOURCE_BARRIER { Type: Direct3D12::D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, @@ -359,7 +359,7 @@ impl crate::CommandEncoder for super::CommandEncoder { }, }; self.temp.barriers.push(raw); - } else if barrier.usage.start == crate::BufferUses::STORAGE_READ_WRITE { + } else if barrier.usage.from == crate::BufferUses::STORAGE_READ_WRITE { let raw = Direct3D12::D3D12_RESOURCE_BARRIER { Type: Direct3D12::D3D12_RESOURCE_BARRIER_TYPE_UAV, Flags: Direct3D12::D3D12_RESOURCE_BARRIER_FLAG_NONE, @@ -392,8 +392,8 @@ impl crate::CommandEncoder for super::CommandEncoder { self.temp.barriers.clear(); for barrier in barriers { - let s0 = conv::map_texture_usage_to_state(barrier.usage.start); - let s1 = conv::map_texture_usage_to_state(barrier.usage.end); + let s0 = conv::map_texture_usage_to_state(barrier.usage.from); + let s1 = conv::map_texture_usage_to_state(barrier.usage.to); if s0 != s1 { let mut raw = Direct3D12::D3D12_RESOURCE_BARRIER { Type: Direct3D12::D3D12_RESOURCE_BARRIER_TYPE_TRANSITION, @@ -458,7 +458,7 @@ impl crate::CommandEncoder for super::CommandEncoder { } } } - } else if barrier.usage.start == crate::TextureUses::STORAGE_READ_WRITE { + } else if barrier.usage.from == crate::TextureUses::STORAGE_READ_WRITE { let raw = Direct3D12::D3D12_RESOURCE_BARRIER { Type: Direct3D12::D3D12_RESOURCE_BARRIER_TYPE_UAV, Flags: Direct3D12::D3D12_RESOURCE_BARRIER_FLAG_NONE, diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index 855ac8d781..640c91bea7 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -289,14 +289,14 @@ impl crate::CommandEncoder for super::CommandEncoder { // GLES only synchronizes storage -> anything explicitly if !bar .usage - .start + .from .contains(crate::BufferUses::STORAGE_READ_WRITE) { continue; } self.cmd_buffer .commands - .push(C::BufferBarrier(bar.buffer.raw.unwrap(), bar.usage.end)); + .push(C::BufferBarrier(bar.buffer.raw.unwrap(), bar.usage.to)); } } @@ -316,14 +316,14 @@ impl crate::CommandEncoder for super::CommandEncoder { // GLES only synchronizes storage -> anything explicitly if !bar .usage - .start + .from .contains(crate::TextureUses::STORAGE_READ_WRITE) { continue; } // unlike buffers, there is no need for a concrete texture // object to be bound anywhere for a barrier - combined_usage |= bar.usage.end; + combined_usage |= bar.usage.to; } if !combined_usage.is_empty() { diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 28779ba66f..124f23cf4a 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -2253,8 +2253,8 @@ pub struct Rect { #[derive(Debug, Clone, PartialEq)] pub struct StateTransition { - pub start: T, - pub end: T, + pub from: T, + pub to: T, } #[derive(Debug, Clone)] diff --git a/wgpu-hal/src/vulkan/command.rs b/wgpu-hal/src/vulkan/command.rs index eb80697336..8c6c5281fe 100644 --- a/wgpu-hal/src/vulkan/command.rs +++ b/wgpu-hal/src/vulkan/command.rs @@ -140,9 +140,9 @@ impl crate::CommandEncoder for super::CommandEncoder { vk_barriers.clear(); for bar in barriers { - let (src_stage, src_access) = conv::map_buffer_usage_to_barrier(bar.usage.start); + let (src_stage, src_access) = conv::map_buffer_usage_to_barrier(bar.usage.from); src_stages |= src_stage; - let (dst_stage, dst_access) = conv::map_buffer_usage_to_barrier(bar.usage.end); + let (dst_stage, dst_access) = conv::map_buffer_usage_to_barrier(bar.usage.to); dst_stages |= dst_stage; vk_barriers.push( @@ -184,11 +184,11 @@ impl crate::CommandEncoder for super::CommandEncoder { bar.texture.format, &self.device.private_caps, ); - let (src_stage, src_access) = conv::map_texture_usage_to_barrier(bar.usage.start); - let src_layout = conv::derive_image_layout(bar.usage.start, bar.texture.format); + let (src_stage, src_access) = conv::map_texture_usage_to_barrier(bar.usage.from); + let src_layout = conv::derive_image_layout(bar.usage.from, bar.texture.format); src_stages |= src_stage; - let (dst_stage, dst_access) = conv::map_texture_usage_to_barrier(bar.usage.end); - let dst_layout = conv::derive_image_layout(bar.usage.end, bar.texture.format); + let (dst_stage, dst_access) = conv::map_texture_usage_to_barrier(bar.usage.to); + let dst_layout = conv::derive_image_layout(bar.usage.to, bar.texture.format); dst_stages |= dst_stage; vk_barriers.push( @@ -648,11 +648,11 @@ impl crate::CommandEncoder for super::CommandEncoder { barrier: crate::AccelerationStructureBarrier, ) { let (src_stage, src_access) = conv::map_acceleration_structure_usage_to_barrier( - barrier.usage.start, + barrier.usage.from, self.device.features, ); let (dst_stage, dst_access) = conv::map_acceleration_structure_usage_to_barrier( - barrier.usage.end, + barrier.usage.to, self.device.features, ); From 3e5964143fcd10ecbcc73249dc7e583571d371b0 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Wed, 11 Dec 2024 05:29:35 -0500 Subject: [PATCH 3/5] changelog --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8539bd3aac..beae54b7a7 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -146,6 +146,7 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148] #### HAL +- Replace `usage: Range`, for `BufferUses`, `TextureUses`, and `AccelerationStructureBarrier` with a new `StateTransition`. By @atlv24 in [#6703](https://github.com/gfx-rs/wgpu/pull/6703) - Change the `DropCallback` API to use `FnOnce` instead of `FnMut`. By @jerzywilczek in [#6482](https://github.com/gfx-rs/wgpu/pull/6482) ### Bug Fixes From 2b346d32208e417991e08c321a28223edfea55f4 Mon Sep 17 00:00:00 2001 From: atlas dostal Date: Wed, 11 Dec 2024 05:36:05 -0500 Subject: [PATCH 4/5] Fix --- wgpu-hal/examples/halmark/main.rs | 25 +++++-- wgpu-hal/examples/ray-traced-triangle/main.rs | 67 +++++++++++++------ 2 files changed, 68 insertions(+), 24 deletions(-) diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 1b44293a00..a5a1b660af 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -331,17 +331,26 @@ impl Example { { let buffer_barrier = hal::BufferBarrier { buffer: &staging_buffer, - usage: hal::BufferUses::empty()..hal::BufferUses::COPY_SRC, + usage: hal::StateTransition { + from: hal::BufferUses::empty(), + to: hal::BufferUses::COPY_SRC, + }, }; let texture_barrier1 = hal::TextureBarrier { texture: &texture, range: wgt::ImageSubresourceRange::default(), - usage: hal::TextureUses::UNINITIALIZED..hal::TextureUses::COPY_DST, + usage: hal::StateTransition { + from: hal::TextureUses::UNINITIALIZED, + to: hal::TextureUses::COPY_DST, + }, }; let texture_barrier2 = hal::TextureBarrier { texture: &texture, range: wgt::ImageSubresourceRange::default(), - usage: hal::TextureUses::COPY_DST..hal::TextureUses::RESOURCE, + usage: hal::StateTransition { + from: hal::TextureUses::COPY_DST, + to: hal::TextureUses::RESOURCE, + }, }; let copy = hal::BufferTextureCopy { buffer_layout: wgt::TexelCopyBufferLayout { @@ -665,7 +674,10 @@ impl Example { let target_barrier0 = hal::TextureBarrier { texture: surface_tex.borrow(), range: wgt::ImageSubresourceRange::default(), - usage: hal::TextureUses::UNINITIALIZED..hal::TextureUses::COLOR_TARGET, + usage: hal::StateTransition { + from: hal::TextureUses::UNINITIALIZED, + to: hal::TextureUses::COLOR_TARGET, + }, }; unsafe { ctx.encoder.begin_encoding(Some("frame")).unwrap(); @@ -732,7 +744,10 @@ impl Example { let target_barrier1 = hal::TextureBarrier { texture: surface_tex.borrow(), range: wgt::ImageSubresourceRange::default(), - usage: hal::TextureUses::COLOR_TARGET..hal::TextureUses::PRESENT, + usage: hal::StateTransition { + from: hal::TextureUses::COLOR_TARGET, + to: hal::TextureUses::PRESENT, + }, }; unsafe { ctx.encoder.end_render_pass(); diff --git a/wgpu-hal/examples/ray-traced-triangle/main.rs b/wgpu-hal/examples/ray-traced-triangle/main.rs index 39928e8cfb..52eaa80eb8 100644 --- a/wgpu-hal/examples/ray-traced-triangle/main.rs +++ b/wgpu-hal/examples/ray-traced-triangle/main.rs @@ -731,8 +731,10 @@ impl Example { unsafe { cmd_encoder.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { - usage: hal::AccelerationStructureUses::empty() - ..hal::AccelerationStructureUses::BUILD_OUTPUT, + usage: hal::StateTransition { + from: hal::AccelerationStructureUses::empty(), + to: hal::AccelerationStructureUses::BUILD_OUTPUT, + }, }); cmd_encoder.build_acceleration_structures( @@ -750,14 +752,18 @@ impl Example { let scratch_buffer_barrier = hal::BufferBarrier { buffer: &scratch_buffer, - usage: hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT - ..hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + usage: hal::StateTransition { + from: hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + to: hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + }, }; cmd_encoder.transition_buffers(iter::once(scratch_buffer_barrier)); cmd_encoder.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { - usage: hal::AccelerationStructureUses::BUILD_OUTPUT - ..hal::AccelerationStructureUses::BUILD_INPUT, + usage: hal::StateTransition { + from: hal::AccelerationStructureUses::BUILD_OUTPUT, + to: hal::AccelerationStructureUses::BUILD_INPUT, + }, }); cmd_encoder.build_acceleration_structures( @@ -774,14 +780,19 @@ impl Example { ); cmd_encoder.place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { - usage: hal::AccelerationStructureUses::BUILD_OUTPUT - ..hal::AccelerationStructureUses::SHADER_INPUT, + usage: hal::StateTransition { + from: hal::AccelerationStructureUses::BUILD_OUTPUT, + to: hal::AccelerationStructureUses::SHADER_INPUT, + }, }); let texture_barrier = hal::TextureBarrier { texture: &texture, range: wgt::ImageSubresourceRange::default(), - usage: hal::TextureUses::UNINITIALIZED..hal::TextureUses::STORAGE_READ_WRITE, + usage: hal::StateTransition { + from: hal::TextureUses::UNINITIALIZED, + to: hal::TextureUses::STORAGE_READ_WRITE, + }, }; cmd_encoder.transition_textures(iter::once(texture_barrier)); @@ -852,7 +863,10 @@ impl Example { let target_barrier0 = hal::TextureBarrier { texture: surface_tex.borrow(), range: wgt::ImageSubresourceRange::default(), - usage: hal::TextureUses::UNINITIALIZED..hal::TextureUses::COPY_DST, + usage: hal::StateTransition { + from: hal::TextureUses::UNINITIALIZED, + to: hal::TextureUses::COPY_DST, + }, }; let instances_buffer_size = @@ -890,8 +904,10 @@ impl Example { ctx.encoder .place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { - usage: hal::AccelerationStructureUses::SHADER_INPUT - ..hal::AccelerationStructureUses::BUILD_INPUT, + usage: hal::StateTransition { + from: hal::AccelerationStructureUses::SHADER_INPUT, + to: hal::AccelerationStructureUses::BUILD_INPUT, + }, }); ctx.encoder.build_acceleration_structures( @@ -909,14 +925,18 @@ impl Example { ctx.encoder .place_acceleration_structure_barrier(hal::AccelerationStructureBarrier { - usage: hal::AccelerationStructureUses::BUILD_OUTPUT - ..hal::AccelerationStructureUses::SHADER_INPUT, + usage: hal::StateTransition { + from: hal::AccelerationStructureUses::BUILD_OUTPUT, + to: hal::AccelerationStructureUses::SHADER_INPUT, + }, }); let scratch_buffer_barrier = hal::BufferBarrier { buffer: &self.scratch_buffer, - usage: hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT - ..hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + usage: hal::StateTransition { + from: hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + to: hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + }, }; ctx.encoder .transition_buffers(iter::once(scratch_buffer_barrier)); @@ -952,17 +972,26 @@ impl Example { let target_barrier1 = hal::TextureBarrier { texture: surface_tex.borrow(), range: wgt::ImageSubresourceRange::default(), - usage: hal::TextureUses::COPY_DST..hal::TextureUses::PRESENT, + usage: hal::StateTransition { + from: hal::TextureUses::COPY_DST, + to: hal::TextureUses::PRESENT, + }, }; let target_barrier2 = hal::TextureBarrier { texture: &self.texture, range: wgt::ImageSubresourceRange::default(), - usage: hal::TextureUses::STORAGE_READ_WRITE..hal::TextureUses::COPY_SRC, + usage: hal::StateTransition { + from: hal::TextureUses::STORAGE_READ_WRITE, + to: hal::TextureUses::COPY_SRC, + }, }; let target_barrier3 = hal::TextureBarrier { texture: &self.texture, range: wgt::ImageSubresourceRange::default(), - usage: hal::TextureUses::COPY_SRC..hal::TextureUses::STORAGE_READ_WRITE, + usage: hal::StateTransition { + from: hal::TextureUses::COPY_SRC, + to: hal::TextureUses::STORAGE_READ_WRITE, + }, }; unsafe { ctx.encoder.end_compute_pass(); From 8e8d04f74c791f9f39deb29f93385c05dfc25db4 Mon Sep 17 00:00:00 2001 From: Erich Gubler Date: Wed, 11 Dec 2024 09:34:52 -0500 Subject: [PATCH 5/5] oops --- wgpu-core/src/resource.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 466eded9e4..4846c257e2 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -645,7 +645,7 @@ impl Buffer { buffer: raw_buf, usage: hal::StateTransition { from: hal::BufferUses::empty(), - to: hal::BufferUses::COPY_SRC, + to: hal::BufferUses::COPY_DST, }, }; let mut pending_writes = queue.pending_writes.lock();