diff --git a/wgpu-core/src/command/bundle.rs b/wgpu-core/src/command/bundle.rs index 3f62056b90..7f2fd259b6 100644 --- a/wgpu-core/src/command/bundle.rs +++ b/wgpu-core/src/command/bundle.rs @@ -46,6 +46,7 @@ use crate::{ hub::{GlobalIdentityHandlerFactory, HalApi, Hub, Resource, Storage, Token}, id, memory_init_tracker::{MemoryInitKind, MemoryInitTrackerAction}, + pipeline::PipelineFlags, track::{TrackerSet, UsageConflict}, validation::check_buffer_usage, Label, LabelHelpers, LifeGuard, Stored, @@ -66,9 +67,9 @@ pub struct RenderBundleEncoderDescriptor<'a> { /// The formats of the color attachments that this render bundle is capable to rendering to. This /// must match the formats of the color attachments in the renderpass this render bundle is executed in. pub color_formats: Cow<'a, [wgt::TextureFormat]>, - /// The formats of the depth attachment that this render bundle is capable to rendering to. This - /// must match the formats of the depth attachments in the renderpass this render bundle is executed in. - pub depth_stencil_format: Option, + /// Information about the depth attachment that this render bundle is capable to rendering to. The format + /// must match the format of the depth attachments in the renderpass this render bundle is executed in. + 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, @@ -80,6 +81,7 @@ pub struct RenderBundleEncoder { base: BasePass, parent_id: id::DeviceId, pub(crate) context: RenderPassContext, + is_ds_read_only: bool, } impl RenderBundleEncoder { @@ -95,7 +97,7 @@ impl RenderBundleEncoder { attachments: AttachmentData { colors: desc.color_formats.iter().cloned().collect(), resolves: ArrayVec::new(), - depth_stencil: desc.depth_stencil_format, + depth_stencil: desc.depth_stencil.map(|ds| ds.format), }, sample_count: { let sc = desc.sample_count; @@ -105,6 +107,14 @@ impl RenderBundleEncoder { sc }, }, + is_ds_read_only: match desc.depth_stencil { + Some(ds) => { + let aspects = hal::FormatAspects::from(ds.format); + (!aspects.contains(hal::FormatAspects::DEPTH) || ds.depth_read_only) + && (!aspects.contains(hal::FormatAspects::STENCIL) || ds.stencil_read_only) + } + None => false, + }, }) } @@ -120,6 +130,7 @@ impl RenderBundleEncoder { }, sample_count: 0, }, + is_ds_read_only: false, } } @@ -235,7 +246,12 @@ impl RenderBundleEncoder { .map_err(RenderCommandError::IncompatiblePipeline) .map_pass_err(scope)?; - //TODO: check read-only depth + if pipeline.flags.contains(PipelineFlags::WRITES_DEPTH_STENCIL) + && self.is_ds_read_only + { + return Err(RenderCommandError::IncompatibleReadOnlyDepthStencil) + .map_pass_err(scope); + } let layout = &pipeline_layout_guard[pipeline.layout_id.value]; pipeline_layout_id = Some(pipeline.layout_id.value); diff --git a/wgpu-core/src/device/mod.rs b/wgpu-core/src/device/mod.rs index 8ea2c934f2..4772733035 100644 --- a/wgpu-core/src/device/mod.rs +++ b/wgpu-core/src/device/mod.rs @@ -1939,7 +1939,7 @@ impl Device { .iter() .any(|ct| ct.write_mask != first.write_mask || ct.blend != first.blend) } { - log::error!("Color targets: {:?}", color_targets); + log::info!("Color targets: {:?}", color_targets); self.require_downlevel_flags(wgt::DownlevelFlags::INDEPENDENT_BLENDING)?; } diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 6fc30da7cc..94ebea08a9 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -2746,6 +2746,20 @@ impl CommandBufferDescriptor { } } +/// Describes the depth/stencil attachment for render bundles. +#[repr(C)] +#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)] +#[cfg_attr(feature = "trace", derive(serde::Serialize))] +#[cfg_attr(feature = "replay", derive(serde::Deserialize))] +pub struct RenderBundleDepthStencil { + /// Format of the attachment. + pub format: TextureFormat, + /// True if the depth aspect is used but not modified. + pub depth_read_only: bool, + /// True if the stencil aspect is used but not modified. + pub stencil_read_only: bool, +} + /// Describes a [`RenderBundle`]. #[repr(C)] #[derive(Clone, Debug, PartialEq, Eq, Hash)] diff --git a/wgpu/examples/msaa-line/main.rs b/wgpu/examples/msaa-line/main.rs index 2430767b60..2b88a4c902 100644 --- a/wgpu/examples/msaa-line/main.rs +++ b/wgpu/examples/msaa-line/main.rs @@ -77,7 +77,7 @@ impl Example { device.create_render_bundle_encoder(&wgpu::RenderBundleEncoderDescriptor { label: None, color_formats: &[sc_desc.format], - depth_stencil_format: None, + depth_stencil: None, sample_count, }); encoder.set_pipeline(&pipeline); diff --git a/wgpu/src/backend/direct.rs b/wgpu/src/backend/direct.rs index 8903194827..16e6efd376 100644 --- a/wgpu/src/backend/direct.rs +++ b/wgpu/src/backend/direct.rs @@ -1291,7 +1291,7 @@ impl crate::Context for Context { let descriptor = wgc::command::RenderBundleEncoderDescriptor { label: desc.label.map(Borrowed), color_formats: Borrowed(desc.color_formats), - depth_stencil_format: desc.depth_stencil_format, + depth_stencil: desc.depth_stencil, sample_count: desc.sample_count, }; match wgc::command::RenderBundleEncoder::new(&descriptor, device.id, None) { diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index fe3d8ea9bf..42b0dbf707 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -1324,9 +1324,9 @@ pub struct RenderBundleEncoderDescriptor<'a> { /// The formats of the color attachments that this render bundle is capable to rendering to. This /// must match the formats of the color attachments in the renderpass this render bundle is executed in. pub color_formats: &'a [TextureFormat], - /// The formats of the depth attachment that this render bundle is capable to rendering to. This - /// must match the formats of the depth attachments in the renderpass this render bundle is executed in. - pub depth_stencil_format: Option, + /// 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, /// 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,