Skip to content

Commit

Permalink
Add validation testing for acos parameters. (gpuweb#3552)
Browse files Browse the repository at this point in the history
This CL adds validation testing for various invalid parameters to the
`acos` command.
  • Loading branch information
dj2 authored Mar 25, 2024
1 parent b4e0679 commit 758c1af
Show file tree
Hide file tree
Showing 2 changed files with 132 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/webgpu/listing_meta.json
Original file line number Diff line number Diff line change
Expand Up @@ -140,9 +140,9 @@
"webgpu:api,operation,render_pipeline,sample_mask:alpha_to_coverage_mask:*": { "subcaseMS": 68.512 },
"webgpu:api,operation,render_pipeline,sample_mask:fragment_output_mask:*": { "subcaseMS": 6.154 },
"webgpu:api,operation,render_pipeline,vertex_only_render_pipeline:draw_depth_and_stencil_with_vertex_only_pipeline:*": { "subcaseMS": 14.100 },
"webgpu:api,operation,rendering,3d_texture_slices:one_color_attachment,mip_levels:*": { "subcaseMS": 54.100 },
"webgpu:api,operation,rendering,3d_texture_slices:multiple_color_attachments,same_mip_level:*": { "subcaseMS": 69.400 },
"webgpu:api,operation,rendering,3d_texture_slices:multiple_color_attachments,same_slice_with_diff_mip_levels:*": { "subcaseMS": 9.800 },
"webgpu:api,operation,rendering,3d_texture_slices:one_color_attachment,mip_levels:*": { "subcaseMS": 54.100 },
"webgpu:api,operation,rendering,basic:clear:*": { "subcaseMS": 3.700 },
"webgpu:api,operation,rendering,basic:fullscreen_quad:*": { "subcaseMS": 16.601 },
"webgpu:api,operation,rendering,basic:large_draw:*": { "subcaseMS": 2335.425 },
Expand Down Expand Up @@ -1829,10 +1829,10 @@
"webgpu:shader,validation,decl,const:no_indirect_recursion:*": { "subcaseMS": 0.950 },
"webgpu:shader,validation,decl,const:no_indirect_recursion_via_array_size:*": { "subcaseMS": 2.601 },
"webgpu:shader,validation,decl,const:no_indirect_recursion_via_struct_attribute:*": { "subcaseMS": 1.034 },
"webgpu:shader,validation,decl,const:type:*": { "subcaseMS": 10.651 },
"webgpu:shader,validation,decl,let:initializer:*": { "subcaseMS": 0.706 },
"webgpu:shader,validation,decl,let:module_scope:*": { "subcaseMS": 0.619 },
"webgpu:shader,validation,decl,let:type:*": { "subcaseMS": 122.199 },
"webgpu:shader,validation,decl,const:type:*": { "subcaseMS": 10.651 },
"webgpu:shader,validation,decl,override:function_scope:*": { "subcaseMS": 1.003 },
"webgpu:shader,validation,decl,override:id:*": { "subcaseMS": 69.432 },
"webgpu:shader,validation,decl,override:initializer:*": { "subcaseMS": 4.810 },
Expand Down Expand Up @@ -1876,6 +1876,7 @@
"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:parameters:*": { "subcaseMS": 44.578 },
"webgpu:shader,validation,expression,call,builtin,acos:values:*": { "subcaseMS": 0.342 },
"webgpu:shader,validation,expression,call,builtin,acosh:integer_argument:*": { "subcaseMS": 1.234 },
"webgpu:shader,validation,expression,call,builtin,acosh:values:*": { "subcaseMS": 0.217 },
Expand Down
129 changes: 129 additions & 0 deletions src/webgpu/shader/validation/expression/call/builtin/acos.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,3 +85,132 @@ Validates that scalar and vector integer arguments are rejected by ${builtin}()
'constant'
);
});

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

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

greater_then_one: {
src: `_ = acos(1.1f);`,
pass: false,
},
less_then_negative_one: {
src: `_ = acos(-1.1f);`,
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 f32_alias = f32;
@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 758c1af

Please sign in to comment.