Skip to content

Commit a9f5d30

Browse files
authored
shader/validation: Add tests for barrier builtins (#3324)
Test that they can only be called from compute shaders, and that they have no return value.
1 parent 25773c0 commit a9f5d30

File tree

2 files changed

+111
-0
lines changed

2 files changed

+111
-0
lines changed

src/webgpu/listing_meta.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1752,6 +1752,8 @@
17521752
"webgpu:shader,validation,expression,call,builtin,atanh:integer_argument:*": { "subcaseMS": 0.912 },
17531753
"webgpu:shader,validation,expression,call,builtin,atanh:values:*": { "subcaseMS": 0.231 },
17541754
"webgpu:shader,validation,expression,call,builtin,atomics:stage:*": { "subcaseMS": 1.346 },
1755+
"webgpu:shader,validation,expression,call,builtin,barriers:only_in_compute:*": { "subcaseMS": 1.500 },
1756+
"webgpu:shader,validation,expression,call,builtin,barriers:no_return_value:*": { "subcaseMS": 1.500 },
17551757
"webgpu:shader,validation,expression,call,builtin,bitcast:bad_const_to_f16:*": { "subcaseMS": 0.753 },
17561758
"webgpu:shader,validation,expression,call,builtin,bitcast:bad_const_to_f32:*": { "subcaseMS": 0.844 },
17571759
"webgpu:shader,validation,expression,call,builtin,bitcast:bad_to_f16:*": { "subcaseMS": 8.518 },
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
export const description = `
2+
Validation tests for {storage,texture,workgroup}Barrier() builtins.
3+
`;
4+
5+
import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
6+
import { keysOf } from '../../../../../../common/util/data_tables.js';
7+
import { ShaderValidationTest } from '../../../shader_validation_test.js';
8+
9+
export const g = makeTestGroup(ShaderValidationTest);
10+
11+
const kEntryPoints = {
12+
none: { supportsBarrier: true, code: `` },
13+
compute: {
14+
supportsBarrier: true,
15+
code: `@compute @workgroup_size(1)
16+
fn main() {
17+
foo();
18+
}`,
19+
},
20+
vertex: {
21+
supportsBarrier: false,
22+
code: `@vertex
23+
fn main() -> @builtin(position) vec4f {
24+
foo();
25+
return vec4f();
26+
}`,
27+
},
28+
fragment: {
29+
supportsBarrier: false,
30+
code: `@fragment
31+
fn main() {
32+
foo();
33+
}`,
34+
},
35+
compute_and_fragment: {
36+
supportsBarrier: false,
37+
code: `@compute @workgroup_size(1)
38+
fn main1() {
39+
foo();
40+
}
41+
42+
@fragment
43+
fn main2() {
44+
foo();
45+
}
46+
`,
47+
},
48+
fragment_without_call: {
49+
supportsBarrier: true,
50+
code: `@fragment
51+
fn main() {
52+
}
53+
`,
54+
},
55+
};
56+
57+
g.test('only_in_compute')
58+
.specURL('https://www.w3.org/TR/WGSL/#sync-builtin-functions')
59+
.desc(
60+
`
61+
Synchronization functions must only be used in the compute shader stage.
62+
`
63+
)
64+
.params(u =>
65+
u
66+
.combine('entry_point', keysOf(kEntryPoints))
67+
.combine('call', ['bar', 'storageBarrier', 'textureBarrier', 'workgroupBarrier'])
68+
)
69+
.fn(t => {
70+
if (t.params.call.startsWith('textureBarrier')) {
71+
t.skipIfLanguageFeatureNotSupported('readonly_and_readwrite_storage_textures');
72+
}
73+
74+
const config = kEntryPoints[t.params.entry_point];
75+
const code = `
76+
${config.code}
77+
fn bar() {}
78+
79+
fn foo() {
80+
${t.params.call}();
81+
}`;
82+
t.expectCompileResult(t.params.call === 'bar' || config.supportsBarrier, code);
83+
});
84+
85+
g.test('no_return_value')
86+
.specURL('https://www.w3.org/TR/WGSL/#sync-builtin-functions')
87+
.desc(
88+
`
89+
Barrier functions do not return a value.
90+
`
91+
)
92+
.params(u =>
93+
u
94+
.combine('assign', [false, true])
95+
.combine('rhs', ['bar', 'storageBarrier', 'textureBarrier', 'workgroupBarrier'])
96+
)
97+
.fn(t => {
98+
if (t.params.rhs.startsWith('textureBarrier')) {
99+
t.skipIfLanguageFeatureNotSupported('readonly_and_readwrite_storage_textures');
100+
}
101+
102+
const code = `
103+
fn bar() {}
104+
105+
fn foo() {
106+
${t.params.assign ? '_ = ' : ''} ${t.params.rhs}();
107+
}`;
108+
t.expectCompileResult(!t.params.assign || t.params.rhs === 'bar()', code);
109+
});

0 commit comments

Comments
 (0)