diff --git a/src/writer/spirv/builder.cc b/src/writer/spirv/builder.cc index 8708769dba..92c239f071 100644 --- a/src/writer/spirv/builder.cc +++ b/src/writer/spirv/builder.cc @@ -2307,6 +2307,12 @@ uint32_t Builder::GenerateTypeIfNeeded(ast::type::Type* type) { } } else if (type->IsSampler()) { push_type(spv::Op::OpTypeSampler, {result}); + + // Register both of the sampler type names. In SPIR-V they're the same + // sampler type, so we need to match that when we do the dedup check. + type_name_to_id_["__sampler_sampler"] = id; + type_name_to_id_["__sampler_comparison"] = id; + } else { error_ = "unable to convert type: " + type->type_name(); return 0; diff --git a/src/writer/spirv/builder_type_test.cc b/src/writer/spirv/builder_type_test.cc index 892e812965..0c153ebdaf 100644 --- a/src/writer/spirv/builder_type_test.cc +++ b/src/writer/spirv/builder_type_test.cc @@ -1181,6 +1181,21 @@ TEST_F(BuilderTest_Type, ComparisonSampler) { EXPECT_EQ(DumpInstructions(b.types()), "%1 = OpTypeSampler\n"); } +TEST_F(BuilderTest_Type, Dedup_Sampler_And_ComparisonSampler) { + ast::Module mod; + Builder b(&mod); + + ast::type::SamplerType comp_sampler( + ast::type::SamplerKind::kComparisonSampler); + EXPECT_EQ(b.GenerateTypeIfNeeded(&comp_sampler), 1u); + + ast::type::SamplerType sampler(ast::type::SamplerKind::kSampler); + EXPECT_EQ(b.GenerateTypeIfNeeded(&sampler), 1u); + + ASSERT_FALSE(b.has_error()) << b.error(); + EXPECT_EQ(DumpInstructions(b.types()), "%1 = OpTypeSampler\n"); +} + } // namespace } // namespace spirv } // namespace writer