diff --git a/CHANGELOG.md b/CHANGELOG.md index cce529cf3..14f04a4fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -257,6 +257,10 @@ By @kpreid in [#9042](https://github.com/gfx-rs/wgpu/pull/9042). Note that the existing workaround to create surfaces before the adapter is no longer valid. - Changing shader constants now correctly recompiles the shader. By @DerSchmale in [#8291](https://github.com/gfx-rs/wgpu/pull/8291). +#### Vulkan + +- Remove incorrect ordered texture uses. By @NiklasEi in [#8924](https://github.com/gfx-rs/wgpu/pull/8924). + ### Documentation #### General @@ -274,10 +278,14 @@ By @kpreid in [#9042](https://github.com/gfx-rs/wgpu/pull/9042). - Naga and `wgpu` now reject shaders with an `enable` directive for functionality that is not available, even if that functionality is not used by the shader. By @andyleiserson in [#8913](https://github.com/gfx-rs/wgpu/pull/8913). - Prevent UB from incorrectly using ray queries on HLSL. By @Vecvec in [#8763](https://github.com/gfx-rs/wgpu/pull/8763). -### deno_webgpu +#### deno_webgpu - Expose the `GPU.wgslLanguageFeatures` property. By @andyleiserson in [#8884](https://github.com/gfx-rs/wgpu/pull/8884). +#### Hal + +- Make ordered texture and buffer uses hal specific. By @NiklasEi in [#8924](https://github.com/gfx-rs/wgpu/pull/8924). + ## v28.0.1 (2025-03-01) ### General diff --git a/wgpu-core/src/command/compute.rs b/wgpu-core/src/command/compute.rs index 9cf1b7904..7ae15dd53 100644 --- a/wgpu-core/src/command/compute.rs +++ b/wgpu-core/src/command/compute.rs @@ -558,7 +558,10 @@ pub(super) fn encode_compute_pass( immediates: Vec::new(), - intermediate_trackers: Tracker::new(), + intermediate_trackers: Tracker::new( + device.ordered_buffer_usages, + device.ordered_texture_usages, + ), }; let indices = &device.tracker_indices; diff --git a/wgpu-core/src/command/mod.rs b/wgpu-core/src/command/mod.rs index 55133d5b6..377ccdc3e 100644 --- a/wgpu-core/src/command/mod.rs +++ b/wgpu-core/src/command/mod.rs @@ -894,7 +894,10 @@ impl CommandEncoder { api: EncodingApi::Undecided, label: label.to_string(), }, - trackers: Tracker::new(), + trackers: Tracker::new( + device.ordered_buffer_usages, + device.ordered_texture_usages, + ), buffer_memory_init_actions: Default::default(), texture_memory_actions: Default::default(), as_actions: Default::default(), diff --git a/wgpu-core/src/device/queue.rs b/wgpu-core/src/device/queue.rs index 93f76392a..30008354f 100644 --- a/wgpu-core/src/device/queue.rs +++ b/wgpu-core/src/device/queue.rs @@ -409,7 +409,7 @@ impl PendingWrites { api: crate::command::EncodingApi::InternalUse, label: "(wgpu internal) PendingWrites command encoder".into(), }, - trackers: Tracker::new(), + trackers: Tracker::new(device.ordered_buffer_usages, device.ordered_texture_usages), temp_resources: mem::take(&mut self.temp_resources), _indirect_draw_validation_resources: crate::indirect_validation::DrawResources::new( device.clone(), diff --git a/wgpu-core/src/device/resource.rs b/wgpu-core/src/device/resource.rs index cb06516cb..654f25469 100644 --- a/wgpu-core/src/device/resource.rs +++ b/wgpu-core/src/device/resource.rs @@ -261,6 +261,16 @@ pub struct Device { pub(crate) limits: wgt::Limits, pub(crate) features: wgt::Features, pub(crate) downlevel: wgt::DownlevelCapabilities, + /// Buffer uses listed here, are expected to be ordered by the underlying hardware. + /// If a usage is ordered, then if the buffer state doesn't change between draw calls, + /// there are no barriers needed for synchronization. + /// See the implementations of [`hal::Adapter::get_ordered_buffer_usages`] for hardware specific info + pub(crate) ordered_buffer_usages: wgt::BufferUses, + /// Texture uses listed here, are expected to be ordered by the underlying hardware. + /// If a usage is ordered, then if the buffer state doesn't change between draw calls, + /// there are no barriers needed for synchronization. + /// See the implementations of [`hal::Adapter::get_ordered_texture_usages`] for hardware specific info + pub(crate) ordered_texture_usages: wgt::TextureUses, pub(crate) instance_flags: wgt::InstanceFlags, pub(crate) deferred_destroy: Mutex>, pub(crate) usage_scopes: UsageScopePool, @@ -435,6 +445,9 @@ impl Device { } }; + let ordered_buffer_usages = adapter.raw.adapter.get_ordered_buffer_usages(); + let ordered_texture_usages = adapter.raw.adapter.get_ordered_texture_usages(); + let fence = unsafe { raw_device.create_fence() }.map_err(DeviceError::from_hal)?; let command_allocator = command::CommandAllocator::new(); @@ -529,7 +542,10 @@ impl Device { snatchable_lock: unsafe { SnatchLock::new(rank::DEVICE_SNATCHABLE_LOCK) }, valid: AtomicBool::new(true), device_lost_closure: Mutex::new(rank::DEVICE_LOST_CLOSURE, None), - trackers: Mutex::new(rank::DEVICE_TRACKERS, DeviceTracker::new()), + trackers: Mutex::new( + rank::DEVICE_TRACKERS, + DeviceTracker::new(ordered_buffer_usages, ordered_texture_usages), + ), tracker_indices: TrackerIndexAllocators::new(), bgl_pool: ResourcePool::new(), #[cfg(feature = "trace")] @@ -538,6 +554,8 @@ impl Device { limits: desc.required_limits.clone(), features: desc.required_features, downlevel, + ordered_buffer_usages, + ordered_texture_usages, instance_flags, deferred_destroy: Mutex::new(rank::DEVICE_DEFERRED_DESTROY, Vec::new()), usage_scopes: Mutex::new(rank::DEVICE_USAGE_SCOPES, Default::default()), @@ -5225,7 +5243,12 @@ impl Device { } pub(crate) fn new_usage_scope(&self) -> UsageScope<'_> { - UsageScope::new_pooled(&self.usage_scopes, &self.tracker_indices) + UsageScope::new_pooled( + &self.usage_scopes, + &self.tracker_indices, + self.ordered_buffer_usages, + self.ordered_texture_usages, + ) } pub fn get_hal_counters(&self) -> wgt::HalCounters { diff --git a/wgpu-core/src/track/buffer.rs b/wgpu-core/src/track/buffer.rs index 167776560..afa389abb 100644 --- a/wgpu-core/src/track/buffer.rs +++ b/wgpu-core/src/track/buffer.rs @@ -31,10 +31,6 @@ impl ResourceUses for BufferUses { Self::bits(&self) } - fn all_ordered(self) -> bool { - Self::ORDERED.contains(self) - } - fn any_exclusive(self) -> bool { self.intersects(Self::EXCLUSIVE) } @@ -81,6 +77,7 @@ impl BufferBindGroupState { pub(crate) struct BufferUsageScope { state: Vec, metadata: ResourceMetadata>, + ordered_uses_mask: BufferUses, } impl Default for BufferUsageScope { @@ -88,6 +85,7 @@ impl Default for BufferUsageScope { Self { state: Vec::new(), metadata: ResourceMetadata::new(), + ordered_uses_mask: BufferUses::empty(), } } } @@ -111,6 +109,10 @@ impl BufferUsageScope { self.metadata.set_size(size); } + pub fn set_ordered_uses_mask(&mut self, ordered_uses_mask: BufferUses) { + self.ordered_uses_mask = ordered_uses_mask; + } + /// Extend the vectors to let the given index be valid. fn allow_index(&mut self, index: usize) { if index >= self.state.len() { @@ -287,10 +289,12 @@ pub(crate) struct BufferTracker { metadata: ResourceMetadata>, temp: Vec>, + + ordered_uses_mask: BufferUses, } impl BufferTracker { - pub fn new() -> Self { + pub fn new(ordered_uses_mask: BufferUses) -> Self { Self { start: Vec::new(), end: Vec::new(), @@ -298,6 +302,8 @@ impl BufferTracker { metadata: ResourceMetadata::new(), temp: Vec::new(), + + ordered_uses_mask, } } @@ -546,7 +552,15 @@ impl BufferTracker { let update_state_provider = end_state_provider.unwrap_or_else(|| start_state_provider.clone()); - unsafe { barrier(&mut self.end, index, start_state_provider, &mut self.temp) }; + unsafe { + barrier( + &mut self.end, + index, + start_state_provider, + &mut self.temp, + self.ordered_uses_mask, + ) + }; unsafe { update(&mut self.end, index, update_state_provider) }; } @@ -557,14 +571,16 @@ pub(crate) struct DeviceBufferTracker { current_states: Vec, metadata: ResourceMetadata>, temp: Vec>, + ordered_uses_mask: BufferUses, } impl DeviceBufferTracker { - pub fn new() -> Self { + pub fn new(ordered_uses_mask: BufferUses) -> Self { Self { current_states: Vec::new(), metadata: ResourceMetadata::new(), temp: Vec::new(), + ordered_uses_mask, } } @@ -632,6 +648,7 @@ impl DeviceBufferTracker { index, start_state_provider.clone(), &mut self.temp, + self.ordered_uses_mask, ) }; unsafe { update(&mut self.current_states, index, start_state_provider) }; @@ -665,6 +682,7 @@ impl DeviceBufferTracker { index, start_state_provider, &mut self.temp, + self.ordered_uses_mask, ) }; unsafe { update(&mut self.current_states, index, end_state_provider) }; @@ -765,11 +783,12 @@ unsafe fn barrier( index: usize, state_provider: BufferStateProvider<'_>, barriers: &mut Vec>, + ordered_uses_mask: BufferUses, ) { let current_state = unsafe { *current_states.get_unchecked(index) }; let new_state = unsafe { state_provider.get_state(index) }; - if skip_barrier(current_state, new_state) { + if skip_barrier(current_state, ordered_uses_mask, new_state) { return; } diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index f050d4e37..7abb8e1a6 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -112,6 +112,7 @@ use crate::{ }; use alloc::{sync::Arc, vec::Vec}; +use bitflags::Flags; use core::{fmt, mem, ops}; use thiserror::Error; @@ -321,8 +322,6 @@ pub(crate) trait ResourceUses: /// Turn the resource into a pile of bits. fn bits(self) -> u16; - /// Returns true if the all the uses are ordered. - fn all_ordered(self) -> bool; /// Returns true if any of the uses are exclusive. fn any_exclusive(self) -> bool; } @@ -337,10 +336,10 @@ fn invalid_resource_state(state: T) -> bool { /// Returns true if the transition from one state to another does not require /// a barrier. -fn skip_barrier(old_state: T, new_state: T) -> bool { +fn skip_barrier(old_state: F, ordered_uses_mask: F, new_state: F) -> bool { // If the state didn't change and all the usages are ordered, the hardware // will guarantee the order of accesses, so we do not need to issue a barrier at all - old_state == new_state && old_state.all_ordered() + old_state.bits() == new_state.bits() && ordered_uses_mask.contains(old_state) } #[derive(Clone, Debug, Error)] @@ -538,6 +537,8 @@ impl UsageScope<'static> { pub fn new_pooled<'d>( pool: &'d UsageScopePool, tracker_indices: &TrackerIndexAllocators, + ordered_buffer_usages: wgt::BufferUses, + ordered_texture_usages: wgt::TextureUses, ) -> UsageScope<'d> { let pooled = pool.lock().pop().unwrap_or_default(); @@ -548,7 +549,9 @@ impl UsageScope<'static> { }; scope.buffers.set_size(tracker_indices.buffers.size()); + scope.buffers.set_ordered_uses_mask(ordered_buffer_usages); scope.textures.set_size(tracker_indices.textures.size()); + scope.textures.set_ordered_uses_mask(ordered_texture_usages); scope } } @@ -602,10 +605,13 @@ pub(crate) struct DeviceTracker { } impl DeviceTracker { - pub fn new() -> Self { + pub fn new( + ordered_buffer_usages: wgt::BufferUses, + ordered_texture_usages: wgt::TextureUses, + ) -> Self { Self { - buffers: DeviceBufferTracker::new(), - textures: DeviceTextureTracker::new(), + buffers: DeviceBufferTracker::new(ordered_buffer_usages), + textures: DeviceTextureTracker::new(ordered_texture_usages), } } } @@ -645,10 +651,13 @@ pub(crate) struct Tracker { } impl Tracker { - pub fn new() -> Self { + pub fn new( + ordered_buffer_usages: wgt::BufferUses, + ordered_texture_usages: wgt::TextureUses, + ) -> Self { Self { - buffers: BufferTracker::new(), - textures: TextureTracker::new(), + buffers: BufferTracker::new(ordered_buffer_usages), + textures: TextureTracker::new(ordered_texture_usages), blas_s: BlasTracker::new(), tlas_s: StatelessTracker::new(), views: StatelessTracker::new(), diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index efdf0c356..aede04287 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -49,10 +49,6 @@ impl ResourceUses for TextureUses { Self::bits(&self) } - fn all_ordered(self) -> bool { - Self::ORDERED.contains(self) - } - fn any_exclusive(self) -> bool { self.intersects(Self::EXCLUSIVE) } @@ -263,6 +259,7 @@ impl TextureStateSet { pub(crate) struct TextureUsageScope { set: TextureStateSet, metadata: ResourceMetadata>, + ordered_uses_mask: TextureUses, } impl Default for TextureUsageScope { @@ -270,6 +267,7 @@ impl Default for TextureUsageScope { Self { set: TextureStateSet::new(), metadata: ResourceMetadata::new(), + ordered_uses_mask: TextureUses::empty(), } } } @@ -294,6 +292,10 @@ impl TextureUsageScope { self.metadata.set_size(size); } + pub fn set_ordered_uses_mask(&mut self, ordered_uses_mask: TextureUses) { + self.ordered_uses_mask = ordered_uses_mask; + } + /// Returns true if the tracker owns no resources. /// /// This is a O(n) operation. @@ -419,10 +421,12 @@ pub(crate) struct TextureTracker { metadata: ResourceMetadata>, temp: Vec>, + + ordered_uses_mask: TextureUses, } impl TextureTracker { - pub fn new() -> Self { + pub fn new(ordered_uses_mask: TextureUses) -> Self { Self { start_set: TextureStateSet::new(), end_set: TextureStateSet::new(), @@ -430,6 +434,8 @@ impl TextureTracker { metadata: ResourceMetadata::new(), temp: Vec::new(), + + ordered_uses_mask, } } @@ -516,6 +522,7 @@ impl TextureTracker { None, ResourceMetadataProvider::Direct { resource: texture }, &mut self.temp, + self.ordered_uses_mask, ) } @@ -557,6 +564,7 @@ impl TextureTracker { metadata: &tracker.metadata, }, &mut self.temp, + self.ordered_uses_mask, ); } } @@ -593,6 +601,7 @@ impl TextureTracker { metadata: &scope.metadata, }, &mut self.temp, + self.ordered_uses_mask, ); } } @@ -648,6 +657,7 @@ impl TextureTracker { metadata: &scope.metadata, }, &mut self.temp, + self.ordered_uses_mask, ) }; @@ -672,14 +682,16 @@ pub(crate) struct DeviceTextureTracker { current_state_set: TextureStateSet, metadata: ResourceMetadata>, temp: Vec>, + ordered_uses_mask: TextureUses, } impl DeviceTextureTracker { - pub fn new() -> Self { + pub fn new(ordered_uses_mask: TextureUses) -> Self { Self { current_state_set: TextureStateSet::new(), metadata: ResourceMetadata::new(), temp: Vec::new(), + ordered_uses_mask, } } @@ -704,7 +716,7 @@ impl DeviceTextureTracker { /// Inserts a single texture and a state into the resource tracker. /// /// If the resource already exists in the tracker, it will be overwritten. - pub fn insert_single(&mut self, texture: &Arc, usage: TextureUses) { + pub fn insert_single(&mut self, texture: &Arc, state: TextureUses) { let index = texture.tracker_index().as_usize(); self.allow_index(index); @@ -718,7 +730,7 @@ impl DeviceTextureTracker { &mut self.current_state_set, &mut self.metadata, index, - TextureStateProvider::KnownSingle { state: usage }, + TextureStateProvider::KnownSingle { state }, None, ResourceMetadataProvider::Direct { resource: &Arc::downgrade(texture), @@ -754,6 +766,7 @@ impl DeviceTextureTracker { index, start_state_provider.clone(), &mut self.temp, + self.ordered_uses_mask, ) }; unsafe { @@ -795,6 +808,7 @@ impl DeviceTextureTracker { index, start_state_provider, &mut self.temp, + self.ordered_uses_mask, ); update( texture_selector, @@ -834,6 +848,7 @@ impl DeviceTextureTracker { index, start_state_provider.clone(), &mut self.temp, + self.ordered_uses_mask, ); update( texture_selector, @@ -1034,6 +1049,7 @@ unsafe fn insert_or_barrier_update( end_state_provider: Option>, metadata_provider: ResourceMetadataProvider<'_, Arc>, barriers: &mut Vec>, + ordered_uses_mask: TextureUses, ) { let currently_owned = unsafe { resource_metadata.contains_unchecked(index) }; @@ -1061,6 +1077,7 @@ unsafe fn insert_or_barrier_update( index, start_state_provider, barriers, + ordered_uses_mask, ) }; unsafe { @@ -1290,6 +1307,7 @@ unsafe fn barrier( index: usize, state_provider: TextureStateProvider<'_>, barriers: &mut Vec>, + ordered_uses_mask: TextureUses, ) { let current_state = unsafe { current_state_set.get_unchecked(index) }; @@ -1297,7 +1315,7 @@ unsafe fn barrier( match (current_state, new_state) { (SingleOrManyStates::Single(current_simple), SingleOrManyStates::Single(new_simple)) => { - if skip_barrier(current_simple, new_simple) { + if skip_barrier(current_simple, ordered_uses_mask, new_simple) { return; } @@ -1316,7 +1334,7 @@ unsafe fn barrier( continue; } - if skip_barrier(current_simple, new_state) { + if skip_barrier(current_simple, ordered_uses_mask, new_state) { continue; } @@ -1339,7 +1357,7 @@ unsafe fn barrier( continue; } - if skip_barrier(current_layer_state, new_simple) { + if skip_barrier(current_layer_state, ordered_uses_mask, new_simple) { continue; } @@ -1371,7 +1389,7 @@ unsafe fn barrier( continue; } - if skip_barrier(*current_layer_state, new_state) { + if skip_barrier(*current_layer_state, ordered_uses_mask, new_state) { continue; } diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index f401558f6..5c81552d0 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -1308,6 +1308,18 @@ impl crate::Adapter for super::Adapter { unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp { wgt::PresentationTimestamp(self.presentation_timer.get_timestamp_ns()) } + + fn get_ordered_buffer_usages(&self) -> wgt::BufferUses { + wgt::BufferUses::INCLUSIVE | wgt::BufferUses::MAP_WRITE + } + + // Don't put barriers between inclusive uses + // DX12 implicitly orders renderpasses on the same resources. + fn get_ordered_texture_usages(&self) -> wgt::TextureUses { + wgt::TextureUses::INCLUSIVE + | wgt::TextureUses::COLOR_TARGET + | wgt::TextureUses::DEPTH_STENCIL_WRITE + } } fn get_adapter_pci_info(vendor_id: u32, device_id: u32) -> String { diff --git a/wgpu-hal/src/dynamic/adapter.rs b/wgpu-hal/src/dynamic/adapter.rs index e97aca1ce..6256a331a 100644 --- a/wgpu-hal/src/dynamic/adapter.rs +++ b/wgpu-hal/src/dynamic/adapter.rs @@ -36,6 +36,10 @@ pub trait DynAdapter: DynResource { unsafe fn surface_capabilities(&self, surface: &dyn DynSurface) -> Option; unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp; + + fn get_ordered_buffer_usages(&self) -> wgt::BufferUses; + + fn get_ordered_texture_usages(&self) -> wgt::TextureUses; } impl DynAdapter for A { @@ -66,4 +70,12 @@ impl DynAdapter for A { unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp { unsafe { A::get_presentation_timestamp(self) } } + + fn get_ordered_buffer_usages(&self) -> wgt::BufferUses { + A::get_ordered_buffer_usages(self) + } + + fn get_ordered_texture_usages(&self) -> wgt::TextureUses { + A::get_ordered_texture_usages(self) + } } diff --git a/wgpu-hal/src/gles/adapter.rs b/wgpu-hal/src/gles/adapter.rs index 3fb16ffb4..0cf5c3ed4 100644 --- a/wgpu-hal/src/gles/adapter.rs +++ b/wgpu-hal/src/gles/adapter.rs @@ -1281,6 +1281,17 @@ impl crate::Adapter for super::Adapter { unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp { wgt::PresentationTimestamp::INVALID_TIMESTAMP } + + fn get_ordered_buffer_usages(&self) -> wgt::BufferUses { + wgt::BufferUses::INCLUSIVE | wgt::BufferUses::MAP_WRITE + } + + // Don't put barriers between inclusive uses + fn get_ordered_texture_usages(&self) -> wgt::TextureUses { + wgt::TextureUses::INCLUSIVE + | wgt::TextureUses::COLOR_TARGET + | wgt::TextureUses::DEPTH_STENCIL_WRITE + } } impl super::AdapterShared { diff --git a/wgpu-hal/src/lib.rs b/wgpu-hal/src/lib.rs index 3ce87a2c7..3f36e675d 100644 --- a/wgpu-hal/src/lib.rs +++ b/wgpu-hal/src/lib.rs @@ -794,6 +794,16 @@ pub trait Adapter: WasmNotSendSync { /// /// [`PresentationTimestamp`]: wgt::PresentationTimestamp unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp; + + /// 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. + fn get_ordered_buffer_usages(&self) -> wgt::BufferUses; + + /// 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. + fn get_ordered_texture_usages(&self) -> wgt::TextureUses; } /// A connection to a GPU and a pool of resources to use with it. diff --git a/wgpu-hal/src/metal/adapter.rs b/wgpu-hal/src/metal/adapter.rs index 44796c63a..54208b192 100644 --- a/wgpu-hal/src/metal/adapter.rs +++ b/wgpu-hal/src/metal/adapter.rs @@ -441,6 +441,17 @@ impl crate::Adapter for super::Adapter { wgt::PresentationTimestamp(timestamp) } + + fn get_ordered_buffer_usages(&self) -> wgt::BufferUses { + wgt::BufferUses::INCLUSIVE | wgt::BufferUses::MAP_WRITE + } + + // Don't put barriers between inclusive uses + fn get_ordered_texture_usages(&self) -> wgt::TextureUses { + wgt::TextureUses::INCLUSIVE + | wgt::TextureUses::COLOR_TARGET + | wgt::TextureUses::DEPTH_STENCIL_WRITE + } } const RESOURCE_HEAP_SUPPORT: &[MTLFeatureSet] = &[ diff --git a/wgpu-hal/src/noop/mod.rs b/wgpu-hal/src/noop/mod.rs index 82dfc2c30..b624a6af5 100644 --- a/wgpu-hal/src/noop/mod.rs +++ b/wgpu-hal/src/noop/mod.rs @@ -287,6 +287,16 @@ impl crate::Adapter for Context { unsafe fn get_presentation_timestamp(&self) -> wgt::PresentationTimestamp { wgt::PresentationTimestamp::INVALID_TIMESTAMP } + + fn get_ordered_buffer_usages(&self) -> wgt::BufferUses { + wgt::BufferUses::INCLUSIVE | wgt::BufferUses::MAP_WRITE + } + + fn get_ordered_texture_usages(&self) -> wgt::TextureUses { + wgt::TextureUses::INCLUSIVE + | wgt::TextureUses::COLOR_TARGET + | wgt::TextureUses::DEPTH_STENCIL_WRITE + } } impl crate::Queue for Context { diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index f91d33e9d..f1373054f 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -3045,6 +3045,18 @@ impl crate::Adapter for super::Adapter { wgt::PresentationTimestamp::INVALID_TIMESTAMP } } + + fn get_ordered_buffer_usages(&self) -> wgt::BufferUses { + wgt::BufferUses::INCLUSIVE | wgt::BufferUses::MAP_WRITE + } + + // Vulkan makes very few execution ordering guarantees + // see https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#synchronization-implicit + // We just don't want to insert barriers between inclusive uses + // See https://github.com/gfx-rs/wgpu/issues/8853 + fn get_ordered_texture_usages(&self) -> wgt::TextureUses { + wgt::TextureUses::INCLUSIVE + } } fn is_format_16bit_norm_supported(instance: &ash::Instance, phd: vk::PhysicalDevice) -> bool { diff --git a/wgpu-types/src/buffer.rs b/wgpu-types/src/buffer.rs index 8361ce681..46d4c044c 100644 --- a/wgpu-types/src/buffer.rs +++ b/wgpu-types/src/buffer.rs @@ -144,10 +144,6 @@ bitflags::bitflags! { 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(); } } diff --git a/wgpu-types/src/texture.rs b/wgpu-types/src/texture.rs index a28abe2f9..c9440c061 100644 --- a/wgpu-types/src/texture.rs +++ b/wgpu-types/src/texture.rs @@ -251,11 +251,6 @@ bitflags::bitflags! { /// The combination of states that a texture must exclusively be in. /// cbindgen:ignore const EXCLUSIVE = Self::COPY_DST.bits() | Self::COLOR_TARGET.bits() | Self::DEPTH_STENCIL_WRITE.bits() | Self::STORAGE_WRITE_ONLY.bits() | Self::STORAGE_READ_WRITE.bits() | Self::STORAGE_ATOMIC.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. - /// cbindgen:ignore - 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 << 13;