Skip to content

Commit

Permalink
Partial evaluation error tests for bit shifts (gpuweb#3796)
Browse files Browse the repository at this point in the history
Contributes to gpuweb#3778

* Tests that runtime shifted by an early evaluation expression is an
  error when shift value is greater or equal than value's width
  • Loading branch information
alan-baker authored Jun 24, 2024
1 parent 176fd9c commit e468100
Show file tree
Hide file tree
Showing 2 changed files with 39 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 @@ -1962,6 +1962,7 @@
"webgpu:shader,validation,expression,binary,and_or_xor:invalid_types:*": { "subcaseMS": 24.069 },
"webgpu:shader,validation,expression,binary,and_or_xor:scalar_vector:*": { "subcaseMS": 666.807 },
"webgpu:shader,validation,expression,binary,bitwise_shift:invalid_types:*": { "subcaseMS": 22.058 },
"webgpu:shader,validation,expression,binary,bitwise_shift:partial_eval_errors:*": { "subcaseMS": 116.339 },
"webgpu:shader,validation,expression,binary,bitwise_shift:scalar_vector:*": { "subcaseMS": 525.052 },
"webgpu:shader,validation,expression,binary,bitwise_shift:shift_left_concrete:*": { "subcaseMS": 1.216 },
"webgpu:shader,validation,expression,binary,bitwise_shift:shift_right_concrete:*": { "subcaseMS": 1.237 },
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -267,3 +267,41 @@ fn main() {
`;
t.expectCompileResult(t.params.case.pass, code);
});

g.test('partial_eval_errors')
.desc('Tests partial evaluation errors for left shift')
.params(u =>
u
.combine('op', ['<<', '>>'] as const)
.combine('type', ['i32', 'u32'] as const)
.beginSubcases()
.combine('stage', ['shader', 'pipeline'] as const)
.combine('value', [32, 33, 64] as const)
)
.fn(t => {
const u32 = Type.u32;
let rhs = 'o';
if (t.params.stage === 'shader') {
rhs = `${u32.create(t.params.value).wgsl()}`;
}
const wgsl = `
override o = 0u;
fn foo() {
var v : ${t.params.type} = 0;
let tmp = v ${t.params.op} ${rhs};
}`;

const expect = t.params.value <= 32;
if (t.params.stage === 'shader') {
t.expectCompileResult(expect, wgsl);
} else {
const constants: Record<string, number> = {};
constants['o'] = t.params.value;
t.expectPipelineResult({
expectedResult: expect,
code: wgsl,
constants,
reference: ['o'],
});
}
});

0 comments on commit e468100

Please sign in to comment.