tint/resolver: Materialize objects when indexed with non-const index
If an abstract-vector or abstract-matrix is indexed with a non-constant index expression, then the resulting value is non-constant, and so cannot be abstract.
In this situation the materialization cannot be done post-index, so materialization must happen on the object before indexing.
Bug: chromium:1345468
Change-Id: I9f29dc40301779a7ff8f173724374bd845a3a5b9
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/96684
Reviewed-by: Antonio Maiorano <amaiorano@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: Ben Clayton <bclayton@chromium.org>
diff --git a/src/tint/resolver/resolver.cc b/src/tint/resolver/resolver.cc
index 611f240..db9851c 100644
--- a/src/tint/resolver/resolver.cc
+++ b/src/tint/resolver/resolver.cc
@@ -1399,7 +1399,13 @@
if (!idx) {
return nullptr;
}
- auto* obj = sem_.Get(expr->object);
+ const auto* obj = sem_.Get(expr->object);
+ if (idx->Stage() != sem::EvaluationStage::kConstant) {
+ // If the index is non-constant, then the resulting expression is non-constant, so we'll
+ // have to materialize the object. For example, consider:
+ // vec2(1, 2)[runtime-index]
+ obj = Materialize(obj);
+ }
auto* obj_raw_ty = obj->Type();
auto* obj_ty = obj_raw_ty->UnwrapRef();
auto* ty = Switch(