|
| 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