diff --git a/tests/tests/wgpu-gpu/pass_ops/mod.rs b/tests/tests/wgpu-gpu/pass_ops/mod.rs index e6fc49606..c16559136 100644 --- a/tests/tests/wgpu-gpu/pass_ops/mod.rs +++ b/tests/tests/wgpu-gpu/pass_ops/mod.rs @@ -1,18 +1,23 @@ use wgpu_test::{ - gpu_test, image::ReadbackBuffers, GpuTestConfiguration, GpuTestInitializer, TestParameters, - TestingContext, + fail, gpu_test, image::ReadbackBuffers, GpuTestConfiguration, GpuTestInitializer, + TestParameters, TestingContext, }; pub fn all_tests(vec: &mut Vec) { - vec.push(DONT_CARE); + vec.extend([ + DONT_CARE, + DONT_CARE_COLOR_STRICT_WEBGPU_COMPLIANCE, + DONT_CARE_DEPTH_STRICT_WEBGPU_COMPLIANCE, + DONT_CARE_STENCIL_STRICT_WEBGPU_COMPLIANCE, + ]); } #[gpu_test] static DONT_CARE: GpuTestConfiguration = GpuTestConfiguration::new() .parameters(TestParameters::default()) - .run_async(run_test); + .run_async(dont_care); -async fn run_test(ctx: TestingContext) { +async fn dont_care(ctx: TestingContext) { let shader_src = " const triangles = array(vec2f(-1.0, -1.0), vec2f(3.0, -1.0), vec2f(-1.0, 3.0)); @@ -109,3 +114,137 @@ async fn run_test(ctx: TestingContext) { .assert_buffer_contents(&ctx, &[127, 127, 127, 127]) .await; } + +#[gpu_test] +static DONT_CARE_COLOR_STRICT_WEBGPU_COMPLIANCE: GpuTestConfiguration = GpuTestConfiguration::new() + .parameters( + TestParameters::default() + .instance_flags(wgpu::InstanceFlags::STRICT_WEBGPU_COMPLIANCE) + .enable_noop(), + ) + .run_sync(|ctx| { + let tex = ctx.device.create_texture(&wgpu::TextureDescriptor { + label: None, + size: wgpu::Extent3d { + width: 1, + height: 1, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::Rgba8Unorm, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + view_formats: &[], + }); + let view = tex.create_view(&wgpu::TextureViewDescriptor::default()); + let mut encoder = ctx + .device + .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); + encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + color_attachments: &[Some(wgpu::RenderPassColorAttachment { + view: &view, + depth_slice: None, + resolve_target: None, + ops: wgpu::Operations { + load: wgpu::LoadOp::DontCare(unsafe { wgpu::LoadOpDontCare::enabled() }), + store: wgpu::StoreOp::Store, + }, + })], + ..Default::default() + }); + fail( + &ctx.device, + || encoder.finish(), + Some("STRICT_WEBGPU_COMPLIANCE"), + ); + }); + +#[gpu_test] +static DONT_CARE_DEPTH_STRICT_WEBGPU_COMPLIANCE: GpuTestConfiguration = GpuTestConfiguration::new() + .parameters( + TestParameters::default() + .instance_flags(wgpu::InstanceFlags::STRICT_WEBGPU_COMPLIANCE) + .enable_noop(), + ) + .run_sync(|ctx| { + let tex = ctx.device.create_texture(&wgpu::TextureDescriptor { + label: None, + size: wgpu::Extent3d { + width: 1, + height: 1, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::Depth16Unorm, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + view_formats: &[], + }); + let view = tex.create_view(&wgpu::TextureViewDescriptor::default()); + let mut encoder = ctx + .device + .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); + encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &view, + depth_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::DontCare(unsafe { wgpu::LoadOpDontCare::enabled() }), + store: wgpu::StoreOp::Store, + }), + stencil_ops: None, + }), + ..Default::default() + }); + fail( + &ctx.device, + || encoder.finish(), + Some("STRICT_WEBGPU_COMPLIANCE"), + ); + }); + +#[gpu_test] +static DONT_CARE_STENCIL_STRICT_WEBGPU_COMPLIANCE: GpuTestConfiguration = + GpuTestConfiguration::new() + .parameters( + TestParameters::default() + .instance_flags(wgpu::InstanceFlags::STRICT_WEBGPU_COMPLIANCE) + .enable_noop(), + ) + .run_sync(|ctx| { + let tex = ctx.device.create_texture(&wgpu::TextureDescriptor { + label: None, + size: wgpu::Extent3d { + width: 1, + height: 1, + depth_or_array_layers: 1, + }, + mip_level_count: 1, + sample_count: 1, + dimension: wgpu::TextureDimension::D2, + format: wgpu::TextureFormat::Stencil8, + usage: wgpu::TextureUsages::RENDER_ATTACHMENT, + view_formats: &[], + }); + let view = tex.create_view(&wgpu::TextureViewDescriptor::default()); + let mut encoder = ctx + .device + .create_command_encoder(&wgpu::CommandEncoderDescriptor::default()); + encoder.begin_render_pass(&wgpu::RenderPassDescriptor { + depth_stencil_attachment: Some(wgpu::RenderPassDepthStencilAttachment { + view: &view, + depth_ops: None, + stencil_ops: Some(wgpu::Operations { + load: wgpu::LoadOp::DontCare(unsafe { wgpu::LoadOpDontCare::enabled() }), + store: wgpu::StoreOp::Store, + }), + }), + ..Default::default() + }); + fail( + &ctx.device, + || encoder.finish(), + Some("STRICT_WEBGPU_COMPLIANCE"), + ); + }); diff --git a/wgpu-core/src/command/render.rs b/wgpu-core/src/command/render.rs index 279e95930..fbbf0bd85 100644 --- a/wgpu-core/src/command/render.rs +++ b/wgpu-core/src/command/render.rs @@ -6,8 +6,8 @@ use arrayvec::ArrayVec; use thiserror::Error; use wgt::{ error::{ErrorType, WebGpuError}, - BufferAddress, BufferSize, BufferUsages, Color, DynamicOffset, IndexFormat, TextureSelector, - TextureUsages, TextureViewDimension, VertexStepMode, + BufferAddress, BufferSize, BufferUsages, Color, DynamicOffset, IndexFormat, InstanceFlags, + TextureSelector, TextureUsages, TextureViewDimension, VertexStepMode, }; use crate::{ @@ -109,6 +109,7 @@ pub struct PassChannel { impl PassChannel> { fn resolve( &self, + instance_flags: InstanceFlags, handle_clear: impl Fn(Option) -> Result, ) -> Result, AttachmentError> { if self.read_only { @@ -123,7 +124,12 @@ impl PassChannel> { Ok(ResolvedPassChannel::Operational(wgt::Operations { load: match self.load_op.ok_or(AttachmentError::NoLoad)? { LoadOp::Clear(clear_value) => LoadOp::Clear(handle_clear(clear_value)?), - LoadOp::DontCare(token) => LoadOp::DontCare(token), + LoadOp::DontCare(token) => { + if instance_flags.contains(InstanceFlags::STRICT_WEBGPU_COMPLIANCE) { + return Err(AttachmentError::LoadOpDontCareUnderStrictWebgpuCompliance); + } + LoadOp::DontCare(token) + } LoadOp::Load => LoadOp::Load, }, store: self.store_op.ok_or(AttachmentError::NoStore)?, @@ -803,6 +809,8 @@ pub enum ColorAttachmentError { }, #[error("Color attachment's usage contains {0:?}. This can only be used with StoreOp::{1:?}, but StoreOp::{2:?} was provided")] InvalidUsageForStoreOp(TextureUsages, StoreOp, StoreOp), + #[error("Color attachment's load op is `LoadOp::DontCare` but `InstanceFlags::STRICT_WEBGPU_COMPLIANCE` is set")] + LoadOpDontCareUnderStrictWebgpuCompliance, } impl WebGpuError for ColorAttachmentError { @@ -838,6 +846,8 @@ pub enum AttachmentError { NoClearValue, #[error("Clear value ({0}) must be between 0.0 and 1.0, inclusive")] ClearValueOutOfRange(f32), + #[error("Load op is `DontCare` but `InstanceFlags::STRICT_WEBGPU_COMPLIANCE` is set")] + LoadOpDontCareUnderStrictWebgpuCompliance, } impl WebGpuError for AttachmentError { @@ -1688,7 +1698,7 @@ impl RenderPassInfo { raw: &mut dyn hal::DynCommandEncoder, snatch_guard: &SnatchGuard, scope: &mut UsageScope<'_>, - instance_flags: wgt::InstanceFlags, + instance_flags: InstanceFlags, ) -> Result<(), RenderPassErrorInner> { profiling::scope!("RenderPassInfo::finish"); unsafe { @@ -1811,6 +1821,16 @@ impl Global { let view = texture_views.get(*view_id).get()?; view.same_device(device)?; + if matches!(*load_op, LoadOp::DontCare(..)) + && device + .instance_flags + .contains(InstanceFlags::STRICT_WEBGPU_COMPLIANCE) + { + return Err(RenderPassErrorInner::ColorAttachment( + ColorAttachmentError::LoadOpDontCareUnderStrictWebgpuCompliance, + )); + } + if view.desc.usage.contains(TextureUsages::TRANSIENT) && *store_op != StoreOp::Discard { @@ -1862,7 +1882,7 @@ impl Global { Some(ResolvedRenderPassDepthStencilAttachment { view, depth: if format.has_depth_aspect() { - depth_stencil_attachment.depth.resolve(|clear| if let Some(clear) = clear { + depth_stencil_attachment.depth.resolve(device.instance_flags, |clear| if let Some(clear) = clear { // If this.depthLoadOp is "clear", this.depthClearValue must be provided and must be between 0.0 and 1.0, inclusive. if !(0.0..=1.0).contains(&clear) { Err(AttachmentError::ClearValueOutOfRange(clear)) @@ -1882,7 +1902,7 @@ impl Global { ResolvedPassChannel::ReadOnly }, stencil: if format.has_stencil_aspect() { - depth_stencil_attachment.stencil.resolve(|clear| { + depth_stencil_attachment.stencil.resolve(device.instance_flags, |clear| { Ok(convert_stencil_value(clear.unwrap_or_default(), Some(format))) })? } else {