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 <dsinclair@chromium.org>
Commit-Queue: Corentin Wallez <cwallez@chromium.org>
This commit is contained in:
Corentin Wallez 2020-11-25 17:02:37 +00:00 committed by Commit Bot service account
parent d49841ca9f
commit 4e91325bf0
2 changed files with 52 additions and 0 deletions

View File

@ -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;

View File

@ -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
)");
}