From 4e91325bf0c4ddab58184203aa4c1a6e46cf20f3 Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Wed, 25 Nov 2020 17:02:37 +0000 Subject: [PATCH] writer/spirv: Emit Image1D and Sampled1D capabilities when needed Fixes: tint:363 Change-Id: Ia0f09e3173f54abaf15aa8f772b097835d451bcb Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33920 Reviewed-by: dan sinclair Commit-Queue: Corentin Wallez --- src/writer/spirv/builder.cc | 6 ++++ src/writer/spirv/builder_type_test.cc | 46 +++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 7b74ecbb60..b2c0a7e8f2 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -2487,6 +2487,12 @@ bool Builder::GenerateTextureType(ast::type::TextureType* texture, if (dim == ast::type::TextureDimension::k1dArray || dim == ast::type::TextureDimension::k1d) { dim_literal = SpvDim1D; + if (texture->IsSampled()) { + push_capability(SpvCapabilitySampled1D); + } else { + assert(texture->IsStorage()); + push_capability(SpvCapabilityImage1D); + } } if (dim == ast::type::TextureDimension::k3d) { dim_literal = SpvDim3D; diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 99e94ebaf6..d7403ba3c7 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -724,6 +724,10 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_i32) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 %1 = OpTypeImage %2 1D 0 0 0 1 Unknown +)"); + + EXPECT_EQ(DumpInstructions(b.capabilities()), + R"(OpCapability Sampled1D )"); } @@ -736,6 +740,10 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_u32) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0 %1 = OpTypeImage %2 1D 0 0 0 1 Unknown +)"); + + EXPECT_EQ(DumpInstructions(b.capabilities()), + R"(OpCapability Sampled1D )"); } @@ -748,6 +756,10 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1d_f32) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 1D 0 0 0 1 Unknown +)"); + + EXPECT_EQ(DumpInstructions(b.capabilities()), + R"(OpCapability Sampled1D )"); } @@ -760,6 +772,10 @@ TEST_F(BuilderTest_Type, SampledTexture_Generate_1dArray) { EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 1D 0 1 0 1 Unknown +)"); + + EXPECT_EQ(DumpInstructions(b.capabilities()), + R"(OpCapability Sampled1D )"); } @@ -834,6 +850,11 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_R16Float) { ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 1D 0 0 0 2 R16f +)"); + + EXPECT_EQ(DumpInstructions(b.capabilities()), + R"(OpCapability Image1D +OpCapability StorageImageExtendedFormats )"); } @@ -847,6 +868,11 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_R8SNorm) { ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 1D 0 0 0 2 R8Snorm +)"); + + EXPECT_EQ(DumpInstructions(b.capabilities()), + R"(OpCapability Image1D +OpCapability StorageImageExtendedFormats )"); } @@ -860,6 +886,11 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_R8UNorm) { ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 1D 0 0 0 2 R8 +)"); + + EXPECT_EQ(DumpInstructions(b.capabilities()), + R"(OpCapability Image1D +OpCapability StorageImageExtendedFormats )"); } @@ -899,6 +930,11 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_array) { ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 1D 0 1 0 2 R16f +)"); + + EXPECT_EQ(DumpInstructions(b.capabilities()), + R"(OpCapability Image1D +OpCapability StorageImageExtendedFormats )"); } @@ -951,6 +987,11 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateWriteonly_1d) { ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid %1 = OpTypeImage %2 1D 0 0 0 2 R16f +)"); + + EXPECT_EQ(DumpInstructions(b.capabilities()), + R"(OpCapability Image1D +OpCapability StorageImageExtendedFormats )"); } @@ -964,6 +1005,11 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateWriteonly_1dArray) { ASSERT_FALSE(b.has_error()) << b.error(); EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeVoid %1 = OpTypeImage %2 1D 0 1 0 2 R16f +)"); + + EXPECT_EQ(DumpInstructions(b.capabilities()), + R"(OpCapability Image1D +OpCapability StorageImageExtendedFormats )"); }