From 93ed9620caa2a8ef76118a63f39b51f4c9600714 Mon Sep 17 00:00:00 2001 From: Ryan Harrison Date: Thu, 21 Mar 2024 16:26:49 -0400 Subject: [PATCH] wgsl: Implement `determinant` validation tests (#3533) This only tests the shapes of the inputs compilation, and not that later validation passes, since this builtin has undefined error. --- src/webgpu/listing_meta.json | 3 + .../call/builtin/determinant.spec.ts | 95 +++++++++++++++++++ 2 files changed, 98 insertions(+) create mode 100644 src/webgpu/shader/validation/expression/call/builtin/determinant.spec.ts diff --git a/src/webgpu/listing_meta.json b/src/webgpu/listing_meta.json index 1be673df5a31..1894d228ec7d 100644 --- a/src/webgpu/listing_meta.json +++ b/src/webgpu/listing_meta.json @@ -1903,6 +1903,9 @@ "webgpu:shader,validation,expression,call,builtin,degrees:values:*": { "subcaseMS": 0.303 }, "webgpu:shader,validation,expression,call,builtin,derivatives:invalid_argument_types:*": { "subcaseMS": 1.000 }, "webgpu:shader,validation,expression,call,builtin,derivatives:only_in_fragment:*": { "subcaseMS": 1.000 }, + "webgpu:shader,validation,expression,call,builtin,determinant:args:*": { "subcaseMS": 15.538 }, + "webgpu:shader,validation,expression,call,builtin,determinant:matrix_args:*": { "subcaseMS": 193.897 }, + "webgpu:shader,validation,expression,call,builtin,determinant:must_use:*": { "subcaseMS": 2.856 }, "webgpu:shader,validation,expression,call,builtin,dot4I8Packed:args:*": { "subcaseMS": 48.785 }, "webgpu:shader,validation,expression,call,builtin,dot4I8Packed:must_use:*": { "subcaseMS": 0.300 }, "webgpu:shader,validation,expression,call,builtin,dot4I8Packed:supported:*": { "subcaseMS": 1.100 }, diff --git a/src/webgpu/shader/validation/expression/call/builtin/determinant.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/determinant.spec.ts new file mode 100644 index 000000000000..1974e7ef9960 --- /dev/null +++ b/src/webgpu/shader/validation/expression/call/builtin/determinant.spec.ts @@ -0,0 +1,95 @@ +const builtin = 'determinant'; +export const description = ` +Validation tests for the ${builtin}() builtin. +`; + +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); + +// Generate a dictionary mapping each matrix type variation (columns,rows, +// floating point type) to a nontrivial matrix value of that type. +const kMatrixCases = ([2, 3, 4] as const) + .flatMap(cols => + ([2, 3, 4] as const).flatMap(rows => + (['abstract-int', 'abstract-float', 'f32', 'f16'] as const).map(type => ({ + [`mat${cols}x${rows}_${type}`]: (() => { + const suffix = (() => { + switch (type) { + case 'abstract-int': + return ''; + case 'abstract-float': + return '.0'; + case 'f32': + return 'f'; + case 'f16': + return 'h'; + } + })(); + return `(mat${cols}x${rows}(${[...Array(cols * rows).keys()] + .map(e => `${e}${suffix}`) + .join(', ')}))`; + })(), + })) + ) + ) + .reduce((a, b) => ({ ...a, ...b }), {}); + +g.test('matrix_args') + .desc(`Test compilation failure of ${builtin} with variously shaped matrices`) + .params(u => + u + .combine('cols', [2, 3, 4] as const) + .combine('rows', [2, 3, 4] as const) + .combine('type', ['abstract-int', 'abstract-float', 'f32', 'f16'] as const) + ) + .beforeAllSubcases(t => { + if (t.params.type === 'f16') { + t.selectDeviceOrSkipTestCase('shader-f16'); + } + }) + .fn(t => { + const cols = t.params.cols; + const rows = t.params.rows; + const type = t.params.type; + const arg = kMatrixCases[`mat${cols}x${rows}_${type}`]; + t.expectCompileResult( + cols === rows, + t.wrapInEntryPoint(`const c = ${builtin}${arg};`, type === 'f16' ? ['f16'] : []) + ); + }); + +const kArgCases = { + good: '(mat2x2(0.0, 2.0, 3.0, 4.0))', // Included to check test implementation + bad_no_parens: '', + // Bad number of args + bad_too_few: '()', + bad_too_many: '(mat2x2(0.0, 2.0, 3.0, 4.0), mat2x2(0.0, 2.0, 3.0, 4.0))', + // Bad value type for arg 0 + bad_0i32: '(1i)', + bad_0u32: '(1u)', + bad_0bool: '(false)', + bad_0vec2u: '(vec2u())', + bad_0array: '(array(1.1,2.2))', + bad_0struct: '(modf(2.2))', +}; + +g.test('args') + .desc(`Test compilation failure of ${builtin} with variously shaped and typed arguments`) + .params(u => u.combine('arg', keysOf(kArgCases))) + .fn(t => { + t.expectCompileResult( + t.params.arg === 'good', + `const c = ${builtin}${kArgCases[t.params.arg]};` + ); + }); + +g.test('must_use') + .desc(`Result of ${builtin} must be used`) + .params(u => u.combine('use', [true, false])) + .fn(t => { + const use_it = t.params.use ? '_ = ' : ''; + t.expectCompileResult(t.params.use, `fn f() { ${use_it}${builtin}${kArgCases['good']}; }`); + });