mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-12-13 15:16:16 +00:00
msl: Overload matrix-vector arithmetic operators
These operators are not defined in the metal namespace when the vector operands are packed. Fixed: tint:1121 Change-Id: I2e8f4302e08117ca41bac6c05fb24a70d1215740 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/62480 Kokoro: Kokoro <noreply+kokoro@google.com> Auto-Submit: James Price <jrprice@google.com> Reviewed-by: Ben Clayton <bclayton@google.com>
This commit is contained in:
@@ -2310,6 +2310,26 @@ bool GeneratorImpl::EmitPackedType(std::ostream& out,
|
||||
if (!EmitType(out, vec, "")) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (vec->is_float_vector() && !matrix_packed_vector_overloads_) {
|
||||
// Overload operators for matrix-vector arithmetic where the vector
|
||||
// operand is packed, as these overloads to not exist in the metal
|
||||
// namespace.
|
||||
TextBuffer b;
|
||||
TINT_DEFER(helpers_.Append(b));
|
||||
line(&b) << R"(template<typename T, int N, int M>
|
||||
inline auto operator*(matrix<T, N, M> lhs, packed_vec<T, N> rhs) {
|
||||
return lhs * vec<T, N>(rhs);
|
||||
}
|
||||
|
||||
template<typename T, int N, int M>
|
||||
inline auto operator*(packed_vec<T, M> lhs, matrix<T, N, M> rhs) {
|
||||
return vec<T, M>(lhs) * rhs;
|
||||
}
|
||||
)";
|
||||
matrix_packed_vector_overloads_ = true;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@@ -355,6 +355,9 @@ class GeneratorImpl : public TextGenerator {
|
||||
/// True if an invariant attribute has been generated.
|
||||
bool has_invariant_ = false;
|
||||
|
||||
/// True if matrix-packed_vector operator overloads have been generated.
|
||||
bool matrix_packed_vector_overloads_ = false;
|
||||
|
||||
std::unordered_map<const sem::Intrinsic*, std::string> intrinsics_;
|
||||
std::unordered_map<const sem::Type*, std::string> unary_minus_funcs_;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user