summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/expression/call/builtin/barriers.spec.ts
blob: 5a4ef1465742dc2ac1bdf2d8b847dc48881d68d8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
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);
  });