[spirv-writer] Deduplicate sampler and comparision_sampler.

Both sampler types generate an `OpTypeSampler` in SPIR-V so we need to
make sure they're considered duplicates in the SPIR-V backend. This CL
registers the generated ID with for both sampler type_names when either
one is emitted.

Bug: tint:272
Change-Id: If459bbb34fe8670a7e29d101686b70bf83b184c2
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/30662
Commit-Queue: dan sinclair <dsinclair@chromium.org>
Commit-Queue: David Neto <dneto@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
dan sinclair 2020-10-20 21:43:29 +00:00 committed by Commit Bot service account
parent 7156d3e314
commit 4f79c84050
2 changed files with 21 additions and 0 deletions

View File

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

View File

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