[wgsl] Resolve push_constant access as read-only
The push constant address space is always read only, so make sure we
resolve it's access mode as `read` instead of `read_write`. This was
causing IR validation failures for some tests that use user-defined
push constants.
Change-Id: Ibcffb04e9edca02302202c683a7f34165702f624
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/209914
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Auto-Submit: James Price <jrprice@google.com>
Reviewed-by: dan sinclair <dsinclair@chromium.org>
Commit-Queue: James Price <jrprice@google.com>
diff --git a/src/tint/lang/wgsl/resolver/address_space_validation_test.cc b/src/tint/lang/wgsl/resolver/address_space_validation_test.cc
index 185bbdb..df50e18 100644
--- a/src/tint/lang/wgsl/resolver/address_space_validation_test.cc
+++ b/src/tint/lang/wgsl/resolver/address_space_validation_test.cc
@@ -866,7 +866,7 @@
EXPECT_EQ(
r()->error(),
R"(12:34 error: type 'bool' cannot be used in address space 'push_constant' as it is non-host-shareable
-note: while instantiating ptr<push_constant, bool, read_write>)");
+note: while instantiating ptr<push_constant, bool, read>)");
}
TEST_F(ResolverAddressSpaceValidationTest, GlobalVariable_PushConstantF16) {
diff --git a/src/tint/lang/wgsl/resolver/resolver.cc b/src/tint/lang/wgsl/resolver/resolver.cc
index 22517a0..71397c2 100644
--- a/src/tint/lang/wgsl/resolver/resolver.cc
+++ b/src/tint/lang/wgsl/resolver/resolver.cc
@@ -880,6 +880,7 @@
core::Access Resolver::DefaultAccessForAddressSpace(core::AddressSpace address_space) {
// https://gpuweb.github.io/gpuweb/wgsl/#storage-class
switch (address_space) {
+ case core::AddressSpace::kPushConstant:
case core::AddressSpace::kStorage:
case core::AddressSpace::kUniform:
case core::AddressSpace::kHandle:
diff --git a/src/tint/lang/wgsl/resolver/variable_test.cc b/src/tint/lang/wgsl/resolver/variable_test.cc
index 6f70683..862e1a2 100644
--- a/src/tint/lang/wgsl/resolver/variable_test.cc
+++ b/src/tint/lang/wgsl/resolver/variable_test.cc
@@ -1050,9 +1050,12 @@
TEST_F(ResolverVariableTest, GlobalVar_AddressSpace) {
// https://gpuweb.github.io/gpuweb/wgsl/#storage-class
+ Enable(wgsl::Extension::kChromiumExperimentalPushConstant);
+
auto* buf = Structure("S", Vector{Member("m", ty.i32())});
auto* private_ = GlobalVar("p", ty.i32(), core::AddressSpace::kPrivate);
auto* workgroup = GlobalVar("w", ty.i32(), core::AddressSpace::kWorkgroup);
+ auto* push_constant = GlobalVar("pc", ty.i32(), core::AddressSpace::kPushConstant);
auto* uniform =
GlobalVar("ub", ty.Of(buf), core::AddressSpace::kUniform, Binding(0_a), Group(0_a));
auto* storage =
@@ -1064,12 +1067,14 @@
ASSERT_TRUE(TypeOf(private_)->Is<core::type::Reference>());
ASSERT_TRUE(TypeOf(workgroup)->Is<core::type::Reference>());
+ ASSERT_TRUE(TypeOf(push_constant)->Is<core::type::Reference>());
ASSERT_TRUE(TypeOf(uniform)->Is<core::type::Reference>());
ASSERT_TRUE(TypeOf(storage)->Is<core::type::Reference>());
ASSERT_TRUE(TypeOf(handle)->Is<core::type::Reference>());
EXPECT_EQ(TypeOf(private_)->As<core::type::Reference>()->Access(), core::Access::kReadWrite);
EXPECT_EQ(TypeOf(workgroup)->As<core::type::Reference>()->Access(), core::Access::kReadWrite);
+ EXPECT_EQ(TypeOf(push_constant)->As<core::type::Reference>()->Access(), core::Access::kRead);
EXPECT_EQ(TypeOf(uniform)->As<core::type::Reference>()->Access(), core::Access::kRead);
EXPECT_EQ(TypeOf(storage)->As<core::type::Reference>()->Access(), core::Access::kRead);
EXPECT_EQ(TypeOf(handle)->As<core::type::Reference>()->Access(), core::Access::kRead);