From cb8acefd16c0a51dcc652a8619c0e3a0b7f2826e Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:38:51 -0800 Subject: [PATCH 01/26] WIP --- wgpu-core/src/command/mod.rs | 1 + wgpu-core/src/command/transition_resources.rs | 16 +++++++ wgpu/src/api/command_encoder.rs | 45 +++++++++++++++++++ wgpu/src/backend/webgpu.rs | 4 ++ wgpu/src/backend/wgpu_core.rs | 14 ++++++ wgpu/src/dispatch.rs | 2 + 6 files changed, 82 insertions(+) create mode 100644 wgpu-core/src/command/transition_resources.rs diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index cbc6969e29..b73aa34f49 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -12,6 +12,7 @@ mod render; mod render_command; mod timestamp_writes; mod transfer; +mod transition_resources; use std::mem::{self, ManuallyDrop}; use std::sync::Arc; diff --git a/wgpu-core/src/command/transition_resources.rs b/wgpu-core/src/command/transition_resources.rs new file mode 100644 index 0000000000..e0cf44a693 --- /dev/null +++ b/wgpu-core/src/command/transition_resources.rs @@ -0,0 +1,16 @@ +use crate::{global::Global, id::CommandEncoderId}; + +use super::CommandEncoderError; + +impl Global { + pub fn command_encoder_transition_resources( + &self, + command_encoder_id: CommandEncoderId, + buffer_transitions: &[()], + texture_transitions: &[()], + ) -> Result<(), CommandEncoderError> { + profiling::scope!("CommandEncoder::transition_resources"); + + Ok(()) + } +} diff --git a/wgpu/src/api/command_encoder.rs b/wgpu/src/api/command_encoder.rs index cd493587a7..31fffc7d21 100644 --- a/wgpu/src/api/command_encoder.rs +++ b/wgpu/src/api/command_encoder.rs @@ -346,4 +346,49 @@ impl CommandEncoder { &mut tlas.into_iter(), ); } + + /// Transition resources to an underlying hal resource state. + /// + /// This is an advanced, native-only API (no-op on web) that has two main use cases: + /// + /// # Batching Barriers + /// + /// Wgpu does not have a global view of the frame when recording command buffers. When you submit multiple command buffers in a single queue submission, wgpu may need to record and + /// insert new command buffers (holding 1 or more barrier commands) in between the user-supplied command buffers in order to ensure that resources are transitioned to the correct state + /// for the start of the next user-supplied command buffer. + /// + /// Wgpu does not currently attempt to batch multiple of these generated command buffers/barriers together, which may lead to suboptimal barrier placement. + /// + /// Consider the following scenario, where the user does `queue.submit(&[a, b, c])`: + /// * CommandBuffer A: Use resource X as a render pass attachment + /// * CommandBuffer B: Use resource Y as a render pass attachment + /// * CommandBuffer C: Use resources X and Y in a bind group + /// + /// At submission time, wgpu will record and insert some new command buffers, resulting in a submission that looks like `queue.submit(&[0, a, 1, b, 2, c])`: + /// * CommandBuffer 0: Barrier to transition resource X from bind group access state (from last frame) to attachment state + /// * CommandBuffer A: Use resource X as a render pass attachment + /// * CommandBuffer 1: Barrier to transition resource Y from bind group access state (from last frame) to attachment state + /// * CommandBuffer B: Use resource Y as a render pass attachment + /// * CommandBuffer 2: Barrier to transition resource X and Y from attachment state to bind group access state + /// * CommandBuffer C: Use resources X and Y in a bind group + /// + /// To prevent this, after profiling their app, an advanced user might choose to instead do `queue.submit(&[a, b, c])`: + /// * CommandBuffer A: + /// * Use [`CommandEncoder::transition_resources`] to transition resources X and Y from bind group access state (from last frame) to attachment state + /// * Use resource X as a render pass attachment + /// * CommandBuffer B: Use resource Y as a render pass attachment + /// * CommandBuffer C: + /// * Use [`CommandEncoder::transition_resources`] to transition resources X and Y from attachment state to bind group access state + /// * Use resources X and Y in a bind group + /// + /// Which is a more optimal barrier placement, and eliminates the extra command buffers that wgpu would otherwise need to generate at submission time. + /// + /// # Native Interoperability + /// + /// A user wanting to interoperate with the underlying native graphics APIs (Vulkan, DirectX12, Metal, etc) can use this API to generate barriers between wgpu commands and + /// the native API commands, for synchronization and resource state transition purposes. + pub fn transition_resources(&mut self, buffer_transitions: &[()], texture_transitions: &[()]) { + self.inner + .transition_resources(buffer_transitions, texture_transitions); + } } diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 789d2f22cd..e14d2e3df4 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -3060,6 +3060,10 @@ impl dispatch::CommandEncoderInterface for WebCommandEncoder { ) { unimplemented!("Raytracing not implemented for web"); } + + fn transition_resources(&mut self, _buffer_transitions: &[()], _texture_transitions: &[()]) { + // no-op + } } impl Drop for WebCommandEncoder { fn drop(&mut self) { diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 41ef582129..f4452523bb 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2549,6 +2549,20 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { ); } } + + fn transition_resources(&mut self, buffer_transitions: &[()], texture_transitions: &[()]) { + if let Err(cause) = self.context.0.command_encoder_transition_resources( + self.id, + buffer_transitions, + texture_transitions, + ) { + self.context.handle_error_nolabel( + &self.error_sink, + cause, + "CommandEncoder::transition_resources", + ); + } + } } impl Drop for CoreCommandEncoder { diff --git a/wgpu/src/dispatch.rs b/wgpu/src/dispatch.rs index 71826eb429..a84803bf26 100644 --- a/wgpu/src/dispatch.rs +++ b/wgpu/src/dispatch.rs @@ -351,6 +351,8 @@ pub trait CommandEncoderInterface: CommonTraits { blas: &mut dyn Iterator>, tlas: &mut dyn Iterator, ); + + fn transition_resources(&mut self, buffer_transitions: &[()], texture_transitions: &[()]); } pub trait ComputePassInterface: CommonTraits { fn set_pipeline(&mut self, pipeline: &DispatchComputePipeline); From fd4b993edc4feacde4a1a36ff4abc128f00aba17 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:58:12 -0800 Subject: [PATCH 02/26] Fix typo --- wgpu-core/src/track/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index 9a66b5f903..215201bc49 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -643,7 +643,7 @@ impl Tracker { /// bind group as a source of which IDs to look at. The bind groups /// must have first been added to the usage scope. /// - /// Only stateful things are merged in herell other resources are owned + /// Only stateful things are merged in here, all other resources are owned /// indirectly by the bind group. /// /// # Safety From 8000e376fe9830166ed29efdc46bd981bf71d0e6 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Fri, 6 Dec 2024 14:59:55 -0800 Subject: [PATCH 03/26] WIP: Implement structure of command_encoder_transition_resources --- wgpu-core/src/command/transition_resources.rs | 52 ++++++++++++++++++- 1 file changed, 50 insertions(+), 2 deletions(-) diff --git a/wgpu-core/src/command/transition_resources.rs b/wgpu-core/src/command/transition_resources.rs index e0cf44a693..3300360646 100644 --- a/wgpu-core/src/command/transition_resources.rs +++ b/wgpu-core/src/command/transition_resources.rs @@ -1,4 +1,9 @@ -use crate::{global::Global, id::CommandEncoderId}; +use thiserror::Error; + +use crate::{ + command::CommandBuffer, device::DeviceError, global::Global, id::CommandEncoderId, + track::ResourceUsageCompatibilityError, +}; use super::CommandEncoderError; @@ -8,9 +13,52 @@ impl Global { command_encoder_id: CommandEncoderId, buffer_transitions: &[()], texture_transitions: &[()], - ) -> Result<(), CommandEncoderError> { + ) -> Result<(), TransitionResourcesError> { profiling::scope!("CommandEncoder::transition_resources"); + let hub = &self.hub; + + let cmd_buf = hub + .command_buffers + .get(command_encoder_id.into_command_buffer_id()); + let mut cmd_buf_data = cmd_buf.data.lock(); + let mut cmd_buf_data_guard = cmd_buf_data.record()?; + let cmd_buf_data = &mut *cmd_buf_data_guard; + + let device = &cmd_buf.device; + let snatch_guard = &device.snatchable_lock.read(); + + let mut usage_scope = device.new_usage_scope(); + + for buffer_transition in buffer_transitions { + usage_scope.buffers.merge_single(todo!(), todo!())?; + } + + for texture_transition in texture_transitions { + unsafe { usage_scope.textures.merge_single(todo!(), todo!(), todo!()) }?; + } + + let cmd_buf_raw = cmd_buf_data.encoder.open(device)?; + CommandBuffer::insert_barriers_from_scope( + cmd_buf_raw, + &mut cmd_buf_data.trackers, + &usage_scope, + snatch_guard, + ); + cmd_buf_data_guard.mark_successful(); + Ok(()) } } + +/// Error encountered while attempting to perform [`Global::command_encoder_transition_resources`]. +#[derive(Clone, Debug, Error)] +#[non_exhaustive] +pub enum TransitionResourcesError { + #[error(transparent)] + Device(#[from] DeviceError), + #[error(transparent)] + Encoder(#[from] CommandEncoderError), + #[error(transparent)] + ResourceUsage(#[from] ResourceUsageCompatibilityError), +} From a441f81bbda2a35eec3fcc588c683d1a22160be2 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Fri, 6 Dec 2024 16:40:38 -0800 Subject: [PATCH 04/26] WIP --- wgpu-core/src/command/transition_resources.rs | 40 +++++++++++++++---- 1 file changed, 32 insertions(+), 8 deletions(-) diff --git a/wgpu-core/src/command/transition_resources.rs b/wgpu-core/src/command/transition_resources.rs index 3300360646..43b32ace29 100644 --- a/wgpu-core/src/command/transition_resources.rs +++ b/wgpu-core/src/command/transition_resources.rs @@ -1,8 +1,13 @@ +use hal::{BufferUses, TextureUses}; use thiserror::Error; use crate::{ - command::CommandBuffer, device::DeviceError, global::Global, id::CommandEncoderId, - track::ResourceUsageCompatibilityError, + command::CommandBuffer, + device::DeviceError, + global::Global, + id::{BufferId, CommandEncoderId, TextureId}, + resource::{InvalidResourceError, ParentDevice}, + track::{ResourceUsageCompatibilityError, TextureSelector}, }; use super::CommandEncoderError; @@ -11,13 +16,14 @@ impl Global { pub fn command_encoder_transition_resources( &self, command_encoder_id: CommandEncoderId, - buffer_transitions: &[()], - texture_transitions: &[()], + buffer_transitions: &[(BufferId, BufferUses)], + texture_transitions: &[(TextureId, Option, TextureUses)], ) -> Result<(), TransitionResourcesError> { profiling::scope!("CommandEncoder::transition_resources"); let hub = &self.hub; + // Lock command encoder for recording let cmd_buf = hub .command_buffers .get(command_encoder_id.into_command_buffer_id()); @@ -25,19 +31,35 @@ impl Global { let mut cmd_buf_data_guard = cmd_buf_data.record()?; let cmd_buf_data = &mut *cmd_buf_data_guard; + // Get and lock device let device = &cmd_buf.device; + device.check_is_valid()?; let snatch_guard = &device.snatchable_lock.read(); let mut usage_scope = device.new_usage_scope(); - for buffer_transition in buffer_transitions { - usage_scope.buffers.merge_single(todo!(), todo!())?; + // Process buffer transitions + for (buffer_id, state) in buffer_transitions { + let buffer = hub.buffers.get(*buffer_id).get()?; + buffer.same_device_as(cmd_buf.as_ref())?; + + usage_scope.buffers.merge_single(&buffer, *state)?; } - for texture_transition in texture_transitions { - unsafe { usage_scope.textures.merge_single(todo!(), todo!(), todo!()) }?; + // Process texture transitions + + for (texture_id, selector, state) in texture_transitions { + let texture = hub.textures.get(*texture_id).get()?; + texture.same_device_as(cmd_buf.as_ref())?; + + unsafe { + usage_scope + .textures + .merge_single(&texture, selector.clone(), *state) + }?; } + // Record any needed barriers based on tracker data let cmd_buf_raw = cmd_buf_data.encoder.open(device)?; CommandBuffer::insert_barriers_from_scope( cmd_buf_raw, @@ -60,5 +82,7 @@ pub enum TransitionResourcesError { #[error(transparent)] Encoder(#[from] CommandEncoderError), #[error(transparent)] + InvalidResource(#[from] InvalidResourceError), + #[error(transparent)] ResourceUsage(#[from] ResourceUsageCompatibilityError), } From e19769ced714586d271694ea921e58b1bcc16135 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:20:42 -0800 Subject: [PATCH 05/26] More work --- wgpu-core/src/command/transition_resources.rs | 13 ++++----- wgpu-core/src/lib.rs | 1 + wgpu-core/src/track/mod.rs | 2 +- wgpu/src/api/command_encoder.rs | 11 ++++++-- wgpu/src/backend/webgpu.rs | 4 --- wgpu/src/backend/wgpu_core.rs | 28 +++++++++++++++---- wgpu/src/dispatch.rs | 2 -- 7 files changed, 39 insertions(+), 22 deletions(-) diff --git a/wgpu-core/src/command/transition_resources.rs b/wgpu-core/src/command/transition_resources.rs index 43b32ace29..37699b2029 100644 --- a/wgpu-core/src/command/transition_resources.rs +++ b/wgpu-core/src/command/transition_resources.rs @@ -16,8 +16,8 @@ impl Global { pub fn command_encoder_transition_resources( &self, command_encoder_id: CommandEncoderId, - buffer_transitions: &[(BufferId, BufferUses)], - texture_transitions: &[(TextureId, Option, TextureUses)], + buffer_transitions: impl Iterator, + texture_transitions: impl Iterator, TextureUses)>, ) -> Result<(), TransitionResourcesError> { profiling::scope!("CommandEncoder::transition_resources"); @@ -40,22 +40,21 @@ impl Global { // Process buffer transitions for (buffer_id, state) in buffer_transitions { - let buffer = hub.buffers.get(*buffer_id).get()?; + let buffer = hub.buffers.get(buffer_id).get()?; buffer.same_device_as(cmd_buf.as_ref())?; - usage_scope.buffers.merge_single(&buffer, *state)?; + usage_scope.buffers.merge_single(&buffer, state)?; } // Process texture transitions - for (texture_id, selector, state) in texture_transitions { - let texture = hub.textures.get(*texture_id).get()?; + let texture = hub.textures.get(texture_id).get()?; texture.same_device_as(cmd_buf.as_ref())?; unsafe { usage_scope .textures - .merge_single(&texture, selector.clone(), *state) + .merge_single(&texture, selector.clone(), state) }?; } diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 1edb27e7ab..e3ac863251 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -92,6 +92,7 @@ pub mod validation; pub use hal::{api, MAX_BIND_GROUPS, MAX_COLOR_ATTACHMENTS, MAX_VERTEX_BUFFERS}; pub use naga; +pub use track::texture::TextureSelector; use std::{borrow::Cow, os::raw::c_char}; diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index 215201bc49..2cb7a058f8 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -100,7 +100,7 @@ mod metadata; mod range; mod ray_tracing; mod stateless; -mod texture; +pub(crate) mod texture; use crate::{ binding_model, command, diff --git a/wgpu/src/api/command_encoder.rs b/wgpu/src/api/command_encoder.rs index 31fffc7d21..05c06c7ee9 100644 --- a/wgpu/src/api/command_encoder.rs +++ b/wgpu/src/api/command_encoder.rs @@ -387,8 +387,13 @@ impl CommandEncoder { /// /// A user wanting to interoperate with the underlying native graphics APIs (Vulkan, DirectX12, Metal, etc) can use this API to generate barriers between wgpu commands and /// the native API commands, for synchronization and resource state transition purposes. - pub fn transition_resources(&mut self, buffer_transitions: &[()], texture_transitions: &[()]) { - self.inner - .transition_resources(buffer_transitions, texture_transitions); + pub fn transition_resources( + &mut self, + buffer_transitions: &[(&Buffer, hal::BufferUses)], + texture_transitions: &[(&Texture, Option, hal::TextureUses)], + ) { + if let Some(encoder) = self.inner.as_core_mut_opt() { + encoder.transition_resources(buffer_transitions, texture_transitions); + } } } diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index e14d2e3df4..789d2f22cd 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -3060,10 +3060,6 @@ impl dispatch::CommandEncoderInterface for WebCommandEncoder { ) { unimplemented!("Raytracing not implemented for web"); } - - fn transition_resources(&mut self, _buffer_transitions: &[()], _texture_transitions: &[()]) { - // no-op - } } impl Drop for WebCommandEncoder { fn drop(&mut self) { diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index f4452523bb..ac454b4ce6 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2549,13 +2549,31 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { ); } } +} - fn transition_resources(&mut self, buffer_transitions: &[()], texture_transitions: &[()]) { - if let Err(cause) = self.context.0.command_encoder_transition_resources( +impl CoreCommandEncoder { + pub fn transition_resources( + &mut self, + buffer_transitions: &[(&crate::Buffer, hal::BufferUses)], + texture_transitions: &[( + &crate::Texture, + Option, + hal::TextureUses, + )], + ) { + let result = self.context.0.command_encoder_transition_resources( self.id, - buffer_transitions, - texture_transitions, - ) { + buffer_transitions + .into_iter() + .map(|(buffer, state)| (buffer.inner.as_core().id, *state)), + texture_transitions + .into_iter() + .map(|(texture, selector, state)| { + (texture.inner.as_core().id, selector.clone(), *state) + }), + ); + + if let Err(cause) = result { self.context.handle_error_nolabel( &self.error_sink, cause, diff --git a/wgpu/src/dispatch.rs b/wgpu/src/dispatch.rs index a84803bf26..71826eb429 100644 --- a/wgpu/src/dispatch.rs +++ b/wgpu/src/dispatch.rs @@ -351,8 +351,6 @@ pub trait CommandEncoderInterface: CommonTraits { blas: &mut dyn Iterator>, tlas: &mut dyn Iterator, ); - - fn transition_resources(&mut self, buffer_transitions: &[()], texture_transitions: &[()]); } pub trait ComputePassInterface: CommonTraits { fn set_pipeline(&mut self, pipeline: &DispatchComputePipeline); From efbb336d1c589f33ce8eb29c330684531e002e58 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Fri, 6 Dec 2024 17:59:45 -0800 Subject: [PATCH 06/26] Clippy --- wgpu/src/backend/wgpu_core.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index ac454b4ce6..f60b74954c 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2564,10 +2564,10 @@ impl CoreCommandEncoder { let result = self.context.0.command_encoder_transition_resources( self.id, buffer_transitions - .into_iter() + .iter() .map(|(buffer, state)| (buffer.inner.as_core().id, *state)), texture_transitions - .into_iter() + .iter() .map(|(texture, selector, state)| { (texture.inner.as_core().id, selector.clone(), *state) }), From 1897bca064573b9fa7c41cc893f99159b0448b5a Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Fri, 6 Dec 2024 18:19:51 -0800 Subject: [PATCH 07/26] Fix web build --- wgpu/src/api/command_encoder.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/wgpu/src/api/command_encoder.rs b/wgpu/src/api/command_encoder.rs index 05c06c7ee9..fde90db7e1 100644 --- a/wgpu/src/api/command_encoder.rs +++ b/wgpu/src/api/command_encoder.rs @@ -349,7 +349,7 @@ impl CommandEncoder { /// Transition resources to an underlying hal resource state. /// - /// This is an advanced, native-only API (no-op on web) that has two main use cases: + /// This is an advanced, native-only API that has two main use cases: /// /// # Batching Barriers /// @@ -387,6 +387,7 @@ impl CommandEncoder { /// /// A user wanting to interoperate with the underlying native graphics APIs (Vulkan, DirectX12, Metal, etc) can use this API to generate barriers between wgpu commands and /// the native API commands, for synchronization and resource state transition purposes. + #[cfg(wgpu_core)] pub fn transition_resources( &mut self, buffer_transitions: &[(&Buffer, hal::BufferUses)], From 328028b509af949f97dbd24b5f488ffe99116be3 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sat, 7 Dec 2024 12:20:11 -0800 Subject: [PATCH 08/26] Use new types for API, more docs --- CHANGELOG.md | 1 + wgpu/src/api/command_encoder.rs | 47 +++++++++++++++++++++++++++------ wgpu/src/backend/wgpu_core.rs | 14 +++------- 3 files changed, 44 insertions(+), 18 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 39d26b7587..b243d1388a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -120,6 +120,7 @@ By @ErichDonGubler in [#6456](https://github.com/gfx-rs/wgpu/pull/6456), [#6148] - Return submission index in `map_async` and `on_submitted_work_done` to track down completion of async callbacks. By @eliemichel in [#6360](https://github.com/gfx-rs/wgpu/pull/6360). - Move raytracing alignments into HAL instead of in core. By @Vecvec in [#6563](https://github.com/gfx-rs/wgpu/pull/6563). - Allow for statically linking DXC rather than including separate `.dll` files. By @DouglasDwyer in [#6574](https://github.com/gfx-rs/wgpu/pull/6574). +- Added `CommandEncoder::transition_resources()` for native API interop, and allowing users to slightly optimize barriers. By @JMS55 in [6678](https://github.com/gfx-rs/wgpu/pull/6678). ### Changes diff --git a/wgpu/src/api/command_encoder.rs b/wgpu/src/api/command_encoder.rs index fde90db7e1..bc8b21e4a9 100644 --- a/wgpu/src/api/command_encoder.rs +++ b/wgpu/src/api/command_encoder.rs @@ -365,23 +365,30 @@ impl CommandEncoder { /// * CommandBuffer C: Use resources X and Y in a bind group /// /// At submission time, wgpu will record and insert some new command buffers, resulting in a submission that looks like `queue.submit(&[0, a, 1, b, 2, c])`: - /// * CommandBuffer 0: Barrier to transition resource X from bind group access state (from last frame) to attachment state + /// * CommandBuffer 0: Barrier to transition resource X from TextureUses::RESOURCE (from last frame) to TextureUses::COLOR_TARGET /// * CommandBuffer A: Use resource X as a render pass attachment - /// * CommandBuffer 1: Barrier to transition resource Y from bind group access state (from last frame) to attachment state + /// * CommandBuffer 1: Barrier to transition resource Y from TextureUses::RESOURCE (from last frame) to TextureUses::COLOR_TARGET /// * CommandBuffer B: Use resource Y as a render pass attachment - /// * CommandBuffer 2: Barrier to transition resource X and Y from attachment state to bind group access state + /// * CommandBuffer 2: Barrier to transition resources X and Y from TextureUses::COLOR_TARGET to TextureUses::RESOURCE /// * CommandBuffer C: Use resources X and Y in a bind group /// /// To prevent this, after profiling their app, an advanced user might choose to instead do `queue.submit(&[a, b, c])`: /// * CommandBuffer A: - /// * Use [`CommandEncoder::transition_resources`] to transition resources X and Y from bind group access state (from last frame) to attachment state + /// * Use [`CommandEncoder::transition_resources`] to transition resources X and Y from TextureUses::RESOURCE (from last frame) to TextureUses::COLOR_TARGET /// * Use resource X as a render pass attachment /// * CommandBuffer B: Use resource Y as a render pass attachment /// * CommandBuffer C: - /// * Use [`CommandEncoder::transition_resources`] to transition resources X and Y from attachment state to bind group access state + /// * Use [`CommandEncoder::transition_resources`] to transition resources X and Y from TextureUses::COLOR_TARGET to TextureUses::RESOURCE /// * Use resources X and Y in a bind group /// - /// Which is a more optimal barrier placement, and eliminates the extra command buffers that wgpu would otherwise need to generate at submission time. + /// At submission time, wgpu will record and insert some new command buffers, resulting in a submission that looks like `queue.submit(&[0, a, b, 1, c])`: + /// * CommandBuffer 0: Barrier to transition resources X and Y from TextureUses::RESOURCE (from last frame) to TextureUses::COLOR_TARGET + /// * CommandBuffer A: Use resource X as a render pass attachment + /// * CommandBuffer B: Use resource Y as a render pass attachment + /// * CommandBuffer 1: Barrier to transition resources X and Y from TextureUses::COLOR_TARGET to TextureUses::RESOURCE + /// * CommandBuffer C: Use resources X and Y in a bind group + /// + /// Which eliminates the extra command buffer and barrier between command buffers A and B. /// /// # Native Interoperability /// @@ -390,11 +397,35 @@ impl CommandEncoder { #[cfg(wgpu_core)] pub fn transition_resources( &mut self, - buffer_transitions: &[(&Buffer, hal::BufferUses)], - texture_transitions: &[(&Texture, Option, hal::TextureUses)], + buffer_transitions: &[BufferTransition<'_>], + texture_transitions: &[TextureTransition<'_>], ) { if let Some(encoder) = self.inner.as_core_mut_opt() { encoder.transition_resources(buffer_transitions, texture_transitions); } } } + +/// A buffer transition for use with [`CommandEncoder::transition_resources`]. +#[cfg(wgpu_core)] +#[derive(Debug)] +pub struct BufferTransition<'a> { + /// The buffer to transition. + pub buffer: &'a Buffer, + /// The new state to transition to. + pub state: hal::BufferUses, +} + +/// A texture transition for use with [`CommandEncoder::transition_resources`]. +#[cfg(wgpu_core)] +#[derive(Debug)] +pub struct TextureTransition<'a> { + /// The texture to transition. + pub texture: &'a Texture, + /// An optional selector to transition only part of the texture. + /// + /// If None, the entire texture will be transitioned. + pub selector: Option, + /// The new state to transition to. + pub state: hal::TextureUses, +} diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index f60b74954c..3a62081914 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2554,23 +2554,17 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { impl CoreCommandEncoder { pub fn transition_resources( &mut self, - buffer_transitions: &[(&crate::Buffer, hal::BufferUses)], - texture_transitions: &[( - &crate::Texture, - Option, - hal::TextureUses, - )], + buffer_transitions: &[crate::BufferTransition<'_>], + texture_transitions: &[crate::TextureTransition<'_>], ) { let result = self.context.0.command_encoder_transition_resources( self.id, buffer_transitions .iter() - .map(|(buffer, state)| (buffer.inner.as_core().id, *state)), + .map(|t| (t.buffer.inner.as_core().id, t.state)), texture_transitions .iter() - .map(|(texture, selector, state)| { - (texture.inner.as_core().id, selector.clone(), *state) - }), + .map(|t| (t.texture.inner.as_core().id, t.selector.clone(), t.state)), ); if let Err(cause) = result { From 8fc87bbdc48d06d8c1465a82db3164eaca3e4db7 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sat, 7 Dec 2024 13:31:39 -0800 Subject: [PATCH 09/26] Add very basic test --- tests/tests/root.rs | 1 + tests/tests/transition_resources.rs | 39 +++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100644 tests/tests/transition_resources.rs diff --git a/tests/tests/root.rs b/tests/tests/root.rs index dac56a9db0..48ea490810 100644 --- a/tests/tests/root.rs +++ b/tests/tests/root.rs @@ -49,6 +49,7 @@ mod subgroup_operations; mod texture_bounds; mod texture_view_creation; mod transfer; +mod transition_resources; mod vertex_formats; mod vertex_indices; mod write_texture; diff --git a/tests/tests/transition_resources.rs b/tests/tests/transition_resources.rs new file mode 100644 index 0000000000..7866e8656a --- /dev/null +++ b/tests/tests/transition_resources.rs @@ -0,0 +1,39 @@ +use wgpu::{hal::TextureUses, TextureTransition}; +use wgpu_test::{gpu_test, GpuTestConfiguration}; +use wgt::{ + CommandEncoderDescriptor, Extent3d, TextureDescriptor, TextureDimension, TextureFormat, + TextureUsages, +}; + +#[gpu_test] +static TRANSITION_RESOURCES: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|ctx| { + let texture = ctx.device.create_texture(&TextureDescriptor { + label: None, + size: Extent3d { + width: 32, + height: 32, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: TextureDimension::D2, + format: TextureFormat::Rgba8Unorm, + usage: TextureUsages::RENDER_ATTACHMENT | TextureUsages::TEXTURE_BINDING, + view_formats: &[], + }); + + let mut encoder = ctx + .device + .create_command_encoder(&CommandEncoderDescriptor { label: None }); + + encoder.transition_resources( + &[], + &[TextureTransition { + texture: &texture, + selector: None, + state: TextureUses::COLOR_TARGET, + }], + ); + + ctx.queue.submit([encoder.finish()]); +}); From 8d711c9b227d1dfa2310f0d4f23ac664e32ed961 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sat, 7 Dec 2024 13:36:04 -0800 Subject: [PATCH 10/26] Try to fix test cfg --- tests/tests/root.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/tests/root.rs b/tests/tests/root.rs index 48ea490810..ca861e32f7 100644 --- a/tests/tests/root.rs +++ b/tests/tests/root.rs @@ -49,6 +49,7 @@ mod subgroup_operations; mod texture_bounds; mod texture_view_creation; mod transfer; +#[cfg(all(feature = "wgc", feature = "hal"))] mod transition_resources; mod vertex_formats; mod vertex_indices; From dacb25933acfc27c6a541ca761f8a3e5b6049ad3 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Tue, 7 Jan 2025 19:27:07 -0500 Subject: [PATCH 11/26] Fix merge --- wgpu-core/src/command/transition_resources.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-core/src/command/transition_resources.rs b/wgpu-core/src/command/transition_resources.rs index 37699b2029..2ef372c632 100644 --- a/wgpu-core/src/command/transition_resources.rs +++ b/wgpu-core/src/command/transition_resources.rs @@ -59,7 +59,7 @@ impl Global { } // Record any needed barriers based on tracker data - let cmd_buf_raw = cmd_buf_data.encoder.open(device)?; + let cmd_buf_raw = cmd_buf_data.encoder.open()?; CommandBuffer::insert_barriers_from_scope( cmd_buf_raw, &mut cmd_buf_data.trackers, From 03084df211d44225aff28fde7b8662661c5c20e7 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sun, 12 Jan 2025 15:46:03 -0800 Subject: [PATCH 12/26] Missed commit --- Cargo.lock | 64 +++++++++++++++++++++++++++--------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 226cdae506..6f344382a2 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -567,9 +567,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.5.23" +version = "4.5.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3135e7ec2ef7b10c6ed8950f0f792ed96ee093fa088608f1c76e569722700c84" +checksum = "9560b07a799281c7e0958b9296854d6fafd4c5f31444a7e5bb1ad6dde5ccf1bd" dependencies = [ "clap_builder", "clap_derive", @@ -577,9 +577,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.5.23" +version = "4.5.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30582fc632330df2bd26877bde0c1f4470d57c582bbc070376afcd04d8cb4838" +checksum = "874e0dd3eb68bf99058751ac9712f622e61e6f393a94f7128fa26e3f02f5c7cd" dependencies = [ "anstream", "anstyle", @@ -589,9 +589,9 @@ dependencies = [ [[package]] name = "clap_derive" -version = "4.5.18" +version = "4.5.24" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "4ac6a0c7b1a9e9a5186361f67dfa1b88213572f427fb9ab038efb2bd8c582dab" +checksum = "54b755194d6389280185988721fffba69495eed5ee9feeee9a599b53db80318c" dependencies = [ "heck 0.5.0", "proc-macro2", @@ -995,7 +995,7 @@ dependencies = [ "deno_core", "raw-window-handle 0.6.2", "serde", - "thiserror 2.0.9", + "thiserror 2.0.10", "tokio", "wgpu-core", "wgpu-types", @@ -1950,9 +1950,9 @@ checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a" [[package]] name = "libfuzzer-sys" -version = "0.4.6" +version = "0.4.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "beb09950ae85a0a94b27676cccf37da5ff13f27076aa1adbc6545dd0d0e1bd4e" +checksum = "a96cfd5557eb82f2b83fed4955246c988d331975a002961b07c81584d107e7f7" dependencies = [ "arbitrary", "cc", @@ -1994,9 +1994,9 @@ dependencies = [ [[package]] name = "linux-raw-sys" -version = "0.4.14" +version = "0.4.15" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89" +checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab" [[package]] name = "litemap" @@ -2182,7 +2182,7 @@ dependencies = [ "spirv 0.3.0+sdk-1.3.268.0", "strum 0.26.3", "termcolor", - "thiserror 2.0.9", + "thiserror 2.0.10", "unicode-xid", ] @@ -2915,9 +2915,9 @@ dependencies = [ [[package]] name = "rustix" -version = "0.38.42" +version = "0.38.43" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85" +checksum = "a78891ee6bf2340288408954ac787aa063d8e8817e9f53abb37c695c6d834ef6" dependencies = [ "bitflags 2.6.0", "errno", @@ -3009,9 +3009,9 @@ dependencies = [ [[package]] name = "serde_json" -version = "1.0.134" +version = "1.0.135" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d00f4175c42ee48b15416f6193a959ba3a0d67fc699a0db9ad12df9f83991c7d" +checksum = "2b0d7ba2887406110130a978386c4e1befb98c674b4fba677954e4db976630d9" dependencies = [ "indexmap", "itoa", @@ -3323,11 +3323,11 @@ dependencies = [ [[package]] name = "thiserror" -version = "2.0.9" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "f072643fd0190df67a8bab670c20ef5d8737177d6ac6b2e9a236cb096206b2cc" +checksum = "a3ac7f54ca534db81081ef1c1e7f6ea8a3ef428d2fc069097c079443d24124d3" dependencies = [ - "thiserror-impl 2.0.9", + "thiserror-impl 2.0.10", ] [[package]] @@ -3343,9 +3343,9 @@ dependencies = [ [[package]] name = "thiserror-impl" -version = "2.0.9" +version = "2.0.10" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7b50fa271071aae2e6ee85f842e2e28ba8cd2c5fb67f11fcb1fd70b276f9e7d4" +checksum = "9e9465d30713b56a37ede7185763c3492a91be2f5fa68d958c44e41ab9248beb" dependencies = [ "proc-macro2", "quote", @@ -3419,9 +3419,9 @@ dependencies = [ [[package]] name = "tokio" -version = "1.42.0" +version = "1.43.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5cec9b21b0450273377fc97bd4c33a8acffc8c996c987a7c5b319a0083707551" +checksum = "3d61fa4ffa3de412bfea335c6ecff681de2b609ba3c77ef3e00e521813a9ed9e" dependencies = [ "backtrace", "bytes", @@ -3437,9 +3437,9 @@ dependencies = [ [[package]] name = "tokio-macros" -version = "2.4.0" +version = "2.5.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" +checksum = "6e06d43f1345a3bcd39f6a56dbb7dcab2ba47e68e8ac134855e7e2bdbaf8cab8" dependencies = [ "proc-macro2", "quote", @@ -3696,9 +3696,9 @@ dependencies = [ [[package]] name = "v8" -version = "130.0.5" +version = "130.0.7" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eefb620efa1e8f2d0f4dd1b2a72b0924a0a0e8b710e27e7ce7da7fac95c7aae5" +checksum = "a511192602f7b435b0a241c1947aa743eb7717f20a9195f4b5e8ed1952e01db1" dependencies = [ "bindgen", "bitflags 2.6.0", @@ -3980,6 +3980,7 @@ name = "wgpu" version = "23.0.1" dependencies = [ "arrayvec", + "bitflags 2.6.0", "cfg_aliases 0.2.1", "document-features", "js-sys", @@ -4008,7 +4009,6 @@ dependencies = [ "criterion", "naga", "nanorand", - "once_cell", "pollster", "profiling", "rayon", @@ -4037,7 +4037,7 @@ dependencies = [ "rustc-hash", "serde", "smallvec", - "thiserror 2.0.9", + "thiserror 2.0.10", "wgpu-hal", "wgpu-types", ] @@ -4116,7 +4116,7 @@ dependencies = [ "renderdoc-sys", "rustc-hash", "smallvec", - "thiserror 2.0.9", + "thiserror 2.0.10", "wasm-bindgen", "web-sys", "wgpu-types", @@ -4672,9 +4672,9 @@ checksum = "b9cc00251562a284751c9973bace760d86c0276c471b4be569fe6b068ee97a56" [[package]] name = "xml-rs" -version = "0.8.24" +version = "0.8.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ea8b391c9a790b496184c29f7f93b9ed5b16abb306c05415b68bcc16e4d06432" +checksum = "c5b940ebc25896e71dd073bad2dbaa2abfe97b0a391415e22ad1326d9c54e3c4" [[package]] name = "yoke" From 1590a1d1d9e5521ec14a086ce8b8ebf35a192e75 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sun, 12 Jan 2025 16:06:23 -0800 Subject: [PATCH 13/26] Use wgt types instead of hal types --- wgpu-types/src/lib.rs | 97 +++++++++++++++++++++++++++++++++ wgpu/src/api/command_encoder.rs | 8 ++- wgpu/src/backend/wgpu_core.rs | 22 ++++++-- 3 files changed, 118 insertions(+), 9 deletions(-) diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index f6426a5221..09f71329e0 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -5500,6 +5500,51 @@ bitflags::bitflags! { } } +bitflags::bitflags! { + /// Similar to `BufferUsages`, but used only for `CommandEncoder::transition_resources`. + #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] + pub struct BufferUses: u16 { + /// The argument to a read-only mapping. + const MAP_READ = 1 << 0; + /// The argument to a write-only mapping. + const MAP_WRITE = 1 << 1; + /// The source of a hardware copy. + const COPY_SRC = 1 << 2; + /// The destination of a hardware copy. + const COPY_DST = 1 << 3; + /// The index buffer used for drawing. + const INDEX = 1 << 4; + /// A vertex buffer used for drawing. + const VERTEX = 1 << 5; + /// A uniform buffer bound in a bind group. + const UNIFORM = 1 << 6; + /// A read-only storage buffer used in a bind group. + const STORAGE_READ_ONLY = 1 << 7; + /// A read-write buffer used in a bind group. + const STORAGE_READ_WRITE = 1 << 8; + /// The indirect or count buffer in a indirect draw or dispatch. + const INDIRECT = 1 << 9; + /// A buffer used to store query results. + const QUERY_RESOLVE = 1 << 10; + /// Buffer used for acceleration structure building. + const ACCELERATION_STRUCTURE_SCRATCH = 1 << 11; + /// Buffer used for bottom level acceleration structure building. + const BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT = 1 << 12; + /// Buffer used for top level acceleration structure building. + const TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT = 1 << 13; + /// The combination of states that a buffer may be in _at the same time_. + const INCLUSIVE = Self::MAP_READ.bits() | Self::COPY_SRC.bits() | + Self::INDEX.bits() | Self::VERTEX.bits() | Self::UNIFORM.bits() | + Self::STORAGE_READ_ONLY.bits() | Self::INDIRECT.bits() | Self::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits() | Self::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits(); + /// The combination of states that a buffer must exclusively be in. + const EXCLUSIVE = Self::MAP_WRITE.bits() | Self::COPY_DST.bits() | Self::STORAGE_READ_WRITE.bits() | Self::ACCELERATION_STRUCTURE_SCRATCH.bits(); + /// The combination of all usages that the are guaranteed to be be ordered by the hardware. + /// If a usage is ordered, then if the buffer state doesn't change between draw calls, there + /// are no barriers needed for synchronization. + const ORDERED = Self::INCLUSIVE.bits() | Self::MAP_WRITE.bits(); + } +} + /// Describes a [`Buffer`](../wgpu/struct.Buffer.html). /// /// Corresponds to [WebGPU `GPUBufferDescriptor`]( @@ -5701,6 +5746,49 @@ bitflags::bitflags! { } } +bitflags::bitflags! { + /// Similar to `TextureUsages`, but used only for `CommandEncoder::transition_resources`. + #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] + pub struct TextureUses: u16 { + /// The texture is in unknown state. + const UNINITIALIZED = 1 << 0; + /// Ready to present image to the surface. + const PRESENT = 1 << 1; + /// The source of a hardware copy. + const COPY_SRC = 1 << 2; + /// The destination of a hardware copy. + const COPY_DST = 1 << 3; + /// Read-only sampled or fetched resource. + const RESOURCE = 1 << 4; + /// The color target of a renderpass. + const COLOR_TARGET = 1 << 5; + /// Read-only depth stencil usage. + const DEPTH_STENCIL_READ = 1 << 6; + /// Read-write depth stencil usage + const DEPTH_STENCIL_WRITE = 1 << 7; + /// Read-only storage texture usage. Corresponds to a UAV in d3d, so is exclusive, despite being read only. + const STORAGE_READ_ONLY = 1 << 8; + /// Write-only storage texture usage. + const STORAGE_WRITE_ONLY = 1 << 9; + /// Read-write storage texture usage. + const STORAGE_READ_WRITE = 1 << 10; + /// The combination of states that a texture may be in _at the same time_. + const INCLUSIVE = Self::COPY_SRC.bits() | Self::RESOURCE.bits() | Self::DEPTH_STENCIL_READ.bits(); + /// The combination of states that a texture must exclusively be in. + const EXCLUSIVE = Self::COPY_DST.bits() | Self::COLOR_TARGET.bits() | Self::DEPTH_STENCIL_WRITE.bits() | Self::STORAGE_READ_ONLY.bits() | Self::STORAGE_WRITE_ONLY.bits() | Self::STORAGE_READ_WRITE.bits() | Self::PRESENT.bits(); + /// The combination of all usages that the are guaranteed to be be ordered by the hardware. + /// If a usage is ordered, then if the texture state doesn't change between draw calls, there + /// are no barriers needed for synchronization. + const ORDERED = Self::INCLUSIVE.bits() | Self::COLOR_TARGET.bits() | Self::DEPTH_STENCIL_WRITE.bits() | Self::STORAGE_READ_ONLY.bits(); + + /// Flag used by the wgpu-core texture tracker to say a texture is in different states for every sub-resource + const COMPLEX = 1 << 11; + /// Flag used by the wgpu-core texture tracker to say that the tracker does not know the state of the sub-resource. + /// This is different from UNINITIALIZED as that says the tracker does know, but the texture has not been initialized. + const UNKNOWN = 1 << 12; + } +} + /// Defines the capabilities of a given surface and adapter. #[derive(Debug)] pub struct SurfaceCapabilities { @@ -8007,3 +8095,12 @@ pub enum DeviceLostReason { /// After Device::destroy Destroyed = 1, } + +/// Specifies a particular set of subresources in a texture. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct TextureSelector { + /// Range of mips to use. + pub mips: Range, + /// Range of layers to use. + pub layers: Range, +} diff --git a/wgpu/src/api/command_encoder.rs b/wgpu/src/api/command_encoder.rs index ed95393c5b..92a1aba994 100644 --- a/wgpu/src/api/command_encoder.rs +++ b/wgpu/src/api/command_encoder.rs @@ -8,6 +8,8 @@ use crate::{ *, }; +use wgt::{BufferUses, TextureSelector, TextureUses}; + /// Encodes a series of GPU operations. /// /// A command encoder can record [`RenderPass`]es, [`ComputePass`]es, @@ -414,7 +416,7 @@ pub struct BufferTransition<'a> { /// The buffer to transition. pub buffer: &'a Buffer, /// The new state to transition to. - pub state: hal::BufferUses, + pub state: BufferUses, } /// A texture transition for use with [`CommandEncoder::transition_resources`]. @@ -426,7 +428,7 @@ pub struct TextureTransition<'a> { /// An optional selector to transition only part of the texture. /// /// If None, the entire texture will be transitioned. - pub selector: Option, + pub selector: Option, /// The new state to transition to. - pub state: hal::TextureUses, + pub state: TextureUses, } diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index cca9edea85..1b92ec93d9 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2562,12 +2562,22 @@ impl CoreCommandEncoder { ) { let result = self.context.0.command_encoder_transition_resources( self.id, - buffer_transitions - .iter() - .map(|t| (t.buffer.inner.as_core().id, t.state)), - texture_transitions - .iter() - .map(|t| (t.texture.inner.as_core().id, t.selector.clone(), t.state)), + buffer_transitions.iter().map(|t| { + ( + t.buffer.inner.as_core().id, + hal::BufferUses::from_bits(t.state.bits()).unwrap(), + ) + }), + texture_transitions.iter().map(|t| { + ( + t.texture.inner.as_core().id, + t.selector.clone().map(|s| wgc::TextureSelector { + mips: s.mips, + layers: s.layers, + }), + hal::TextureUses::from_bits(t.state.bits()).unwrap(), + ) + }), ); if let Err(cause) = result { From fb3cb547fdd989f9c85b94d305fa5b6925c7529b Mon Sep 17 00:00:00 2001 From: Alphyr <47725341+a1phyr@users.noreply.github.com> Date: Fri, 17 Jan 2025 17:40:47 +0100 Subject: [PATCH 14/26] Implement `Clone` for `ShaderModule` (#6939) --- wgpu/src/api/shader_module.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu/src/api/shader_module.rs b/wgpu/src/api/shader_module.rs index e3d2f39b74..2f3e39fc9b 100644 --- a/wgpu/src/api/shader_module.rs +++ b/wgpu/src/api/shader_module.rs @@ -10,7 +10,7 @@ use crate::*; /// of a pipeline. /// /// Corresponds to [WebGPU `GPUShaderModule`](https://gpuweb.github.io/gpuweb/#shader-module). -#[derive(Debug)] +#[derive(Debug, Clone)] pub struct ShaderModule { pub(crate) inner: dispatch::DispatchShaderModule, } From 1c13ef941f3642745b7661d7753273f2a3b9194f Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sat, 18 Jan 2025 11:01:57 -0800 Subject: [PATCH 15/26] Move to dispatch trait, move more things to wgt --- tests/tests/root.rs | 1 - tests/tests/transition_resources.rs | 3 +- wgpu-core/src/command/transition_resources.rs | 30 ++++++++------ wgpu-types/src/lib.rs | 40 ++++++++++++++----- wgpu/src/api/command_encoder.rs | 38 +++--------------- wgpu/src/backend/webgpu.rs | 8 ++++ wgpu/src/backend/wgpu_core.rs | 29 +++++--------- wgpu/src/dispatch.rs | 6 +++ 8 files changed, 79 insertions(+), 76 deletions(-) diff --git a/tests/tests/root.rs b/tests/tests/root.rs index 4f4b7de515..eba2f7ef07 100644 --- a/tests/tests/root.rs +++ b/tests/tests/root.rs @@ -52,7 +52,6 @@ mod texture_blit; mod texture_bounds; mod texture_view_creation; mod transfer; -#[cfg(all(feature = "wgc", feature = "hal"))] mod transition_resources; mod vertex_formats; mod vertex_indices; diff --git a/tests/tests/transition_resources.rs b/tests/tests/transition_resources.rs index 7866e8656a..dc2a274b56 100644 --- a/tests/tests/transition_resources.rs +++ b/tests/tests/transition_resources.rs @@ -1,8 +1,7 @@ -use wgpu::{hal::TextureUses, TextureTransition}; use wgpu_test::{gpu_test, GpuTestConfiguration}; use wgt::{ CommandEncoderDescriptor, Extent3d, TextureDescriptor, TextureDimension, TextureFormat, - TextureUsages, + TextureTransition, TextureUsages, TextureUses, }; #[gpu_test] diff --git a/wgpu-core/src/command/transition_resources.rs b/wgpu-core/src/command/transition_resources.rs index 2ef372c632..794343e27f 100644 --- a/wgpu-core/src/command/transition_resources.rs +++ b/wgpu-core/src/command/transition_resources.rs @@ -1,4 +1,3 @@ -use hal::{BufferUses, TextureUses}; use thiserror::Error; use crate::{ @@ -7,7 +6,7 @@ use crate::{ global::Global, id::{BufferId, CommandEncoderId, TextureId}, resource::{InvalidResourceError, ParentDevice}, - track::{ResourceUsageCompatibilityError, TextureSelector}, + track::ResourceUsageCompatibilityError, }; use super::CommandEncoderError; @@ -16,8 +15,8 @@ impl Global { pub fn command_encoder_transition_resources( &self, command_encoder_id: CommandEncoderId, - buffer_transitions: impl Iterator, - texture_transitions: impl Iterator, TextureUses)>, + buffer_transitions: impl Iterator>, + texture_transitions: impl Iterator>, ) -> Result<(), TransitionResourcesError> { profiling::scope!("CommandEncoder::transition_resources"); @@ -37,24 +36,31 @@ impl Global { let snatch_guard = &device.snatchable_lock.read(); let mut usage_scope = device.new_usage_scope(); + let indices = &device.tracker_indices; + usage_scope.buffers.set_size(indices.buffers.size()); + usage_scope.textures.set_size(indices.textures.size()); // Process buffer transitions - for (buffer_id, state) in buffer_transitions { - let buffer = hub.buffers.get(buffer_id).get()?; + for buffer_transition in buffer_transitions { + let buffer = hub.buffers.get(buffer_transition.buffer).get()?; buffer.same_device_as(cmd_buf.as_ref())?; - usage_scope.buffers.merge_single(&buffer, state)?; + usage_scope + .buffers + .merge_single(&buffer, buffer_transition.state)?; } // Process texture transitions - for (texture_id, selector, state) in texture_transitions { - let texture = hub.textures.get(texture_id).get()?; + for texture_transition in texture_transitions { + let texture = hub.textures.get(texture_transition.texture).get()?; texture.same_device_as(cmd_buf.as_ref())?; unsafe { - usage_scope - .textures - .merge_single(&texture, selector.clone(), state) + usage_scope.textures.merge_single( + &texture, + texture_transition.selector, + texture_transition.state, + ) }?; } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 09f71329e0..703895475b 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -5545,6 +5545,15 @@ bitflags::bitflags! { } } +/// A buffer transition for use with `CommandEncoder::transition_resources`. +#[derive(Debug)] +pub struct BufferTransition { + /// The buffer to transition. + pub buffer: T, + /// The new state to transition to. + pub state: BufferUses, +} + /// Describes a [`Buffer`](../wgpu/struct.Buffer.html). /// /// Corresponds to [WebGPU `GPUBufferDescriptor`]( @@ -5789,6 +5798,28 @@ bitflags::bitflags! { } } +/// A texture transition for use with `CommandEncoder::transition_resources`. +#[derive(Debug)] +pub struct TextureTransition { + /// The texture to transition. + pub texture: T, + /// An optional selector to transition only part of the texture. + /// + /// If None, the entire texture will be transitioned. + pub selector: Option, + /// The new state to transition to. + pub state: TextureUses, +} + +/// Specifies a particular set of subresources in a texture. +#[derive(Clone, Debug, PartialEq, Eq)] +pub struct TextureSelector { + /// Range of mips to use. + pub mips: Range, + /// Range of layers to use. + pub layers: Range, +} + /// Defines the capabilities of a given surface and adapter. #[derive(Debug)] pub struct SurfaceCapabilities { @@ -8095,12 +8126,3 @@ pub enum DeviceLostReason { /// After Device::destroy Destroyed = 1, } - -/// Specifies a particular set of subresources in a texture. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct TextureSelector { - /// Range of mips to use. - pub mips: Range, - /// Range of layers to use. - pub layers: Range, -} diff --git a/wgpu/src/api/command_encoder.rs b/wgpu/src/api/command_encoder.rs index 92a1aba994..1111053acd 100644 --- a/wgpu/src/api/command_encoder.rs +++ b/wgpu/src/api/command_encoder.rs @@ -8,8 +8,6 @@ use crate::{ *, }; -use wgt::{BufferUses, TextureSelector, TextureUses}; - /// Encodes a series of GPU operations. /// /// A command encoder can record [`RenderPass`]es, [`ComputePass`]es, @@ -352,7 +350,7 @@ impl CommandEncoder { /// Transition resources to an underlying hal resource state. /// - /// This is an advanced, native-only API that has two main use cases: + /// This is an advanced, native-only API (no-op on web) that has two main use cases: /// /// # Batching Barriers /// @@ -397,38 +395,12 @@ impl CommandEncoder { /// /// A user wanting to interoperate with the underlying native graphics APIs (Vulkan, DirectX12, Metal, etc) can use this API to generate barriers between wgpu commands and /// the native API commands, for synchronization and resource state transition purposes. - #[cfg(wgpu_core)] pub fn transition_resources( &mut self, - buffer_transitions: &[BufferTransition<'_>], - texture_transitions: &[TextureTransition<'_>], + buffer_transitions: &[wgt::BufferTransition<&Buffer>], + texture_transitions: &[wgt::TextureTransition<&Texture>], ) { - if let Some(encoder) = self.inner.as_core_mut_opt() { - encoder.transition_resources(buffer_transitions, texture_transitions); - } + self.inner + .transition_resources(buffer_transitions, texture_transitions); } } - -/// A buffer transition for use with [`CommandEncoder::transition_resources`]. -#[cfg(wgpu_core)] -#[derive(Debug)] -pub struct BufferTransition<'a> { - /// The buffer to transition. - pub buffer: &'a Buffer, - /// The new state to transition to. - pub state: BufferUses, -} - -/// A texture transition for use with [`CommandEncoder::transition_resources`]. -#[cfg(wgpu_core)] -#[derive(Debug)] -pub struct TextureTransition<'a> { - /// The texture to transition. - pub texture: &'a Texture, - /// An optional selector to transition only part of the texture. - /// - /// If None, the entire texture will be transitioned. - pub selector: Option, - /// The new state to transition to. - pub state: TextureUses, -} diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 1f6af6d9d5..70b6ae5a99 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -3107,6 +3107,14 @@ impl dispatch::CommandEncoderInterface for WebCommandEncoder { ) { unimplemented!("Raytracing not implemented for web"); } + + fn transition_resources( + &mut self, + _buffer_transitions: &[wgt::BufferTransition<&DispatchBuffer>], + _texture_transitions: &[wgt::TextureTransition<&DispatchTexture>], + ) { + // no-op + } } impl Drop for WebCommandEncoder { fn drop(&mut self) { diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 1b92ec93d9..2e1426b9e8 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2552,31 +2552,22 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { ); } } -} -impl CoreCommandEncoder { - pub fn transition_resources( + fn transition_resources( &mut self, - buffer_transitions: &[crate::BufferTransition<'_>], - texture_transitions: &[crate::TextureTransition<'_>], + buffer_transitions: &[wgt::BufferTransition<&crate::Buffer>], + texture_transitions: &[wgt::TextureTransition<&crate::Texture>], ) { let result = self.context.0.command_encoder_transition_resources( self.id, - buffer_transitions.iter().map(|t| { - ( - t.buffer.inner.as_core().id, - hal::BufferUses::from_bits(t.state.bits()).unwrap(), - ) + buffer_transitions.iter().map(|t| wgt::BufferTransition { + buffer: t.buffer.inner.as_core().id, + state: t.state, }), - texture_transitions.iter().map(|t| { - ( - t.texture.inner.as_core().id, - t.selector.clone().map(|s| wgc::TextureSelector { - mips: s.mips, - layers: s.layers, - }), - hal::TextureUses::from_bits(t.state.bits()).unwrap(), - ) + texture_transitions.iter().map(|t| wgt::TextureTransition { + texture: t.texture.inner.as_core().id, + selector: t.selector, + state: t.state, }), ); diff --git a/wgpu/src/dispatch.rs b/wgpu/src/dispatch.rs index bdf57b24c8..7cba0cf108 100644 --- a/wgpu/src/dispatch.rs +++ b/wgpu/src/dispatch.rs @@ -354,6 +354,12 @@ pub trait CommandEncoderInterface: CommonTraits { blas: &mut dyn Iterator>, tlas: &mut dyn Iterator, ); + + fn transition_resources( + &mut self, + buffer_transitions: &[wgt::BufferTransition<&DispatchBuffer>], + texture_transitions: &[wgt::TextureTransition<&DispatchTexture>], + ); } pub trait ComputePassInterface: CommonTraits { fn set_pipeline(&mut self, pipeline: &DispatchComputePipeline); From 4e46c968e33f22b04257486b3e9e6707a4380729 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sat, 18 Jan 2025 11:15:44 -0800 Subject: [PATCH 16/26] Move existing code to use new wgt types --- wgpu-core/src/command/bundle.rs | 6 +- wgpu-core/src/command/clear.rs | 19 +-- wgpu-core/src/command/compute.rs | 12 +- wgpu-core/src/command/memory_init.rs | 2 +- wgpu-core/src/command/query.rs | 2 +- wgpu-core/src/command/ray_tracing.rs | 2 +- wgpu-core/src/command/render.rs | 32 ++--- wgpu-core/src/command/transfer.rs | 23 ++-- wgpu-core/src/conv.rs | 74 +++++----- wgpu-core/src/device/queue.rs | 26 ++-- wgpu-core/src/device/ray_tracing.rs | 4 +- wgpu-core/src/device/resource.rs | 68 +++++----- wgpu-core/src/indirect_validation.rs | 2 +- wgpu-core/src/init_tracker/texture.rs | 3 +- wgpu-core/src/lib.rs | 1 - wgpu-core/src/present.rs | 8 +- wgpu-core/src/resource.rs | 22 +-- wgpu-core/src/scratch.rs | 2 +- wgpu-core/src/track/buffer.rs | 4 +- wgpu-core/src/track/mod.rs | 28 ++-- wgpu-core/src/track/texture.rs | 12 +- wgpu-hal/examples/halmark/main.rs | 38 +++--- wgpu-hal/examples/raw-gles.rs | 4 +- wgpu-hal/examples/ray-traced-triangle/main.rs | 56 ++++---- wgpu-hal/src/auxil/dxgi/conv.rs | 10 +- wgpu-hal/src/dx12/adapter.rs | 6 +- wgpu-hal/src/dx12/command.rs | 10 +- wgpu-hal/src/dx12/conv.rs | 32 ++--- wgpu-hal/src/dx12/device.rs | 22 ++- wgpu-hal/src/dx12/suballocation.rs | 8 +- wgpu-hal/src/dynamic/command.rs | 10 +- wgpu-hal/src/empty.rs | 4 +- wgpu-hal/src/gles/adapter.rs | 2 +- wgpu-hal/src/gles/command.rs | 10 +- wgpu-hal/src/gles/device.rs | 26 ++-- wgpu-hal/src/gles/mod.rs | 4 +- wgpu-hal/src/gles/queue.rs | 32 ++--- wgpu-hal/src/lib.rs | 123 +++-------------- wgpu-hal/src/metal/adapter.rs | 12 +- wgpu-hal/src/metal/command.rs | 4 +- wgpu-hal/src/metal/conv.rs | 4 +- wgpu-hal/src/metal/device.rs | 4 +- wgpu-hal/src/metal/surface.rs | 2 +- wgpu-hal/src/vulkan/command.rs | 6 +- wgpu-hal/src/vulkan/conv.rs | 126 +++++++++--------- wgpu-hal/src/vulkan/device.rs | 6 +- wgpu-hal/src/vulkan/mod.rs | 4 +- wgpu/src/backend/wgpu_core.rs | 2 +- 48 files changed, 410 insertions(+), 509 deletions(-) diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index c7f433c3a0..11ca2c48c5 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -683,7 +683,7 @@ fn set_index_buffer( state .trackers .buffers - .merge_single(&buffer, hal::BufferUses::INDEX)?; + .merge_single(&buffer, wgt::BufferUses::INDEX)?; buffer.same_device(&state.device)?; buffer.check_usage(wgt::BufferUsages::INDEX)?; @@ -725,7 +725,7 @@ fn set_vertex_buffer( state .trackers .buffers - .merge_single(&buffer, hal::BufferUses::VERTEX)?; + .merge_single(&buffer, wgt::BufferUses::VERTEX)?; buffer.same_device(&state.device)?; buffer.check_usage(wgt::BufferUsages::VERTEX)?; @@ -864,7 +864,7 @@ fn multi_draw_indirect( state .trackers .buffers - .merge_single(&buffer, hal::BufferUses::INDIRECT)?; + .merge_single(&buffer, wgt::BufferUses::INDIRECT)?; buffer.same_device(&state.device)?; buffer.check_usage(wgt::BufferUsages::INDIRECT)?; diff --git a/wgpu-core/src/command/clear.rs b/wgpu-core/src/command/clear.rs index 0811c2ac42..6efb7eeb54 100644 --- a/wgpu-core/src/command/clear.rs +++ b/wgpu-core/src/command/clear.rs @@ -15,11 +15,14 @@ use crate::{ ParentDevice, ResourceErrorIdent, Texture, TextureClearMode, }, snatch::SnatchGuard, - track::{TextureSelector, TextureTrackerSetSingle}, + track::TextureTrackerSetSingle, }; use thiserror::Error; -use wgt::{math::align_to, BufferAddress, BufferUsages, ImageSubresourceRange, TextureAspect}; +use wgt::{ + math::align_to, BufferAddress, BufferUsages, ImageSubresourceRange, TextureAspect, + TextureSelector, +}; /// Error encountered while attempting a clear. #[derive(Clone, Debug, Error)] @@ -107,7 +110,7 @@ impl Global { let dst_pending = cmd_buf_data .trackers .buffers - .set_single(&dst_buffer, hal::BufferUses::COPY_DST); + .set_single(&dst_buffer, wgt::BufferUses::COPY_DST); let snatch_guard = dst_buffer.device.snatchable_lock.read(); let dst_raw = dst_buffer.try_raw(&snatch_guard)?; @@ -269,12 +272,12 @@ pub(crate) fn clear_texture( // Issue the right barrier. let clear_usage = match dst_texture.clear_mode { - TextureClearMode::BufferCopy => hal::TextureUses::COPY_DST, + TextureClearMode::BufferCopy => wgt::TextureUses::COPY_DST, TextureClearMode::RenderPass { is_color: false, .. - } => hal::TextureUses::DEPTH_STENCIL_WRITE, + } => wgt::TextureUses::DEPTH_STENCIL_WRITE, TextureClearMode::Surface { .. } | TextureClearMode::RenderPass { is_color: true, .. } => { - hal::TextureUses::COLOR_TARGET + wgt::TextureUses::COLOR_TARGET } TextureClearMode::None => { return Err(ClearError::NoValidTextureClearMode( @@ -455,7 +458,7 @@ fn clear_texture_via_render_passes( mip_level, depth_or_layer, ), - usage: hal::TextureUses::COLOR_TARGET, + usage: wgt::TextureUses::COLOR_TARGET, }, resolve_target: None, ops: hal::AttachmentOps::STORE, @@ -473,7 +476,7 @@ fn clear_texture_via_render_passes( mip_level, depth_or_layer, ), - usage: hal::TextureUses::DEPTH_STENCIL_WRITE, + usage: wgt::TextureUses::DEPTH_STENCIL_WRITE, }, depth_ops: hal::AttachmentOps::STORE, stencil_ops: hal::AttachmentOps::STORE, diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 0fa6845d28..d9b0b19052 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -938,7 +938,7 @@ fn dispatch_indirect( let src_transition = state .intermediate_trackers .buffers - .set_single(&buffer, hal::BufferUses::STORAGE_READ_ONLY); + .set_single(&buffer, wgt::BufferUses::STORAGE_READ_ONLY); let src_barrier = src_transition.map(|transition| transition.into_hal(&buffer, &state.snatch_guard)); unsafe { @@ -949,8 +949,8 @@ fn dispatch_indirect( state.raw_encoder.transition_buffers(&[hal::BufferBarrier { buffer: params.dst_buffer, usage: hal::StateTransition { - from: hal::BufferUses::INDIRECT, - to: hal::BufferUses::STORAGE_READ_WRITE, + from: wgt::BufferUses::INDIRECT, + to: wgt::BufferUses::STORAGE_READ_WRITE, }, }]); } @@ -996,8 +996,8 @@ fn dispatch_indirect( state.raw_encoder.transition_buffers(&[hal::BufferBarrier { buffer: params.dst_buffer, usage: hal::StateTransition { - from: hal::BufferUses::STORAGE_READ_WRITE, - to: hal::BufferUses::INDIRECT, + from: wgt::BufferUses::STORAGE_READ_WRITE, + to: wgt::BufferUses::INDIRECT, }, }]); } @@ -1012,7 +1012,7 @@ fn dispatch_indirect( state .scope .buffers - .merge_single(&buffer, hal::BufferUses::INDIRECT)?; + .merge_single(&buffer, wgt::BufferUses::INDIRECT)?; use crate::resource::Trackable; state.flush_states(Some(buffer.tracker_index()))?; diff --git a/wgpu-core/src/command/memory_init.rs b/wgpu-core/src/command/memory_init.rs index 50a2772a95..cc6bbe9046 100644 --- a/wgpu-core/src/command/memory_init.rs +++ b/wgpu-core/src/command/memory_init.rs @@ -211,7 +211,7 @@ impl BakedCommands { // must already know about it. let transition = device_tracker .buffers - .set_single(&buffer, hal::BufferUses::COPY_DST); + .set_single(&buffer, wgt::BufferUses::COPY_DST); let raw_buf = buffer.try_raw(snatch_guard)?; diff --git a/wgpu-core/src/command/query.rs b/wgpu-core/src/command/query.rs index c2444aa129..42f7360ceb 100644 --- a/wgpu-core/src/command/query.rs +++ b/wgpu-core/src/command/query.rs @@ -396,7 +396,7 @@ impl Global { let dst_pending = cmd_buf_data .trackers .buffers - .set_single(&dst_buffer, hal::BufferUses::COPY_DST); + .set_single(&dst_buffer, wgt::BufferUses::COPY_DST); let dst_barrier = dst_pending.map(|pending| pending.into_hal(&dst_buffer, &snatch_guard)); diff --git a/wgpu-core/src/command/ray_tracing.rs b/wgpu-core/src/command/ray_tracing.rs index 9395c20fc1..5f9d4739da 100644 --- a/wgpu-core/src/command/ray_tracing.rs +++ b/wgpu-core/src/command/ray_tracing.rs @@ -20,7 +20,7 @@ use crate::{ use wgt::{math::align_to, BufferUsages, Features}; use super::CommandBufferMutable; -use hal::BufferUses; +use wgt::BufferUses; use std::{ cmp::max, num::NonZeroU64, diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index abbbcfb46a..58f7f126b3 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -29,7 +29,7 @@ use crate::{ DestroyedResourceError, Labeled, MissingBufferUsageError, MissingTextureUsageError, ParentDevice, QuerySet, Texture, TextureView, TextureViewNotRenderableReason, }, - track::{ResourceUsageCompatibilityError, TextureSelector, Tracker, UsageScope}, + track::{ResourceUsageCompatibilityError, Tracker, UsageScope}, Label, }; @@ -37,7 +37,7 @@ use arrayvec::ArrayVec; use thiserror::Error; use wgt::{ BufferAddress, BufferSize, BufferUsages, Color, DynamicOffset, IndexFormat, ShaderStages, - TextureUsages, TextureViewDimension, VertexStepMode, + TextureSelector, TextureUsages, TextureViewDimension, VertexStepMode, }; #[cfg(feature = "serde")] @@ -779,11 +779,11 @@ where struct RenderAttachment { texture: Arc, selector: TextureSelector, - usage: hal::TextureUses, + usage: wgt::TextureUses, } impl TextureView { - fn to_render_attachment(&self, usage: hal::TextureUses) -> RenderAttachment { + fn to_render_attachment(&self, usage: wgt::TextureUses) -> RenderAttachment { RenderAttachment { texture: self.parent.clone(), selector: self.selector.clone(), @@ -1049,9 +1049,9 @@ impl<'d> RenderPassInfo<'d> { .flags .contains(wgt::DownlevelFlags::READ_ONLY_DEPTH_STENCIL) { - hal::TextureUses::DEPTH_STENCIL_READ | hal::TextureUses::RESOURCE + wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::RESOURCE } else { - hal::TextureUses::DEPTH_STENCIL_WRITE + wgt::TextureUses::DEPTH_STENCIL_WRITE }; render_attachments.push(view.to_render_attachment(usage)); @@ -1104,7 +1104,7 @@ impl<'d> RenderPassInfo<'d> { &mut pending_discard_init_fixups, ); render_attachments - .push(color_view.to_render_attachment(hal::TextureUses::COLOR_TARGET)); + .push(color_view.to_render_attachment(wgt::TextureUses::COLOR_TARGET)); let mut hal_resolve_target = None; if let Some(resolve_view) = &at.resolve_target { @@ -1160,18 +1160,18 @@ impl<'d> RenderPassInfo<'d> { TextureInitRange::from(resolve_view.selector.clone()), ); render_attachments - .push(resolve_view.to_render_attachment(hal::TextureUses::COLOR_TARGET)); + .push(resolve_view.to_render_attachment(wgt::TextureUses::COLOR_TARGET)); hal_resolve_target = Some(hal::Attachment { view: resolve_view.try_raw(snatch_guard)?, - usage: hal::TextureUses::COLOR_TARGET, + usage: wgt::TextureUses::COLOR_TARGET, }); } color_attachments_hal.push(Some(hal::ColorAttachment { target: hal::Attachment { view: color_view.try_raw(snatch_guard)?, - usage: hal::TextureUses::COLOR_TARGET, + usage: wgt::TextureUses::COLOR_TARGET, }, resolve_target: hal_resolve_target, ops: at.hal_ops(), @@ -1333,7 +1333,7 @@ impl<'d> RenderPassInfo<'d> { depth_stencil_attachment: Some(hal::DepthStencilAttachment { target: hal::Attachment { view: view.try_raw(snatch_guard)?, - usage: hal::TextureUses::DEPTH_STENCIL_WRITE, + usage: wgt::TextureUses::DEPTH_STENCIL_WRITE, }, depth_ops, stencil_ops, @@ -2167,7 +2167,7 @@ fn set_index_buffer( .info .usage_scope .buffers - .merge_single(&buffer, hal::BufferUses::INDEX)?; + .merge_single(&buffer, wgt::BufferUses::INDEX)?; buffer.same_device_as(cmd_buf.as_ref())?; @@ -2216,7 +2216,7 @@ fn set_vertex_buffer( .info .usage_scope .buffers - .merge_single(&buffer, hal::BufferUses::VERTEX)?; + .merge_single(&buffer, wgt::BufferUses::VERTEX)?; buffer.same_device_as(cmd_buf.as_ref())?; @@ -2496,7 +2496,7 @@ fn multi_draw_indirect( .info .usage_scope .buffers - .merge_single(&indirect_buffer, hal::BufferUses::INDIRECT)?; + .merge_single(&indirect_buffer, wgt::BufferUses::INDIRECT)?; indirect_buffer.check_usage(BufferUsages::INDIRECT)?; let indirect_raw = indirect_buffer.try_raw(state.snatch_guard)?; @@ -2573,7 +2573,7 @@ fn multi_draw_indirect_count( .info .usage_scope .buffers - .merge_single(&indirect_buffer, hal::BufferUses::INDIRECT)?; + .merge_single(&indirect_buffer, wgt::BufferUses::INDIRECT)?; indirect_buffer.check_usage(BufferUsages::INDIRECT)?; let indirect_raw = indirect_buffer.try_raw(state.snatch_guard)?; @@ -2582,7 +2582,7 @@ fn multi_draw_indirect_count( .info .usage_scope .buffers - .merge_single(&count_buffer, hal::BufferUses::INDIRECT)?; + .merge_single(&count_buffer, wgt::BufferUses::INDIRECT)?; count_buffer.check_usage(BufferUsages::INDIRECT)?; let count_raw = count_buffer.try_raw(state.snatch_guard)?; diff --git a/wgpu-core/src/command/transfer.rs b/wgpu-core/src/command/transfer.rs index 291c44bd2c..1113e9b3eb 100644 --- a/wgpu-core/src/command/transfer.rs +++ b/wgpu-core/src/command/transfer.rs @@ -16,12 +16,11 @@ use crate::{ MissingTextureUsageError, ParentDevice, Texture, TextureErrorDimension, }, snatch::SnatchGuard, - track::TextureSelector, }; use arrayvec::ArrayVec; use thiserror::Error; -use wgt::{BufferAddress, BufferUsages, Extent3d, TextureUsages}; +use wgt::{BufferAddress, BufferUsages, Extent3d, TextureSelector, TextureUsages}; use std::sync::Arc; @@ -576,7 +575,7 @@ impl Global { let src_pending = cmd_buf_data .trackers .buffers - .set_single(&src_buffer, hal::BufferUses::COPY_SRC); + .set_single(&src_buffer, wgt::BufferUses::COPY_SRC); let src_raw = src_buffer.try_raw(&snatch_guard)?; src_buffer @@ -592,7 +591,7 @@ impl Global { let dst_pending = cmd_buf_data .trackers .buffers - .set_single(&dst_buffer, hal::BufferUses::COPY_DST); + .set_single(&dst_buffer, wgt::BufferUses::COPY_DST); let dst_raw = dst_buffer.try_raw(&snatch_guard)?; dst_buffer @@ -767,7 +766,7 @@ impl Global { let src_pending = cmd_buf_data .trackers .buffers - .set_single(&src_buffer, hal::BufferUses::COPY_SRC); + .set_single(&src_buffer, wgt::BufferUses::COPY_SRC); let src_raw = src_buffer.try_raw(&snatch_guard)?; src_buffer @@ -778,7 +777,7 @@ impl Global { let dst_pending = cmd_buf_data.trackers.textures.set_single( &dst_texture, dst_range, - hal::TextureUses::COPY_DST, + wgt::TextureUses::COPY_DST, ); let dst_raw = dst_texture.try_raw(&snatch_guard)?; dst_texture @@ -916,7 +915,7 @@ impl Global { let src_pending = cmd_buf_data.trackers.textures.set_single( &src_texture, src_range, - hal::TextureUses::COPY_SRC, + wgt::TextureUses::COPY_SRC, ); let src_raw = src_texture.try_raw(&snatch_guard)?; src_texture @@ -946,7 +945,7 @@ impl Global { let dst_pending = cmd_buf_data .trackers .buffers - .set_single(&dst_buffer, hal::BufferUses::COPY_DST); + .set_single(&dst_buffer, wgt::BufferUses::COPY_DST); let dst_raw = dst_buffer.try_raw(&snatch_guard)?; dst_buffer @@ -1010,7 +1009,7 @@ impl Global { cmd_buf_raw.transition_textures(&src_barrier); cmd_buf_raw.copy_texture_to_buffer( src_raw, - hal::TextureUses::COPY_SRC, + wgt::TextureUses::COPY_SRC, dst_raw, ®ions, ); @@ -1125,7 +1124,7 @@ impl Global { let src_pending = cmd_buf_data.trackers.textures.set_single( &src_texture, src_range, - hal::TextureUses::COPY_SRC, + wgt::TextureUses::COPY_SRC, ); let src_raw = src_texture.try_raw(&snatch_guard)?; src_texture @@ -1141,7 +1140,7 @@ impl Global { let dst_pending = cmd_buf_data.trackers.textures.set_single( &dst_texture, dst_range, - hal::TextureUses::COPY_DST, + wgt::TextureUses::COPY_DST, ); let dst_raw = dst_texture.try_raw(&snatch_guard)?; dst_texture @@ -1173,7 +1172,7 @@ impl Global { cmd_buf_raw.transition_textures(&barriers); cmd_buf_raw.copy_texture_to_texture( src_raw, - hal::TextureUses::COPY_SRC, + wgt::TextureUses::COPY_SRC, dst_raw, ®ions, ); diff --git a/wgpu-core/src/conv.rs b/wgpu-core/src/conv.rs index a4f967c4c5..636f9b9348 100644 --- a/wgpu-core/src/conv.rs +++ b/wgpu-core/src/conv.rs @@ -51,54 +51,54 @@ pub fn is_valid_external_image_copy_dst_texture_format(format: wgt::TextureForma } } -pub fn map_buffer_usage(usage: wgt::BufferUsages) -> hal::BufferUses { - let mut u = hal::BufferUses::empty(); +pub fn map_buffer_usage(usage: wgt::BufferUsages) -> wgt::BufferUses { + let mut u = wgt::BufferUses::empty(); u.set( - hal::BufferUses::MAP_READ, + wgt::BufferUses::MAP_READ, usage.contains(wgt::BufferUsages::MAP_READ), ); u.set( - hal::BufferUses::MAP_WRITE, + wgt::BufferUses::MAP_WRITE, usage.contains(wgt::BufferUsages::MAP_WRITE), ); u.set( - hal::BufferUses::COPY_SRC, + wgt::BufferUses::COPY_SRC, usage.contains(wgt::BufferUsages::COPY_SRC), ); u.set( - hal::BufferUses::COPY_DST, + wgt::BufferUses::COPY_DST, usage.contains(wgt::BufferUsages::COPY_DST), ); u.set( - hal::BufferUses::INDEX, + wgt::BufferUses::INDEX, usage.contains(wgt::BufferUsages::INDEX), ); u.set( - hal::BufferUses::VERTEX, + wgt::BufferUses::VERTEX, usage.contains(wgt::BufferUsages::VERTEX), ); u.set( - hal::BufferUses::UNIFORM, + wgt::BufferUses::UNIFORM, usage.contains(wgt::BufferUsages::UNIFORM), ); u.set( - hal::BufferUses::STORAGE_READ_ONLY | hal::BufferUses::STORAGE_READ_WRITE, + wgt::BufferUses::STORAGE_READ_ONLY | wgt::BufferUses::STORAGE_READ_WRITE, usage.contains(wgt::BufferUsages::STORAGE), ); u.set( - hal::BufferUses::INDIRECT, + wgt::BufferUses::INDIRECT, usage.contains(wgt::BufferUsages::INDIRECT), ); u.set( - hal::BufferUses::QUERY_RESOLVE, + wgt::BufferUses::QUERY_RESOLVE, usage.contains(wgt::BufferUsages::QUERY_RESOLVE), ); u.set( - hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, usage.contains(wgt::BufferUsages::BLAS_INPUT), ); u.set( - hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, usage.contains(wgt::BufferUsages::TLAS_INPUT), ); u @@ -108,41 +108,41 @@ pub fn map_texture_usage( usage: wgt::TextureUsages, aspect: hal::FormatAspects, flags: wgt::TextureFormatFeatureFlags, -) -> hal::TextureUses { - let mut u = hal::TextureUses::empty(); +) -> wgt::TextureUses { + let mut u = wgt::TextureUses::empty(); u.set( - hal::TextureUses::COPY_SRC, + wgt::TextureUses::COPY_SRC, usage.contains(wgt::TextureUsages::COPY_SRC), ); u.set( - hal::TextureUses::COPY_DST, + wgt::TextureUses::COPY_DST, usage.contains(wgt::TextureUsages::COPY_DST), ); u.set( - hal::TextureUses::RESOURCE, + wgt::TextureUses::RESOURCE, usage.contains(wgt::TextureUsages::TEXTURE_BINDING), ); if usage.contains(wgt::TextureUsages::STORAGE_BINDING) { u.set( - hal::TextureUses::STORAGE_READ_ONLY, + wgt::TextureUses::STORAGE_READ_ONLY, flags.contains(wgt::TextureFormatFeatureFlags::STORAGE_READ_ONLY), ); u.set( - hal::TextureUses::STORAGE_WRITE_ONLY, + wgt::TextureUses::STORAGE_WRITE_ONLY, flags.contains(wgt::TextureFormatFeatureFlags::STORAGE_WRITE_ONLY), ); u.set( - hal::TextureUses::STORAGE_READ_WRITE, + wgt::TextureUses::STORAGE_READ_WRITE, flags.contains(wgt::TextureFormatFeatureFlags::STORAGE_READ_WRITE), ); } let is_color = aspect.contains(hal::FormatAspects::COLOR); u.set( - hal::TextureUses::COLOR_TARGET, + wgt::TextureUses::COLOR_TARGET, usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT) && is_color, ); u.set( - hal::TextureUses::DEPTH_STENCIL_READ | hal::TextureUses::DEPTH_STENCIL_WRITE, + wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::DEPTH_STENCIL_WRITE, usage.contains(wgt::TextureUsages::RENDER_ATTACHMENT) && !is_color, ); u @@ -151,14 +151,14 @@ pub fn map_texture_usage( pub fn map_texture_usage_for_texture( desc: &TextureDescriptor, format_features: &TextureFormatFeatures, -) -> hal::TextureUses { +) -> wgt::TextureUses { // Enforce having COPY_DST/DEPTH_STENCIL_WRITE/COLOR_TARGET otherwise we // wouldn't be able to initialize the texture. map_texture_usage(desc.usage, desc.format.into(), format_features.flags) | if desc.format.is_depth_stencil_format() { - hal::TextureUses::DEPTH_STENCIL_WRITE + wgt::TextureUses::DEPTH_STENCIL_WRITE } else if desc.usage.contains(wgt::TextureUsages::COPY_DST) { - hal::TextureUses::COPY_DST // (set already) + wgt::TextureUses::COPY_DST // (set already) } else { // Use COPY_DST only if we can't use COLOR_TARGET if format_features @@ -167,38 +167,38 @@ pub fn map_texture_usage_for_texture( && desc.dimension == wgt::TextureDimension::D2 // Render targets dimension must be 2d { - hal::TextureUses::COLOR_TARGET + wgt::TextureUses::COLOR_TARGET } else { - hal::TextureUses::COPY_DST + wgt::TextureUses::COPY_DST } } } -pub fn map_texture_usage_from_hal(uses: hal::TextureUses) -> wgt::TextureUsages { +pub fn map_texture_usage_from_hal(uses: wgt::TextureUses) -> wgt::TextureUsages { let mut u = wgt::TextureUsages::empty(); u.set( wgt::TextureUsages::COPY_SRC, - uses.contains(hal::TextureUses::COPY_SRC), + uses.contains(wgt::TextureUses::COPY_SRC), ); u.set( wgt::TextureUsages::COPY_DST, - uses.contains(hal::TextureUses::COPY_DST), + uses.contains(wgt::TextureUses::COPY_DST), ); u.set( wgt::TextureUsages::TEXTURE_BINDING, - uses.contains(hal::TextureUses::RESOURCE), + uses.contains(wgt::TextureUses::RESOURCE), ); u.set( wgt::TextureUsages::STORAGE_BINDING, uses.intersects( - hal::TextureUses::STORAGE_READ_ONLY - | hal::TextureUses::STORAGE_WRITE_ONLY - | hal::TextureUses::STORAGE_READ_WRITE, + wgt::TextureUses::STORAGE_READ_ONLY + | wgt::TextureUses::STORAGE_WRITE_ONLY + | wgt::TextureUses::STORAGE_READ_WRITE, ), ); u.set( wgt::TextureUsages::RENDER_ATTACHMENT, - uses.contains(hal::TextureUses::COLOR_TARGET), + uses.contains(wgt::TextureUses::COLOR_TARGET), ); u } diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index cd6731ae04..22f8ef4ec0 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -74,8 +74,8 @@ impl Queue { .transition_buffers(&[hal::BufferBarrier { buffer: zero_buffer, usage: hal::StateTransition { - from: hal::BufferUses::empty(), - to: hal::BufferUses::COPY_DST, + from: wgt::BufferUses::empty(), + to: wgt::BufferUses::COPY_DST, }, }]); pending_writes @@ -86,8 +86,8 @@ impl Queue { .transition_buffers(&[hal::BufferBarrier { buffer: zero_buffer, usage: hal::StateTransition { - from: hal::BufferUses::COPY_DST, - to: hal::BufferUses::COPY_SRC, + from: wgt::BufferUses::COPY_DST, + to: wgt::BufferUses::COPY_SRC, }, }]); } @@ -616,7 +616,7 @@ impl Queue { let mut trackers = self.device.trackers.lock(); trackers .buffers - .set_single(&buffer, hal::BufferUses::COPY_DST) + .set_single(&buffer, wgt::BufferUses::COPY_DST) }; let snatch_guard = self.device.snatchable_lock.read(); @@ -634,8 +634,8 @@ impl Queue { let barriers = iter::once(hal::BufferBarrier { buffer: staging_buffer.raw(), usage: hal::StateTransition { - from: hal::BufferUses::MAP_WRITE, - to: hal::BufferUses::COPY_SRC, + from: wgt::BufferUses::MAP_WRITE, + to: wgt::BufferUses::COPY_SRC, }, }) .chain(transition.map(|pending| pending.into_hal(&buffer, &snatch_guard))) @@ -856,8 +856,8 @@ impl Queue { let buffer_barrier = hal::BufferBarrier { buffer: staging_buffer.raw(), usage: hal::StateTransition { - from: hal::BufferUses::MAP_WRITE, - to: hal::BufferUses::COPY_SRC, + from: wgt::BufferUses::MAP_WRITE, + to: wgt::BufferUses::COPY_SRC, }, }; @@ -865,7 +865,7 @@ impl Queue { let transition = trackers .textures - .set_single(&dst, selector, hal::TextureUses::COPY_DST); + .set_single(&dst, selector, wgt::TextureUses::COPY_DST); let texture_barriers = transition .map(|pending| pending.into_hal(dst_raw)) .collect::>(); @@ -1042,7 +1042,7 @@ impl Queue { let mut trackers = self.device.trackers.lock(); let transitions = trackers .textures - .set_single(&dst, selector, hal::TextureUses::COPY_DST); + .set_single(&dst, selector, wgt::TextureUses::COPY_DST); // `copy_external_image_to_texture` is exclusive to the WebGL backend. // Don't go through the `DynCommandEncoder` abstraction and directly to the WebGL backend. @@ -1250,7 +1250,7 @@ impl Queue { unsafe { used_surface_textures - .merge_single(texture, None, hal::TextureUses::PRESENT) + .merge_single(texture, None, wgt::TextureUses::PRESENT) .unwrap() }; } @@ -1564,7 +1564,7 @@ fn validate_command_buffer( if should_extend { unsafe { used_surface_textures - .merge_single(texture, None, hal::TextureUses::PRESENT) + .merge_single(texture, None, wgt::TextureUses::PRESENT) .unwrap(); }; } diff --git a/wgpu-core/src/device/ray_tracing.rs b/wgpu-core/src/device/ray_tracing.rs index 12afc7e6a8..d1e16ccd84 100644 --- a/wgpu-core/src/device/ray_tracing.rs +++ b/wgpu-core/src/device/ray_tracing.rs @@ -140,8 +140,8 @@ impl Device { self.raw().create_buffer(&hal::BufferDescriptor { label: Some("(wgpu-core) instances_buffer"), size: instance_buffer_size as u64, - usage: hal::BufferUses::COPY_DST - | hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + usage: wgt::BufferUses::COPY_DST + | wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, memory_flags: hal::MemoryFlags::PREFER_COHERENT, }) } diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index 79d70f424e..4415b88ed7 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -23,10 +23,7 @@ use crate::{ }, resource_log, snatch::{SnatchGuard, SnatchLock, Snatchable}, - track::{ - BindGroupStates, DeviceTracker, TextureSelector, TrackerIndexAllocators, UsageScope, - UsageScopePool, - }, + track::{BindGroupStates, DeviceTracker, TrackerIndexAllocators, UsageScope, UsageScopePool}, validation::{self, validate_color_attachment_bytes_per_sample}, weak_vec::WeakVec, FastHashMap, LabelHelpers, @@ -35,7 +32,8 @@ use crate::{ use arrayvec::ArrayVec; use smallvec::SmallVec; use wgt::{ - math::align_to, DeviceLostReason, TextureFormat, TextureSampleType, TextureViewDimension, + math::align_to, DeviceLostReason, TextureFormat, TextureSampleType, TextureSelector, + TextureViewDimension, }; use crate::resource::{AccelerationStructure, DestroyedResourceError, Tlas}; @@ -209,7 +207,7 @@ impl Device { raw_device.create_buffer(&hal::BufferDescriptor { label: hal_label(Some("(wgpu internal) zero init buffer"), instance_flags), size: ZERO_BUFFER_SIZE, - usage: hal::BufferUses::COPY_SRC | hal::BufferUses::COPY_DST, + usage: wgt::BufferUses::COPY_SRC | wgt::BufferUses::COPY_DST, memory_flags: hal::MemoryFlags::empty(), }) } @@ -521,7 +519,7 @@ impl Device { self.require_downlevel_flags(wgt::DownlevelFlags::INDIRECT_EXECUTION)?; // We are going to be reading from it, internally; // when validating the content of the buffer - usage |= hal::BufferUses::STORAGE_READ_ONLY | hal::BufferUses::STORAGE_READ_WRITE; + usage |= wgt::BufferUses::STORAGE_READ_ONLY | wgt::BufferUses::STORAGE_READ_WRITE; } if desc.mapped_at_creation { @@ -530,12 +528,12 @@ impl Device { } if !desc.usage.contains(wgt::BufferUsages::MAP_WRITE) { // we are going to be copying into it, internally - usage |= hal::BufferUses::COPY_DST; + usage |= wgt::BufferUses::COPY_DST; } } else { // We are required to zero out (initialize) all memory. This is done // on demand using clear_buffer which requires write transfer usage! - usage |= hal::BufferUses::COPY_DST; + usage |= wgt::BufferUses::COPY_DST; } let actual_size = if desc.size == 0 { @@ -587,7 +585,7 @@ impl Device { let buffer = Arc::new(buffer); let buffer_use = if !desc.mapped_at_creation { - hal::BufferUses::empty() + wgt::BufferUses::empty() } else if desc.usage.contains(wgt::BufferUsages::MAP_WRITE) { // buffer is mappable, so we are just doing that at start let map_size = buffer.size; @@ -605,7 +603,7 @@ impl Device { range: 0..map_size, host: HostMap::Write, }; - hal::BufferUses::MAP_WRITE + wgt::BufferUses::MAP_WRITE } else { let mut staging_buffer = StagingBuffer::new(self, wgt::BufferSize::new(aligned_size).unwrap())?; @@ -616,7 +614,7 @@ impl Device { buffer.initialization_status.write().drain(0..aligned_size); *buffer.map_state.lock() = resource::BufferMapState::Init { staging_buffer }; - hal::BufferUses::COPY_DST + wgt::BufferUses::COPY_DST }; self.trackers @@ -653,7 +651,7 @@ impl Device { self.trackers .lock() .textures - .insert_single(&texture, hal::TextureUses::UNINITIALIZED); + .insert_single(&texture, wgt::TextureUses::UNINITIALIZED); Ok(texture) } @@ -697,7 +695,7 @@ impl Device { self.trackers .lock() .buffers - .insert_single(&buffer, hal::BufferUses::empty()); + .insert_single(&buffer, wgt::BufferUses::empty()); (Fallible::Valid(buffer), None) } @@ -946,12 +944,12 @@ impl Device { .map_err(|e| self.handle_hal_error(e))?; let clear_mode = if hal_usage - .intersects(hal::TextureUses::DEPTH_STENCIL_WRITE | hal::TextureUses::COLOR_TARGET) + .intersects(wgt::TextureUses::DEPTH_STENCIL_WRITE | wgt::TextureUses::COLOR_TARGET) { let (is_color, usage) = if desc.format.is_depth_stencil_format() { - (false, hal::TextureUses::DEPTH_STENCIL_WRITE) + (false, wgt::TextureUses::DEPTH_STENCIL_WRITE) } else { - (true, hal::TextureUses::COLOR_TARGET) + (true, wgt::TextureUses::COLOR_TARGET) }; let dimension = match desc.dimension { wgt::TextureDimension::D1 => TextureViewDimension::D1, @@ -1025,7 +1023,7 @@ impl Device { self.trackers .lock() .textures - .insert_single(&texture, hal::TextureUses::UNINITIALIZED); + .insert_single(&texture, wgt::TextureUses::UNINITIALIZED); Ok(texture) } @@ -1278,23 +1276,23 @@ impl Device { // filter the usages based on the other criteria let usage = { - let mask_copy = !(hal::TextureUses::COPY_SRC | hal::TextureUses::COPY_DST); + let mask_copy = !(wgt::TextureUses::COPY_SRC | wgt::TextureUses::COPY_DST); let mask_dimension = match resolved_dimension { TextureViewDimension::Cube | TextureViewDimension::CubeArray => { - hal::TextureUses::RESOURCE + wgt::TextureUses::RESOURCE } TextureViewDimension::D3 => { - hal::TextureUses::RESOURCE - | hal::TextureUses::STORAGE_READ_ONLY - | hal::TextureUses::STORAGE_WRITE_ONLY - | hal::TextureUses::STORAGE_READ_WRITE + wgt::TextureUses::RESOURCE + | wgt::TextureUses::STORAGE_READ_ONLY + | wgt::TextureUses::STORAGE_WRITE_ONLY + | wgt::TextureUses::STORAGE_READ_WRITE } - _ => hal::TextureUses::all(), + _ => wgt::TextureUses::all(), }; let mask_mip_level = if resolved_mip_level_count == 1 { - hal::TextureUses::all() + wgt::TextureUses::all() } else { - hal::TextureUses::RESOURCE + wgt::TextureUses::RESOURCE }; texture.hal_usage & mask_copy & mask_dimension & mask_mip_level }; @@ -1943,15 +1941,15 @@ impl Device { let (pub_usage, internal_use, range_limit) = match binding_ty { wgt::BufferBindingType::Uniform => ( wgt::BufferUsages::UNIFORM, - hal::BufferUses::UNIFORM, + wgt::BufferUses::UNIFORM, self.limits.max_uniform_buffer_binding_size, ), wgt::BufferBindingType::Storage { read_only } => ( wgt::BufferUsages::STORAGE, if read_only { - hal::BufferUses::STORAGE_READ_ONLY + wgt::BufferUses::STORAGE_READ_ONLY } else { - hal::BufferUses::STORAGE_READ_WRITE + wgt::BufferUses::STORAGE_READ_WRITE }, self.limits.max_storage_buffer_binding_size, ), @@ -2428,7 +2426,7 @@ impl Device { decl: &wgt::BindGroupLayoutEntry, view: &TextureView, expected: &'static str, - ) -> Result { + ) -> Result { use crate::binding_model::CreateBindGroupError as Error; if view .desc @@ -2488,7 +2486,7 @@ impl Device { }); } view.check_usage(wgt::TextureUsages::TEXTURE_BINDING)?; - Ok(hal::TextureUses::RESOURCE) + Ok(wgt::TextureUses::RESOURCE) } wgt::BindingType::StorageTexture { access, @@ -2527,7 +2525,7 @@ impl Device { { return Err(Error::StorageWriteNotSupported(view.desc.format)); } - hal::TextureUses::STORAGE_WRITE_ONLY + wgt::TextureUses::STORAGE_WRITE_ONLY } wgt::StorageTextureAccess::ReadOnly => { if !view @@ -2537,7 +2535,7 @@ impl Device { { return Err(Error::StorageReadNotSupported(view.desc.format)); } - hal::TextureUses::STORAGE_READ_ONLY + wgt::TextureUses::STORAGE_READ_ONLY } wgt::StorageTextureAccess::ReadWrite => { if !view @@ -2548,7 +2546,7 @@ impl Device { return Err(Error::StorageReadWriteNotSupported(view.desc.format)); } - hal::TextureUses::STORAGE_READ_WRITE + wgt::TextureUses::STORAGE_READ_WRITE } }; view.check_usage(wgt::TextureUsages::STORAGE_BINDING)?; diff --git a/wgpu-core/src/indirect_validation.rs b/wgpu-core/src/indirect_validation.rs index 3045965435..e16828aede 100644 --- a/wgpu-core/src/indirect_validation.rs +++ b/wgpu-core/src/indirect_validation.rs @@ -226,7 +226,7 @@ impl IndirectValidation { let dst_buffer_desc = hal::BufferDescriptor { label: None, size: DST_BUFFER_SIZE.get(), - usage: hal::BufferUses::INDIRECT | hal::BufferUses::STORAGE_READ_WRITE, + usage: wgt::BufferUses::INDIRECT | wgt::BufferUses::STORAGE_READ_WRITE, memory_flags: hal::MemoryFlags::empty(), }; let dst_buffer = diff --git a/wgpu-core/src/init_tracker/texture.rs b/wgpu-core/src/init_tracker/texture.rs index 4bf7278f21..f3cc471aac 100644 --- a/wgpu-core/src/init_tracker/texture.rs +++ b/wgpu-core/src/init_tracker/texture.rs @@ -1,7 +1,8 @@ use super::{InitTracker, MemoryInitKind}; -use crate::{resource::Texture, track::TextureSelector}; +use crate::resource::Texture; use arrayvec::ArrayVec; use std::{ops::Range, sync::Arc}; +use wgt::TextureSelector; #[derive(Debug, Clone)] pub(crate) struct TextureInitRange { diff --git a/wgpu-core/src/lib.rs b/wgpu-core/src/lib.rs index 510a71a781..5bab0ee2a2 100644 --- a/wgpu-core/src/lib.rs +++ b/wgpu-core/src/lib.rs @@ -92,7 +92,6 @@ pub mod validation; pub use hal::{api, MAX_BIND_GROUPS, MAX_COLOR_ATTACHMENTS, MAX_VERTEX_BUFFERS}; pub use naga; -pub use track::texture::TextureSelector; use std::{borrow::Cow, os::raw::c_char}; diff --git a/wgpu-core/src/present.rs b/wgpu-core/src/present.rs index f1b01a1a21..1646111635 100644 --- a/wgpu-core/src/present.rs +++ b/wgpu-core/src/present.rs @@ -89,8 +89,8 @@ pub enum ConfigureSurfaceError { }, #[error("Requested usage {requested:?} is not in the list of supported usages: {available:?}")] UnsupportedUsage { - requested: hal::TextureUses, - available: hal::TextureUses, + requested: wgt::TextureUses, + available: wgt::TextureUses, }, } @@ -170,7 +170,7 @@ impl Surface { ), format: config.format, dimension: wgt::TextureViewDimension::D2, - usage: hal::TextureUses::COLOR_TARGET, + usage: wgt::TextureUses::COLOR_TARGET, range: wgt::ImageSubresourceRange::default(), }; let clear_view = unsafe { @@ -200,7 +200,7 @@ impl Surface { .trackers .lock() .textures - .insert_single(&texture, hal::TextureUses::UNINITIALIZED); + .insert_single(&texture, wgt::TextureUses::UNINITIALIZED); if present.acquired_texture.is_some() { return Err(SurfaceError::AlreadyAcquired); diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index 0b13ad3bd0..69f510bb0f 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -13,11 +13,13 @@ use crate::{ lock::{rank, Mutex, RwLock}, resource_log, snatch::{SnatchGuard, Snatchable}, - track::{SharedTrackerIndexAllocator, TextureSelector, TrackerIndex}, + track::{SharedTrackerIndexAllocator, TrackerIndex}, weak_vec::WeakVec, Label, LabelHelpers, SubmissionIndex, }; +use wgt::TextureSelector; + use smallvec::SmallVec; use thiserror::Error; @@ -455,8 +457,8 @@ impl Buffer { } let (pub_usage, internal_use) = match op.host { - HostMap::Read => (wgt::BufferUsages::MAP_READ, hal::BufferUses::MAP_READ), - HostMap::Write => (wgt::BufferUsages::MAP_WRITE, hal::BufferUses::MAP_WRITE), + HostMap::Read => (wgt::BufferUsages::MAP_READ, wgt::BufferUses::MAP_READ), + HostMap::Write => (wgt::BufferUsages::MAP_WRITE, wgt::BufferUses::MAP_WRITE), }; if let Err(e) = self.check_usage(pub_usage) { @@ -634,15 +636,15 @@ impl Buffer { let transition_src = hal::BufferBarrier { buffer: staging_buffer.raw(), usage: hal::StateTransition { - from: hal::BufferUses::MAP_WRITE, - to: hal::BufferUses::COPY_SRC, + from: wgt::BufferUses::MAP_WRITE, + to: wgt::BufferUses::COPY_SRC, }, }; let transition_dst = hal::BufferBarrier:: { buffer: raw_buf, usage: hal::StateTransition { - from: hal::BufferUses::empty(), - to: hal::BufferUses::COPY_DST, + from: wgt::BufferUses::empty(), + to: wgt::BufferUses::COPY_DST, }, }; let mut pending_writes = queue.pending_writes.lock(); @@ -856,7 +858,7 @@ impl StagingBuffer { let stage_desc = hal::BufferDescriptor { label: crate::hal_label(Some("(wgpu internal) Staging"), device.instance_flags), size: size.get(), - usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::COPY_SRC, + usage: wgt::BufferUses::MAP_WRITE | wgt::BufferUses::COPY_SRC, memory_flags: hal::MemoryFlags::TRANSIENT, }; @@ -1010,7 +1012,7 @@ pub struct Texture { pub(crate) inner: Snatchable, pub(crate) device: Arc, pub(crate) desc: wgt::TextureDescriptor<(), Vec>, - pub(crate) hal_usage: hal::TextureUses, + pub(crate) hal_usage: wgt::TextureUses, pub(crate) format_features: wgt::TextureFormatFeatures, pub(crate) initialization_status: RwLock, pub(crate) full_range: TextureSelector, @@ -1026,7 +1028,7 @@ impl Texture { pub(crate) fn new( device: &Arc, inner: TextureInner, - hal_usage: hal::TextureUses, + hal_usage: wgt::TextureUses, desc: &TextureDescriptor, format_features: wgt::TextureFormatFeatures, clear_mode: TextureClearMode, diff --git a/wgpu-core/src/scratch.rs b/wgpu-core/src/scratch.rs index dcd2d28fb4..a8242be075 100644 --- a/wgpu-core/src/scratch.rs +++ b/wgpu-core/src/scratch.rs @@ -1,8 +1,8 @@ use crate::device::{Device, DeviceError}; use crate::resource_log; -use hal::BufferUses; use std::mem::ManuallyDrop; use std::sync::Arc; +use wgt::BufferUses; #[derive(Debug)] pub struct ScratchBuffer { diff --git a/wgpu-core/src/track/buffer.rs b/wgpu-core/src/track/buffer.rs index cfd166070d..ba23dbcd6e 100644 --- a/wgpu-core/src/track/buffer.rs +++ b/wgpu-core/src/track/buffer.rs @@ -15,8 +15,8 @@ use crate::{ ResourceUsageCompatibilityError, ResourceUses, }, }; -use hal::{BufferBarrier, BufferUses}; -use wgt::{strict_assert, strict_assert_eq}; +use hal::BufferBarrier; +use wgt::{strict_assert, strict_assert_eq, BufferUses}; impl ResourceUses for BufferUses { const EXCLUSIVE: Self = Self::EXCLUSIVE; diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index f904b1fe3b..8c138d9eef 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -120,8 +120,8 @@ pub(crate) use buffer::{ use metadata::{ResourceMetadata, ResourceMetadataProvider}; pub(crate) use stateless::StatelessTracker; pub(crate) use texture::{ - DeviceTextureTracker, TextureSelector, TextureTracker, TextureTrackerSetSingle, - TextureUsageScope, TextureViewBindGroupState, + DeviceTextureTracker, TextureTracker, TextureTrackerSetSingle, TextureUsageScope, + TextureViewBindGroupState, }; use wgt::strict_assert_ne; @@ -258,9 +258,9 @@ pub(crate) struct PendingTransition { pub usage: hal::StateTransition, } -pub(crate) type PendingTransitionList = Vec>; +pub(crate) type PendingTransitionList = Vec>; -impl PendingTransition { +impl PendingTransition { /// Produce the hal barrier corresponding to the transition. pub fn into_hal<'a>( self, @@ -275,15 +275,15 @@ impl PendingTransition { } } -impl PendingTransition { +impl PendingTransition { /// Produce the hal barrier corresponding to the transition. pub fn into_hal( self, texture: &dyn hal::DynTexture, ) -> hal::TextureBarrier<'_, dyn hal::DynTexture> { // These showing up in a barrier is always a bug - strict_assert_ne!(self.usage.from, hal::TextureUses::UNKNOWN); - strict_assert_ne!(self.usage.to, hal::TextureUses::UNKNOWN); + strict_assert_ne!(self.usage.from, wgt::TextureUses::UNKNOWN); + strict_assert_ne!(self.usage.to, wgt::TextureUses::UNKNOWN); let mip_count = self.selector.mips.end - self.selector.mips.start; strict_assert_ne!(mip_count, 0); @@ -343,7 +343,7 @@ pub enum ResourceUsageCompatibilityError { #[error("Attempted to use {res} with {invalid_use}.")] Buffer { res: ResourceErrorIdent, - invalid_use: InvalidUse, + invalid_use: InvalidUse, }, #[error( "Attempted to use {res} (mips {mip_levels:?} layers {array_layers:?}) with {invalid_use}." @@ -352,15 +352,15 @@ pub enum ResourceUsageCompatibilityError { res: ResourceErrorIdent, mip_levels: ops::Range, array_layers: ops::Range, - invalid_use: InvalidUse, + invalid_use: InvalidUse, }, } impl ResourceUsageCompatibilityError { fn from_buffer( buffer: &resource::Buffer, - current_state: hal::BufferUses, - new_state: hal::BufferUses, + current_state: wgt::BufferUses, + new_state: wgt::BufferUses, ) -> Self { Self::Buffer { res: buffer.error_ident(), @@ -373,9 +373,9 @@ impl ResourceUsageCompatibilityError { fn from_texture( texture: &resource::Texture, - selector: TextureSelector, - current_state: hal::TextureUses, - new_state: hal::TextureUses, + selector: wgt::TextureSelector, + current_state: wgt::TextureUses, + new_state: wgt::TextureUses, ) -> Self { Self::Texture { res: texture.error_ident(), diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index 0a9a5f5489..268e81c4b2 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -27,27 +27,19 @@ use crate::{ ResourceUsageCompatibilityError, ResourceUses, }, }; -use hal::{TextureBarrier, TextureUses}; +use hal::TextureBarrier; use arrayvec::ArrayVec; use naga::FastHashMap; -use wgt::{strict_assert, strict_assert_eq}; +use wgt::{strict_assert, strict_assert_eq, TextureSelector, TextureUses}; use std::{ iter, - ops::Range, sync::{Arc, Weak}, vec::Drain, }; -/// Specifies a particular set of subresources in a texture. -#[derive(Clone, Debug, PartialEq, Eq)] -pub struct TextureSelector { - pub mips: Range, - pub layers: Range, -} - impl ResourceUses for TextureUses { const EXCLUSIVE: Self = Self::EXCLUSIVE; diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 2261203682..1c7c7135d4 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -149,7 +149,7 @@ impl Example { height: window_size.1, depth_or_array_layers: 1, }, - usage: hal::TextureUses::COLOR_TARGET, + usage: wgt::TextureUses::COLOR_TARGET, view_formats: vec![], }; unsafe { @@ -288,7 +288,7 @@ impl Example { let staging_buffer_desc = hal::BufferDescriptor { label: Some("stage"), size: texture_data.len() as wgt::BufferAddress, - usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::COPY_SRC, + usage: wgt::BufferUses::MAP_WRITE | wgt::BufferUses::COPY_SRC, memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT, }; let staging_buffer = unsafe { device.create_buffer(&staging_buffer_desc).unwrap() }; @@ -316,7 +316,7 @@ impl Example { sample_count: 1, dimension: wgt::TextureDimension::D2, format: wgt::TextureFormat::Rgba8UnormSrgb, - usage: hal::TextureUses::COPY_DST | hal::TextureUses::RESOURCE, + usage: wgt::TextureUses::COPY_DST | wgt::TextureUses::RESOURCE, memory_flags: hal::MemoryFlags::empty(), view_formats: vec![], }; @@ -332,24 +332,24 @@ impl Example { let buffer_barrier = hal::BufferBarrier { buffer: &staging_buffer, usage: hal::StateTransition { - from: hal::BufferUses::empty(), - to: hal::BufferUses::COPY_SRC, + from: wgt::BufferUses::empty(), + to: wgt::BufferUses::COPY_SRC, }, }; let texture_barrier1 = hal::TextureBarrier { texture: &texture, range: wgt::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: hal::TextureUses::UNINITIALIZED, - to: hal::TextureUses::COPY_DST, + from: wgt::TextureUses::UNINITIALIZED, + to: wgt::TextureUses::COPY_DST, }, }; let texture_barrier2 = hal::TextureBarrier { texture: &texture, range: wgt::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: hal::TextureUses::COPY_DST, - to: hal::TextureUses::RESOURCE, + from: wgt::TextureUses::COPY_DST, + to: wgt::TextureUses::RESOURCE, }, }; let copy = hal::BufferTextureCopy { @@ -406,7 +406,7 @@ impl Example { let global_buffer_desc = hal::BufferDescriptor { label: Some("global"), size: size_of::() as wgt::BufferAddress, - usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::UNIFORM, + usage: wgt::BufferUses::MAP_WRITE | wgt::BufferUses::UNIFORM, memory_flags: hal::MemoryFlags::PREFER_COHERENT, }; let global_buffer = unsafe { @@ -431,7 +431,7 @@ impl Example { let local_buffer_desc = hal::BufferDescriptor { label: Some("local"), size: (MAX_BUNNIES as wgt::BufferAddress) * (local_alignment as wgt::BufferAddress), - usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::UNIFORM, + usage: wgt::BufferUses::MAP_WRITE | wgt::BufferUses::UNIFORM, memory_flags: hal::MemoryFlags::PREFER_COHERENT, }; let local_buffer = unsafe { device.create_buffer(&local_buffer_desc).unwrap() }; @@ -440,7 +440,7 @@ impl Example { label: None, format: texture_desc.format, dimension: wgt::TextureViewDimension::D2, - usage: hal::TextureUses::RESOURCE, + usage: wgt::TextureUses::RESOURCE, range: wgt::ImageSubresourceRange::default(), }; let texture_view = unsafe { device.create_texture_view(&texture, &view_desc).unwrap() }; @@ -453,7 +453,7 @@ impl Example { }; let texture_binding = hal::TextureBinding { view: &texture_view, - usage: hal::TextureUses::RESOURCE, + usage: wgt::TextureUses::RESOURCE, }; let global_group_desc = hal::BindGroupDescriptor { label: Some("global"), @@ -675,8 +675,8 @@ impl Example { texture: surface_tex.borrow(), range: wgt::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: hal::TextureUses::UNINITIALIZED, - to: hal::TextureUses::COLOR_TARGET, + from: wgt::TextureUses::UNINITIALIZED, + to: wgt::TextureUses::COLOR_TARGET, }, }; unsafe { @@ -688,7 +688,7 @@ impl Example { label: None, format: self.surface_format, dimension: wgt::TextureViewDimension::D2, - usage: hal::TextureUses::COLOR_TARGET, + usage: wgt::TextureUses::COLOR_TARGET, range: wgt::ImageSubresourceRange::default(), }; let surface_tex_view = unsafe { @@ -707,7 +707,7 @@ impl Example { color_attachments: &[Some(hal::ColorAttachment { target: hal::Attachment { view: &surface_tex_view, - usage: hal::TextureUses::COLOR_TARGET, + usage: wgt::TextureUses::COLOR_TARGET, }, resolve_target: None, ops: hal::AttachmentOps::STORE, @@ -745,8 +745,8 @@ impl Example { texture: surface_tex.borrow(), range: wgt::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: hal::TextureUses::COLOR_TARGET, - to: hal::TextureUses::PRESENT, + from: wgt::TextureUses::COLOR_TARGET, + to: wgt::TextureUses::PRESENT, }, }; unsafe { diff --git a/wgpu-hal/examples/raw-gles.rs b/wgpu-hal/examples/raw-gles.rs index bd086c2dce..9d3621bdb9 100644 --- a/wgpu-hal/examples/raw-gles.rs +++ b/wgpu-hal/examples/raw-gles.rs @@ -290,7 +290,7 @@ fn fill_screen(exposed: &hal::ExposedAdapter, width: u32, height label: None, format, dimension: wgt::TextureViewDimension::D2, - usage: hal::TextureUses::COLOR_TARGET, + usage: wgt::TextureUses::COLOR_TARGET, range: wgt::ImageSubresourceRange::default(), }, ) @@ -318,7 +318,7 @@ fn fill_screen(exposed: &hal::ExposedAdapter, width: u32, height color_attachments: &[Some(hal::ColorAttachment { target: hal::Attachment { view: &view, - usage: hal::TextureUses::COLOR_TARGET, + usage: wgt::TextureUses::COLOR_TARGET, }, resolve_target: None, ops: hal::AttachmentOps::STORE, diff --git a/wgpu-hal/examples/ray-traced-triangle/main.rs b/wgpu-hal/examples/ray-traced-triangle/main.rs index 9987380c34..484fc6fbb5 100644 --- a/wgpu-hal/examples/ray-traced-triangle/main.rs +++ b/wgpu-hal/examples/ray-traced-triangle/main.rs @@ -302,7 +302,7 @@ impl Example { height: window_size.1, depth_or_array_layers: 1, }, - usage: hal::TextureUses::COLOR_TARGET | hal::TextureUses::COPY_DST, + usage: wgt::TextureUses::COLOR_TARGET | wgt::TextureUses::COPY_DST, view_formats: vec![surface_format], }; unsafe { @@ -419,8 +419,8 @@ impl Example { .create_buffer(&hal::BufferDescriptor { label: Some("vertices buffer"), size: vertices_size_in_bytes as u64, - usage: hal::BufferUses::MAP_WRITE - | hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + usage: wgt::BufferUses::MAP_WRITE + | wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT, }) .unwrap(); @@ -445,8 +445,8 @@ impl Example { .create_buffer(&hal::BufferDescriptor { label: Some("indices buffer"), size: indices_size_in_bytes as u64, - usage: hal::BufferUses::MAP_WRITE - | hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + usage: wgt::BufferUses::MAP_WRITE + | wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT, }) @@ -552,7 +552,7 @@ impl Example { .create_buffer(&hal::BufferDescriptor { label: Some("uniform buffer"), size: uniforms_size as u64, - usage: hal::BufferUses::MAP_WRITE | hal::BufferUses::UNIFORM, + usage: wgt::BufferUses::MAP_WRITE | wgt::BufferUses::UNIFORM, memory_flags: hal::MemoryFlags::PREFER_COHERENT, }) .unwrap(); @@ -581,7 +581,7 @@ impl Example { sample_count: 1, dimension: wgt::TextureDimension::D2, format: wgt::TextureFormat::Rgba8Unorm, - usage: hal::TextureUses::STORAGE_READ_WRITE | hal::TextureUses::COPY_SRC, + usage: wgt::TextureUses::STORAGE_READ_WRITE | wgt::TextureUses::COPY_SRC, memory_flags: hal::MemoryFlags::empty(), view_formats: vec![wgt::TextureFormat::Rgba8Unorm], }; @@ -591,7 +591,7 @@ impl Example { label: None, format: texture_desc.format, dimension: wgt::TextureViewDimension::D2, - usage: hal::TextureUses::STORAGE_READ_WRITE | hal::TextureUses::COPY_SRC, + usage: wgt::TextureUses::STORAGE_READ_WRITE | wgt::TextureUses::COPY_SRC, range: wgt::ImageSubresourceRange::default(), }; let texture_view = unsafe { device.create_texture_view(&texture, &view_desc).unwrap() }; @@ -604,7 +604,7 @@ impl Example { }; let texture_binding = hal::TextureBinding { view: &texture_view, - usage: hal::TextureUses::STORAGE_READ_WRITE, + usage: wgt::TextureUses::STORAGE_READ_WRITE, }; let group_desc = hal::BindGroupDescriptor { label: Some("bind group"), @@ -641,7 +641,7 @@ impl Example { size: blas_sizes .build_scratch_size .max(tlas_sizes.build_scratch_size), - usage: hal::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + usage: wgt::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, memory_flags: hal::MemoryFlags::empty(), }) .unwrap() @@ -693,8 +693,8 @@ impl Example { .create_buffer(&hal::BufferDescriptor { label: Some("instances_buffer"), size: instances_buffer_size as u64, - usage: hal::BufferUses::MAP_WRITE - | hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + usage: wgt::BufferUses::MAP_WRITE + | wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT, }) .unwrap(); @@ -753,8 +753,8 @@ impl Example { let scratch_buffer_barrier = hal::BufferBarrier { buffer: &scratch_buffer, usage: hal::StateTransition { - from: hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, - to: hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + from: wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + to: wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, }, }; cmd_encoder.transition_buffers(iter::once(scratch_buffer_barrier)); @@ -790,8 +790,8 @@ impl Example { texture: &texture, range: wgt::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: hal::TextureUses::UNINITIALIZED, - to: hal::TextureUses::STORAGE_READ_WRITE, + from: wgt::TextureUses::UNINITIALIZED, + to: wgt::TextureUses::STORAGE_READ_WRITE, }, }; @@ -864,8 +864,8 @@ impl Example { texture: surface_tex.borrow(), range: wgt::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: hal::TextureUses::UNINITIALIZED, - to: hal::TextureUses::COPY_DST, + from: wgt::TextureUses::UNINITIALIZED, + to: wgt::TextureUses::COPY_DST, }, }; @@ -934,8 +934,8 @@ impl Example { let scratch_buffer_barrier = hal::BufferBarrier { buffer: &self.scratch_buffer, usage: hal::StateTransition { - from: hal::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, - to: hal::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + from: wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + to: wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, }, }; ctx.encoder @@ -948,7 +948,7 @@ impl Example { label: None, format: self.surface_format, dimension: wgt::TextureViewDimension::D2, - usage: hal::TextureUses::COPY_DST, + usage: wgt::TextureUses::COPY_DST, range: wgt::ImageSubresourceRange::default(), }; let surface_tex_view = unsafe { @@ -973,24 +973,24 @@ impl Example { texture: surface_tex.borrow(), range: wgt::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: hal::TextureUses::COPY_DST, - to: hal::TextureUses::PRESENT, + from: wgt::TextureUses::COPY_DST, + to: wgt::TextureUses::PRESENT, }, }; let target_barrier2 = hal::TextureBarrier { texture: &self.texture, range: wgt::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: hal::TextureUses::STORAGE_READ_WRITE, - to: hal::TextureUses::COPY_SRC, + from: wgt::TextureUses::STORAGE_READ_WRITE, + to: wgt::TextureUses::COPY_SRC, }, }; let target_barrier3 = hal::TextureBarrier { texture: &self.texture, range: wgt::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: hal::TextureUses::COPY_SRC, - to: hal::TextureUses::STORAGE_READ_WRITE, + from: wgt::TextureUses::COPY_SRC, + to: wgt::TextureUses::STORAGE_READ_WRITE, }, }; unsafe { @@ -998,7 +998,7 @@ impl Example { ctx.encoder.transition_textures(iter::once(target_barrier2)); ctx.encoder.copy_texture_to_texture( &self.texture, - hal::TextureUses::COPY_SRC, + wgt::TextureUses::COPY_SRC, surface_tex.borrow(), std::iter::once(hal::TextureCopy { src_base: hal::TextureCopyBase { diff --git a/wgpu-hal/src/auxil/dxgi/conv.rs b/wgpu-hal/src/auxil/dxgi/conv.rs index 0f94575df8..d834e219d5 100644 --- a/wgpu-hal/src/auxil/dxgi/conv.rs +++ b/wgpu-hal/src/auxil/dxgi/conv.rs @@ -180,7 +180,7 @@ pub fn map_texture_format_for_copy( pub fn map_texture_format_for_resource( format: wgt::TextureFormat, - usage: crate::TextureUses, + usage: wgt::TextureUses, has_view_formats: bool, casting_fully_typed_format_supported: bool, ) -> Dxgi::Common::DXGI_FORMAT { @@ -205,10 +205,10 @@ pub fn map_texture_format_for_resource( // We might view this resource as SRV/UAV but also as DSV } else if format.is_depth_stencil_format() && usage.intersects( - crate::TextureUses::RESOURCE - | crate::TextureUses::STORAGE_READ_ONLY - | crate::TextureUses::STORAGE_WRITE_ONLY - | crate::TextureUses::STORAGE_READ_WRITE, + wgt::TextureUses::RESOURCE + | wgt::TextureUses::STORAGE_READ_ONLY + | wgt::TextureUses::STORAGE_WRITE_ONLY + | wgt::TextureUses::STORAGE_READ_WRITE, ) { match format { diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 0ef706d8c8..7ef3bd7173 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -789,9 +789,9 @@ impl crate::Adapter for super::Adapter { // See https://learn.microsoft.com/en-us/windows/win32/api/dxgi/nf-dxgi-idxgidevice1-setmaximumframelatency maximum_frame_latency: 1..=16, current_extent, - usage: crate::TextureUses::COLOR_TARGET - | crate::TextureUses::COPY_SRC - | crate::TextureUses::COPY_DST, + usage: wgt::TextureUses::COLOR_TARGET + | wgt::TextureUses::COPY_SRC + | wgt::TextureUses::COPY_DST, present_modes, composite_alpha_modes: vec![wgt::CompositeAlphaMode::Opaque], }) diff --git a/wgpu-hal/src/dx12/command.rs b/wgpu-hal/src/dx12/command.rs index 9296a20393..4fc60fb6db 100644 --- a/wgpu-hal/src/dx12/command.rs +++ b/wgpu-hal/src/dx12/command.rs @@ -359,7 +359,7 @@ impl crate::CommandEncoder for super::CommandEncoder { }, }; self.temp.barriers.push(raw); - } else if barrier.usage.from == crate::BufferUses::STORAGE_READ_WRITE { + } else if barrier.usage.from == wgt::BufferUses::STORAGE_READ_WRITE { let raw = Direct3D12::D3D12_RESOURCE_BARRIER { Type: Direct3D12::D3D12_RESOURCE_BARRIER_TYPE_UAV, Flags: Direct3D12::D3D12_RESOURCE_BARRIER_FLAG_NONE, @@ -458,7 +458,7 @@ impl crate::CommandEncoder for super::CommandEncoder { } } } - } else if barrier.usage.from == crate::TextureUses::STORAGE_READ_WRITE { + } else if barrier.usage.from == wgt::TextureUses::STORAGE_READ_WRITE { let raw = Direct3D12::D3D12_RESOURCE_BARRIER { Type: Direct3D12::D3D12_RESOURCE_BARRIER_TYPE_UAV, Flags: Direct3D12::D3D12_RESOURCE_BARRIER_FLAG_NONE, @@ -521,7 +521,7 @@ impl crate::CommandEncoder for super::CommandEncoder { unsafe fn copy_texture_to_texture( &mut self, src: &super::Texture, - _src_usage: crate::TextureUses, + _src_usage: wgt::TextureUses, dst: &super::Texture, regions: T, ) where @@ -602,7 +602,7 @@ impl crate::CommandEncoder for super::CommandEncoder { unsafe fn copy_texture_to_buffer( &mut self, src: &super::Texture, - _src_usage: crate::TextureUses, + _src_usage: wgt::TextureUses, dst: &super::Buffer, regions: T, ) where @@ -711,7 +711,7 @@ impl crate::CommandEncoder for super::CommandEncoder { } let ds_view = desc.depth_stencil_attachment.as_ref().map(|ds| { - if ds.target.usage == crate::TextureUses::DEPTH_STENCIL_WRITE { + if ds.target.usage == wgt::TextureUses::DEPTH_STENCIL_WRITE { ds.target.view.handle_dsv_rw.as_ref().unwrap().raw } else { ds.target.view.handle_dsv_ro.as_ref().unwrap().raw diff --git a/wgpu-hal/src/dx12/conv.rs b/wgpu-hal/src/dx12/conv.rs index 3457d6446e..d8c07ae381 100644 --- a/wgpu-hal/src/dx12/conv.rs +++ b/wgpu-hal/src/dx12/conv.rs @@ -1,10 +1,10 @@ use windows::Win32::Graphics::{Direct3D, Direct3D12}; pub fn map_buffer_usage_to_resource_flags( - usage: crate::BufferUses, + usage: wgt::BufferUses, ) -> Direct3D12::D3D12_RESOURCE_FLAGS { let mut flags = Direct3D12::D3D12_RESOURCE_FLAG_NONE; - if usage.contains(crate::BufferUses::STORAGE_READ_WRITE) { + if usage.contains(wgt::BufferUses::STORAGE_READ_WRITE) { flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; } flags @@ -19,25 +19,25 @@ pub fn map_texture_dimension(dim: wgt::TextureDimension) -> Direct3D12::D3D12_RE } pub fn map_texture_usage_to_resource_flags( - usage: crate::TextureUses, + usage: wgt::TextureUses, ) -> Direct3D12::D3D12_RESOURCE_FLAGS { let mut flags = Direct3D12::D3D12_RESOURCE_FLAG_NONE; - if usage.contains(crate::TextureUses::COLOR_TARGET) { + if usage.contains(wgt::TextureUses::COLOR_TARGET) { flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_RENDER_TARGET; } - if usage.intersects( - crate::TextureUses::DEPTH_STENCIL_READ | crate::TextureUses::DEPTH_STENCIL_WRITE, - ) { + if usage + .intersects(wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::DEPTH_STENCIL_WRITE) + { flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL; - if !usage.contains(crate::TextureUses::RESOURCE) { + if !usage.contains(wgt::TextureUses::RESOURCE) { flags |= Direct3D12::D3D12_RESOURCE_FLAG_DENY_SHADER_RESOURCE; } } if usage.intersects( - crate::TextureUses::STORAGE_READ_ONLY - | crate::TextureUses::STORAGE_WRITE_ONLY - | crate::TextureUses::STORAGE_READ_WRITE, + wgt::TextureUses::STORAGE_READ_ONLY + | wgt::TextureUses::STORAGE_WRITE_ONLY + | wgt::TextureUses::STORAGE_READ_WRITE, ) { flags |= Direct3D12::D3D12_RESOURCE_FLAG_ALLOW_UNORDERED_ACCESS; } @@ -116,8 +116,8 @@ pub fn map_binding_type(ty: &wgt::BindingType) -> Direct3D12::D3D12_DESCRIPTOR_R } } -pub fn map_buffer_usage_to_state(usage: crate::BufferUses) -> Direct3D12::D3D12_RESOURCE_STATES { - use crate::BufferUses as Bu; +pub fn map_buffer_usage_to_state(usage: wgt::BufferUses) -> Direct3D12::D3D12_RESOURCE_STATES { + use wgt::BufferUses as Bu; let mut state = Direct3D12::D3D12_RESOURCE_STATE_COMMON; if usage.intersects(Bu::COPY_SRC) { @@ -144,12 +144,12 @@ pub fn map_buffer_usage_to_state(usage: crate::BufferUses) -> Direct3D12::D3D12_ state } -pub fn map_texture_usage_to_state(usage: crate::TextureUses) -> Direct3D12::D3D12_RESOURCE_STATES { - use crate::TextureUses as Tu; +pub fn map_texture_usage_to_state(usage: wgt::TextureUses) -> Direct3D12::D3D12_RESOURCE_STATES { + use wgt::TextureUses as Tu; let mut state = Direct3D12::D3D12_RESOURCE_STATE_COMMON; //Note: `RESOLVE_SOURCE` and `RESOLVE_DEST` are not used here //Note: `PRESENT` is the same as `COMMON` - if usage == crate::TextureUses::UNINITIALIZED { + if usage == wgt::TextureUses::UNINITIALIZED { return state; } diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 20dc20164f..a55ea86845 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -404,7 +404,7 @@ impl crate::Device for super::Device { desc: &crate::BufferDescriptor, ) -> Result { let mut size = desc.size; - if desc.usage.contains(crate::BufferUses::UNIFORM) { + if desc.usage.contains(wgt::BufferUses::UNIFORM) { let align_mask = Direct3D12::D3D12_CONSTANT_BUFFER_DATA_PLACEMENT_ALIGNMENT as u64 - 1; size = ((size - 1) | align_mask) + 1; } @@ -565,7 +565,7 @@ impl crate::Device for super::Device { texture.resource.clone(), texture.calc_subresource(desc.range.base_mip_level, desc.range.base_array_layer, 0), ), - handle_srv: if desc.usage.intersects(crate::TextureUses::RESOURCE) { + handle_srv: if desc.usage.intersects(wgt::TextureUses::RESOURCE) { match unsafe { view_desc.to_srv() } { Some(raw_desc) => { let handle = self.srv_uav_pool.lock().alloc_handle()?; @@ -584,9 +584,9 @@ impl crate::Device for super::Device { None }, handle_uav: if desc.usage.intersects( - crate::TextureUses::STORAGE_READ_ONLY - | crate::TextureUses::STORAGE_WRITE_ONLY - | crate::TextureUses::STORAGE_READ_WRITE, + wgt::TextureUses::STORAGE_READ_ONLY + | wgt::TextureUses::STORAGE_WRITE_ONLY + | wgt::TextureUses::STORAGE_READ_WRITE, ) { match unsafe { view_desc.to_uav() } { Some(raw_desc) => { @@ -606,7 +606,7 @@ impl crate::Device for super::Device { } else { None }, - handle_rtv: if desc.usage.intersects(crate::TextureUses::COLOR_TARGET) { + handle_rtv: if desc.usage.intersects(wgt::TextureUses::COLOR_TARGET) { let raw_desc = unsafe { view_desc.to_rtv() }; let handle = self.rtv_pool.lock().alloc_handle()?; unsafe { @@ -617,10 +617,7 @@ impl crate::Device for super::Device { } else { None }, - handle_dsv_ro: if desc - .usage - .intersects(crate::TextureUses::DEPTH_STENCIL_READ) - { + handle_dsv_ro: if desc.usage.intersects(wgt::TextureUses::DEPTH_STENCIL_READ) { let raw_desc = unsafe { view_desc.to_dsv(true) }; let handle = self.dsv_pool.lock().alloc_handle()?; unsafe { @@ -631,10 +628,7 @@ impl crate::Device for super::Device { } else { None }, - handle_dsv_rw: if desc - .usage - .intersects(crate::TextureUses::DEPTH_STENCIL_WRITE) - { + handle_dsv_rw: if desc.usage.intersects(wgt::TextureUses::DEPTH_STENCIL_WRITE) { let raw_desc = unsafe { view_desc.to_dsv(false) }; let handle = self.dsv_pool.lock().alloc_handle()?; unsafe { diff --git a/wgpu-hal/src/dx12/suballocation.rs b/wgpu-hal/src/dx12/suballocation.rs index bdb3e85129..de9a437d85 100644 --- a/wgpu-hal/src/dx12/suballocation.rs +++ b/wgpu-hal/src/dx12/suballocation.rs @@ -53,8 +53,8 @@ pub(crate) fn create_buffer_resource( desc: &crate::BufferDescriptor, raw_desc: Direct3D12::D3D12_RESOURCE_DESC, ) -> Result<(Direct3D12::ID3D12Resource, Option), crate::DeviceError> { - let is_cpu_read = desc.usage.contains(crate::BufferUses::MAP_READ); - let is_cpu_write = desc.usage.contains(crate::BufferUses::MAP_WRITE); + let is_cpu_read = desc.usage.contains(wgt::BufferUses::MAP_READ); + let is_cpu_write = desc.usage.contains(wgt::BufferUses::MAP_WRITE); // Workaround for Intel Xe drivers if !device.private_caps.suballocation_supported { @@ -225,8 +225,8 @@ pub(crate) fn create_committed_buffer_resource( desc: &crate::BufferDescriptor, raw_desc: Direct3D12::D3D12_RESOURCE_DESC, ) -> Result { - let is_cpu_read = desc.usage.contains(crate::BufferUses::MAP_READ); - let is_cpu_write = desc.usage.contains(crate::BufferUses::MAP_WRITE); + let is_cpu_read = desc.usage.contains(wgt::BufferUses::MAP_READ); + let is_cpu_write = desc.usage.contains(wgt::BufferUses::MAP_WRITE); let heap_properties = Direct3D12::D3D12_HEAP_PROPERTIES { Type: Direct3D12::D3D12_HEAP_TYPE_CUSTOM, diff --git a/wgpu-hal/src/dynamic/command.rs b/wgpu-hal/src/dynamic/command.rs index 4ecdf74723..8fb65fa161 100644 --- a/wgpu-hal/src/dynamic/command.rs +++ b/wgpu-hal/src/dynamic/command.rs @@ -4,7 +4,7 @@ use crate::{ AccelerationStructureBarrier, Api, Attachment, BufferBarrier, BufferBinding, BufferCopy, BufferTextureCopy, BuildAccelerationStructureDescriptor, ColorAttachment, CommandEncoder, ComputePassDescriptor, DepthStencilAttachment, DeviceError, Label, MemoryRange, - PassTimestampWrites, Rect, RenderPassDescriptor, TextureBarrier, TextureCopy, TextureUses, + PassTimestampWrites, Rect, RenderPassDescriptor, TextureBarrier, TextureCopy, }; use super::{ @@ -37,7 +37,7 @@ pub trait DynCommandEncoder: DynResource + std::fmt::Debug { unsafe fn copy_texture_to_texture( &mut self, src: &dyn DynTexture, - src_usage: TextureUses, + src_usage: wgt::TextureUses, dst: &dyn DynTexture, regions: &[TextureCopy], ); @@ -52,7 +52,7 @@ pub trait DynCommandEncoder: DynResource + std::fmt::Debug { unsafe fn copy_texture_to_buffer( &mut self, src: &dyn DynTexture, - src_usage: TextureUses, + src_usage: wgt::TextureUses, dst: &dyn DynBuffer, regions: &[BufferTextureCopy], ); @@ -240,7 +240,7 @@ impl DynCommandEncoder for C { unsafe fn copy_texture_to_texture( &mut self, src: &dyn DynTexture, - src_usage: TextureUses, + src_usage: wgt::TextureUses, dst: &dyn DynTexture, regions: &[TextureCopy], ) { @@ -267,7 +267,7 @@ impl DynCommandEncoder for C { unsafe fn copy_texture_to_buffer( &mut self, src: &dyn DynTexture, - src_usage: TextureUses, + src_usage: wgt::TextureUses, dst: &dyn DynBuffer, regions: &[BufferTextureCopy], ) { diff --git a/wgpu-hal/src/empty.rs b/wgpu-hal/src/empty.rs index dd1e183ed2..d3d3908ac3 100644 --- a/wgpu-hal/src/empty.rs +++ b/wgpu-hal/src/empty.rs @@ -358,7 +358,7 @@ impl crate::CommandEncoder for Encoder { unsafe fn copy_texture_to_texture( &mut self, src: &Resource, - src_usage: crate::TextureUses, + src_usage: wgt::TextureUses, dst: &Resource, regions: T, ) { @@ -369,7 +369,7 @@ impl crate::CommandEncoder for Encoder { unsafe fn copy_texture_to_buffer( &mut self, src: &Resource, - src_usage: crate::TextureUses, + src_usage: wgt::TextureUses, dst: &Resource, regions: T, ) { diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index d901324205..81bc217d41 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -1207,7 +1207,7 @@ impl crate::Adapter for super::Adapter { composite_alpha_modes: vec![wgt::CompositeAlphaMode::Opaque], //TODO maximum_frame_latency: 2..=2, //TODO, unused currently current_extent: None, - usage: crate::TextureUses::COLOR_TARGET, + usage: wgt::TextureUses::COLOR_TARGET, }) } else { None diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index 0f495b4834..b3d67ace91 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -290,7 +290,7 @@ impl crate::CommandEncoder for super::CommandEncoder { if !bar .usage .from - .contains(crate::BufferUses::STORAGE_READ_WRITE) + .contains(wgt::BufferUses::STORAGE_READ_WRITE) { continue; } @@ -311,13 +311,13 @@ impl crate::CommandEncoder for super::CommandEncoder { return; } - let mut combined_usage = crate::TextureUses::empty(); + let mut combined_usage = wgt::TextureUses::empty(); for bar in barriers { // GLES only synchronizes storage -> anything explicitly if !bar .usage .from - .contains(crate::TextureUses::STORAGE_READ_WRITE) + .contains(wgt::TextureUses::STORAGE_READ_WRITE) { continue; } @@ -393,7 +393,7 @@ impl crate::CommandEncoder for super::CommandEncoder { unsafe fn copy_texture_to_texture( &mut self, src: &super::Texture, - _src_usage: crate::TextureUses, + _src_usage: wgt::TextureUses, dst: &super::Texture, regions: T, ) where @@ -439,7 +439,7 @@ impl crate::CommandEncoder for super::CommandEncoder { unsafe fn copy_texture_to_buffer( &mut self, src: &super::Texture, - _src_usage: crate::TextureUses, + _src_usage: wgt::TextureUses, dst: &super::Buffer, regions: T, ) where diff --git a/wgpu-hal/src/gles/device.rs b/wgpu-hal/src/gles/device.rs index 0df9568698..94ef400c80 100644 --- a/wgpu-hal/src/gles/device.rs +++ b/wgpu-hal/src/gles/device.rs @@ -505,7 +505,7 @@ impl crate::Device for super::Device { &self, desc: &crate::BufferDescriptor, ) -> Result { - let target = if desc.usage.contains(crate::BufferUses::INDEX) { + let target = if desc.usage.contains(wgt::BufferUses::INDEX) { glow::ELEMENT_ARRAY_BUFFER } else { glow::ARRAY_BUFFER @@ -520,7 +520,7 @@ impl crate::Device for super::Device { .private_caps .contains(PrivateCapabilities::BUFFER_ALLOCATION); - if emulate_map && desc.usage.intersects(crate::BufferUses::MAP_WRITE) { + if emulate_map && desc.usage.intersects(wgt::BufferUses::MAP_WRITE) { return Ok(super::Buffer { raw: None, target, @@ -533,7 +533,7 @@ impl crate::Device for super::Device { let gl = &self.shared.context.lock(); - let target = if desc.usage.contains(crate::BufferUses::INDEX) { + let target = if desc.usage.contains(wgt::BufferUses::INDEX) { glow::ELEMENT_ARRAY_BUFFER } else { glow::ARRAY_BUFFER @@ -541,16 +541,16 @@ impl crate::Device for super::Device { let is_host_visible = desc .usage - .intersects(crate::BufferUses::MAP_READ | crate::BufferUses::MAP_WRITE); + .intersects(wgt::BufferUses::MAP_READ | wgt::BufferUses::MAP_WRITE); let is_coherent = desc .memory_flags .contains(crate::MemoryFlags::PREFER_COHERENT); let mut map_flags = 0; - if desc.usage.contains(crate::BufferUses::MAP_READ) { + if desc.usage.contains(wgt::BufferUses::MAP_READ) { map_flags |= glow::MAP_READ_BIT; } - if desc.usage.contains(crate::BufferUses::MAP_WRITE) { + if desc.usage.contains(wgt::BufferUses::MAP_WRITE) { map_flags |= glow::MAP_WRITE_BIT; } @@ -573,14 +573,14 @@ impl crate::Device for super::Device { } } // TODO: may also be required for other calls involving `buffer_sub_data_u8_slice` (e.g. copy buffer to buffer and clear buffer) - if desc.usage.intersects(crate::BufferUses::QUERY_RESOLVE) { + if desc.usage.intersects(wgt::BufferUses::QUERY_RESOLVE) { map_flags |= glow::DYNAMIC_STORAGE_BIT; } unsafe { gl.buffer_storage(target, raw_size, None, map_flags) }; } else { assert!(!is_coherent); let usage = if is_host_visible { - if desc.usage.contains(crate::BufferUses::MAP_READ) { + if desc.usage.contains(wgt::BufferUses::MAP_READ) { glow::STREAM_READ } else { glow::DYNAMIC_DRAW @@ -596,7 +596,7 @@ impl crate::Device for super::Device { unsafe { gl.bind_buffer(target, None) }; - if !is_coherent && desc.usage.contains(crate::BufferUses::MAP_WRITE) { + if !is_coherent && desc.usage.contains(wgt::BufferUses::MAP_WRITE) { map_flags |= glow::MAP_FLUSH_EXPLICIT_BIT; } //TODO: do we need `glow::MAP_UNSYNCHRONIZED_BIT`? @@ -613,7 +613,7 @@ impl crate::Device for super::Device { } } - let data = if emulate_map && desc.usage.contains(crate::BufferUses::MAP_READ) { + let data = if emulate_map && desc.usage.contains(wgt::BufferUses::MAP_READ) { Some(Arc::new(Mutex::new(vec![0; desc.size as usize]))) } else { None @@ -727,9 +727,9 @@ impl crate::Device for super::Device { ) -> Result { let gl = &self.shared.context.lock(); - let render_usage = crate::TextureUses::COLOR_TARGET - | crate::TextureUses::DEPTH_STENCIL_WRITE - | crate::TextureUses::DEPTH_STENCIL_READ; + let render_usage = wgt::TextureUses::COLOR_TARGET + | wgt::TextureUses::DEPTH_STENCIL_WRITE + | wgt::TextureUses::DEPTH_STENCIL_READ; let format_desc = self.shared.describe_texture_format(desc.format); let inner = if render_usage.contains(desc.usage) diff --git a/wgpu-hal/src/gles/mod.rs b/wgpu-hal/src/gles/mod.rs index 2b693a2dd8..33778be685 100644 --- a/wgpu-hal/src/gles/mod.rs +++ b/wgpu-hal/src/gles/mod.rs @@ -979,8 +979,8 @@ enum Command { // It is also more efficient to emit a single command instead of two for // this. ClearDepthAndStencil(f32, u32), - BufferBarrier(glow::Buffer, crate::BufferUses), - TextureBarrier(crate::TextureUses), + BufferBarrier(glow::Buffer, wgt::BufferUses), + TextureBarrier(wgt::TextureUses), SetViewport { rect: crate::Rect, depth: Range, diff --git a/wgpu-hal/src/gles/queue.rs b/wgpu-hal/src/gles/queue.rs index 8896aa4ed0..93991a2abc 100644 --- a/wgpu-hal/src/gles/queue.rs +++ b/wgpu-hal/src/gles/queue.rs @@ -1197,35 +1197,35 @@ impl super::Queue { } C::BufferBarrier(raw, usage) => { let mut flags = 0; - if usage.contains(crate::BufferUses::VERTEX) { + if usage.contains(wgt::BufferUses::VERTEX) { flags |= glow::VERTEX_ATTRIB_ARRAY_BARRIER_BIT; unsafe { gl.bind_buffer(glow::ARRAY_BUFFER, Some(raw)) }; unsafe { gl.vertex_attrib_pointer_f32(0, 1, glow::BYTE, true, 0, 0) }; } - if usage.contains(crate::BufferUses::INDEX) { + if usage.contains(wgt::BufferUses::INDEX) { flags |= glow::ELEMENT_ARRAY_BARRIER_BIT; unsafe { gl.bind_buffer(glow::ELEMENT_ARRAY_BUFFER, Some(raw)) }; } - if usage.contains(crate::BufferUses::UNIFORM) { + if usage.contains(wgt::BufferUses::UNIFORM) { flags |= glow::UNIFORM_BARRIER_BIT; } - if usage.contains(crate::BufferUses::INDIRECT) { + if usage.contains(wgt::BufferUses::INDIRECT) { flags |= glow::COMMAND_BARRIER_BIT; unsafe { gl.bind_buffer(glow::DRAW_INDIRECT_BUFFER, Some(raw)) }; } - if usage.contains(crate::BufferUses::COPY_SRC) { + if usage.contains(wgt::BufferUses::COPY_SRC) { flags |= glow::PIXEL_BUFFER_BARRIER_BIT; unsafe { gl.bind_buffer(glow::PIXEL_UNPACK_BUFFER, Some(raw)) }; } - if usage.contains(crate::BufferUses::COPY_DST) { + if usage.contains(wgt::BufferUses::COPY_DST) { flags |= glow::PIXEL_BUFFER_BARRIER_BIT; unsafe { gl.bind_buffer(glow::PIXEL_PACK_BUFFER, Some(raw)) }; } - if usage.intersects(crate::BufferUses::MAP_READ | crate::BufferUses::MAP_WRITE) { + if usage.intersects(wgt::BufferUses::MAP_READ | wgt::BufferUses::MAP_WRITE) { flags |= glow::BUFFER_UPDATE_BARRIER_BIT; } if usage.intersects( - crate::BufferUses::STORAGE_READ_ONLY | crate::BufferUses::STORAGE_READ_WRITE, + wgt::BufferUses::STORAGE_READ_ONLY | wgt::BufferUses::STORAGE_READ_WRITE, ) { flags |= glow::SHADER_STORAGE_BARRIER_BIT; } @@ -1233,23 +1233,23 @@ impl super::Queue { } C::TextureBarrier(usage) => { let mut flags = 0; - if usage.contains(crate::TextureUses::RESOURCE) { + if usage.contains(wgt::TextureUses::RESOURCE) { flags |= glow::TEXTURE_FETCH_BARRIER_BIT; } if usage.intersects( - crate::TextureUses::STORAGE_READ_ONLY - | crate::TextureUses::STORAGE_WRITE_ONLY - | crate::TextureUses::STORAGE_READ_WRITE, + wgt::TextureUses::STORAGE_READ_ONLY + | wgt::TextureUses::STORAGE_WRITE_ONLY + | wgt::TextureUses::STORAGE_READ_WRITE, ) { flags |= glow::SHADER_IMAGE_ACCESS_BARRIER_BIT; } - if usage.contains(crate::TextureUses::COPY_DST) { + if usage.contains(wgt::TextureUses::COPY_DST) { flags |= glow::TEXTURE_UPDATE_BARRIER_BIT; } if usage.intersects( - crate::TextureUses::COLOR_TARGET - | crate::TextureUses::DEPTH_STENCIL_READ - | crate::TextureUses::DEPTH_STENCIL_WRITE, + wgt::TextureUses::COLOR_TARGET + | wgt::TextureUses::DEPTH_STENCIL_READ + | wgt::TextureUses::DEPTH_STENCIL_WRITE, ) { flags |= glow::FRAMEBUFFER_BARRIER_BIT; } diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 12234d6364..34782ce4f7 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -708,7 +708,7 @@ pub trait Device: WasmNotSendSync { /// Creates a new buffer. /// - /// The initial usage is `BufferUses::empty()`. + /// The initial usage is `wgt::BufferUses::empty()`. unsafe fn create_buffer( &self, desc: &BufferDescriptor, @@ -774,8 +774,8 @@ pub trait Device: WasmNotSendSync { /// - The returned [`BufferMapping::ptr`] must not be used after a call to /// [`Device::unmap_buffer`]. /// - /// [`MAP_READ`]: BufferUses::MAP_READ - /// [`MAP_WRITE`]: BufferUses::MAP_WRITE + /// [`MAP_READ`]: wgt::BufferUses::MAP_READ + /// [`MAP_WRITE`]: wgt::BufferUses::MAP_WRITE unsafe fn map_buffer( &self, buffer: &::Buffer, @@ -813,7 +813,7 @@ pub trait Device: WasmNotSendSync { /// Creates a new texture. /// - /// The initial usage for all subresources is `TextureUses::UNINITIALIZED`. + /// The initial usage for all subresources is `wgt::TextureUses::UNINITIALIZED`. unsafe fn create_texture( &self, desc: &TextureDescriptor, @@ -1198,7 +1198,7 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { /// Copy from an external image to an internal texture. /// Works with a single array layer. - /// Note: `dst` current usage has to be `TextureUses::COPY_DST`. + /// Note: `dst` current usage has to be `wgt::TextureUses::COPY_DST`. /// Note: the copy extent is in physical size (rounded to the block size) #[cfg(webgl)] unsafe fn copy_external_image_to_texture( @@ -1212,12 +1212,12 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { /// Copy from one texture to another. /// Works with a single array layer. - /// Note: `dst` current usage has to be `TextureUses::COPY_DST`. + /// Note: `dst` current usage has to be `wgt::TextureUses::COPY_DST`. /// Note: the copy extent is in physical size (rounded to the block size) unsafe fn copy_texture_to_texture( &mut self, src: &::Texture, - src_usage: TextureUses, + src_usage: wgt::TextureUses, dst: &::Texture, regions: T, ) where @@ -1225,7 +1225,7 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { /// Copy from buffer to texture. /// Works with a single array layer. - /// Note: `dst` current usage has to be `TextureUses::COPY_DST`. + /// Note: `dst` current usage has to be `wgt::TextureUses::COPY_DST`. /// Note: the copy extent is in physical size (rounded to the block size) unsafe fn copy_buffer_to_texture( &mut self, @@ -1241,7 +1241,7 @@ pub trait CommandEncoder: WasmNotSendSync + fmt::Debug { unsafe fn copy_texture_to_buffer( &mut self, src: &::Texture, - src_usage: TextureUses, + src_usage: wgt::TextureUses, dst: &::Buffer, regions: T, ) where @@ -1660,91 +1660,6 @@ bitflags!( } ); -bitflags::bitflags! { - /// Similar to `wgt::BufferUsages` but for internal use. - #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] - pub struct BufferUses: u16 { - /// The argument to a read-only mapping. - const MAP_READ = 1 << 0; - /// The argument to a write-only mapping. - const MAP_WRITE = 1 << 1; - /// The source of a hardware copy. - const COPY_SRC = 1 << 2; - /// The destination of a hardware copy. - const COPY_DST = 1 << 3; - /// The index buffer used for drawing. - const INDEX = 1 << 4; - /// A vertex buffer used for drawing. - const VERTEX = 1 << 5; - /// A uniform buffer bound in a bind group. - const UNIFORM = 1 << 6; - /// A read-only storage buffer used in a bind group. - const STORAGE_READ_ONLY = 1 << 7; - /// A read-write buffer used in a bind group. - const STORAGE_READ_WRITE = 1 << 8; - /// The indirect or count buffer in a indirect draw or dispatch. - const INDIRECT = 1 << 9; - /// A buffer used to store query results. - const QUERY_RESOLVE = 1 << 10; - const ACCELERATION_STRUCTURE_SCRATCH = 1 << 11; - const BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT = 1 << 12; - const TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT = 1 << 13; - /// The combination of states that a buffer may be in _at the same time_. - const INCLUSIVE = Self::MAP_READ.bits() | Self::COPY_SRC.bits() | - Self::INDEX.bits() | Self::VERTEX.bits() | Self::UNIFORM.bits() | - Self::STORAGE_READ_ONLY.bits() | Self::INDIRECT.bits() | Self::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits() | Self::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT.bits(); - /// The combination of states that a buffer must exclusively be in. - const EXCLUSIVE = Self::MAP_WRITE.bits() | Self::COPY_DST.bits() | Self::STORAGE_READ_WRITE.bits() | Self::ACCELERATION_STRUCTURE_SCRATCH.bits(); - /// The combination of all usages that the are guaranteed to be be ordered by the hardware. - /// If a usage is ordered, then if the buffer state doesn't change between draw calls, there - /// are no barriers needed for synchronization. - const ORDERED = Self::INCLUSIVE.bits() | Self::MAP_WRITE.bits(); - } -} - -bitflags::bitflags! { - /// Similar to `wgt::TextureUsages` but for internal use. - #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] - pub struct TextureUses: u16 { - /// The texture is in unknown state. - const UNINITIALIZED = 1 << 0; - /// Ready to present image to the surface. - const PRESENT = 1 << 1; - /// The source of a hardware copy. - const COPY_SRC = 1 << 2; - /// The destination of a hardware copy. - const COPY_DST = 1 << 3; - /// Read-only sampled or fetched resource. - const RESOURCE = 1 << 4; - /// The color target of a renderpass. - const COLOR_TARGET = 1 << 5; - /// Read-only depth stencil usage. - const DEPTH_STENCIL_READ = 1 << 6; - /// Read-write depth stencil usage - const DEPTH_STENCIL_WRITE = 1 << 7; - /// Read-only storage texture usage. Corresponds to a UAV in d3d, so is exclusive, despite being read only. - const STORAGE_READ_ONLY = 1 << 8; - /// Write-only storage texture usage. - const STORAGE_WRITE_ONLY = 1 << 9; - /// Read-write storage texture usage. - const STORAGE_READ_WRITE = 1 << 10; - /// The combination of states that a texture may be in _at the same time_. - const INCLUSIVE = Self::COPY_SRC.bits() | Self::RESOURCE.bits() | Self::DEPTH_STENCIL_READ.bits(); - /// The combination of states that a texture must exclusively be in. - const EXCLUSIVE = Self::COPY_DST.bits() | Self::COLOR_TARGET.bits() | Self::DEPTH_STENCIL_WRITE.bits() | Self::STORAGE_READ_ONLY.bits() | Self::STORAGE_WRITE_ONLY.bits() | Self::STORAGE_READ_WRITE.bits() | Self::PRESENT.bits(); - /// The combination of all usages that the are guaranteed to be be ordered by the hardware. - /// If a usage is ordered, then if the texture state doesn't change between draw calls, there - /// are no barriers needed for synchronization. - const ORDERED = Self::INCLUSIVE.bits() | Self::COLOR_TARGET.bits() | Self::DEPTH_STENCIL_WRITE.bits() | Self::STORAGE_READ_ONLY.bits(); - - /// Flag used by the wgpu-core texture tracker to say a texture is in different states for every sub-resource - const COMPLEX = 1 << 11; - /// Flag used by the wgpu-core texture tracker to say that the tracker does not know the state of the sub-resource. - /// This is different from UNINITIALIZED as that says the tracker does know, but the texture has not been initialized. - const UNKNOWN = 1 << 12; - } -} - #[derive(Clone, Debug)] pub struct InstanceDescriptor<'a> { pub name: &'a str, @@ -1824,8 +1739,8 @@ pub struct SurfaceCapabilities { /// Supported texture usage flags. /// - /// Must have at least `TextureUses::COLOR_TARGET` - pub usage: TextureUses, + /// Must have at least `wgt::TextureUses::COLOR_TARGET` + pub usage: wgt::TextureUses, /// List of supported V-sync modes. /// @@ -1863,7 +1778,7 @@ pub struct BufferMapping { pub struct BufferDescriptor<'a> { pub label: Label<'a>, pub size: wgt::BufferAddress, - pub usage: BufferUses, + pub usage: wgt::BufferUses, pub memory_flags: MemoryFlags, } @@ -1875,7 +1790,7 @@ pub struct TextureDescriptor<'a> { pub sample_count: u32, pub dimension: wgt::TextureDimension, pub format: wgt::TextureFormat, - pub usage: TextureUses, + pub usage: wgt::TextureUses, pub memory_flags: MemoryFlags, /// Allows views of this texture to have a different format /// than the texture does. @@ -1914,7 +1829,7 @@ pub struct TextureViewDescriptor<'a> { pub label: Label<'a>, pub format: wgt::TextureFormat, pub dimension: wgt::TextureViewDimension, - pub usage: TextureUses, + pub usage: wgt::TextureUses, pub range: wgt::ImageSubresourceRange, } @@ -2026,7 +1941,7 @@ impl<'a, T: DynBuffer + ?Sized> Clone for BufferBinding<'a, T> { #[derive(Debug)] pub struct TextureBinding<'a, T: DynTextureView + ?Sized> { pub view: &'a T, - pub usage: TextureUses, + pub usage: wgt::TextureUses, } impl<'a, T: DynTextureView + ?Sized> Clone for TextureBinding<'a, T> { @@ -2228,7 +2143,7 @@ pub struct SurfaceConfiguration { /// `SurfaceCapabilities::extents` range. pub extent: wgt::Extent3d, /// Allowed usage of surface textures, - pub usage: TextureUses, + pub usage: wgt::TextureUses, /// Allows views of swapchain texture to have a different format /// than the texture does. pub view_formats: Vec, @@ -2251,14 +2166,14 @@ pub struct StateTransition { #[derive(Debug, Clone)] pub struct BufferBarrier<'a, B: DynBuffer + ?Sized> { pub buffer: &'a B, - pub usage: StateTransition, + pub usage: StateTransition, } #[derive(Debug, Clone)] pub struct TextureBarrier<'a, T: DynTexture + ?Sized> { pub texture: &'a T, pub range: wgt::ImageSubresourceRange, - pub usage: StateTransition, + pub usage: StateTransition, } #[derive(Clone, Copy, Debug)] @@ -2304,7 +2219,7 @@ pub struct Attachment<'a, T: DynTextureView + ?Sized> { pub view: &'a T, /// Contains either a single mutating usage as a target, /// or a valid combination of read-only usages. - pub usage: TextureUses, + pub usage: wgt::TextureUses, } #[derive(Clone, Debug)] diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index c2a9541bee..a1320d00dc 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -355,12 +355,12 @@ impl crate::Adapter for super::Adapter { ], current_extent, - usage: crate::TextureUses::COLOR_TARGET - | crate::TextureUses::COPY_SRC - | crate::TextureUses::COPY_DST - | crate::TextureUses::STORAGE_READ_ONLY - | crate::TextureUses::STORAGE_WRITE_ONLY - | crate::TextureUses::STORAGE_READ_WRITE, + usage: wgt::TextureUses::COLOR_TARGET + | wgt::TextureUses::COPY_SRC + | wgt::TextureUses::COPY_DST + | wgt::TextureUses::STORAGE_READ_ONLY + | wgt::TextureUses::STORAGE_WRITE_ONLY + | wgt::TextureUses::STORAGE_READ_WRITE, }) } diff --git a/wgpu-hal/src/metal/command.rs b/wgpu-hal/src/metal/command.rs index a66349cbf4..c3f2c8cc59 100644 --- a/wgpu-hal/src/metal/command.rs +++ b/wgpu-hal/src/metal/command.rs @@ -279,7 +279,7 @@ impl crate::CommandEncoder for super::CommandEncoder { unsafe fn copy_texture_to_texture( &mut self, src: &super::Texture, - _src_usage: crate::TextureUses, + _src_usage: wgt::TextureUses, dst: &super::Texture, regions: T, ) where @@ -358,7 +358,7 @@ impl crate::CommandEncoder for super::CommandEncoder { unsafe fn copy_texture_to_buffer( &mut self, src: &super::Texture, - _src_usage: crate::TextureUses, + _src_usage: wgt::TextureUses, dst: &super::Buffer, regions: T, ) where diff --git a/wgpu-hal/src/metal/conv.rs b/wgpu-hal/src/metal/conv.rs index ef71f168ca..8ac7d5943e 100644 --- a/wgpu-hal/src/metal/conv.rs +++ b/wgpu-hal/src/metal/conv.rs @@ -1,8 +1,8 @@ pub fn map_texture_usage( format: wgt::TextureFormat, - usage: crate::TextureUses, + usage: wgt::TextureUses, ) -> metal::MTLTextureUsage { - use crate::TextureUses as Tu; + use wgt::TextureUses as Tu; let mut mtl_usage = metal::MTLTextureUsage::Unknown; diff --git a/wgpu-hal/src/metal/device.rs b/wgpu-hal/src/metal/device.rs index b64fa7c935..1296bafbaf 100644 --- a/wgpu-hal/src/metal/device.rs +++ b/wgpu-hal/src/metal/device.rs @@ -340,8 +340,8 @@ impl crate::Device for super::Device { type A = super::Api; unsafe fn create_buffer(&self, desc: &crate::BufferDescriptor) -> DeviceResult { - let map_read = desc.usage.contains(crate::BufferUses::MAP_READ); - let map_write = desc.usage.contains(crate::BufferUses::MAP_WRITE); + let map_read = desc.usage.contains(wgt::BufferUses::MAP_READ); + let map_write = desc.usage.contains(wgt::BufferUses::MAP_WRITE); let mut options = metal::MTLResourceOptions::empty(); options |= if map_read || map_write { diff --git a/wgpu-hal/src/metal/surface.rs b/wgpu-hal/src/metal/surface.rs index b35c73c910..5f4bcaeb81 100644 --- a/wgpu-hal/src/metal/surface.rs +++ b/wgpu-hal/src/metal/surface.rs @@ -289,7 +289,7 @@ impl crate::Surface for super::Surface { *self.extent.write() = config.extent; let render_layer = self.render_layer.lock(); - let framebuffer_only = config.usage == crate::TextureUses::COLOR_TARGET; + let framebuffer_only = config.usage == wgt::TextureUses::COLOR_TARGET; let display_sync = match config.present_mode { wgt::PresentMode::Fifo => true, wgt::PresentMode::Immediate => false, diff --git a/wgpu-hal/src/vulkan/command.rs b/wgpu-hal/src/vulkan/command.rs index 8c6c5281fe..8e5f243ee5 100644 --- a/wgpu-hal/src/vulkan/command.rs +++ b/wgpu-hal/src/vulkan/command.rs @@ -285,7 +285,7 @@ impl crate::CommandEncoder for super::CommandEncoder { unsafe fn copy_texture_to_texture( &mut self, src: &super::Texture, - src_usage: crate::TextureUses, + src_usage: wgt::TextureUses, dst: &super::Texture, regions: T, ) where @@ -345,7 +345,7 @@ impl crate::CommandEncoder for super::CommandEncoder { unsafe fn copy_texture_to_buffer( &mut self, src: &super::Texture, - src_usage: crate::TextureUses, + src_usage: wgt::TextureUses, dst: &super::Buffer, regions: T, ) where @@ -1157,7 +1157,7 @@ impl crate::CommandEncoder for super::CommandEncoder { #[test] fn check_dst_image_layout() { assert_eq!( - conv::derive_image_layout(crate::TextureUses::COPY_DST, wgt::TextureFormat::Rgba8Unorm), + conv::derive_image_layout(wgt::TextureUses::COPY_DST, wgt::TextureFormat::Rgba8Unorm), DST_IMAGE_LAYOUT ); } diff --git a/wgpu-hal/src/vulkan/conv.rs b/wgpu-hal/src/vulkan/conv.rs index b5ae72b4db..70d0bdfcd9 100644 --- a/wgpu-hal/src/vulkan/conv.rs +++ b/wgpu-hal/src/vulkan/conv.rs @@ -218,22 +218,22 @@ impl crate::ColorAttachment<'_, super::TextureView> { } pub fn derive_image_layout( - usage: crate::TextureUses, + usage: wgt::TextureUses, format: wgt::TextureFormat, ) -> vk::ImageLayout { // Note: depth textures are always sampled with RODS layout let is_color = !format.is_depth_stencil_format(); match usage { - crate::TextureUses::UNINITIALIZED => vk::ImageLayout::UNDEFINED, - crate::TextureUses::COPY_SRC => vk::ImageLayout::TRANSFER_SRC_OPTIMAL, - crate::TextureUses::COPY_DST => vk::ImageLayout::TRANSFER_DST_OPTIMAL, - crate::TextureUses::RESOURCE if is_color => vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, - crate::TextureUses::COLOR_TARGET => vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL, - crate::TextureUses::DEPTH_STENCIL_WRITE => { + wgt::TextureUses::UNINITIALIZED => vk::ImageLayout::UNDEFINED, + wgt::TextureUses::COPY_SRC => vk::ImageLayout::TRANSFER_SRC_OPTIMAL, + wgt::TextureUses::COPY_DST => vk::ImageLayout::TRANSFER_DST_OPTIMAL, + wgt::TextureUses::RESOURCE if is_color => vk::ImageLayout::SHADER_READ_ONLY_OPTIMAL, + wgt::TextureUses::COLOR_TARGET => vk::ImageLayout::COLOR_ATTACHMENT_OPTIMAL, + wgt::TextureUses::DEPTH_STENCIL_WRITE => { vk::ImageLayout::DEPTH_STENCIL_ATTACHMENT_OPTIMAL } _ => { - if usage == crate::TextureUses::PRESENT { + if usage == wgt::TextureUses::PRESENT { vk::ImageLayout::PRESENT_SRC_KHR } else if is_color { vk::ImageLayout::GENERAL @@ -244,29 +244,29 @@ pub fn derive_image_layout( } } -pub fn map_texture_usage(usage: crate::TextureUses) -> vk::ImageUsageFlags { +pub fn map_texture_usage(usage: wgt::TextureUses) -> vk::ImageUsageFlags { let mut flags = vk::ImageUsageFlags::empty(); - if usage.contains(crate::TextureUses::COPY_SRC) { + if usage.contains(wgt::TextureUses::COPY_SRC) { flags |= vk::ImageUsageFlags::TRANSFER_SRC; } - if usage.contains(crate::TextureUses::COPY_DST) { + if usage.contains(wgt::TextureUses::COPY_DST) { flags |= vk::ImageUsageFlags::TRANSFER_DST; } - if usage.contains(crate::TextureUses::RESOURCE) { + if usage.contains(wgt::TextureUses::RESOURCE) { flags |= vk::ImageUsageFlags::SAMPLED; } - if usage.contains(crate::TextureUses::COLOR_TARGET) { + if usage.contains(wgt::TextureUses::COLOR_TARGET) { flags |= vk::ImageUsageFlags::COLOR_ATTACHMENT; } if usage.intersects( - crate::TextureUses::DEPTH_STENCIL_READ | crate::TextureUses::DEPTH_STENCIL_WRITE, + wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::DEPTH_STENCIL_WRITE, ) { flags |= vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT; } if usage.intersects( - crate::TextureUses::STORAGE_READ_ONLY - | crate::TextureUses::STORAGE_WRITE_ONLY - | crate::TextureUses::STORAGE_READ_WRITE, + wgt::TextureUses::STORAGE_READ_ONLY + | wgt::TextureUses::STORAGE_WRITE_ONLY + | wgt::TextureUses::STORAGE_READ_WRITE, ) { flags |= vk::ImageUsageFlags::STORAGE; } @@ -274,7 +274,7 @@ pub fn map_texture_usage(usage: crate::TextureUses) -> vk::ImageUsageFlags { } pub fn map_texture_usage_to_barrier( - usage: crate::TextureUses, + usage: wgt::TextureUses, ) -> (vk::PipelineStageFlags, vk::AccessFlags) { let mut stages = vk::PipelineStageFlags::empty(); let mut access = vk::AccessFlags::empty(); @@ -282,47 +282,47 @@ pub fn map_texture_usage_to_barrier( | vk::PipelineStageFlags::FRAGMENT_SHADER | vk::PipelineStageFlags::COMPUTE_SHADER; - if usage.contains(crate::TextureUses::COPY_SRC) { + if usage.contains(wgt::TextureUses::COPY_SRC) { stages |= vk::PipelineStageFlags::TRANSFER; access |= vk::AccessFlags::TRANSFER_READ; } - if usage.contains(crate::TextureUses::COPY_DST) { + if usage.contains(wgt::TextureUses::COPY_DST) { stages |= vk::PipelineStageFlags::TRANSFER; access |= vk::AccessFlags::TRANSFER_WRITE; } - if usage.contains(crate::TextureUses::RESOURCE) { + if usage.contains(wgt::TextureUses::RESOURCE) { stages |= shader_stages; access |= vk::AccessFlags::SHADER_READ; } - if usage.contains(crate::TextureUses::COLOR_TARGET) { + if usage.contains(wgt::TextureUses::COLOR_TARGET) { stages |= vk::PipelineStageFlags::COLOR_ATTACHMENT_OUTPUT; access |= vk::AccessFlags::COLOR_ATTACHMENT_READ | vk::AccessFlags::COLOR_ATTACHMENT_WRITE; } - if usage.intersects(crate::TextureUses::DEPTH_STENCIL_READ) { + if usage.intersects(wgt::TextureUses::DEPTH_STENCIL_READ) { stages |= vk::PipelineStageFlags::EARLY_FRAGMENT_TESTS | vk::PipelineStageFlags::LATE_FRAGMENT_TESTS; access |= vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_READ; } - if usage.intersects(crate::TextureUses::DEPTH_STENCIL_WRITE) { + if usage.intersects(wgt::TextureUses::DEPTH_STENCIL_WRITE) { stages |= vk::PipelineStageFlags::EARLY_FRAGMENT_TESTS | vk::PipelineStageFlags::LATE_FRAGMENT_TESTS; access |= vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_READ | vk::AccessFlags::DEPTH_STENCIL_ATTACHMENT_WRITE; } if usage - .intersects(crate::TextureUses::STORAGE_READ_ONLY | crate::TextureUses::STORAGE_READ_WRITE) + .intersects(wgt::TextureUses::STORAGE_READ_ONLY | wgt::TextureUses::STORAGE_READ_WRITE) { stages |= shader_stages; access |= vk::AccessFlags::SHADER_READ; } if usage - .intersects(crate::TextureUses::STORAGE_WRITE_ONLY | crate::TextureUses::STORAGE_READ_WRITE) + .intersects(wgt::TextureUses::STORAGE_WRITE_ONLY | wgt::TextureUses::STORAGE_READ_WRITE) { stages |= shader_stages; access |= vk::AccessFlags::SHADER_WRITE; } - if usage == crate::TextureUses::UNINITIALIZED || usage == crate::TextureUses::PRESENT { + if usage == wgt::TextureUses::UNINITIALIZED || usage == wgt::TextureUses::PRESENT { ( vk::PipelineStageFlags::TOP_OF_PIPE, vk::AccessFlags::empty(), @@ -332,27 +332,27 @@ pub fn map_texture_usage_to_barrier( } } -pub fn map_vk_image_usage(usage: vk::ImageUsageFlags) -> crate::TextureUses { - let mut bits = crate::TextureUses::empty(); +pub fn map_vk_image_usage(usage: vk::ImageUsageFlags) -> wgt::TextureUses { + let mut bits = wgt::TextureUses::empty(); if usage.contains(vk::ImageUsageFlags::TRANSFER_SRC) { - bits |= crate::TextureUses::COPY_SRC; + bits |= wgt::TextureUses::COPY_SRC; } if usage.contains(vk::ImageUsageFlags::TRANSFER_DST) { - bits |= crate::TextureUses::COPY_DST; + bits |= wgt::TextureUses::COPY_DST; } if usage.contains(vk::ImageUsageFlags::SAMPLED) { - bits |= crate::TextureUses::RESOURCE; + bits |= wgt::TextureUses::RESOURCE; } if usage.contains(vk::ImageUsageFlags::COLOR_ATTACHMENT) { - bits |= crate::TextureUses::COLOR_TARGET; + bits |= wgt::TextureUses::COLOR_TARGET; } if usage.contains(vk::ImageUsageFlags::DEPTH_STENCIL_ATTACHMENT) { - bits |= crate::TextureUses::DEPTH_STENCIL_READ | crate::TextureUses::DEPTH_STENCIL_WRITE; + bits |= wgt::TextureUses::DEPTH_STENCIL_READ | wgt::TextureUses::DEPTH_STENCIL_WRITE; } if usage.contains(vk::ImageUsageFlags::STORAGE) { - bits |= crate::TextureUses::STORAGE_READ_ONLY - | crate::TextureUses::STORAGE_WRITE_ONLY - | crate::TextureUses::STORAGE_READ_WRITE; + bits |= wgt::TextureUses::STORAGE_READ_ONLY + | wgt::TextureUses::STORAGE_WRITE_ONLY + | wgt::TextureUses::STORAGE_READ_WRITE; } bits } @@ -516,37 +516,35 @@ pub fn map_vk_composite_alpha(flags: vk::CompositeAlphaFlagsKHR) -> Vec vk::BufferUsageFlags { +pub fn map_buffer_usage(usage: wgt::BufferUses) -> vk::BufferUsageFlags { let mut flags = vk::BufferUsageFlags::empty(); - if usage.contains(crate::BufferUses::COPY_SRC) { + if usage.contains(wgt::BufferUses::COPY_SRC) { flags |= vk::BufferUsageFlags::TRANSFER_SRC; } - if usage.contains(crate::BufferUses::COPY_DST) { + if usage.contains(wgt::BufferUses::COPY_DST) { flags |= vk::BufferUsageFlags::TRANSFER_DST; } - if usage.contains(crate::BufferUses::UNIFORM) { + if usage.contains(wgt::BufferUses::UNIFORM) { flags |= vk::BufferUsageFlags::UNIFORM_BUFFER; } - if usage - .intersects(crate::BufferUses::STORAGE_READ_ONLY | crate::BufferUses::STORAGE_READ_WRITE) - { + if usage.intersects(wgt::BufferUses::STORAGE_READ_ONLY | wgt::BufferUses::STORAGE_READ_WRITE) { flags |= vk::BufferUsageFlags::STORAGE_BUFFER; } - if usage.contains(crate::BufferUses::INDEX) { + if usage.contains(wgt::BufferUses::INDEX) { flags |= vk::BufferUsageFlags::INDEX_BUFFER; } - if usage.contains(crate::BufferUses::VERTEX) { + if usage.contains(wgt::BufferUses::VERTEX) { flags |= vk::BufferUsageFlags::VERTEX_BUFFER; } - if usage.contains(crate::BufferUses::INDIRECT) { + if usage.contains(wgt::BufferUses::INDIRECT) { flags |= vk::BufferUsageFlags::INDIRECT_BUFFER; } - if usage.contains(crate::BufferUses::ACCELERATION_STRUCTURE_SCRATCH) { + if usage.contains(wgt::BufferUses::ACCELERATION_STRUCTURE_SCRATCH) { flags |= vk::BufferUsageFlags::STORAGE_BUFFER | vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS; } if usage.intersects( - crate::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT - | crate::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT + | wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, ) { flags |= vk::BufferUsageFlags::ACCELERATION_STRUCTURE_BUILD_INPUT_READ_ONLY_KHR | vk::BufferUsageFlags::SHADER_DEVICE_ADDRESS; @@ -555,7 +553,7 @@ pub fn map_buffer_usage(usage: crate::BufferUses) -> vk::BufferUsageFlags { } pub fn map_buffer_usage_to_barrier( - usage: crate::BufferUses, + usage: wgt::BufferUses, ) -> (vk::PipelineStageFlags, vk::AccessFlags) { let mut stages = vk::PipelineStageFlags::empty(); let mut access = vk::AccessFlags::empty(); @@ -563,50 +561,50 @@ pub fn map_buffer_usage_to_barrier( | vk::PipelineStageFlags::FRAGMENT_SHADER | vk::PipelineStageFlags::COMPUTE_SHADER; - if usage.contains(crate::BufferUses::MAP_READ) { + if usage.contains(wgt::BufferUses::MAP_READ) { stages |= vk::PipelineStageFlags::HOST; access |= vk::AccessFlags::HOST_READ; } - if usage.contains(crate::BufferUses::MAP_WRITE) { + if usage.contains(wgt::BufferUses::MAP_WRITE) { stages |= vk::PipelineStageFlags::HOST; access |= vk::AccessFlags::HOST_WRITE; } - if usage.contains(crate::BufferUses::COPY_SRC) { + if usage.contains(wgt::BufferUses::COPY_SRC) { stages |= vk::PipelineStageFlags::TRANSFER; access |= vk::AccessFlags::TRANSFER_READ; } - if usage.contains(crate::BufferUses::COPY_DST) { + if usage.contains(wgt::BufferUses::COPY_DST) { stages |= vk::PipelineStageFlags::TRANSFER; access |= vk::AccessFlags::TRANSFER_WRITE; } - if usage.contains(crate::BufferUses::UNIFORM) { + if usage.contains(wgt::BufferUses::UNIFORM) { stages |= shader_stages; access |= vk::AccessFlags::UNIFORM_READ; } - if usage.intersects(crate::BufferUses::STORAGE_READ_ONLY) { + if usage.intersects(wgt::BufferUses::STORAGE_READ_ONLY) { stages |= shader_stages; access |= vk::AccessFlags::SHADER_READ; } - if usage.intersects(crate::BufferUses::STORAGE_READ_WRITE) { + if usage.intersects(wgt::BufferUses::STORAGE_READ_WRITE) { stages |= shader_stages; access |= vk::AccessFlags::SHADER_READ | vk::AccessFlags::SHADER_WRITE; } - if usage.contains(crate::BufferUses::INDEX) { + if usage.contains(wgt::BufferUses::INDEX) { stages |= vk::PipelineStageFlags::VERTEX_INPUT; access |= vk::AccessFlags::INDEX_READ; } - if usage.contains(crate::BufferUses::VERTEX) { + if usage.contains(wgt::BufferUses::VERTEX) { stages |= vk::PipelineStageFlags::VERTEX_INPUT; access |= vk::AccessFlags::VERTEX_ATTRIBUTE_READ; } - if usage.contains(crate::BufferUses::INDIRECT) { + if usage.contains(wgt::BufferUses::INDIRECT) { stages |= vk::PipelineStageFlags::DRAW_INDIRECT; access |= vk::AccessFlags::INDIRECT_COMMAND_READ; } if usage.intersects( - crate::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT - | crate::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT - | crate::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT + | wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT + | wgt::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, ) { stages |= vk::PipelineStageFlags::ACCELERATION_STRUCTURE_BUILD_KHR; access |= vk::AccessFlags::ACCELERATION_STRUCTURE_READ_KHR diff --git a/wgpu-hal/src/vulkan/device.rs b/wgpu-hal/src/vulkan/device.rs index fdf1f3e3ef..bb05010057 100644 --- a/wgpu-hal/src/vulkan/device.rs +++ b/wgpu-hal/src/vulkan/device.rs @@ -1039,17 +1039,17 @@ impl crate::Device for super::Device { let mut alloc_usage = if desc .usage - .intersects(crate::BufferUses::MAP_READ | crate::BufferUses::MAP_WRITE) + .intersects(wgt::BufferUses::MAP_READ | wgt::BufferUses::MAP_WRITE) { let mut flags = gpu_alloc::UsageFlags::HOST_ACCESS; //TODO: find a way to use `crate::MemoryFlags::PREFER_COHERENT` flags.set( gpu_alloc::UsageFlags::DOWNLOAD, - desc.usage.contains(crate::BufferUses::MAP_READ), + desc.usage.contains(wgt::BufferUses::MAP_READ), ); flags.set( gpu_alloc::UsageFlags::UPLOAD, - desc.usage.contains(crate::BufferUses::MAP_WRITE), + desc.usage.contains(wgt::BufferUses::MAP_WRITE), ); flags } else { diff --git a/wgpu-hal/src/vulkan/mod.rs b/wgpu-hal/src/vulkan/mod.rs index 1f75bba215..3cc147e00f 100644 --- a/wgpu-hal/src/vulkan/mod.rs +++ b/wgpu-hal/src/vulkan/mod.rs @@ -613,7 +613,7 @@ struct FramebufferAttachment { /// Can be NULL if the framebuffer is image-less raw: vk::ImageView, raw_image_flags: vk::ImageCreateFlags, - view_usage: crate::TextureUses, + view_usage: wgt::TextureUses, view_format: wgt::TextureFormat, raw_view_formats: Vec, } @@ -792,7 +792,7 @@ pub struct Texture { drop_guard: Option, external_memory: Option, block: Option>, - usage: crate::TextureUses, + usage: wgt::TextureUses, format: wgt::TextureFormat, raw_flags: vk::ImageCreateFlags, copy_size: crate::CopyExtent, diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index 2e1426b9e8..b38c9cc3c6 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2566,7 +2566,7 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { }), texture_transitions.iter().map(|t| wgt::TextureTransition { texture: t.texture.inner.as_core().id, - selector: t.selector, + selector: t.selector.clone(), state: t.state, }), ); From 0e98d93a053129673fe53800a6e4a1f5e888aee6 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sat, 18 Jan 2025 11:24:25 -0800 Subject: [PATCH 17/26] Fixes --- wgpu/src/api/command_encoder.rs | 19 ++++++++++++++----- wgpu/src/backend/webgpu.rs | 6 +++--- wgpu/src/backend/wgpu_core.rs | 18 +++++++++++------- wgpu/src/dispatch.rs | 6 +++--- 4 files changed, 31 insertions(+), 18 deletions(-) diff --git a/wgpu/src/api/command_encoder.rs b/wgpu/src/api/command_encoder.rs index 1111053acd..688a12acf0 100644 --- a/wgpu/src/api/command_encoder.rs +++ b/wgpu/src/api/command_encoder.rs @@ -395,12 +395,21 @@ impl CommandEncoder { /// /// A user wanting to interoperate with the underlying native graphics APIs (Vulkan, DirectX12, Metal, etc) can use this API to generate barriers between wgpu commands and /// the native API commands, for synchronization and resource state transition purposes. - pub fn transition_resources( + pub fn transition_resources<'a>( &mut self, - buffer_transitions: &[wgt::BufferTransition<&Buffer>], - texture_transitions: &[wgt::TextureTransition<&Texture>], + buffer_transitions: impl Iterator>, + texture_transitions: impl Iterator>, ) { - self.inner - .transition_resources(buffer_transitions, texture_transitions); + self.inner.transition_resources( + &mut buffer_transitions.map(|t| wgt::BufferTransition { + buffer: &t.buffer.inner, + state: t.state, + }), + &mut texture_transitions.map(|t| wgt::TextureTransition { + texture: &t.texture.inner, + selector: t.selector, + state: t.state, + }), + ); } } diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 70b6ae5a99..e5b8fffa88 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -3108,10 +3108,10 @@ impl dispatch::CommandEncoderInterface for WebCommandEncoder { unimplemented!("Raytracing not implemented for web"); } - fn transition_resources( + fn transition_resources<'a>( &mut self, - _buffer_transitions: &[wgt::BufferTransition<&DispatchBuffer>], - _texture_transitions: &[wgt::TextureTransition<&DispatchTexture>], + _buffer_transitions: &mut dyn Iterator>, + _texture_transitions: &mut dyn Iterator>, ) { // no-op } diff --git a/wgpu/src/backend/wgpu_core.rs b/wgpu/src/backend/wgpu_core.rs index b38c9cc3c6..7ab4d3f449 100644 --- a/wgpu/src/backend/wgpu_core.rs +++ b/wgpu/src/backend/wgpu_core.rs @@ -2553,19 +2553,23 @@ impl dispatch::CommandEncoderInterface for CoreCommandEncoder { } } - fn transition_resources( + fn transition_resources<'a>( &mut self, - buffer_transitions: &[wgt::BufferTransition<&crate::Buffer>], - texture_transitions: &[wgt::TextureTransition<&crate::Texture>], + buffer_transitions: &mut dyn Iterator< + Item = wgt::BufferTransition<&'a dispatch::DispatchBuffer>, + >, + texture_transitions: &mut dyn Iterator< + Item = wgt::TextureTransition<&'a dispatch::DispatchTexture>, + >, ) { let result = self.context.0.command_encoder_transition_resources( self.id, - buffer_transitions.iter().map(|t| wgt::BufferTransition { - buffer: t.buffer.inner.as_core().id, + buffer_transitions.map(|t| wgt::BufferTransition { + buffer: t.buffer.as_core().id, state: t.state, }), - texture_transitions.iter().map(|t| wgt::TextureTransition { - texture: t.texture.inner.as_core().id, + texture_transitions.map(|t| wgt::TextureTransition { + texture: t.texture.as_core().id, selector: t.selector.clone(), state: t.state, }), diff --git a/wgpu/src/dispatch.rs b/wgpu/src/dispatch.rs index 7cba0cf108..ba9e328f33 100644 --- a/wgpu/src/dispatch.rs +++ b/wgpu/src/dispatch.rs @@ -355,10 +355,10 @@ pub trait CommandEncoderInterface: CommonTraits { tlas: &mut dyn Iterator, ); - fn transition_resources( + fn transition_resources<'a>( &mut self, - buffer_transitions: &[wgt::BufferTransition<&DispatchBuffer>], - texture_transitions: &[wgt::TextureTransition<&DispatchTexture>], + buffer_transitions: &mut dyn Iterator>, + texture_transitions: &mut dyn Iterator>, ); } pub trait ComputePassInterface: CommonTraits { From 08807c3d21964d09eb6055386bc72632500fc276 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sat, 18 Jan 2025 11:30:17 -0800 Subject: [PATCH 18/26] Format import --- wgpu-core/src/command/ray_tracing.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/wgpu-core/src/command/ray_tracing.rs b/wgpu-core/src/command/ray_tracing.rs index c0891b45e5..2e6d2f66cf 100644 --- a/wgpu-core/src/command/ray_tracing.rs +++ b/wgpu-core/src/command/ray_tracing.rs @@ -17,10 +17,9 @@ use crate::{ FastHashSet, }; -use wgt::{math::align_to, BufferUsages, Features}; +use wgt::{math::align_to, BufferUsages, BufferUses, Features}; use super::CommandBufferMutable; -use wgt::BufferUses; use std::{ cmp::max, num::NonZeroU64, From 8e3b178b7459d9c22928c9127573923378460f50 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sat, 18 Jan 2025 11:30:45 -0800 Subject: [PATCH 19/26] Format another file --- wgpu-hal/src/gles/command.rs | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/wgpu-hal/src/gles/command.rs b/wgpu-hal/src/gles/command.rs index b3d67ace91..b706c116e8 100644 --- a/wgpu-hal/src/gles/command.rs +++ b/wgpu-hal/src/gles/command.rs @@ -287,11 +287,7 @@ impl crate::CommandEncoder for super::CommandEncoder { } for bar in barriers { // GLES only synchronizes storage -> anything explicitly - if !bar - .usage - .from - .contains(wgt::BufferUses::STORAGE_READ_WRITE) - { + if !bar.usage.from.contains(wgt::BufferUses::STORAGE_READ_WRITE) { continue; } self.cmd_buffer From b81c1c927222fbfcf8cd96a3aef6b6db4fc40daa Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Sat, 18 Jan 2025 11:33:39 -0800 Subject: [PATCH 20/26] Fixes --- tests/tests/transition_resources.rs | 7 ++++--- wgpu/src/backend/webgpu.rs | 8 ++++++-- 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/tests/tests/transition_resources.rs b/tests/tests/transition_resources.rs index dc2a274b56..ad54a0cfc8 100644 --- a/tests/tests/transition_resources.rs +++ b/tests/tests/transition_resources.rs @@ -26,12 +26,13 @@ static TRANSITION_RESOURCES: GpuTestConfiguration = GpuTestConfiguration::new(). .create_command_encoder(&CommandEncoderDescriptor { label: None }); encoder.transition_resources( - &[], - &[TextureTransition { + std::iter::empty(), + [TextureTransition { texture: &texture, selector: None, state: TextureUses::COLOR_TARGET, - }], + }] + .into_iter(), ); ctx.queue.submit([encoder.finish()]); diff --git a/wgpu/src/backend/webgpu.rs b/wgpu/src/backend/webgpu.rs index 0113512eed..ad4f7d7099 100644 --- a/wgpu/src/backend/webgpu.rs +++ b/wgpu/src/backend/webgpu.rs @@ -3106,8 +3106,12 @@ impl dispatch::CommandEncoderInterface for WebCommandEncoder { fn transition_resources<'a>( &mut self, - _buffer_transitions: &mut dyn Iterator>, - _texture_transitions: &mut dyn Iterator>, + _buffer_transitions: &mut dyn Iterator< + Item = wgt::BufferTransition<&'a dispatch::DispatchBuffer>, + >, + _texture_transitions: &mut dyn Iterator< + Item = wgt::TextureTransition<&'a dispatch::DispatchTexture>, + >, ) { // no-op } From cefa9bab00f9184497d7c78b4383f883bd211f50 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Wed, 22 Jan 2025 19:13:12 -0800 Subject: [PATCH 21/26] Make module private --- wgpu-core/src/track/mod.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index a3586ea638..3cd9a4ecba 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -99,7 +99,7 @@ mod buffer; mod metadata; mod range; mod stateless; -pub(crate) mod texture; +mod texture; use crate::{ binding_model, command, From 4e49e5d23dd3a1e85e81095d7884733d4e45aa6a Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Thu, 23 Jan 2025 19:05:41 -0800 Subject: [PATCH 22/26] Fix imports --- wgpu-hal/src/dx12/device.rs | 2 +- wgpu/src/util/device.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 47e2027a2d..e5a1b738f2 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -1550,7 +1550,7 @@ impl crate::Device for super::Device { let buffer_desc = crate::BufferDescriptor { label: None, size: buffer_size, - usage: crate::BufferUses::STORAGE_READ_ONLY | crate::BufferUses::MAP_WRITE, + usage: wgt::BufferUses::STORAGE_READ_ONLY | wgt::BufferUses::MAP_WRITE, // D3D12 backend doesn't care about the memory flags memory_flags: crate::MemoryFlags::empty(), }; diff --git a/wgpu/src/util/device.rs b/wgpu/src/util/device.rs index 9e087cb7a2..54dc77b176 100644 --- a/wgpu/src/util/device.rs +++ b/wgpu/src/util/device.rs @@ -9,7 +9,7 @@ pub struct BufferInitDescriptor<'a> { pub contents: &'a [u8], /// Usages of a buffer. If the buffer is used in any way that isn't specified here, the operation /// will panic. - pub usage: crate::BufferUsages, + pub usage: wgt::BufferUsages, } /// Utility methods not meant to be in the main API. From 2f2e9ddfbfd1733803d0ab37435b67c62b7cee59 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Thu, 23 Jan 2025 19:13:03 -0800 Subject: [PATCH 23/26] Fix test imports --- tests/tests/transition_resources.rs | 20 ++++++++------------ 1 file changed, 8 insertions(+), 12 deletions(-) diff --git a/tests/tests/transition_resources.rs b/tests/tests/transition_resources.rs index ad54a0cfc8..b54ffd24e9 100644 --- a/tests/tests/transition_resources.rs +++ b/tests/tests/transition_resources.rs @@ -1,36 +1,32 @@ use wgpu_test::{gpu_test, GpuTestConfiguration}; -use wgt::{ - CommandEncoderDescriptor, Extent3d, TextureDescriptor, TextureDimension, TextureFormat, - TextureTransition, TextureUsages, TextureUses, -}; #[gpu_test] static TRANSITION_RESOURCES: GpuTestConfiguration = GpuTestConfiguration::new().run_sync(|ctx| { - let texture = ctx.device.create_texture(&TextureDescriptor { + let texture = ctx.device.create_texture(&wgpu::TextureDescriptor { label: None, - size: Extent3d { + size: wgpu::Extent3d { width: 32, height: 32, depth_or_array_layers: 1, }, mip_level_count: 1, sample_count: 1, - dimension: TextureDimension::D2, - format: TextureFormat::Rgba8Unorm, - usage: TextureUsages::RENDER_ATTACHMENT | TextureUsages::TEXTURE_BINDING, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::Rgba8Unorm, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT | wgpu::TextureUsages::TEXTURE_BINDING, view_formats: &[], }); let mut encoder = ctx .device - .create_command_encoder(&CommandEncoderDescriptor { label: None }); + .create_command_encoder(&wgpu::CommandEncoderDescriptor { label: None }); encoder.transition_resources( std::iter::empty(), - [TextureTransition { + [wgpu::wgt::TextureTransition { texture: &texture, selector: None, - state: TextureUses::COLOR_TARGET, + state: wgpu::wgt::TextureUses::COLOR_TARGET, }] .into_iter(), ); From 11a6d379e0622cc7743788919b3dfa9efebc154b Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Thu, 23 Jan 2025 19:14:15 -0800 Subject: [PATCH 24/26] Rexport types --- tests/tests/transition_resources.rs | 4 ++-- wgpu/src/lib.rs | 36 ++++++++++++++--------------- 2 files changed, 20 insertions(+), 20 deletions(-) diff --git a/tests/tests/transition_resources.rs b/tests/tests/transition_resources.rs index b54ffd24e9..5ae8f9a272 100644 --- a/tests/tests/transition_resources.rs +++ b/tests/tests/transition_resources.rs @@ -23,10 +23,10 @@ static TRANSITION_RESOURCES: GpuTestConfiguration = GpuTestConfiguration::new(). encoder.transition_resources( std::iter::empty(), - [wgpu::wgt::TextureTransition { + [wgpu::TextureTransition { texture: &texture, selector: None, - state: wgpu::wgt::TextureUses::COLOR_TARGET, + state: wgpu::TextureUses::COLOR_TARGET, }] .into_iter(), ); diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 8fb2a425ad..29cf6fe163 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -60,24 +60,24 @@ pub use api::*; pub use wgt::{ AdapterInfo, AddressMode, AstcBlock, AstcChannel, Backend, BackendOptions, Backends, BindGroupLayoutEntry, BindingType, BlendComponent, BlendFactor, BlendOperation, BlendState, - BufferAddress, BufferBindingType, BufferSize, BufferUsages, Color, ColorTargetState, - ColorWrites, CommandBufferDescriptor, CompareFunction, CompositeAlphaMode, - CopyExternalImageDestInfo, CoreCounters, DepthBiasState, DepthStencilState, DeviceLostReason, - DeviceType, DownlevelCapabilities, DownlevelFlags, DownlevelLimits, Dx12BackendOptions, - Dx12Compiler, DynamicOffset, Extent3d, Face, Features, FilterMode, FrontFace, GlBackendOptions, - Gles3MinorVersion, HalCounters, ImageSubresourceRange, IndexFormat, InstanceDescriptor, - InstanceFlags, InternalCounters, Limits, MaintainResult, MemoryHints, MultisampleState, - Origin2d, Origin3d, PipelineStatisticsTypes, PolygonMode, PowerPreference, - PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState, PrimitiveTopology, - PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBindingType, SamplerBorderColor, - ShaderLocation, ShaderModel, ShaderRuntimeChecks, ShaderStages, StencilFaceState, - StencilOperation, StencilState, StorageTextureAccess, SurfaceCapabilities, SurfaceStatus, - TexelCopyBufferLayout, TextureAspect, TextureDimension, TextureFormat, - TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, TextureUsages, - TextureViewDimension, VertexAttribute, VertexFormat, VertexStepMode, WasmNotSend, - WasmNotSendSync, WasmNotSync, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, - MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT, QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, - QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT, + BufferAddress, BufferBindingType, BufferSize, BufferTransition, BufferUsages, BufferUses, + Color, ColorTargetState, ColorWrites, CommandBufferDescriptor, CompareFunction, + CompositeAlphaMode, CopyExternalImageDestInfo, CoreCounters, DepthBiasState, DepthStencilState, + DeviceLostReason, DeviceType, DownlevelCapabilities, DownlevelFlags, DownlevelLimits, + Dx12BackendOptions, Dx12Compiler, DynamicOffset, Extent3d, Face, Features, FilterMode, + FrontFace, GlBackendOptions, Gles3MinorVersion, HalCounters, ImageSubresourceRange, + IndexFormat, InstanceDescriptor, InstanceFlags, InternalCounters, Limits, MaintainResult, + MemoryHints, MultisampleState, Origin2d, Origin3d, PipelineStatisticsTypes, PolygonMode, + PowerPreference, PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState, + PrimitiveTopology, PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBindingType, + SamplerBorderColor, ShaderLocation, ShaderModel, ShaderRuntimeChecks, ShaderStages, + StencilFaceState, StencilOperation, StencilState, StorageTextureAccess, SurfaceCapabilities, + SurfaceStatus, TexelCopyBufferLayout, TextureAspect, TextureDimension, TextureFormat, + TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, TextureTransition, + TextureUsages, TextureUses, TextureViewDimension, VertexAttribute, VertexFormat, + VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync, COPY_BUFFER_ALIGNMENT, + COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT, + QUERY_RESOLVE_BUFFER_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT, }; #[expect(deprecated)] pub use wgt::{ImageCopyBuffer, ImageCopyTexture, ImageCopyTextureTagged, ImageDataLayout}; From a90542e2ab319379d40c2d390aba67b21e8b8f2e Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Thu, 23 Jan 2025 19:22:52 -0800 Subject: [PATCH 25/26] Fix imports --- wgpu-hal/examples/halmark/main.rs | 26 +++++----- wgpu-hal/examples/raw-gles.rs | 2 +- wgpu-hal/examples/ray-traced-triangle/main.rs | 50 +++++++++---------- 3 files changed, 39 insertions(+), 39 deletions(-) diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index 7fa5cfedcf..ea4e27487c 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -148,7 +148,7 @@ impl Example { height: window_size.1, depth_or_array_layers: 1, }, - usage: wgt::TextureUses::COLOR_TARGET, + usage: wgpu_types::TextureUses::COLOR_TARGET, view_formats: vec![], }; unsafe { @@ -331,24 +331,24 @@ impl Example { let buffer_barrier = hal::BufferBarrier { buffer: &staging_buffer, usage: hal::StateTransition { - from: wgt::BufferUses::empty(), - to: wgt::BufferUses::COPY_SRC, + from: wgpu_types::BufferUses::empty(), + to: wgpu_types::BufferUses::COPY_SRC, }, }; let texture_barrier1 = hal::TextureBarrier { texture: &texture, range: wgpu_types::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: wgt::TextureUses::UNINITIALIZED, - to: wgt::TextureUses::COPY_DST, + from: wgpu_types::TextureUses::UNINITIALIZED, + to: wgpu_types::TextureUses::COPY_DST, }, }; let texture_barrier2 = hal::TextureBarrier { texture: &texture, range: wgpu_types::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: wgt::TextureUses::COPY_DST, - to: wgt::TextureUses::RESOURCE, + from: wgpu_types::TextureUses::COPY_DST, + to: wgpu_types::TextureUses::RESOURCE, }, }; let copy = hal::BufferTextureCopy { @@ -453,7 +453,7 @@ impl Example { }; let texture_binding = hal::TextureBinding { view: &texture_view, - usage: wgt::TextureUses::RESOURCE, + usage: wgpu_types::TextureUses::RESOURCE, }; let global_group_desc = hal::BindGroupDescriptor { label: Some("global"), @@ -675,8 +675,8 @@ impl Example { texture: surface_tex.borrow(), range: wgpu_types::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: wgt::TextureUses::UNINITIALIZED, - to: wgt::TextureUses::COLOR_TARGET, + from: wgpu_types::TextureUses::UNINITIALIZED, + to: wgpu_types::TextureUses::COLOR_TARGET, }, }; unsafe { @@ -707,7 +707,7 @@ impl Example { color_attachments: &[Some(hal::ColorAttachment { target: hal::Attachment { view: &surface_tex_view, - usage: wgt::TextureUses::COLOR_TARGET, + usage: wgpu_types::TextureUses::COLOR_TARGET, }, resolve_target: None, ops: hal::AttachmentOps::STORE, @@ -746,8 +746,8 @@ impl Example { texture: surface_tex.borrow(), range: wgpu_types::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: wgt::TextureUses::COLOR_TARGET, - to: wgt::TextureUses::PRESENT, + from: wgpu_types::TextureUses::COLOR_TARGET, + to: wgpu_types::TextureUses::PRESENT, }, }; unsafe { diff --git a/wgpu-hal/examples/raw-gles.rs b/wgpu-hal/examples/raw-gles.rs index 8e9afa28a3..5215a4282b 100644 --- a/wgpu-hal/examples/raw-gles.rs +++ b/wgpu-hal/examples/raw-gles.rs @@ -321,7 +321,7 @@ fn fill_screen(exposed: &hal::ExposedAdapter, width: u32, height color_attachments: &[Some(hal::ColorAttachment { target: hal::Attachment { view: &view, - usage: wgt::TextureUses::COLOR_TARGET, + usage: wgpu_types::TextureUses::COLOR_TARGET, }, resolve_target: None, ops: hal::AttachmentOps::STORE, diff --git a/wgpu-hal/examples/ray-traced-triangle/main.rs b/wgpu-hal/examples/ray-traced-triangle/main.rs index bfb8646b94..79984ae43e 100644 --- a/wgpu-hal/examples/ray-traced-triangle/main.rs +++ b/wgpu-hal/examples/ray-traced-triangle/main.rs @@ -304,7 +304,7 @@ impl Example { height: window_size.1, depth_or_array_layers: 1, }, - usage: wgt::TextureUses::COLOR_TARGET | wgt::TextureUses::COPY_DST, + usage: wgpu_types::TextureUses::COLOR_TARGET | wgpu_types::TextureUses::COPY_DST, view_formats: vec![surface_format], }; unsafe { @@ -421,8 +421,8 @@ impl Example { .create_buffer(&hal::BufferDescriptor { label: Some("vertices buffer"), size: vertices_size_in_bytes as u64, - usage: wgt::BufferUses::MAP_WRITE - | wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + usage: wgpu_types::BufferUses::MAP_WRITE + | wgpu_types::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT, }) .unwrap(); @@ -447,8 +447,8 @@ impl Example { .create_buffer(&hal::BufferDescriptor { label: Some("indices buffer"), size: indices_size_in_bytes as u64, - usage: wgt::BufferUses::MAP_WRITE - | wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + usage: wgpu_types::BufferUses::MAP_WRITE + | wgpu_types::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT, }) @@ -555,7 +555,7 @@ impl Example { .create_buffer(&hal::BufferDescriptor { label: Some("uniform buffer"), size: uniforms_size as u64, - usage: wgt::BufferUses::MAP_WRITE | wgt::BufferUses::UNIFORM, + usage: wgpu_types::BufferUses::MAP_WRITE | wgpu_types::BufferUses::UNIFORM, memory_flags: hal::MemoryFlags::PREFER_COHERENT, }) .unwrap(); @@ -607,7 +607,7 @@ impl Example { }; let texture_binding = hal::TextureBinding { view: &texture_view, - usage: wgt::TextureUses::STORAGE_READ_WRITE, + usage: wgpu_types::TextureUses::STORAGE_READ_WRITE, }; let group_desc = hal::BindGroupDescriptor { label: Some("bind group"), @@ -644,7 +644,7 @@ impl Example { size: blas_sizes .build_scratch_size .max(tlas_sizes.build_scratch_size), - usage: wgt::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, + usage: wgpu_types::BufferUses::ACCELERATION_STRUCTURE_SCRATCH, memory_flags: hal::MemoryFlags::empty(), }) .unwrap() @@ -696,8 +696,8 @@ impl Example { .create_buffer(&hal::BufferDescriptor { label: Some("instances_buffer"), size: instances_buffer_size as u64, - usage: wgt::BufferUses::MAP_WRITE - | wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + usage: wgpu_types::BufferUses::MAP_WRITE + | wgpu_types::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT, }) .unwrap(); @@ -756,8 +756,8 @@ impl Example { let scratch_buffer_barrier = hal::BufferBarrier { buffer: &scratch_buffer, usage: hal::StateTransition { - from: wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, - to: wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + from: wgpu_types::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + to: wgpu_types::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, }, }; cmd_encoder.transition_buffers(iter::once(scratch_buffer_barrier)); @@ -793,8 +793,8 @@ impl Example { texture: &texture, range: wgpu_types::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: wgt::TextureUses::UNINITIALIZED, - to: wgt::TextureUses::STORAGE_READ_WRITE, + from: wgpu_types::TextureUses::UNINITIALIZED, + to: wgpu_types::TextureUses::STORAGE_READ_WRITE, }, }; @@ -867,8 +867,8 @@ impl Example { texture: surface_tex.borrow(), range: wgpu_types::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: wgt::TextureUses::UNINITIALIZED, - to: wgt::TextureUses::COPY_DST, + from: wgpu_types::TextureUses::UNINITIALIZED, + to: wgpu_types::TextureUses::COPY_DST, }, }; @@ -937,8 +937,8 @@ impl Example { let scratch_buffer_barrier = hal::BufferBarrier { buffer: &self.scratch_buffer, usage: hal::StateTransition { - from: wgt::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, - to: wgt::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, + from: wgpu_types::BufferUses::BOTTOM_LEVEL_ACCELERATION_STRUCTURE_INPUT, + to: wgpu_types::BufferUses::TOP_LEVEL_ACCELERATION_STRUCTURE_INPUT, }, }; ctx.encoder @@ -976,24 +976,24 @@ impl Example { texture: surface_tex.borrow(), range: wgpu_types::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: wgt::TextureUses::COPY_DST, - to: wgt::TextureUses::PRESENT, + from: wgpu_types::TextureUses::COPY_DST, + to: wgpu_types::TextureUses::PRESENT, }, }; let target_barrier2 = hal::TextureBarrier { texture: &self.texture, range: wgpu_types::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: wgt::TextureUses::STORAGE_READ_WRITE, - to: wgt::TextureUses::COPY_SRC, + from: wgpu_types::TextureUses::STORAGE_READ_WRITE, + to: wgpu_types::TextureUses::COPY_SRC, }, }; let target_barrier3 = hal::TextureBarrier { texture: &self.texture, range: wgpu_types::ImageSubresourceRange::default(), usage: hal::StateTransition { - from: wgt::TextureUses::COPY_SRC, - to: wgt::TextureUses::STORAGE_READ_WRITE, + from: wgpu_types::TextureUses::COPY_SRC, + to: wgpu_types::TextureUses::STORAGE_READ_WRITE, }, }; unsafe { @@ -1001,7 +1001,7 @@ impl Example { ctx.encoder.transition_textures(iter::once(target_barrier2)); ctx.encoder.copy_texture_to_texture( &self.texture, - wgt::TextureUses::COPY_SRC, + wgpu_types::TextureUses::COPY_SRC, surface_tex.borrow(), std::iter::once(hal::TextureCopy { src_base: hal::TextureCopyBase { From 4483082069e8b94251fd36d820698199813b4358 Mon Sep 17 00:00:00 2001 From: JMS55 <47158642+JMS55@users.noreply.github.com> Date: Thu, 23 Jan 2025 19:29:43 -0800 Subject: [PATCH 26/26] Fix import --- wgpu-hal/examples/halmark/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/wgpu-hal/examples/halmark/main.rs b/wgpu-hal/examples/halmark/main.rs index ea4e27487c..778cad0e0e 100644 --- a/wgpu-hal/examples/halmark/main.rs +++ b/wgpu-hal/examples/halmark/main.rs @@ -287,7 +287,7 @@ impl Example { let staging_buffer_desc = hal::BufferDescriptor { label: Some("stage"), size: texture_data.len() as wgpu_types::BufferAddress, - usage: hal::wgpu_types::MAP_WRITE | hal::wgpu_types::COPY_SRC, + usage: wgpu_types::BufferUses::MAP_WRITE | wgpu_types::BufferUses::COPY_SRC, memory_flags: hal::MemoryFlags::TRANSIENT | hal::MemoryFlags::PREFER_COHERENT, }; let staging_buffer = unsafe { device.create_buffer(&staging_buffer_desc).unwrap() };