Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

wgsl: Update value creation and type comparisons #3482

Merged
merged 1 commit into from
Mar 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,8 @@ g.test('scalar_vector')
const hasF16 = lhsElement === Type.f16 || rhsElement === Type.f16;
const code = `
${hasF16 ? 'enable f16;' : ''}
const lhs = ${lhs.create(lhsElement.kind === 'abstract-int' ? 0n : 0).wgsl()};
const rhs = ${rhs.create(rhsElement.kind === 'abstract-int' ? 0n : 0).wgsl()};
const lhs = ${lhs.create(0).wgsl()};
const rhs = ${rhs.create(0).wgsl()};
const foo = lhs ${op.op} rhs;
`;

Expand Down Expand Up @@ -92,7 +92,7 @@ const foo = lhs ${op.op} rhs;
valid = lhs.width === rhs.width && elementIsCompatible;
}

if (lhsElement.kind === 'bool') {
if (lhsElement === Type.bool) {
valid &&= op.supportsBool;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,25 +64,25 @@ g.test('scalar_vector')
const hasF16 = lhsElement === Type.f16 || rhsElement === Type.f16;
const code = `
${hasF16 ? 'enable f16;' : ''}
const lhs = ${lhs.create(lhsElement.kind === 'abstract-int' ? 0n : 0).wgsl()};
const rhs = ${rhs.create(rhsElement.kind === 'abstract-int' ? 0n : 0).wgsl()};
const lhs = ${lhs.create(0).wgsl()};
const rhs = ${rhs.create(0).wgsl()};
const foo = lhs ${kComparisonOperators[t.params.op].op} rhs;
`;

let valid = false;

// Determine if the element types are comparable.
let elementIsCompatible = false;
if (lhsElement.kind === 'abstract-int') {
if (lhsElement === Type.abstractInt) {
// Abstract integers are comparable to any other numeric type.
elementIsCompatible = rhsElement.kind !== 'bool';
} else if (rhsElement.kind === 'abstract-int') {
elementIsCompatible = rhsElement !== Type.bool;
} else if (rhsElement === Type.abstractInt) {
// Abstract integers are comparable to any other numeric type.
elementIsCompatible = lhsElement.kind !== 'bool';
} else if (lhsElement.kind === 'abstract-float') {
elementIsCompatible = lhsElement !== Type.bool;
} else if (lhsElement === Type.abstractFloat) {
// Abstract floats are comparable to any other float type.
elementIsCompatible = isFloatType(rhsElement);
} else if (rhsElement.kind === 'abstract-float') {
} else if (rhsElement === Type.abstractFloat) {
// Abstract floats are comparable to any other float type.
elementIsCompatible = isFloatType(lhsElement);
} else {
Expand All @@ -98,7 +98,7 @@ const foo = lhs ${kComparisonOperators[t.params.op].op} rhs;
valid = lhs.width === rhs.width && elementIsCompatible;
}

if (lhsElement.kind === 'bool') {
if (lhsElement === Type.bool) {
valid &&= kComparisonOperators[t.params.op].supportsBool;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ g.test('scalar_vector')
const hasF16 = elementTy === Type.f16;
const code = `
${hasF16 ? 'enable f16;' : ''}
const rhs = ${type.create(elementTy.kind === 'abstract-int' ? 0n : 0).wgsl()};
const rhs = ${type.create(0).wgsl()};
const foo = !rhs;
`;

Expand Down
Loading