File tree Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Expand file tree Collapse file tree 4 files changed +44
-2
lines changed Original file line number Diff line number Diff line change @@ -40,13 +40,32 @@ Bottom level categories:
40
40
41
41
## Unreleased
42
42
43
+ ### Major Changes
44
+
45
+ #### @invariant Warning
46
+
47
+ When using CompareFunction::Equal or CompareFunction::NotEqual on a pipeline, there is now a warning logged if the vertex
48
+ shader does not have a @invariant tag on it. On some machines, rendering the same triangles multiple times without an
49
+ @invariant tag will result in slightly different depths for every pixel. Because the * Equal functions rely on depth being
50
+ the same every time it is rendered, we now warn if it is missing.
51
+
52
+ ``` diff
53
+ - @vertex
54
+ - fn vert_main(v_in: VertexInput) -> @builtin(position) vec4<f32> {...}
55
+ + @vertex
56
+ + fn vert_main(v_in: VertexInput) -> @builtin(position) @invariant vec4<f32> {...}
57
+ ```
58
+
43
59
### Bug Fixes
44
60
45
61
#### General
46
62
- Improve the validation and error reporting of buffer mappings by @nical in [ #2848 ] ( https://github.com/gfx-rs/wgpu/pull/2848 )
47
63
48
64
### Changes
49
65
66
+ #### General
67
+ - Add warning when using CompareFunction::* Equal with vertex shader that is missing @invariant tag by @cwfitzgerald in [ #2887 ] ( https://github.com/gfx-rs/wgpu/pull/2887 )
68
+
50
69
#### Metal
51
70
- Extract the generic code into ` get_metal_layer ` by @jinleili in [ #2826 ] ( https://github.com/gfx-rs/wgpu/pull/2826 )
52
71
Original file line number Diff line number Diff line change @@ -2379,6 +2379,7 @@ impl<A: HalApi> Device<A> {
2379
2379
& desc. stage . entry_point ,
2380
2380
flag,
2381
2381
io,
2382
+ None ,
2382
2383
) ?;
2383
2384
}
2384
2385
}
@@ -2704,6 +2705,7 @@ impl<A: HalApi> Device<A> {
2704
2705
& stage. entry_point ,
2705
2706
flag,
2706
2707
io,
2708
+ desc. depth_stencil . as_ref ( ) . map ( |d| d. depth_compare ) ,
2707
2709
)
2708
2710
. map_err ( |error| pipeline:: CreateRenderPipelineError :: Stage {
2709
2711
stage : flag,
@@ -2750,6 +2752,7 @@ impl<A: HalApi> Device<A> {
2750
2752
& fragment. stage . entry_point ,
2751
2753
flag,
2752
2754
io,
2755
+ desc. depth_stencil . as_ref ( ) . map ( |d| d. depth_compare ) ,
2753
2756
)
2754
2757
. map_err ( |error| pipeline:: CreateRenderPipelineError :: Stage {
2755
2758
stage : flag,
Original file line number Diff line number Diff line change @@ -963,6 +963,7 @@ impl Interface {
963
963
entry_point_name : & str ,
964
964
stage_bit : wgt:: ShaderStages ,
965
965
inputs : StageIo ,
966
+ compare_function : Option < wgt:: CompareFunction > ,
966
967
) -> Result < StageIo , StageError > {
967
968
// Since a shader module can have multiple entry points with the same name,
968
969
// we need to look for one with the right execution model.
@@ -1183,6 +1184,21 @@ impl Interface {
1183
1184
Varying :: Local { ref iv, .. } => iv. ty . dim . num_components ( ) ,
1184
1185
Varying :: BuiltIn ( _) => 0 ,
1185
1186
} ;
1187
+
1188
+ if let Some (
1189
+ cmp @ wgt:: CompareFunction :: Equal | cmp @ wgt:: CompareFunction :: NotEqual ,
1190
+ ) = compare_function
1191
+ {
1192
+ if let Varying :: BuiltIn ( naga:: BuiltIn :: Position { invariant : false } ) = * output
1193
+ {
1194
+ log:: warn!(
1195
+ "Vertex shader with entry point {entry_point_name} outputs a @builtin(position) without the @invariant \
1196
+ attribute and is used in a pipeline with {cmp:?}. On some machines, this can cause bad artifacting as {cmp:?} assumes \
1197
+ the values output from the vertex shader exactly match the value in the depth buffer. The @invariant attribute on the \
1198
+ @builtin(position) vertex output ensures that the exact same pixel depths are used every render."
1199
+ ) ;
1200
+ }
1201
+ }
1186
1202
}
1187
1203
}
1188
1204
Original file line number Diff line number Diff line change @@ -2602,13 +2602,17 @@ pub enum CompareFunction {
2602
2602
Never = 1 ,
2603
2603
/// Function passes if new value less than existing value
2604
2604
Less = 2 ,
2605
- /// Function passes if new value is equal to existing value
2605
+ /// Function passes if new value is equal to existing value. When using
2606
+ /// this compare function, make sure to mark your Vertex Shader's `@builtin(position)`
2607
+ /// output as `@invariant` to prevent artifacting.
2606
2608
Equal = 3 ,
2607
2609
/// Function passes if new value is less than or equal to existing value
2608
2610
LessEqual = 4 ,
2609
2611
/// Function passes if new value is greater than existing value
2610
2612
Greater = 5 ,
2611
- /// Function passes if new value is not equal to existing value
2613
+ /// Function passes if new value is not equal to existing value. When using
2614
+ /// this compare function, make sure to mark your Vertex Shader's `@builtin(position)`
2615
+ /// output as `@invariant` to prevent artifacting.
2612
2616
NotEqual = 6 ,
2613
2617
/// Function passes if new value is greater than or equal to existing value
2614
2618
GreaterEqual = 7 ,
You can’t perform that action at this time.
0 commit comments