summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/shader/validation/shader_io/entry_point.spec.ts
blob: 9aa7319348a2b55bc266de24842f1e8cdc12acbd (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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
export const description = `Validation tests for attributes and entry point requirements`;

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

export const g = makeTestGroup(ShaderValidationTest);

g.test('missing_attribute_on_param')
  .desc(`Test that an entry point without an IO attribute on one of its parameters is rejected.`)
  .params(u =>
    u.combine('target_stage', ['', 'vertex', 'fragment', 'compute'] as const).beginSubcases()
  )
  .fn(t => {
    const vertex_attr = t.params.target_stage === 'vertex' ? '' : '@location(1)';
    const fragment_attr = t.params.target_stage === 'fragment' ? '' : '@location(1)';
    const compute_attr = t.params.target_stage === 'compute' ? '' : '@builtin(workgroup_id)';
    const code = `
@vertex
fn vert_main(@location(0) a : f32,
             ${vertex_attr}  b : f32,
@             location(2) c : f32) -> @builtin(position) vec4<f32> {
  return vec4<f32>();
}

@fragment
fn frag_main(@location(0)  a : f32,
             ${fragment_attr} b : f32,
@             location(2)  c : f32) {
}

@compute @workgroup_size(1)
fn comp_main(@builtin(global_invocation_id) a : vec3<u32>,
             ${compute_attr}                   b : vec3<u32>,
             @builtin(local_invocation_id)  c : vec3<u32>) {
}
`;
    t.expectCompileResult(t.params.target_stage === '', code);
  });

g.test('missing_attribute_on_param_struct')
  .desc(
    `Test that an entry point struct parameter without an IO attribute on one of its members is rejected.`
  )
  .params(u =>
    u.combine('target_stage', ['', 'vertex', 'fragment', 'compute'] as const).beginSubcases()
  )
  .fn(t => {
    const vertex_attr = t.params.target_stage === 'vertex' ? '' : '@location(1)';
    const fragment_attr = t.params.target_stage === 'fragment' ? '' : '@location(1)';
    const compute_attr = t.params.target_stage === 'compute' ? '' : '@builtin(workgroup_id)';
    const code = `
struct VertexInputs {
  @location(0) a : f32,
  ${vertex_attr}  b : f32,
@  location(2) c : f32,
};
struct FragmentInputs {
  @location(0)  a : f32,
  ${fragment_attr} b : f32,
@  location(2)  c : f32,
};
struct ComputeInputs {
  @builtin(global_invocation_id) a : vec3<u32>,
  ${compute_attr}                   b : vec3<u32>,
  @builtin(local_invocation_id)  c : vec3<u32>,
};

@vertex
fn vert_main(inputs : VertexInputs) -> @builtin(position) vec4<f32> {
  return vec4<f32>();
}

@fragment
fn frag_main(inputs : FragmentInputs) {
}

@compute @workgroup_size(1)
fn comp_main(inputs : ComputeInputs) {
}
`;
    t.expectCompileResult(t.params.target_stage === '', code);
  });

g.test('missing_attribute_on_return_type')
  .desc(`Test that an entry point without an IO attribute on its return type is rejected.`)
  .params(u => u.combine('target_stage', ['', 'vertex', 'fragment'] as const).beginSubcases())
  .fn(t => {
    const vertex_attr = t.params.target_stage === 'vertex' ? '' : '@builtin(position)';
    const fragment_attr = t.params.target_stage === 'fragment' ? '' : '@location(0)';
    const code = `
@vertex
fn vert_main() -> ${vertex_attr} vec4<f32> {
  return vec4<f32>();
}

@fragment
fn frag_main() -> ${fragment_attr} vec4<f32> {
  return vec4<f32>();
}
`;
    t.expectCompileResult(t.params.target_stage === '', code);
  });

g.test('missing_attribute_on_return_type_struct')
  .desc(
    `Test that an entry point struct return type without an IO attribute on one of its members is rejected.`
  )
  .params(u => u.combine('target_stage', ['', 'vertex', 'fragment'] as const).beginSubcases())
  .fn(t => {
    const vertex_attr = t.params.target_stage === 'vertex' ? '' : '@location(1)';
    const fragment_attr = t.params.target_stage === 'fragment' ? '' : '@location(1)';
    const code = `
struct VertexOutputs {
  @location(0)       a : f32,
  ${vertex_attr}        b : f32,
  @builtin(position) c : vec4<f32>,
};
struct FragmentOutputs {
  @location(0)  a : f32,
  ${fragment_attr} b : f32,
@  location(2)  c : f32,
};

@vertex
fn vert_main() -> VertexOutputs {
  return VertexOutputs();
}

@fragment
fn frag_main() -> FragmentOutputs {
  return FragmentOutputs();
}
`;
    t.expectCompileResult(t.params.target_stage === '', code);
  });

g.test('no_entry_point_provided')
  .desc(`Tests that a shader without an entry point is accepted`)
  .fn(t => {
    t.expectCompileResult(true, 'fn main() {}');
  });