diff --git a/wgpu-core/src/binding_model.rs b/wgpu-core/src/binding_model.rs index 076590460..99342194b 100644 --- a/wgpu-core/src/binding_model.rs +++ b/wgpu-core/src/binding_model.rs @@ -5,7 +5,7 @@ use crate::{ id::{BindGroupLayoutId, BufferId, DeviceId, SamplerId, TextureViewId}, resource::TextureViewDimension, - track::TrackerSet, + track::{DUMMY_SELECTOR, TrackerSet}, BufferAddress, LifeGuard, RefCount, @@ -125,3 +125,9 @@ impl Borrow for BindGroup { &self.life_guard.ref_count } } + +impl Borrow<()> for BindGroup { + fn borrow(&self) -> &() { + &DUMMY_SELECTOR + } +} diff --git a/wgpu-core/src/device.rs b/wgpu-core/src/device.rs index e80eeba09..ba90a39e9 100644 --- a/wgpu-core/src/device.rs +++ b/wgpu-core/src/device.rs @@ -29,7 +29,7 @@ use crate::{ pipeline, resource, swap_chain, - track::{Stitch, TrackerSet}, + track::{SEPARATE_DEPTH_STENCIL_STATES, Stitch, TrackerSet}, BufferAddress, FastHashMap, Features, @@ -931,10 +931,14 @@ impl> Global { (desc.base_array_layer + desc.array_layer_count) as u16 }; let range = hal::image::SubresourceRange { - aspects: match desc.aspect { - resource::TextureAspect::All => texture.full_range.aspects, - resource::TextureAspect::DepthOnly => hal::format::Aspects::DEPTH, - resource::TextureAspect::StencilOnly => hal::format::Aspects::STENCIL, + aspects: if SEPARATE_DEPTH_STENCIL_STATES { + match desc.aspect { + resource::TextureAspect::All => texture.full_range.aspects, + resource::TextureAspect::DepthOnly => hal::format::Aspects::DEPTH, + resource::TextureAspect::StencilOnly => hal::format::Aspects::STENCIL, + } + } else { + texture.full_range.aspects }, levels: desc.base_mip_level as u8 .. end_level, layers: desc.base_array_layer as u16 .. end_layer, diff --git a/wgpu-core/src/resource.rs b/wgpu-core/src/resource.rs index d8f01ee8c..5314f97c3 100644 --- a/wgpu-core/src/resource.rs +++ b/wgpu-core/src/resource.rs @@ -5,6 +5,7 @@ use crate::{ device::{BufferMapReadCallback, BufferMapWriteCallback}, id::{DeviceId, SwapChainId, TextureId}, + track::DUMMY_SELECTOR, BufferAddress, Extent3d, LifeGuard, @@ -103,6 +104,12 @@ impl Borrow for Buffer { } } +impl Borrow<()> for Buffer { + fn borrow(&self) -> &() { + &DUMMY_SELECTOR + } +} + #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub enum TextureDimension { @@ -225,6 +232,12 @@ impl Borrow for Texture { } } +impl Borrow for Texture { + fn borrow(&self) -> &hal::image::SubresourceRange { + &self.full_range + } +} + #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub enum TextureAspect { @@ -292,6 +305,12 @@ impl Borrow for TextureView { } } +impl Borrow<()> for TextureView { + fn borrow(&self) -> &() { + &DUMMY_SELECTOR + } +} + #[repr(C)] #[derive(Copy, Clone, Debug, Hash, Eq, PartialEq)] pub enum AddressMode { @@ -367,3 +386,9 @@ impl Borrow for Sampler { &self.life_guard.ref_count } } + +impl Borrow<()> for Sampler { + fn borrow(&self) -> &() { + &DUMMY_SELECTOR + } +} diff --git a/wgpu-core/src/track/mod.rs b/wgpu-core/src/track/mod.rs index 67aa3b5e7..e0af127b5 100644 --- a/wgpu-core/src/track/mod.rs +++ b/wgpu-core/src/track/mod.rs @@ -29,6 +29,8 @@ use buffer::BufferState; use texture::TextureState; +pub const SEPARATE_DEPTH_STENCIL_STATES: bool = false; + /// A single unit of state tracking. It keeps an initial /// usage as well as the last/current one, similar to `Range`. #[derive(Clone, Copy, Debug, PartialEq)] @@ -349,7 +351,7 @@ impl ResourceTracker { /// the last read-only usage, if possible. /// /// Returns the old usage as an error if there is a conflict. - pub fn use_extend<'a, T: 'a + Borrow>( + pub fn use_extend<'a, T: 'a + Borrow + Borrow>( &mut self, storage: &'a Storage, id: S::Id, @@ -366,7 +368,7 @@ impl ResourceTracker { /// Combines storage access by 'Id' with the transition that replaces /// the last usage with a new one, returning an iterator over these /// transitions. - pub fn use_replace<'a, T: 'a + Borrow>( + pub fn use_replace<'a, T: 'a + Borrow + Borrow>( &mut self, storage: &'a Storage, id: S::Id, @@ -412,6 +414,8 @@ impl ResourceState for PhantomData { fn optimize(&mut self) {} } +pub const DUMMY_SELECTOR: () = (); + /// A set of trackers for all relevant resources. #[derive(Debug)] diff --git a/wgpu-core/src/track/texture.rs b/wgpu-core/src/track/texture.rs index f46d795ab..3a0b23c65 100644 --- a/wgpu-core/src/track/texture.rs +++ b/wgpu-core/src/track/texture.rs @@ -129,7 +129,7 @@ impl ResourceState for TextureState { let pending = PendingTransition { id, selector: hal::image::SubresourceRange { - aspects: hal::format::Aspects::COLOR, + aspects: aspect, levels: level .. level + 1, layers: range.clone(), }, @@ -158,7 +158,7 @@ impl ResourceState for TextureState { for (mip_id, (mip_self, mip_other)) in self.mips.iter_mut().zip(&other.mips).enumerate() { let level = mip_id as hal::image::Level; - for &mut (aspects, ref mut planes_self, planes_other) in &mut [ + for &mut (aspect, ref mut planes_self, planes_other) in &mut [ ( hal::format::Aspects::COLOR, &mut mip_self.color, @@ -203,7 +203,7 @@ impl ResourceState for TextureState { let pending = PendingTransition { id, selector: hal::image::SubresourceRange { - aspects, + aspects: aspect, levels: level .. level + 1, layers: layers.clone(), },