From 395ec2c4aed8c08fe0d43bc915b4062acc2b69cc Mon Sep 17 00:00:00 2001 From: Ben Clayton Date: Wed, 13 Jan 2021 19:28:12 +0000 Subject: [PATCH] writer/spirv: Add TextureStorageWithDifferentAccess test Checks that multiple texture_storage types with different access modifiers only produces a single OpTypeImage. This was broken before Ia944ed8 Bug: tint:286 Change-Id: Idbcd0189d46b78b31d5ec38f355d2369cb86327a Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/37707 Reviewed-by: dan sinclair Commit-Queue: Ben Clayton --- .../spirv/builder_global_variable_test.cc | 31 +++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/writer/spirv/builder_global_variable_test.cc b/src/writer/spirv/builder_global_variable_test.cc index c4830f6ff7..ccfcca4df8 100644 --- a/src/writer/spirv/builder_global_variable_test.cc +++ b/src/writer/spirv/builder_global_variable_test.cc @@ -539,6 +539,37 @@ TEST_F(BuilderTest, GlobalVar_TextureStorageWriteOnly) { )"); } +// Check that multiple texture_storage types with different access modifiers +// only produces a single OpTypeImage. +TEST_F(BuilderTest, GlobalVar_TextureStorageWithDifferentAccess) { + // var a : texture_storage_ro_2d; + // var b : texture_storage_wo_2d; + + ast::type::StorageTexture st(ast::type::TextureDimension::k2d, + ast::type::ImageFormat::kR32Uint); + ASSERT_TRUE(td.DetermineStorageTextureSubtype(&st)) << td.error(); + + ast::type::AccessControl type_a(ast::AccessControl::kReadOnly, &st); + auto* var_a = Var("a", ast::StorageClass::kUniformConstant, &type_a); + EXPECT_TRUE(b.GenerateGlobalVariable(var_a)) << b.error(); + + ast::type::AccessControl type_b(ast::AccessControl::kWriteOnly, &st); + auto* var_b = Var("b", ast::StorageClass::kUniformConstant, &type_b); + EXPECT_TRUE(b.GenerateGlobalVariable(var_b)) << b.error(); + + EXPECT_EQ(DumpInstructions(b.annots()), R"(OpDecorate %1 NonWritable +OpDecorate %5 NonReadable +)"); + // There must only be one OpTypeImage declaration with the same arguments + EXPECT_EQ(DumpInstructions(b.types()), R"(%4 = OpTypeInt 32 0 +%3 = OpTypeImage %4 2D 0 0 0 2 R32ui +%2 = OpTypePointer UniformConstant %3 +%1 = OpVariable %2 UniformConstant +%6 = OpTypePointer UniformConstant %3 +%5 = OpVariable %6 UniformConstant +)"); +} + } // namespace } // namespace spirv } // namespace writer