From bed7a32b3b44f9e2c4b462518717d5ad3b11fa9b Mon Sep 17 00:00:00 2001 From: Corentin Wallez Date: Wed, 25 Nov 2020 13:58:47 +0000 Subject: [PATCH] type_determiner: use f32 as the subtype for u/norm storage texture. Fixes: tint:367 Change-Id: I311f5b9524d6251c88ae774dc8dc80f6d52e457d Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33922 Commit-Queue: Corentin Wallez Reviewed-by: David Neto --- src/ast/type/storage_texture_type_test.cc | 2 +- src/type_determiner.cc | 20 +++++++-------- src/type_determiner_test.cc | 10 ++++---- src/writer/spirv/builder_type_test.cc | 30 +++++++++++++++++++++-- 4 files changed, 44 insertions(+), 18 deletions(-) diff --git a/src/ast/type/storage_texture_type_test.cc b/src/ast/type/storage_texture_type_test.cc index 1600298e0c..dd5b32c359 100644 --- a/src/ast/type/storage_texture_type_test.cc +++ b/src/ast/type/storage_texture_type_test.cc @@ -96,7 +96,7 @@ TEST_F(StorageTextureTypeTest, U32Type) { ast::Module mod; ast::type::Type* s = mod.create( TextureDimension::k2dArray, AccessControl::kReadOnly, - ImageFormat::kRgba8Unorm); + ImageFormat::kRg32Uint); TypeDeterminer td(&ctx, &mod); ASSERT_TRUE(td.Determine()) << td.error(); diff --git a/src/type_determiner.cc b/src/type_determiner.cc index d9800867c1..36d5fbccaa 100644 --- a/src/type_determiner.cc +++ b/src/type_determiner.cc @@ -1166,13 +1166,6 @@ bool TypeDeterminer::DetermineStorageTextureSubtype( } switch (tex->image_format()) { - case ast::type::ImageFormat::kR8Unorm: - case ast::type::ImageFormat::kRg8Unorm: - case ast::type::ImageFormat::kRgba8Unorm: - case ast::type::ImageFormat::kRgba8UnormSrgb: - case ast::type::ImageFormat::kBgra8Unorm: - case ast::type::ImageFormat::kBgra8UnormSrgb: - case ast::type::ImageFormat::kRgb10A2Unorm: case ast::type::ImageFormat::kR8Uint: case ast::type::ImageFormat::kR16Uint: case ast::type::ImageFormat::kRg8Uint: @@ -1186,9 +1179,6 @@ bool TypeDeterminer::DetermineStorageTextureSubtype( return true; } - case ast::type::ImageFormat::kR8Snorm: - case ast::type::ImageFormat::kRg8Snorm: - case ast::type::ImageFormat::kRgba8Snorm: case ast::type::ImageFormat::kR8Sint: case ast::type::ImageFormat::kR16Sint: case ast::type::ImageFormat::kRg8Sint: @@ -1202,6 +1192,16 @@ bool TypeDeterminer::DetermineStorageTextureSubtype( return true; } + case ast::type::ImageFormat::kR8Unorm: + case ast::type::ImageFormat::kRg8Unorm: + case ast::type::ImageFormat::kRgba8Unorm: + case ast::type::ImageFormat::kRgba8UnormSrgb: + case ast::type::ImageFormat::kBgra8Unorm: + case ast::type::ImageFormat::kBgra8UnormSrgb: + case ast::type::ImageFormat::kRgb10A2Unorm: + case ast::type::ImageFormat::kR8Snorm: + case ast::type::ImageFormat::kRg8Snorm: + case ast::type::ImageFormat::kRgba8Snorm: case ast::type::ImageFormat::kR16Float: case ast::type::ImageFormat::kR32Float: case ast::type::ImageFormat::kRg16Float: diff --git a/src/type_determiner_test.cc b/src/type_determiner_test.cc index c007cac4c0..6503585e29 100644 --- a/src/type_determiner_test.cc +++ b/src/type_determiner_test.cc @@ -1821,31 +1821,31 @@ INSTANTIATE_TEST_SUITE_P( ast::type::ImageFormat::kR16Float}, TextureTestParams{ast::type::TextureDimension::k1d, TextureType::kI32, ast::type::ImageFormat::kR16Sint}, - TextureTestParams{ast::type::TextureDimension::k1d, TextureType::kU32, + TextureTestParams{ast::type::TextureDimension::k1d, TextureType::kF32, ast::type::ImageFormat::kR8Unorm}, TextureTestParams{ast::type::TextureDimension::k1dArray, TextureType::kF32, ast::type::ImageFormat::kR16Float}, TextureTestParams{ast::type::TextureDimension::k1dArray, TextureType::kI32, ast::type::ImageFormat::kR16Sint}, TextureTestParams{ast::type::TextureDimension::k1dArray, - TextureType::kU32, ast::type::ImageFormat::kR8Unorm}, + TextureType::kF32, ast::type::ImageFormat::kR8Unorm}, TextureTestParams{ast::type::TextureDimension::k2d, TextureType::kF32, ast::type::ImageFormat::kR16Float}, TextureTestParams{ast::type::TextureDimension::k2d, TextureType::kI32, ast::type::ImageFormat::kR16Sint}, - TextureTestParams{ast::type::TextureDimension::k2d, TextureType::kU32, + TextureTestParams{ast::type::TextureDimension::k2d, TextureType::kF32, ast::type::ImageFormat::kR8Unorm}, TextureTestParams{ast::type::TextureDimension::k2dArray, TextureType::kF32, ast::type::ImageFormat::kR16Float}, TextureTestParams{ast::type::TextureDimension::k2dArray, TextureType::kI32, ast::type::ImageFormat::kR16Sint}, TextureTestParams{ast::type::TextureDimension::k2dArray, - TextureType::kU32, ast::type::ImageFormat::kR8Unorm}, + TextureType::kF32, ast::type::ImageFormat::kR8Unorm}, TextureTestParams{ast::type::TextureDimension::k3d, TextureType::kF32, ast::type::ImageFormat::kR16Float}, TextureTestParams{ast::type::TextureDimension::k3d, TextureType::kI32, ast::type::ImageFormat::kR16Sint}, - TextureTestParams{ast::type::TextureDimension::k3d, TextureType::kU32, + TextureTestParams{ast::type::TextureDimension::k3d, TextureType::kF32, ast::type::ImageFormat::kR8Unorm})); using Intrinsic_SampledTextureOperation = Intrinsic_TextureOperation; diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 01109a488a..99e94ebaf6 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -845,7 +845,7 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_R8SNorm) { ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 + EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 1D 0 0 0 2 R8Snorm )"); } @@ -858,11 +858,37 @@ TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_R8UNorm) { ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); ASSERT_FALSE(b.has_error()) << b.error(); - EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0 + EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeFloat 32 %1 = OpTypeImage %2 1D 0 0 0 2 R8 )"); } +TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_R8Uint) { + ast::type::StorageTextureType s(ast::type::TextureDimension::k1d, + ast::AccessControl::kReadOnly, + ast::type::ImageFormat::kR8Uint); + + ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); + EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); + ASSERT_FALSE(b.has_error()) << b.error(); + EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 0 +%1 = OpTypeImage %2 1D 0 0 0 2 R8ui +)"); +} + +TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_R8Sint) { + ast::type::StorageTextureType s(ast::type::TextureDimension::k1d, + ast::AccessControl::kReadOnly, + ast::type::ImageFormat::kR8Sint); + + ASSERT_TRUE(td.DetermineStorageTextureSubtype(&s)) << td.error(); + EXPECT_EQ(b.GenerateTypeIfNeeded(&s), 1u); + ASSERT_FALSE(b.has_error()) << b.error(); + EXPECT_EQ(DumpInstructions(b.types()), R"(%2 = OpTypeInt 32 1 +%1 = OpTypeImage %2 1D 0 0 0 2 R8i +)"); +} + TEST_F(BuilderTest_Type, StorageTexture_GenerateReadonly_1d_array) { ast::type::StorageTextureType s(ast::type::TextureDimension::k1dArray, ast::AccessControl::kReadOnly,