Fix MSL packed_int casting.

In 104681 the vectors were cast to themselves to fixup an issue
with `packed_int`. That CL used an `as_type` which does a bit cast.
A `packed_int` can not be bitcast to an `int`. This CL changes to
a type cast, so instead of `as_type<int3>()` it does `int3()`.

Bug: tint:1677
Change-Id: I72218c06853e4e5ae1a0d34e2fc3e1ca597de993
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/104682
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Auto-Submit: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Dan Sinclair <dsinclair@chromium.org>
Commit-Queue: Ben Clayton <bclayton@google.com>
This commit is contained in:
dan sinclair
2022-10-05 17:49:00 +00:00
committed by Dawn LUCI CQ
parent f35c719054
commit 8fd4ef26f5
21 changed files with 55 additions and 29 deletions

View File

@@ -152,6 +152,32 @@ class ScopedBitCast {
std::ostream& s;
};
class ScopedCast {
public:
ScopedCast(GeneratorImpl* generator,
std::ostream& stream,
const sem::Type* curr_type,
const sem::Type* target_type)
: s(stream) {
auto* target_vec_type = target_type->As<sem::Vector>();
// If we need to promote from scalar to vector, cast the scalar to the
// vector element type.
if (curr_type->is_scalar() && target_vec_type) {
target_type = target_vec_type->type();
}
// Cast
generator->EmitType(s, target_type, "");
s << "(";
}
~ScopedCast() { s << ")"; }
private:
std::ostream& s;
};
} // namespace
SanitizedResult::SanitizedResult() = default;
@@ -521,7 +547,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, const ast::BinaryExpression* e
// In case the type is packed, cast to our own type in order to remove the packing.
// Otherwise, this just casts to itself.
if (lhs_type->is_signed_integer_vector()) {
ScopedBitCast lhs_self_cast(this, out, lhs_type, lhs_type);
ScopedCast lhs_self_cast(this, out, lhs_type, lhs_type);
if (!EmitExpression(out, expr->lhs)) {
return false;
}
@@ -540,7 +566,7 @@ bool GeneratorImpl::EmitBinary(std::ostream& out, const ast::BinaryExpression* e
// In case the type is packed, cast to our own type in order to remove the packing.
// Otherwise, this just casts to itself.
if (rhs_type->is_signed_integer_vector()) {
ScopedBitCast rhs_self_cast(this, out, rhs_type, rhs_type);
ScopedCast rhs_self_cast(this, out, rhs_type, rhs_type);
if (!EmitExpression(out, expr->rhs)) {
return false;
}