tint: add syntax sugar for dereferencing pointers
Adds support to Tint for syntax sugar for dereferencing pointers for
member or index access as per:
https://github.com/gpuweb/gpuweb/pull/4311
- Resolver: when the lhs of a accessor expression is a pointer, it is
now resolved to a sem::Reference.
- Added "pointer_composite_access" feature as experimental, hooked up
validation in Resolver, and added tests.
- Added resolver tests for the new syntax to resolver/ptr_ref_test.cc.
- Fixed multiple transforms to deal with the fact that the lhs of
accessor expressions can now be pointers, including: Robustness,
Renamer, Std140, and SimplifyPointers.
- In transforms that rely on other transforms, such as
SimplifyPointers, to remove/inline pointers, I added asserts that
the type is not a pointer.
- Added unit tests for transforms that use pointer-dot/index for
accessor expressions.
- Fixed uniformity analysis code so that ProcessLValueExpression
correctly deals with accessor expressions where the object is a
pointer, in the same way we do for UnaryOp::kIndirection, including
partial pointer checks. Added many tests for these new cases.
- Fixed ProgramToIR so that EmitAccess handles the new syntax. Added
multiple tests.
- Added end2end tests under test/tint/ptr_sugar
For Googlers, see my work log at
go/add-syntax-sugar-for-dereferencing-composites for more details.
Bug: tint:2113
Change-Id: I7a0093f52ca2237be598e44245b45049f21d056c
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/164900
Kokoro: Kokoro <noreply+kokoro@google.com>
Reviewed-by: Corentin Wallez <cwallez@chromium.org>
Reviewed-by: James Price <jrprice@google.com>
Reviewed-by: Ben Clayton <bclayton@google.com>
Commit-Queue: Antonio Maiorano <amaiorano@google.com>
diff --git a/test/tint/ptr_sugar/vector_member.wgsl b/test/tint/ptr_sugar/vector_member.wgsl
new file mode 100644
index 0000000..cd2eab8
--- /dev/null
+++ b/test/tint/ptr_sugar/vector_member.wgsl
@@ -0,0 +1,19 @@
+fn deref() {
+ var a : vec3<i32>;
+ let p = &a;
+ var b = (*p).x;
+ (*p).x = 42;
+}
+
+fn no_deref() {
+ var a : vec3<i32>;
+ let p = &a;
+ var b = p.x;
+ p.x = 42;
+}
+
+@compute @workgroup_size(1)
+fn main() {
+ deref();
+ no_deref();
+}