diff --git a/src/reader/spirv/parser_impl.cc b/src/reader/spirv/parser_impl.cc index 7068857ffb..8caacf215d 100644 --- a/src/reader/spirv/parser_impl.cc +++ b/src/reader/spirv/parser_impl.cc @@ -305,6 +305,12 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) { // But the SPIR-V defines those before defining the function // type. No further work is required here. return nullptr; + case spvtools::opt::analysis::Type::kSampler: + case spvtools::opt::analysis::Type::kSampledImage: + case spvtools::opt::analysis::Type::kImage: + // Fake it for sampler and texture types. These are handled in an + // entirely different way. + return save(ctx_.type_mgr().Get(std::make_unique())); default: break; } @@ -890,6 +896,7 @@ ast::type::Type* ParserImpl::ConvertType( const auto* inst = def_use_mgr_->GetDef(type_id); const auto pointee_type_id = inst->GetSingleWordInOperand(1); const auto storage_class = SpvStorageClass(inst->GetSingleWordInOperand(0)); + if (pointee_type_id == builtin_position_.struct_type_id) { builtin_position_.pointer_type_id = type_id; builtin_position_.storage_class = storage_class; diff --git a/src/reader/spirv/parser_impl.h b/src/reader/spirv/parser_impl.h index f4e1a1ef50..f44659278e 100644 --- a/src/reader/spirv/parser_impl.h +++ b/src/reader/spirv/parser_impl.h @@ -123,7 +123,9 @@ class ParserImpl : Reader { /// Converts a SPIR-V type to a Tint type, and saves it for fast lookup. /// If the type is only used for builtins, then register that specially, - /// and return null. + /// and return null. If the type is a sampler, image, or sampled image, then + /// return the Void type, because those opaque types are handled in a + /// different way. /// On failure, logs an error and returns null. This should only be called /// after the internal representation of the module has been built. /// @param type_id the SPIR-V ID of a type. diff --git a/src/reader/spirv/parser_impl_convert_type_test.cc b/src/reader/spirv/parser_impl_convert_type_test.cc index 567446575d..aaba532a6a 100644 --- a/src/reader/spirv/parser_impl_convert_type_test.cc +++ b/src/reader/spirv/parser_impl_convert_type_test.cc @@ -816,6 +816,44 @@ TEST_F(SpvParserTest, ConvertType_PointerToPointer) { EXPECT_TRUE(p->error().empty()); } +TEST_F(SpvParserTest, ConvertType_Sampler_PretendVoid) { + // We fake the type suport for samplers, images, and sampled images. + auto* p = parser(test::Assemble(R"( + %1 = OpTypeSampler + )")); + EXPECT_TRUE(p->BuildInternalModule()); + + auto* type = p->ConvertType(1); + EXPECT_TRUE(type->IsVoid()); + EXPECT_TRUE(p->error().empty()); +} + +TEST_F(SpvParserTest, ConvertType_Image_PretendVoid) { + // We fake the type suport for samplers, images, and sampled images. + auto* p = parser(test::Assemble(R"( + %float = OpTypeFloat 32 + %1 = OpTypeImage %float 2D 0 0 0 1 Unknown + )")); + EXPECT_TRUE(p->BuildInternalModule()); + + auto* type = p->ConvertType(1); + EXPECT_TRUE(type->IsVoid()); + EXPECT_TRUE(p->error().empty()); +} + +TEST_F(SpvParserTest, ConvertType_SampledImage_PretendVoid) { + auto* p = parser(test::Assemble(R"( + %float = OpTypeFloat 32 + %im = OpTypeImage %float 2D 0 0 0 1 Unknown + %1 = OpTypeSampledImage %im + )")); + EXPECT_TRUE(p->BuildInternalModule()); + + auto* type = p->ConvertType(1); + EXPECT_TRUE(type->IsVoid()); + EXPECT_TRUE(p->error().empty()); +} + } // namespace } // namespace spirv } // namespace reader