Skip to content

Commit

Permalink
wgsl: Implement determinant validation tests (#3533)
Browse files Browse the repository at this point in the history
This only tests the shapes of the inputs compilation, and not that
later validation passes, since this builtin has undefined error.
  • Loading branch information
zoddicus authored Mar 21, 2024
1 parent 2bd217f commit 93ed962
Show file tree
Hide file tree
Showing 2 changed files with 98 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
Expand Down
Original file line number Diff line number Diff line change
@@ -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']}; }`);
});

0 comments on commit 93ed962

Please sign in to comment.