From 248f2adacd772947c2b7e115b3e3f15ad46e4b5a Mon Sep 17 00:00:00 2001 From: David Neto Date: Wed, 13 Mar 2024 16:22:04 -0400 Subject: [PATCH] wgsl: validate bad arg counts, arg types, must_use for log, log2 --- src/webgpu/listing_meta.json | 4 +++ .../expression/call/builtin/log.spec.ts | 33 +++++++++++++++++++ .../expression/call/builtin/log2.spec.ts | 33 +++++++++++++++++++ 3 files changed, 70 insertions(+) diff --git a/src/webgpu/listing_meta.json b/src/webgpu/listing_meta.json index 6e30934e818c..ad6f2698b289 100644 --- a/src/webgpu/listing_meta.json +++ b/src/webgpu/listing_meta.json @@ -1892,9 +1892,13 @@ "webgpu:shader,validation,expression,call,builtin,length:vec2:*": { "subcaseMS": 0.319 }, "webgpu:shader,validation,expression,call,builtin,length:vec3:*": { "subcaseMS": 1.401 }, "webgpu:shader,validation,expression,call,builtin,length:vec4:*": { "subcaseMS": 1.301 }, + "webgpu:shader,validation,expression,call,builtin,log2:args:*": { "subcaseMS": 4.528 }, "webgpu:shader,validation,expression,call,builtin,log2:integer_argument:*": { "subcaseMS": 1.034 }, + "webgpu:shader,validation,expression,call,builtin,log2:must_use:*": { "subcaseMS": 1.149 }, "webgpu:shader,validation,expression,call,builtin,log2:values:*": { "subcaseMS": 0.398 }, + "webgpu:shader,validation,expression,call,builtin,log:args:*": { "subcaseMS": 5.197 }, "webgpu:shader,validation,expression,call,builtin,log:integer_argument:*": { "subcaseMS": 1.134 }, + "webgpu:shader,validation,expression,call,builtin,log:must_use:*": { "subcaseMS": 1597.590 }, "webgpu:shader,validation,expression,call,builtin,log:values:*": { "subcaseMS": 0.291 }, "webgpu:shader,validation,expression,call,builtin,modf:integer_argument:*": { "subcaseMS": 1.089 }, "webgpu:shader,validation,expression,call,builtin,modf:values:*": { "subcaseMS": 1.866 }, diff --git a/src/webgpu/shader/validation/expression/call/builtin/log.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/log.spec.ts index 6d755304f2ff..4ef0d553c972 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/log.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/log.spec.ts @@ -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_0args: '()', + bad_2args: '(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']}; }`); + }); diff --git a/src/webgpu/shader/validation/expression/call/builtin/log2.spec.ts b/src/webgpu/shader/validation/expression/call/builtin/log2.spec.ts index 0dfe64153651..d242e1a41069 100644 --- a/src/webgpu/shader/validation/expression/call/builtin/log2.spec.ts +++ b/src/webgpu/shader/validation/expression/call/builtin/log2.spec.ts @@ -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_0args: '()', + bad_2args: '(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']}; }`); + });