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 diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 84fcfb5874..44b65b6d6e 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 { + from: hal::BufferUses::INDIRECT, + to: 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 { + 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 8732377560..35fc581127 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 { + from: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + to: 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 { + from: hal::AccelerationStructureUses::BUILD_OUTPUT, + to: 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 { + from: BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + to: 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 { + from: BufferUses::MAP_WRITE, + to: 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 { + 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: BufferUses::MAP_READ..BufferUses::COPY_DST, + usage: hal::StateTransition { + from: BufferUses::MAP_READ, + to: 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 { + from: hal::AccelerationStructureUses::BUILD_OUTPUT, + to: 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 { + from: hal::AccelerationStructureUses::BUILD_INPUT, + to: 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 { + from: source_usage, + to: destination_usage, + }, }); } } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 3fbfeeb38c..6ba9728e9e 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 { + from: hal::BufferUses::empty(), + to: 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 { + from: hal::BufferUses::COPY_DST, + to: 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 { + from: hal::BufferUses::MAP_WRITE, + to: 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 { + from: hal::BufferUses::MAP_WRITE, + to: 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..4846c257e2 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 { + from: hal::BufferUses::MAP_WRITE, + to: hal::BufferUses::COPY_SRC, + }, }; let transition_dst = hal::BufferBarrier:: { buffer: raw_buf, - usage: hal::BufferUses::empty()..hal::BufferUses::COPY_DST, + usage: hal::StateTransition { + from: hal::BufferUses::empty(), + to: hal::BufferUses::COPY_DST, + }, }; 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..0cdc9dc966 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 { + from: current_state, + to: new_state, + }, }); } diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index 9a66b5f903..261bb0458e 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>; @@ -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 f3b4c76176..8ea1e04cd1 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 { + from: current_simple, + to: 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 { + from: current_simple, + to: 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 { + from: current_layer_state, + to: 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 { + from: *current_layer_state, + to: new_state, + }, }); } } 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(); 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 2de9d3e71c..124f23cf4a 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 from: T, + pub to: 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)] 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, );