Skip to content

Commit e78b04a

Browse files
committed
DepthStencilState validation fixes
The depth-related fields are optional in the WebGPU API, and must be specified iff they are relevant to the configuration. Fixes #8830
1 parent ad925ca commit e78b04a

File tree

22 files changed

+329
-124
lines changed

22 files changed

+329
-124
lines changed

CHANGELOG.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,40 @@ Bottom level categories:
4242

4343
## Unreleased
4444

45+
### Major Changes
46+
47+
#### Depth/stencil state changes
48+
49+
BREAKING CHANGE: Pipeline descriptors now use `DepthStencilStateIdl` instead of `DepthStencilState`.
50+
The new struct makes the `depth_write_enabled` and `depth_compare` fields optional, to match WebGPU.
51+
52+
The simplest way to adapt to this change is to use `.into()` to convert to the new struct:
53+
54+
```diff
55+
-depth_stencil: Some(wgpu::DepthStencilState {
56+
- format: wgpu::TextureFormat::Depth32Float,
57+
- depth_write_enabled: true,
58+
- depth_compare: wgpu::CompareFunction::Less,
59+
- stencil: wgpu::StencilState::default(),
60+
- bias: wgpu::DepthBiasState::default(),
61+
-}),
62+
+depth_stencil: Some(wgpu::DepthStencilState {
63+
+ format: wgpu::TextureFormat::Depth32Float,
64+
+ depth_write_enabled: true,
65+
+ depth_compare: wgpu::CompareFunction::Less,
66+
+ stencil: wgpu::StencilState::default(),
67+
+ bias: wgpu::DepthBiasState::default(),
68+
+}.into()),
69+
```
70+
71+
There are also new constructors which may be used instead of a struct literal:
72+
`DepthStencilState::new` (for simultaneous depth and stencil operations),
73+
`DepthStencilState::depth` (for depth operations), and `DepthStencilState::stencil` (for stencil operations).
74+
75+
`DepthStencilState` may be updated to match `DepthStencilStateIdl` in the future.
76+
In anticipation of this, the constructors are associated methods on
77+
`DepthStencilState` even though they construct `DepthStencilStateIdl`.
78+
4579
### New Features
4680

4781
#### General

cts_runner/test.lst

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -229,13 +229,7 @@ webgpu:api,validation,render_pass,render_pass_descriptor:resolveTarget,*
229229
webgpu:api,validation,render_pass,render_pass_descriptor:timestampWrite,query_index:*
230230
webgpu:api,validation,render_pass,render_pass_descriptor:timestampWrites,query_set_type:*
231231
webgpu:api,validation,render_pass,resolve:resolve_attachment:*
232-
webgpu:api,validation,render_pipeline,depth_stencil_state:depth_bias:*
233-
webgpu:api,validation,render_pipeline,depth_stencil_state:depth_test:*
234-
webgpu:api,validation,render_pipeline,depth_stencil_state:depth_write,frag_depth:*
235-
webgpu:api,validation,render_pipeline,depth_stencil_state:depth_write:*
236-
webgpu:api,validation,render_pipeline,depth_stencil_state:format:*
237-
webgpu:api,validation,render_pipeline,depth_stencil_state:stencil_test:*
238-
webgpu:api,validation,render_pipeline,depth_stencil_state:stencil_write:*
232+
webgpu:api,validation,render_pipeline,depth_stencil_state:*
239233
webgpu:api,validation,render_pipeline,float32_blendable:*
240234
webgpu:api,validation,render_pipeline,fragment_state:color_target_exists:*
241235
webgpu:api,validation,render_pipeline,fragment_state:dual_source_blending,use_blend_src:*

deno_webgpu/device.rs

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -882,15 +882,10 @@ impl GPUDevice {
882882
pass_op: depth_stencil.stencil_back.pass_op.into(),
883883
};
884884

885-
wgpu_types::DepthStencilState {
885+
wgpu_types::DepthStencilStateIdl {
886886
format: depth_stencil.format.into(),
887-
depth_write_enabled: depth_stencil
888-
.depth_write_enabled
889-
.unwrap_or_default(),
890-
depth_compare: depth_stencil
891-
.depth_compare
892-
.map(Into::into)
893-
.unwrap_or(wgpu_types::CompareFunction::Never), // TODO(wgpu): should be optional here
887+
depth_write_enabled: depth_stencil.depth_write_enabled,
888+
depth_compare: depth_stencil.depth_compare.map(Into::into),
894889
stencil: wgpu_types::StencilState {
895890
front,
896891
back,

examples/features/src/shadow/mod.rs

Lines changed: 24 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -506,17 +506,20 @@ impl crate::framework::Example for Example {
506506
.contains(wgpu::Features::DEPTH_CLIP_CONTROL),
507507
..Default::default()
508508
},
509-
depth_stencil: Some(wgpu::DepthStencilState {
510-
format: Self::SHADOW_FORMAT,
511-
depth_write_enabled: true,
512-
depth_compare: wgpu::CompareFunction::LessEqual,
513-
stencil: wgpu::StencilState::default(),
514-
bias: wgpu::DepthBiasState {
515-
constant: 2, // corresponds to bilinear filtering
516-
slope_scale: 2.0,
517-
clamp: 0.0,
518-
},
519-
}),
509+
depth_stencil: Some(
510+
wgpu::DepthStencilState {
511+
format: Self::SHADOW_FORMAT,
512+
depth_write_enabled: true,
513+
depth_compare: wgpu::CompareFunction::LessEqual,
514+
stencil: wgpu::StencilState::default(),
515+
bias: wgpu::DepthBiasState {
516+
constant: 2, // corresponds to bilinear filtering
517+
slope_scale: 2.0,
518+
clamp: 0.0,
519+
},
520+
}
521+
.into(),
522+
),
520523
multisample: wgpu::MultisampleState::default(),
521524
multiview_mask: None,
522525
cache: None,
@@ -645,13 +648,16 @@ impl crate::framework::Example for Example {
645648
cull_mode: Some(wgpu::Face::Back),
646649
..Default::default()
647650
},
648-
depth_stencil: Some(wgpu::DepthStencilState {
649-
format: Self::DEPTH_FORMAT,
650-
depth_write_enabled: true,
651-
depth_compare: wgpu::CompareFunction::Less,
652-
stencil: wgpu::StencilState::default(),
653-
bias: wgpu::DepthBiasState::default(),
654-
}),
651+
depth_stencil: Some(
652+
wgpu::DepthStencilState {
653+
format: Self::DEPTH_FORMAT,
654+
depth_write_enabled: true,
655+
depth_compare: wgpu::CompareFunction::Less,
656+
stencil: wgpu::StencilState::default(),
657+
bias: wgpu::DepthBiasState::default(),
658+
}
659+
.into(),
660+
),
655661
multisample: wgpu::MultisampleState::default(),
656662
multiview_mask: None,
657663
cache: None,

examples/features/src/skybox/mod.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -210,13 +210,16 @@ impl crate::framework::Example for Example {
210210
front_face: wgpu::FrontFace::Cw,
211211
..Default::default()
212212
},
213-
depth_stencil: Some(wgpu::DepthStencilState {
214-
format: Self::DEPTH_FORMAT,
215-
depth_write_enabled: false,
216-
depth_compare: wgpu::CompareFunction::LessEqual,
217-
stencil: wgpu::StencilState::default(),
218-
bias: wgpu::DepthBiasState::default(),
219-
}),
213+
depth_stencil: Some(
214+
wgpu::DepthStencilState {
215+
format: Self::DEPTH_FORMAT,
216+
depth_write_enabled: false,
217+
depth_compare: wgpu::CompareFunction::LessEqual,
218+
stencil: wgpu::StencilState::default(),
219+
bias: wgpu::DepthBiasState::default(),
220+
}
221+
.into(),
222+
),
220223
multisample: wgpu::MultisampleState::default(),
221224
multiview_mask: None,
222225
cache: None,
@@ -244,13 +247,16 @@ impl crate::framework::Example for Example {
244247
front_face: wgpu::FrontFace::Cw,
245248
..Default::default()
246249
},
247-
depth_stencil: Some(wgpu::DepthStencilState {
248-
format: Self::DEPTH_FORMAT,
249-
depth_write_enabled: true,
250-
depth_compare: wgpu::CompareFunction::LessEqual,
251-
stencil: wgpu::StencilState::default(),
252-
bias: wgpu::DepthBiasState::default(),
253-
}),
250+
depth_stencil: Some(
251+
wgpu::DepthStencilState {
252+
format: Self::DEPTH_FORMAT,
253+
depth_write_enabled: true,
254+
depth_compare: wgpu::CompareFunction::LessEqual,
255+
stencil: wgpu::StencilState::default(),
256+
bias: wgpu::DepthBiasState::default(),
257+
}
258+
.into(),
259+
),
254260
multisample: wgpu::MultisampleState::default(),
255261
multiview_mask: None,
256262
cache: None,

examples/features/src/stencil_triangles/mod.rs

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -83,22 +83,25 @@ impl crate::framework::Example for Example {
8383
})],
8484
}),
8585
primitive: Default::default(),
86-
depth_stencil: Some(wgpu::DepthStencilState {
87-
format: wgpu::TextureFormat::Stencil8,
88-
depth_write_enabled: false,
89-
depth_compare: wgpu::CompareFunction::Always,
90-
stencil: wgpu::StencilState {
91-
front: wgpu::StencilFaceState {
92-
compare: wgpu::CompareFunction::Always,
93-
pass_op: wgpu::StencilOperation::Replace,
94-
..Default::default()
86+
depth_stencil: Some(
87+
wgpu::DepthStencilState {
88+
format: wgpu::TextureFormat::Stencil8,
89+
depth_write_enabled: false,
90+
depth_compare: wgpu::CompareFunction::Always,
91+
stencil: wgpu::StencilState {
92+
front: wgpu::StencilFaceState {
93+
compare: wgpu::CompareFunction::Always,
94+
pass_op: wgpu::StencilOperation::Replace,
95+
..Default::default()
96+
},
97+
back: wgpu::StencilFaceState::IGNORE,
98+
read_mask: !0,
99+
write_mask: !0,
95100
},
96-
back: wgpu::StencilFaceState::IGNORE,
97-
read_mask: !0,
98-
write_mask: !0,
99-
},
100-
bias: Default::default(),
101-
}),
101+
bias: Default::default(),
102+
}
103+
.into(),
104+
),
102105
multisample: wgpu::MultisampleState::default(),
103106
multiview_mask: None,
104107
cache: None,
@@ -120,11 +123,9 @@ impl crate::framework::Example for Example {
120123
targets: &[Some(config.view_formats[0].into())],
121124
}),
122125
primitive: Default::default(),
123-
depth_stencil: Some(wgpu::DepthStencilState {
124-
format: wgpu::TextureFormat::Stencil8,
125-
depth_write_enabled: false,
126-
depth_compare: wgpu::CompareFunction::Always,
127-
stencil: wgpu::StencilState {
126+
depth_stencil: Some(wgpu::DepthStencilState::stencil(
127+
wgpu::TextureFormat::Stencil8,
128+
wgpu::StencilState {
128129
front: wgpu::StencilFaceState {
129130
compare: wgpu::CompareFunction::Greater,
130131
..Default::default()
@@ -133,8 +134,7 @@ impl crate::framework::Example for Example {
133134
read_mask: !0,
134135
write_mask: !0,
135136
},
136-
bias: Default::default(),
137-
}),
137+
)),
138138
multisample: wgpu::MultisampleState::default(),
139139
multiview_mask: None,
140140
cache: None,

examples/features/src/water/mod.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -555,16 +555,14 @@ impl crate::framework::Example for Example {
555555
// will work. Since this is water, we need to read from the
556556
// depth buffer both as a texture in the shader, and as an
557557
// input attachment to do depth-testing. We don't write, so
558-
// depth_write_enabled is set to false. This is called
559-
// RODS or read-only depth stencil.
560-
depth_stencil: Some(wgpu::DepthStencilState {
561-
// We don't use stencil.
562-
format: wgpu::TextureFormat::Depth32Float,
563-
depth_write_enabled: false,
564-
depth_compare: wgpu::CompareFunction::Less,
565-
stencil: wgpu::StencilState::default(),
566-
bias: wgpu::DepthBiasState::default(),
567-
}),
558+
// depth_write_enabled is set to false. This is called RODS,
559+
// or read-only depth stencil. Here, we don't use stencil.
560+
depth_stencil: Some(wgpu::DepthStencilState::depth(
561+
wgpu::TextureFormat::Depth32Float,
562+
false,
563+
wgpu::CompareFunction::Less,
564+
wgpu::DepthBiasState::default(),
565+
)),
568566
// No multisampling is used.
569567
multisample: wgpu::MultisampleState::default(),
570568
multiview_mask: None,
@@ -603,7 +601,7 @@ impl crate::framework::Example for Example {
603601
depth_compare: wgpu::CompareFunction::Less,
604602
stencil: wgpu::StencilState::default(),
605603
bias: wgpu::DepthBiasState::default(),
606-
}),
604+
}.into()),
607605
multisample: wgpu::MultisampleState::default(),
608606
multiview_mask: None,
609607
cache: None

tests/tests/wgpu-gpu/mesh_shader/mod.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -238,7 +238,7 @@ fn mesh_pipeline_build(ctx: &TestingContext, info: MeshPipelineTestInfo) {
238238
cull_mode: Some(wgpu::Face::Back),
239239
..Default::default()
240240
},
241-
depth_stencil: Some(depth_state),
241+
depth_stencil: Some(depth_state.into()),
242242
multisample: Default::default(),
243243
multiview: None,
244244
cache: None,
@@ -324,7 +324,7 @@ fn mesh_draw(ctx: &TestingContext, draw_type: DrawType, info: MeshPipelineTestIn
324324
cull_mode: Some(wgpu::Face::Back),
325325
..Default::default()
326326
},
327-
depth_stencil: Some(depth_state),
327+
depth_stencil: Some(depth_state.into()),
328328
multisample: Default::default(),
329329
multiview: None,
330330
cache: None,

tests/tests/wgpu-gpu/occlusion_query/mod.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -48,13 +48,16 @@ static OCCLUSION_QUERY: GpuTestConfiguration = GpuTestConfiguration::new()
4848
},
4949
fragment: None,
5050
primitive: wgpu::PrimitiveState::default(),
51-
depth_stencil: Some(wgpu::DepthStencilState {
52-
format: wgpu::TextureFormat::Depth32Float,
53-
depth_write_enabled: true,
54-
depth_compare: wgpu::CompareFunction::Less,
55-
stencil: wgpu::StencilState::default(),
56-
bias: wgpu::DepthBiasState::default(),
57-
}),
51+
depth_stencil: Some(
52+
wgpu::DepthStencilState {
53+
format: wgpu::TextureFormat::Depth32Float,
54+
depth_write_enabled: true,
55+
depth_compare: wgpu::CompareFunction::Less,
56+
stencil: wgpu::StencilState::default(),
57+
bias: wgpu::DepthBiasState::default(),
58+
}
59+
.into(),
60+
),
5861
multisample: wgpu::MultisampleState::default(),
5962
multiview_mask: None,
6063
cache: None,

tests/tests/wgpu-gpu/render_pass_ownership.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -537,13 +537,16 @@ fn resource_setup(ctx: &TestingContext) -> ResourceSetup {
537537
strip_index_format: Some(wgpu::IndexFormat::Uint32),
538538
..Default::default()
539539
},
540-
depth_stencil: Some(wgpu::DepthStencilState {
541-
format: depth_stencil_format,
542-
depth_write_enabled: true,
543-
depth_compare: wgpu::CompareFunction::LessEqual,
544-
stencil: wgpu::StencilState::default(),
545-
bias: wgpu::DepthBiasState::default(),
546-
}),
540+
depth_stencil: Some(
541+
wgpu::DepthStencilState {
542+
format: depth_stencil_format,
543+
depth_write_enabled: true,
544+
depth_compare: wgpu::CompareFunction::LessEqual,
545+
stencil: wgpu::StencilState::default(),
546+
bias: wgpu::DepthBiasState::default(),
547+
}
548+
.into(),
549+
),
547550
multisample: wgpu::MultisampleState {
548551
count: target_msaa,
549552
mask: !0,

0 commit comments

Comments
 (0)