tint: Simplify the resolver constant evaluation

And expand the handling to include matrices.

Bug: tint:1504
Change-Id: I6fd9ce239d13acf0e2f74b8ea19dfac3457e348c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/91026
Commit-Queue: Ben Clayton <bclayton@google.com>
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
This commit is contained in:
Ben Clayton
2022-05-20 19:55:50 +00:00
committed by Dawn LUCI CQ
parent 8f4f449540
commit d3de38d7e3
4 changed files with 72 additions and 44 deletions

View File

@@ -81,7 +81,14 @@ class Constant {
/// @return the value of the scalar `static_cast` to type T.
template <typename T>
T ElementAs(size_t index) const {
return std::visit([](auto val) { return static_cast<T>(val); }, elems_[index]);
return Cast<T>(elems_[index]);
}
/// @param s the input scalar
/// @returns the scalar `s` cast to the type `T`.
template <typename T>
static T Cast(Scalar s) {
return std::visit([](auto v) { return static_cast<T>(v); }, s);
}
private: