From 52734bf87a5a69414bae0fa3b40df7ffb930adf1 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Fri, 23 Jul 2021 11:23:04 -0400 Subject: [PATCH] Fix tracing feature for RODS --- wgpu-core/src/command/bundle.rs | 2 +- wgpu-core/src/device/mod.rs | 1 + wgpu-core/src/device/trace.rs | 10 +++++++- wgpu/src/backend/web.rs | 4 +-- wgpu/src/lib.rs | 45 ++++++++++++++------------------- 5 files changed, 32 insertions(+), 30 deletions(-) diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 1be82838d6..3ba7a1e567 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -81,7 +81,7 @@ pub struct RenderBundleEncoder { base: BasePass, parent_id: id::DeviceId, pub(crate) context: RenderPassContext, - is_ds_read_only: bool, + pub(crate) is_ds_read_only: bool, } impl RenderBundleEncoder { diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 4772733035..c82a5f3100 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -3779,6 +3779,7 @@ impl Global { desc: trace::new_render_bundle_encoder_descriptor( desc.label.clone(), &bundle_encoder.context, + bundle_encoder.is_ds_read_only, ), base: bundle_encoder.to_base_pass(), }); diff --git a/wgpu-core/src/device/trace.rs b/wgpu-core/src/device/trace.rs index a87e843701..7fdd48f27a 100644 --- a/wgpu-core/src/device/trace.rs +++ b/wgpu-core/src/device/trace.rs @@ -13,11 +13,19 @@ pub const FILE_NAME: &str = "trace.ron"; pub(crate) fn new_render_bundle_encoder_descriptor<'a>( label: crate::Label<'a>, context: &'a super::RenderPassContext, + is_ds_read_only: bool, ) -> crate::command::RenderBundleEncoderDescriptor<'a> { crate::command::RenderBundleEncoderDescriptor { label, color_formats: Cow::Borrowed(&context.attachments.colors), - depth_stencil_format: context.attachments.depth_stencil, + depth_stencil: context.attachments.depth_stencil.map(|format| { + let aspects = hal::FormatAspects::from(format); + wgt::RenderBundleDepthStencil { + format, + depth_read_only: is_ds_read_only && aspects.contains(hal::FormatAspects::DEPTH), + stencil_read_only: is_ds_read_only && aspects.contains(hal::FormatAspects::STENCIL), + } + }), sample_count: context.sample_count, } } diff --git a/wgpu/src/backend/web.rs b/wgpu/src/backend/web.rs index b786656444..f4ec059784 100644 --- a/wgpu/src/backend/web.rs +++ b/wgpu/src/backend/web.rs @@ -1514,8 +1514,8 @@ impl crate::Context for Context { if let Some(ref label) = desc.label { mapped_desc.label(label); } - if let Some(dsf) = desc.depth_stencil_format { - mapped_desc.depth_stencil_format(map_texture_format(dsf)); + if let Some(ds) = desc.depth_stencil { + mapped_desc.depth_stencil_format(map_texture_format(ds.format)); } mapped_desc.sample_count(desc.sample_count); RenderBundleEncoder(device.0.create_render_bundle_encoder(&mapped_desc)) diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 42b0dbf707..1d75d4efbf 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -29,16 +29,16 @@ pub use wgt::{ BlendFactor, BlendOperation, BlendState, BufferAddress, BufferBindingType, BufferSize, BufferUsages, Color, ColorTargetState, ColorWrites, CommandBufferDescriptor, CompareFunction, DepthBiasState, DepthStencilState, DeviceType, DownlevelCapabilities, DownlevelFlags, - DynamicOffset, Extent3d, Face, Features, FilterMode, FrontFace, ImageDataLayout, IndexFormat, - Limits, MultisampleState, Origin3d, PipelineStatisticsTypes, PolygonMode, PowerPreference, - PresentMode, PrimitiveState, PrimitiveTopology, PushConstantRange, QueryType, - SamplerBorderColor, ShaderLocation, ShaderModel, ShaderStages, StencilFaceState, - StencilOperation, StencilState, StorageTextureAccess, SwapChainDescriptor, SwapChainStatus, - TextureAspect, TextureDimension, TextureFormat, TextureFormatFeatureFlags, - TextureFormatFeatures, TextureSampleType, TextureUsages, TextureViewDimension, VertexAttribute, - VertexFormat, VertexStepMode, BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, - COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, PUSH_CONSTANT_ALIGNMENT, QUERY_SET_MAX_QUERIES, - QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT, + DynamicOffset, Extent3d, Face, Features, FilterMode, FrontFace, ImageDataLayout, + ImageSubresourceRange, IndexFormat, Limits, MultisampleState, Origin3d, + PipelineStatisticsTypes, PolygonMode, PowerPreference, PresentMode, PrimitiveState, + PrimitiveTopology, PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBorderColor, + ShaderLocation, ShaderModel, ShaderStages, StencilFaceState, StencilOperation, StencilState, + StorageTextureAccess, SwapChainDescriptor, SwapChainStatus, TextureAspect, TextureDimension, + TextureFormat, TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, + TextureUsages, TextureViewDimension, VertexAttribute, VertexFormat, VertexStepMode, + BIND_BUFFER_ALIGNMENT, COPY_BUFFER_ALIGNMENT, COPY_BYTES_PER_ROW_ALIGNMENT, MAP_ALIGNMENT, + PUSH_CONSTANT_ALIGNMENT, QUERY_SET_MAX_QUERIES, QUERY_SIZE, VERTEX_STRIDE_ALIGNMENT, }; use backend::{BufferMappedRange, Context as C}; @@ -88,7 +88,7 @@ trait RenderInner { offset: BufferAddress, size: Option, ); - fn set_push_constants(&mut self, stages: wgt::ShaderStages, offset: u32, data: &[u8]); + fn set_push_constants(&mut self, stages: ShaderStages, offset: u32, data: &[u8]); fn draw(&mut self, vertices: Range, instances: Range); fn draw_indexed(&mut self, indices: Range, base_vertex: i32, instances: Range); fn draw_indirect(&mut self, indirect_buffer: &Ctx::BufferId, indirect_offset: BufferAddress); @@ -211,8 +211,8 @@ trait Context: Debug + Send + Sized + Sync { fn adapter_get_texture_format_features( &self, adapter: &Self::AdapterId, - format: wgt::TextureFormat, - ) -> wgt::TextureFormatFeatures; + format: TextureFormat, + ) -> TextureFormatFeatures; fn device_features(&self, device: &Self::DeviceId) -> Features; fn device_limits(&self, device: &Self::DeviceId) -> Limits; @@ -410,7 +410,7 @@ trait Context: Debug + Send + Sized + Sync { &self, encoder: &Self::CommandEncoderId, texture: &Texture, - subresource_range: &wgt::ImageSubresourceRange, + subresource_range: &ImageSubresourceRange, ); fn command_encoder_clear_buffer( &self, @@ -1326,7 +1326,7 @@ pub struct RenderBundleEncoderDescriptor<'a> { pub color_formats: &'a [TextureFormat], /// Information about the depth attachment that this render bundle is capable to rendering to. This /// must match the format of the depth attachments in the renderpass this render bundle is executed in. - pub depth_stencil: Option, + pub depth_stencil: Option, /// Sample count this render bundle is capable of rendering to. This must match the pipelines and /// the renderpasses it is used in. pub sample_count: u32, @@ -1540,10 +1540,7 @@ impl Adapter { /// /// Note that the WebGPU spec further restricts the available usages/features. /// To disable these restrictions on a device, request the [`Features::TEXTURE_ADAPTER_SPECIFIC_FORMAT_FEATURES`] feature. - pub fn get_texture_format_features( - &self, - format: wgt::TextureFormat, - ) -> wgt::TextureFormatFeatures { + pub fn get_texture_format_features(&self, format: TextureFormat) -> TextureFormatFeatures { Context::adapter_get_texture_format_features(&*self.context, &self.id, format) } } @@ -2187,11 +2184,7 @@ impl CommandEncoder { /// - `CLEAR_COMMANDS` extension not enabled /// - Texture does not have `COPY_DST` usage. /// - Range it out of bounds - pub fn clear_texture( - &mut self, - texture: &Texture, - subresource_range: &wgt::ImageSubresourceRange, - ) { + pub fn clear_texture(&mut self, texture: &Texture, subresource_range: &ImageSubresourceRange) { Context::command_encoder_clear_image( &*self.context, self.id.as_ref().unwrap(), @@ -2642,7 +2635,7 @@ impl<'a> RenderPass<'a> { /// /// You would need to upload this in three set_push_constants calls. First for the `Vertex` only range 0..4, second /// for the `Vertex | Fragment` range 4..8, third for the `Fragment` range 8..12. - pub fn set_push_constants(&mut self, stages: wgt::ShaderStages, offset: u32, data: &[u8]) { + pub fn set_push_constants(&mut self, stages: ShaderStages, offset: u32, data: &[u8]) { self.id.set_push_constants(stages, offset, data); } } @@ -2949,7 +2942,7 @@ impl<'a> RenderBundleEncoder<'a> { /// /// You would need to upload this in three set_push_constants calls. First for the `Vertex` only range 0..4, second /// for the `Vertex | Fragment` range 4..8, third for the `Fragment` range 8..12. - pub fn set_push_constants(&mut self, stages: wgt::ShaderStages, offset: u32, data: &[u8]) { + pub fn set_push_constants(&mut self, stages: ShaderStages, offset: u32, data: &[u8]) { self.id.set_push_constants(stages, offset, data); } }