Skip to content

Commit

Permalink
Test validation of arg numbers and types, must_use for degrees, radia…
Browse files Browse the repository at this point in the history
…ns, sqrt
  • Loading branch information
dneto0 committed Mar 18, 2024
1 parent 40acfb6 commit 260eaf1
Show file tree
Hide file tree
Showing 4 changed files with 105 additions and 0 deletions.
6 changes: 6 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,9 @@
"webgpu:shader,validation,expression,call,builtin,cos:values:*": { "subcaseMS": 0.338 },
"webgpu:shader,validation,expression,call,builtin,cosh:integer_argument:*": { "subcaseMS": 0.889 },
"webgpu:shader,validation,expression,call,builtin,cosh:values:*": { "subcaseMS": 0.272 },
"webgpu:shader,validation,expression,call,builtin,degrees:args:*": { "subcaseMS": 4.949 },
"webgpu:shader,validation,expression,call,builtin,degrees:integer_argument:*": { "subcaseMS": 1.311 },
"webgpu:shader,validation,expression,call,builtin,degrees:must_use:*": { "subcaseMS": 1.406 },
"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 },
Expand Down Expand Up @@ -1947,7 +1949,9 @@
"webgpu:shader,validation,expression,call,builtin,pack4xU8Clamp:must_use:*": { "subcaseMS": 32.600 },
"webgpu:shader,validation,expression,call,builtin,pack4xU8Clamp:supported:*": { "subcaseMS": 134.750 },
"webgpu:shader,validation,expression,call,builtin,pack4xU8Clamp:unsupported:*": { "subcaseMS": 570.500 },
"webgpu:shader,validation,expression,call,builtin,radians:args:*": { "subcaseMS": 4.561 },
"webgpu:shader,validation,expression,call,builtin,radians:integer_argument:*": { "subcaseMS": 1.811 },
"webgpu:shader,validation,expression,call,builtin,radians:must_use:*": { "subcaseMS": 0.757 },
"webgpu:shader,validation,expression,call,builtin,radians:values:*": { "subcaseMS": 0.382 },
"webgpu:shader,validation,expression,call,builtin,round:integer_argument:*": { "subcaseMS": 1.834 },
"webgpu:shader,validation,expression,call,builtin,round:values:*": { "subcaseMS": 0.382 },
Expand All @@ -1961,7 +1965,9 @@
"webgpu:shader,validation,expression,call,builtin,sin:values:*": { "subcaseMS": 0.349 },
"webgpu:shader,validation,expression,call,builtin,sinh:integer_argument:*": { "subcaseMS": 1.078 },
"webgpu:shader,validation,expression,call,builtin,sinh:values:*": { "subcaseMS": 0.357 },
"webgpu:shader,validation,expression,call,builtin,sqrt:args:*": { "subcaseMS": 5.398 },
"webgpu:shader,validation,expression,call,builtin,sqrt:integer_argument:*": { "subcaseMS": 1.356 },
"webgpu:shader,validation,expression,call,builtin,sqrt:must_use:*": { "subcaseMS": 1.286 },
"webgpu:shader,validation,expression,call,builtin,sqrt:values:*": { "subcaseMS": 0.302 },
"webgpu:shader,validation,expression,call,builtin,tan:integer_argument:*": { "subcaseMS": 1.734 },
"webgpu:shader,validation,expression,call,builtin,tan:values:*": { "subcaseMS": 0.350 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,36 @@ Validates that scalar and vector integer arguments are rejected by ${builtin}()
'constant'
);
});

const kArgCases = {
good: '(1.1)',
bad_no_parens: '',
// Bad number of args
bad_too_few: '()',
bad_too_many: '(1.0,2.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']}; }`);
});
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,36 @@ Validates that scalar and vector integer arguments are rejected by ${builtin}()
'constant'
);
});

const kArgCases = {
good: '(1.1)',
bad_no_parens: '',
// Bad number of args
bad_too_few: '()',
bad_too_many: '(1.0,2.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']}; }`);
});
33 changes: 33 additions & 0 deletions src/webgpu/shader/validation/expression/call/builtin/sqrt.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,3 +88,36 @@ Validates that scalar and vector integer arguments are rejected by ${builtin}()
'constant'
);
});

const kArgCases = {
good: '(1.1)',
bad_no_parens: '',
// Bad number of args
bad_too_few: '()',
bad_too_many: '(1.0,2.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 260eaf1

Please sign in to comment.