Skip to content

Commit

Permalink
shader/validation: Add tests for barrier builtins (#3324)
Browse files Browse the repository at this point in the history
Test that they can only be called from compute shaders, and that they
have no return value.
  • Loading branch information
jrprice authored Jan 25, 2024
1 parent 25773c0 commit a9f5d30
Show file tree
Hide file tree
Showing 2 changed files with 111 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1752,6 +1752,8 @@
"webgpu:shader,validation,expression,call,builtin,atanh:integer_argument:*": { "subcaseMS": 0.912 },
"webgpu:shader,validation,expression,call,builtin,atanh:values:*": { "subcaseMS": 0.231 },
"webgpu:shader,validation,expression,call,builtin,atomics:stage:*": { "subcaseMS": 1.346 },
"webgpu:shader,validation,expression,call,builtin,barriers:only_in_compute:*": { "subcaseMS": 1.500 },
"webgpu:shader,validation,expression,call,builtin,barriers:no_return_value:*": { "subcaseMS": 1.500 },
"webgpu:shader,validation,expression,call,builtin,bitcast:bad_const_to_f16:*": { "subcaseMS": 0.753 },
"webgpu:shader,validation,expression,call,builtin,bitcast:bad_const_to_f32:*": { "subcaseMS": 0.844 },
"webgpu:shader,validation,expression,call,builtin,bitcast:bad_to_f16:*": { "subcaseMS": 8.518 },
Expand Down
109 changes: 109 additions & 0 deletions src/webgpu/shader/validation/expression/call/builtin/barriers.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
export const description = `
Validation tests for {storage,texture,workgroup}Barrier() builtins.
`;

import { makeTestGroup } from '../../../../../../common/framework/test_group.js';
import { keysOf } from '../../../../../../common/util/data_tables.js';
import { ShaderValidationTest } from '../../../shader_validation_test.js';

export const g = makeTestGroup(ShaderValidationTest);

const kEntryPoints = {
none: { supportsBarrier: true, code: `` },
compute: {
supportsBarrier: true,
code: `@compute @workgroup_size(1)
fn main() {
foo();
}`,
},
vertex: {
supportsBarrier: false,
code: `@vertex
fn main() -> @builtin(position) vec4f {
foo();
return vec4f();
}`,
},
fragment: {
supportsBarrier: false,
code: `@fragment
fn main() {
foo();
}`,
},
compute_and_fragment: {
supportsBarrier: false,
code: `@compute @workgroup_size(1)
fn main1() {
foo();
}
@fragment
fn main2() {
foo();
}
`,
},
fragment_without_call: {
supportsBarrier: true,
code: `@fragment
fn main() {
}
`,
},
};

g.test('only_in_compute')
.specURL('https://www.w3.org/TR/WGSL/#sync-builtin-functions')
.desc(
`
Synchronization functions must only be used in the compute shader stage.
`
)
.params(u =>
u
.combine('entry_point', keysOf(kEntryPoints))
.combine('call', ['bar', 'storageBarrier', 'textureBarrier', 'workgroupBarrier'])
)
.fn(t => {
if (t.params.call.startsWith('textureBarrier')) {
t.skipIfLanguageFeatureNotSupported('readonly_and_readwrite_storage_textures');
}

const config = kEntryPoints[t.params.entry_point];
const code = `
${config.code}
fn bar() {}
fn foo() {
${t.params.call}();
}`;
t.expectCompileResult(t.params.call === 'bar' || config.supportsBarrier, code);
});

g.test('no_return_value')
.specURL('https://www.w3.org/TR/WGSL/#sync-builtin-functions')
.desc(
`
Barrier functions do not return a value.
`
)
.params(u =>
u
.combine('assign', [false, true])
.combine('rhs', ['bar', 'storageBarrier', 'textureBarrier', 'workgroupBarrier'])
)
.fn(t => {
if (t.params.rhs.startsWith('textureBarrier')) {
t.skipIfLanguageFeatureNotSupported('readonly_and_readwrite_storage_textures');
}

const code = `
fn bar() {}
fn foo() {
${t.params.assign ? '_ = ' : ''} ${t.params.rhs}();
}`;
t.expectCompileResult(!t.params.assign || t.params.rhs === 'bar()', code);
});

0 comments on commit a9f5d30

Please sign in to comment.