summaryrefslogtreecommitdiffstats
path: root/dom/webgpu/tests/cts/checkout/src/webgpu/api/validation/render_pipeline/overrides.spec.ts
blob: bdf0024722491c1ee6ae66453233499f5d9ceb94 (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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
export const description = `
This test dedicatedly tests validation of pipeline overridable constants of createRenderPipeline.
`;

import { makeTestGroup } from '../../../../common/framework/test_group.js';
import { kValue } from '../../../util/constants.js';

import { CreateRenderPipelineValidationTest } from './common.js';

export const g = makeTestGroup(CreateRenderPipelineValidationTest);

g.test('identifier,vertex')
  .desc(
    `
Tests calling createRenderPipeline(Async) validation for overridable constants identifiers in vertex state.
`
  )
  .params(u =>
    u //
      .combine('isAsync', [true, false])
      .combineWithParams([
        { vertexConstants: {}, _success: true },
        { vertexConstants: { x: 1, y: 1 }, _success: true },
        { vertexConstants: { x: 1, y: 1, 1: 1, 1000: 1 }, _success: true },
        { vertexConstants: { xxx: 1 }, _success: false },
        { vertexConstants: { 1: 1 }, _success: true },
        { vertexConstants: { 2: 1 }, _success: false },
        { vertexConstants: { z: 1 }, _success: false }, // pipeline constant id is specified for z
        { vertexConstants: { w: 1 }, _success: false }, // pipeline constant id is specified for w
        { vertexConstants: { 1: 1, z: 1 }, _success: false }, // pipeline constant id is specified for z
      ] as { vertexConstants: Record<string, GPUPipelineConstantValue>; _success: boolean }[])
  )
  .fn(async t => {
    const { isAsync, vertexConstants, _success } = t.params;

    t.doCreateRenderPipelineTest(isAsync, _success, {
      layout: 'auto',
      vertex: {
        module: t.device.createShaderModule({
          code: `
            override x: f32 = 0.0;
            override y: f32 = 0.0;
            @id(1) override z: f32 = 0.0;
            @id(1000) override w: f32 = 1.0;
            @vertex fn main() -> @builtin(position) vec4<f32> {
              return vec4<f32>(x, y, z, w);
            }`,
        }),
        entryPoint: 'main',
        constants: vertexConstants,
      },
      fragment: {
        module: t.device.createShaderModule({
          code: `@fragment fn main() -> @location(0) vec4<f32> {
              return vec4<f32>(0.0, 1.0, 0.0, 1.0);
            }`,
        }),
        entryPoint: 'main',
        targets: [{ format: 'rgba8unorm' }],
      },
    });
  });

g.test('identifier,fragment')
  .desc(
    `
Tests calling createRenderPipeline(Async) validation for overridable constants identifiers in fragment state.
`
  )
  .params(u =>
    u //
      .combine('isAsync', [true, false])
      .combineWithParams([
        { fragmentConstants: {}, _success: true },
        { fragmentConstants: { r: 1, g: 1 }, _success: true },
        { fragmentConstants: { r: 1, g: 1, 1: 1, 1000: 1 }, _success: true },
        { fragmentConstants: { xxx: 1 }, _success: false },
        { fragmentConstants: { 1: 1 }, _success: true },
        { fragmentConstants: { 2: 1 }, _success: false },
        { fragmentConstants: { b: 1 }, _success: false }, // pipeline constant id is specified for b
        { fragmentConstants: { a: 1 }, _success: false }, // pipeline constant id is specified for a
        { fragmentConstants: { 1: 1, b: 1 }, _success: false }, // pipeline constant id is specified for b
      ] as { fragmentConstants: Record<string, GPUPipelineConstantValue>; _success: boolean }[])
  )
  .fn(async t => {
    const { isAsync, fragmentConstants, _success } = t.params;

    const descriptor = t.getDescriptor({
      fragmentShaderCode: `
        override r: f32 = 0.0;
        override g: f32 = 0.0;
        @id(1) override b: f32 = 0.0;
        @id(1000) override a: f32 = 0.0;
        @fragment fn main()
            -> @location(0) vec4<f32> {
            return vec4<f32>(r, g, b, a);
        }`,
      fragmentConstants,
    });

    t.doCreateRenderPipelineTest(isAsync, _success, descriptor);
  });

g.test('uninitialized,vertex')
  .desc(
    `
Tests calling createRenderPipeline(Async) validation for uninitialized overridable constants in vertex state.
`
  )
  .params(u =>
    u //
      .combine('isAsync', [true, false])
      .combineWithParams([
        { vertexConstants: {}, _success: false },
        { vertexConstants: { x: 1, y: 1 }, _success: false }, // z is missing
        { vertexConstants: { x: 1, z: 1 }, _success: true },
        { vertexConstants: { x: 1, y: 1, z: 1, w: 1 }, _success: true },
      ] as { vertexConstants: Record<string, GPUPipelineConstantValue>; _success: boolean }[])
  )
  .fn(async t => {
    const { isAsync, vertexConstants, _success } = t.params;

    t.doCreateRenderPipelineTest(isAsync, _success, {
      layout: 'auto',
      vertex: {
        module: t.device.createShaderModule({
          code: `
            override x: f32;
            override y: f32 = 0.0;
            override z: f32;
            override w: f32 = 1.0;
            @vertex fn main() -> @builtin(position) vec4<f32> {
              return vec4<f32>(x, y, z, w);
            }`,
        }),
        entryPoint: 'main',
        constants: vertexConstants,
      },
      fragment: {
        module: t.device.createShaderModule({
          code: `@fragment fn main() -> @location(0) vec4<f32> {
              return vec4<f32>(0.0, 1.0, 0.0, 1.0);
            }`,
        }),
        entryPoint: 'main',
        targets: [{ format: 'rgba8unorm' }],
      },
    });
  });

g.test('uninitialized,fragment')
  .desc(
    `
Tests calling createRenderPipeline(Async) validation for uninitialized overridable constants in fragment state.
`
  )
  .params(u =>
    u //
      .combine('isAsync', [true, false])
      .combineWithParams([
        { fragmentConstants: {}, _success: false },
        { fragmentConstants: { r: 1, g: 1 }, _success: false }, // b is missing
        { fragmentConstants: { r: 1, b: 1 }, _success: true },
        { fragmentConstants: { r: 1, g: 1, b: 1, a: 1 }, _success: true },
      ] as { fragmentConstants: Record<string, GPUPipelineConstantValue>; _success: boolean }[])
  )
  .fn(async t => {
    const { isAsync, fragmentConstants, _success } = t.params;

    const descriptor = t.getDescriptor({
      fragmentShaderCode: `
        override r: f32;
        override g: f32 = 0.0;
        override b: f32;
        override a: f32 = 0.0;
        @fragment fn main()
            -> @location(0) vec4<f32> {
            return vec4<f32>(r, g, b, a);
        }
          `,
      fragmentConstants,
    });

    t.doCreateRenderPipelineTest(isAsync, _success, descriptor);
  });

g.test('value,type_error,vertex')
  .desc(
    `
Tests calling createRenderPipeline(Async) validation for invalid constant values like inf, NaN will results in TypeError.
`
  )
  .params(u =>
    u //
      .combine('isAsync', [true, false])
      .combineWithParams([
        { vertexConstants: { cf: 1 }, _success: true }, // control
        { vertexConstants: { cf: NaN }, _success: false },
        { vertexConstants: { cf: Number.POSITIVE_INFINITY }, _success: false },
        { vertexConstants: { cf: Number.NEGATIVE_INFINITY }, _success: false },
      ] as { vertexConstants: Record<string, GPUPipelineConstantValue>; _success: boolean }[])
  )
  .fn(async t => {
    const { isAsync, vertexConstants, _success } = t.params;

    t.doCreateRenderPipelineTest(
      isAsync,
      _success,
      {
        layout: 'auto',
        vertex: {
          module: t.device.createShaderModule({
            code: `
            override cf: f32 = 0.0;
            @vertex fn main() -> @builtin(position) vec4<f32> {
              _ = cf;
              return vec4<f32>(0.0, 0.0, 0.0, 1.0);
            }`,
          }),
          entryPoint: 'main',
          constants: vertexConstants,
        },
        fragment: {
          module: t.device.createShaderModule({
            code: `@fragment fn main() -> @location(0) vec4<f32> {
              return vec4<f32>(0.0, 1.0, 0.0, 1.0);
            }`,
          }),
          entryPoint: 'main',
          targets: [{ format: 'rgba8unorm' }],
        },
      },
      'TypeError'
    );
  });

g.test('value,type_error,fragment')
  .desc(
    `
Tests calling createRenderPipeline(Async) validation for invalid constant values like inf, NaN will results in TypeError.
`
  )
  .params(u =>
    u //
      .combine('isAsync', [true, false])
      .combineWithParams([
        { fragmentConstants: { cf: 1 }, _success: true }, // control
        { fragmentConstants: { cf: NaN }, _success: false },
        { fragmentConstants: { cf: Number.POSITIVE_INFINITY }, _success: false },
        { fragmentConstants: { cf: Number.NEGATIVE_INFINITY }, _success: false },
      ] as const)
  )
  .fn(async t => {
    const { isAsync, fragmentConstants, _success } = t.params;

    const descriptor = t.getDescriptor({
      fragmentShaderCode: `
        override cf: f32 = 0.0;
        @fragment fn main()
            -> @location(0) vec4<f32> {
            _ = cf;
            return vec4<f32>(1.0, 1.0, 1.0, 1.0);
        }
          `,
      fragmentConstants,
    });

    t.doCreateRenderPipelineTest(isAsync, _success, descriptor, 'TypeError');
  });

g.test('value,validation_error,vertex')
  .desc(
    `
Tests calling createRenderPipeline(Async) validation for unrepresentable constant values in vertex stage.

TODO(#2060): test with last_f64_castable.
`
  )
  .params(u =>
    u //
      .combine('isAsync', [true, false])
      .combineWithParams([
        { vertexConstants: { cu: kValue.u32.min }, _success: true },
        { vertexConstants: { cu: kValue.u32.min - 1 }, _success: false },
        { vertexConstants: { cu: kValue.u32.max }, _success: true },
        { vertexConstants: { cu: kValue.u32.max + 1 }, _success: false },
        { vertexConstants: { ci: kValue.i32.negative.min }, _success: true },
        { vertexConstants: { ci: kValue.i32.negative.min - 1 }, _success: false },
        { vertexConstants: { ci: kValue.i32.positive.max }, _success: true },
        { vertexConstants: { ci: kValue.i32.positive.max + 1 }, _success: false },
        { vertexConstants: { cf: kValue.f32.negative.min }, _success: true },
        { vertexConstants: { cf: kValue.f32.negative.first_f64_not_castable }, _success: false },
        { vertexConstants: { cf: kValue.f32.positive.max }, _success: true },
        { vertexConstants: { cf: kValue.f32.positive.first_f64_not_castable }, _success: false },
        // Conversion to boolean can't fail
        { vertexConstants: { cb: Number.MAX_VALUE }, _success: true },
        { vertexConstants: { cb: kValue.i32.negative.min - 1 }, _success: true },
      ] as { vertexConstants: Record<string, GPUPipelineConstantValue>; _success: boolean }[])
  )
  .fn(async t => {
    const { isAsync, vertexConstants, _success } = t.params;

    t.doCreateRenderPipelineTest(isAsync, _success, {
      layout: 'auto',
      vertex: {
        module: t.device.createShaderModule({
          code: `
          override cb: bool = false;
          override cu: u32 = 0u;
          override ci: i32 = 0;
          override cf: f32 = 0.0;
          @vertex fn main() -> @builtin(position) vec4<f32> {
            _ = cb;
            _ = cu;
            _ = ci;
            _ = cf;
            return vec4<f32>(0.0, 0.0, 0.0, 1.0);
          }`,
        }),
        entryPoint: 'main',
        constants: vertexConstants,
      },
      fragment: {
        module: t.device.createShaderModule({
          code: `@fragment fn main() -> @location(0) vec4<f32> {
              return vec4<f32>(0.0, 1.0, 0.0, 1.0);
            }`,
        }),
        entryPoint: 'main',
        targets: [{ format: 'rgba8unorm' }],
      },
    });
  });

g.test('value,validation_error,fragment')
  .desc(
    `
Tests calling createRenderPipeline(Async) validation for unrepresentable constant values in fragment stage.

TODO(#2060): test with last_f64_castable.
`
  )
  .params(u =>
    u //
      .combine('isAsync', [true, false])
      .combineWithParams([
        { fragmentConstants: { cu: kValue.u32.min }, _success: true },
        { fragmentConstants: { cu: kValue.u32.min - 1 }, _success: false },
        { fragmentConstants: { cu: kValue.u32.max }, _success: true },
        { fragmentConstants: { cu: kValue.u32.max + 1 }, _success: false },
        { fragmentConstants: { ci: kValue.i32.negative.min }, _success: true },
        { fragmentConstants: { ci: kValue.i32.negative.min - 1 }, _success: false },
        { fragmentConstants: { ci: kValue.i32.positive.max }, _success: true },
        { fragmentConstants: { ci: kValue.i32.positive.max + 1 }, _success: false },
        { fragmentConstants: { cf: kValue.f32.negative.min }, _success: true },
        { fragmentConstants: { cf: kValue.f32.negative.first_f64_not_castable }, _success: false },
        { fragmentConstants: { cf: kValue.f32.positive.max }, _success: true },
        { fragmentConstants: { cf: kValue.f32.positive.first_f64_not_castable }, _success: false },
        // Conversion to boolean can't fail
        { fragmentConstants: { cb: Number.MAX_VALUE }, _success: true },
        { fragmentConstants: { cb: kValue.i32.negative.min - 1 }, _success: true },
      ] as { fragmentConstants: Record<string, GPUPipelineConstantValue>; _success: boolean }[])
  )
  .fn(async t => {
    const { isAsync, fragmentConstants, _success } = t.params;

    const descriptor = t.getDescriptor({
      fragmentShaderCode: `
        override cb: bool = false;
        override cu: u32 = 0u;
        override ci: i32 = 0;
        override cf: f32 = 0.0;
        @fragment fn main()
            -> @location(0) vec4<f32> {
            _ = cb;
            _ = cu;
            _ = ci;
            _ = cf;
            return vec4<f32>(1.0, 1.0, 1.0, 1.0);
        }
          `,
      fragmentConstants,
    });

    t.doCreateRenderPipelineTest(isAsync, _success, descriptor);
  });

g.test('value,validation_error,f16,vertex')
  .desc(
    `
Tests calling createRenderPipeline(Async) validation for unrepresentable f16 constant values in vertex stage.

TODO(#2060): Tighten the cases around the valid/invalid boundary once we have WGSL spec
clarity on whether values like f16.positive.last_f64_castable would be valid. See issue.
`
  )
  .params(u =>
    u //
      .combine('isAsync', [true, false])
      .combineWithParams([
        { vertexConstants: { cf16: kValue.f16.negative.min }, _success: true },
        { vertexConstants: { cf16: kValue.f16.negative.first_f64_not_castable }, _success: false },
        { vertexConstants: { cf16: kValue.f16.positive.max }, _success: true },
        { vertexConstants: { cf16: kValue.f16.positive.first_f64_not_castable }, _success: false },
        { vertexConstants: { cf16: kValue.f32.negative.min }, _success: false },
        { vertexConstants: { cf16: kValue.f32.positive.max }, _success: false },
        { vertexConstants: { cf16: kValue.f32.negative.first_f64_not_castable }, _success: false },
        { vertexConstants: { cf16: kValue.f32.positive.first_f64_not_castable }, _success: false },
      ] as const)
  )
  .beforeAllSubcases(t => {
    t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
  })
  .fn(async t => {
    const { isAsync, vertexConstants, _success } = t.params;

    t.doCreateRenderPipelineTest(isAsync, _success, {
      layout: 'auto',
      vertex: {
        module: t.device.createShaderModule({
          code: `
          enable f16;

          override cf16: f16 = 0.0h;
          @vertex fn main() -> @builtin(position) vec4<f32> {
            _ = cf16;
            return vec4<f32>(0.0, 0.0, 0.0, 1.0);
          }`,
        }),
        entryPoint: 'main',
        constants: vertexConstants,
      },
      fragment: {
        module: t.device.createShaderModule({
          code: `@fragment fn main() -> @location(0) vec4<f32> {
              return vec4<f32>(0.0, 1.0, 0.0, 1.0);
            }`,
        }),
        entryPoint: 'main',
        targets: [{ format: 'rgba8unorm' }],
      },
    });
  });

g.test('value,validation_error,f16,fragment')
  .desc(
    `
Tests calling createRenderPipeline(Async) validation for unrepresentable f16 constant values in fragment stage.

TODO(#2060): Tighten the cases around the valid/invalid boundary once we have WGSL spec
clarity on whether values like f16.positive.last_f64_castable would be valid. See issue.
`
  )
  .beforeAllSubcases(t => {
    t.selectDeviceOrSkipTestCase({ requiredFeatures: ['shader-f16'] });
  })
  .params(u =>
    u //
      .combine('isAsync', [true, false])
      .combineWithParams([
        { fragmentConstants: { cf16: kValue.f16.negative.min }, _success: true },
        {
          fragmentConstants: { cf16: kValue.f16.negative.first_f64_not_castable },
          _success: false,
        },
        { fragmentConstants: { cf16: kValue.f16.positive.max }, _success: true },
        {
          fragmentConstants: { cf16: kValue.f16.positive.first_f64_not_castable },
          _success: false,
        },
        { fragmentConstants: { cf16: kValue.f32.negative.min }, _success: false },
        { fragmentConstants: { cf16: kValue.f32.positive.max }, _success: false },
        {
          fragmentConstants: { cf16: kValue.f32.negative.first_f64_not_castable },
          _success: false,
        },
        {
          fragmentConstants: { cf16: kValue.f32.positive.first_f64_not_castable },
          _success: false,
        },
      ] as const)
  )
  .fn(async t => {
    const { isAsync, fragmentConstants, _success } = t.params;

    const descriptor = t.getDescriptor({
      fragmentShaderCode: `
        enable f16;

        override cf16: f16 = 0.0h;
        @fragment fn main()
            -> @location(0) vec4<f32> {
            _ = cf16;
            return vec4<f32>(1.0, 1.0, 1.0, 1.0);
        }
          `,
      fragmentConstants,
    });

    t.doCreateRenderPipelineTest(isAsync, _success, descriptor);
  });