Skip to content

Commit

Permalink
Fix div/rem early eval error cases (gpuweb#3787)
Browse files Browse the repository at this point in the history
Contributes to gpuweb#3778

* scalar_vector_out_of_range already covers the const and override cases
  generally
* modified scalar_vector tests to 0 and 1 rhs values
  * this test set covers compound assignments
  * previously the tests had invalid constant cases for 0 / 0 variants
  • Loading branch information
alan-baker authored Jun 24, 2024
1 parent e468100 commit 4163461
Showing 1 changed file with 11 additions and 3 deletions.
14 changes: 11 additions & 3 deletions src/webgpu/shader/validation/expression/binary/div_rem.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ g.test('scalar_vector')
.combine('compound_assignment', [false, true] as const)
.beginSubcases()
.combine('op', keysOf(kOperators))
.combine('rhs_value', [0, 1] as const)
)
.beforeAllSubcases(t => {
if (
Expand All @@ -82,19 +83,26 @@ g.test('scalar_vector')
${hasF16 ? 'enable f16;' : ''}
fn f() {
var v = ${lhs.create(0).wgsl()};
v ${op.op}= ${rhs.create(0).wgsl()};
v ${op.op}= ${rhs.create(t.params.rhs_value).wgsl()};
}
`
: `
${hasF16 ? 'enable f16;' : ''}
const lhs = ${lhs.create(1).wgsl()};
const rhs = ${rhs.create(1).wgsl()};
const rhs = ${rhs.create(t.params.rhs_value).wgsl()};
const foo ${resTypeIsTypeable ? `: ${resType}` : ''} = lhs ${op.op} rhs;
`;

const scalarLHS = scalarTypeOf(concreteTypeOf(lhs));
const integral = scalarLHS === Type.u32 || scalarLHS === Type.i32;
let valid = !hasBool && resType !== null;
if (valid && t.params.compound_assignment) {
valid = valid && isConvertible(resType!, concreteTypeOf(lhs));
valid =
valid &&
isConvertible(resType!, concreteTypeOf(lhs)) &&
(!integral || t.params.rhs_value === 1);
} else {
valid = valid && t.params.rhs_value === 1;
}
t.expectCompileResult(valid, code);
});
Expand Down

0 comments on commit 4163461

Please sign in to comment.