Skip to content

Commit

Permalink
Add abs parameter validation. (#3455)
Browse files Browse the repository at this point in the history
This CL adds validation for invalid `abs` parameters.
  • Loading branch information
dj2 authored Mar 6, 2024
1 parent 70ac878 commit 3dcdba7
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -1807,6 +1807,7 @@
"webgpu:shader,validation,expression,binary,bitwise_shift:shift_left_vec_size_mismatch:*": { "subcaseMS": 1.367 },
"webgpu:shader,validation,expression,binary,bitwise_shift:shift_right_concrete:*": { "subcaseMS": 1.237 },
"webgpu:shader,validation,expression,binary,bitwise_shift:shift_right_vec_size_mismatch:*": { "subcaseMS": 1.334 },
"webgpu:shader,validation,expression,call,builtin,abs:parameters:*": { "subcaseMS": 10.133 },
"webgpu:shader,validation,expression,call,builtin,abs:values:*": { "subcaseMS": 0.391 },
"webgpu:shader,validation,expression,call,builtin,acos:integer_argument:*": { "subcaseMS": 1.512 },
"webgpu:shader,validation,expression,call,builtin,acos:values:*": { "subcaseMS": 0.342 },
Expand Down
104 changes: 104 additions & 0 deletions src/webgpu/shader/validation/expression/call/builtin/abs.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,107 @@ Validates that constant evaluation and override evaluation of ${builtin}() never
t.params.stage
);
});

const kTests = {
valid: {
src: `_ = abs(1);`,
pass: true,
},
alias: {
src: `_ = abs(i32_alias(1));`,
pass: true,
},

bool: {
src: `_ = abs(false);`,
pass: false,
},
vec_bool: {
src: `_ = abs(vec2<bool>(false, true));`,
pass: false,
},
matrix: {
src: `_ = abs(mat2x2(1, 1, 1, 1));`,
pass: false,
},
atomic: {
src: ` _ = abs(a);`,
pass: false,
},
array: {
src: `var a: array<u32, 5>;
_ = abs(a);`,
pass: false,
},
array_runtime: {
src: `_ = abs(k.arry);`,
pass: false,
},
struct: {
src: `var a: A;
_ = abs(a);`,
pass: false,
},
enumerant: {
src: `_ = abs(read_write);`,
pass: false,
},
ptr: {
src: `var<function> a = 1u;
let p: ptr<function, u32> = &a;
_ = abs(p);`,
pass: false,
},
ptr_deref: {
src: `var<function> a = 1u;
let p: ptr<function, u32> = &a;
_ = abs(*p);`,
pass: true,
},
sampler: {
src: `_ = abs(s);`,
pass: false,
},
texture: {
src: `_ = abs(t);`,
pass: false,
},
no_params: {
src: `_ = abs();`,
pass: false,
},
too_many_params: {
src: `_ = abs(1, 2);`,
pass: false,
},
};

g.test('parameters')
.desc(`Test that ${builtin} is validated correctly.`)
.params(u => u.combine('test', keysOf(kTests)))
.fn(t => {
const src = kTests[t.params.test].src;
const code = `
alias i32_alias = i32;
@group(0) @binding(0) var s: sampler;
@group(0) @binding(1) var t: texture_2d<f32>;
var<workgroup> a: atomic<u32>;
struct A {
i: u32,
}
struct B {
arry: array<u32>,
}
@group(0) @binding(3) var<storage> k: B;
@vertex
fn main() -> @builtin(position) vec4<f32> {
${src}
return vec4<f32>(.4, .2, .3, .1);
}`;
t.expectCompileResult(kTests[t.params.test].pass, code);
});

0 comments on commit 3dcdba7

Please sign in to comment.