Skip to content

Commit

Permalink
wgsl: validate bad arg counts, arg types, must_use for sin, cos
Browse files Browse the repository at this point in the history
  • Loading branch information
dneto0 committed Mar 13, 2024
1 parent f1aa942 commit df52143
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1861,7 +1861,9 @@
"webgpu:shader,validation,expression,call,builtin,ceil:integer_argument:*": { "subcaseMS": 1.456 },
"webgpu:shader,validation,expression,call,builtin,ceil:values:*": { "subcaseMS": 1.539 },
"webgpu:shader,validation,expression,call,builtin,clamp:values:*": { "subcaseMS": 0.377 },
"webgpu:shader,validation,expression,call,builtin,cos:bad_args:*": { "subcaseMS": 2.868 },
"webgpu:shader,validation,expression,call,builtin,cos:integer_argument:*": { "subcaseMS": 1.601 },
"webgpu:shader,validation,expression,call,builtin,cos:must_use:*": { "subcaseMS": 0.526 },
"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 },
Expand Down Expand Up @@ -1922,7 +1924,9 @@
"webgpu:shader,validation,expression,call,builtin,saturate:values:*": { "subcaseMS": 0.317 },
"webgpu:shader,validation,expression,call,builtin,sign:unsigned_integer_argument:*": { "subcaseMS": 1.120 },
"webgpu:shader,validation,expression,call,builtin,sign:values:*": { "subcaseMS": 0.343 },
"webgpu:shader,validation,expression,call,builtin,sin:bad_args:*": { "subcaseMS": 3.338 },
"webgpu:shader,validation,expression,call,builtin,sin:integer_argument:*": { "subcaseMS": 1.189 },
"webgpu:shader,validation,expression,call,builtin,sin:must_use:*": { "subcaseMS": 0.588 },
"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 },
Expand Down
30 changes: 30 additions & 0 deletions src/webgpu/shader/validation/expression/call/builtin/cos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,33 @@ Validates that scalar and vector integer arguments are rejected by ${builtin}()
'constant'
);
});

const kGoodArgs = '(1.1)';
const kBadArgs = {
no_parens: '',
// Bad number of args
'0args': '()',
'2args': '(1.0,2.0)',
// Bad value for arg 0
'0i32': '(1i)',
'0u32': '(1u)',
'0bool': '(false)',
'0vec2u': '(vec2u())',
'0array': '(array(1.1,2.2))',
'0struct': '(modf(2.2))',
};

g.test('bad_args')
.desc(`Test compilation failure of ${builtin} with bad arguments`)
.params(u => u.combine('arg', keysOf(kBadArgs)))
.fn(t => {
t.expectCompileResult(false, `const c = ${builtin}${kBadArgs[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}${kGoodArgs}; }`);
});
30 changes: 30 additions & 0 deletions src/webgpu/shader/validation/expression/call/builtin/sin.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,3 +79,33 @@ Validates that scalar and vector integer arguments are rejected by ${builtin}()
'constant'
);
});

const kGoodArgs = '(1.1)';
const kBadArgs = {
no_parens: '',
// Bad number of args
'0args': '()',
'2args': '(1.0,2.0)',
// Bad value for arg 0
'0i32': '(1i)',
'0u32': '(1u)',
'0bool': '(false)',
'0vec2u': '(vec2u())',
'0array': '(array(1.1,2.2))',
'0struct': '(modf(2.2))',
};

g.test('bad_args')
.desc(`Test compilation failure of ${builtin} with bad arguments`)
.params(u => u.combine('arg', keysOf(kBadArgs)))
.fn(t => {
t.expectCompileResult(false, `const c = ${builtin}${kBadArgs[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}${kGoodArgs}; }`);
});

0 comments on commit df52143

Please sign in to comment.