[tint] Allow read-only storage textures
Iff the chromium_experimental_read_write_storage_texture extension is
enabled.
Bug: tint:2007
Change-Id: Ic76c22b3d88d0b76253f9a0ed7b0befcd498ca0f
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/146960
Reviewed-by: Ben Clayton <bclayton@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
diff --git a/src/tint/lang/wgsl/resolver/type_validation_test.cc b/src/tint/lang/wgsl/resolver/type_validation_test.cc
index 27bc29b..541856e 100644
--- a/src/tint/lang/wgsl/resolver/type_validation_test.cc
+++ b/src/tint/lang/wgsl/resolver/type_validation_test.cc
@@ -1143,7 +1143,19 @@
EXPECT_EQ(r()->error(), R"(12:34 error: 'texture_storage_1d' requires 2 template arguments)");
}
-TEST_F(StorageTextureAccessTest, ReadOnlyAccess_Fail) {
+TEST_F(StorageTextureAccessTest, WriteOnlyAccess_Pass) {
+ // @group(0) @binding(0)
+ // var a : texture_storage_1d<r32uint, write>;
+
+ auto st = ty.storage_texture(core::type::TextureDimension::k1d, core::TexelFormat::kR32Uint,
+ core::Access::kWrite);
+
+ GlobalVar("a", st, Group(0_a), Binding(0_a));
+
+ EXPECT_TRUE(r()->Resolve()) << r()->error();
+}
+
+TEST_F(StorageTextureAccessTest, ReadOnlyAccess_WithoutExtension_Fail) {
// @group(0) @binding(0)
// var a : texture_storage_1d<r32uint, read>;
@@ -1154,15 +1166,18 @@
EXPECT_FALSE(r()->Resolve());
EXPECT_EQ(r()->error(),
- "12:34 error: storage textures currently only support 'write' access control");
+ "12:34 error: read-only storage textures require the "
+ "chromium_experimental_read_write_storage_texture extension to be enabled");
}
-TEST_F(StorageTextureAccessTest, WriteOnlyAccess_Pass) {
+TEST_F(StorageTextureAccessTest, ReadOnlyAccess_WithExtension_Pass) {
+ // enable chromium_experimental_read_write_storage_texture;
// @group(0) @binding(0)
- // var a : texture_storage_1d<r32uint, write>;
+ // var a : texture_storage_1d<r32uint, read>;
- auto st = ty.storage_texture(core::type::TextureDimension::k1d, core::TexelFormat::kR32Uint,
- core::Access::kWrite);
+ Enable(core::Extension::kChromiumExperimentalReadWriteStorageTexture);
+ auto st = ty.storage_texture(Source{{12, 34}}, core::type::TextureDimension::k1d,
+ core::TexelFormat::kR32Uint, core::Access::kRead);
GlobalVar("a", st, Group(0_a), Binding(0_a));
diff --git a/src/tint/lang/wgsl/resolver/validator.cc b/src/tint/lang/wgsl/resolver/validator.cc
index 11b9971..42f7e84 100644
--- a/src/tint/lang/wgsl/resolver/validator.cc
+++ b/src/tint/lang/wgsl/resolver/validator.cc
@@ -312,6 +312,16 @@
bool Validator::StorageTexture(const core::type::StorageTexture* t, const Source& source) const {
switch (t->access()) {
+ case core::Access::kRead:
+ if (!enabled_extensions_.Contains(
+ core::Extension::kChromiumExperimentalReadWriteStorageTexture)) {
+ AddError(
+ "read-only storage textures require the "
+ "chromium_experimental_read_write_storage_texture extension to be enabled",
+ source);
+ return false;
+ }
+ break;
case core::Access::kReadWrite:
if (!enabled_extensions_.Contains(
core::Extension::kChromiumExperimentalReadWriteStorageTexture)) {
@@ -327,9 +337,6 @@
case core::Access::kUndefined:
AddError("storage texture missing access control", source);
return false;
- default:
- AddError("storage textures currently only support 'write' access control", source);
- return false;
}
if (!IsValidStorageTextureDimension(t->dim())) {