spirv-reader: pretend handles are void
We convert types of samplers, images, and sampled images entirely differently, but still find it useful to generalize ParserImpl::ConvertType to cover them. Fake it: Make ConvertType return void for them. Bug: tint:109 Change-Id: I0982eb987d0914db8227bc0fce552989831129b9 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/33020 Commit-Queue: David Neto <dneto@google.com> Commit-Queue: dan sinclair <dsinclair@chromium.org> Auto-Submit: David Neto <dneto@google.com> Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
2733c2693b
commit
90f3253645
|
@ -305,6 +305,12 @@ ast::type::Type* ParserImpl::ConvertType(uint32_t type_id) {
|
||||||
// But the SPIR-V defines those before defining the function
|
// But the SPIR-V defines those before defining the function
|
||||||
// type. No further work is required here.
|
// type. No further work is required here.
|
||||||
return nullptr;
|
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<ast::type::VoidType>()));
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -890,6 +896,7 @@ ast::type::Type* ParserImpl::ConvertType(
|
||||||
const auto* inst = def_use_mgr_->GetDef(type_id);
|
const auto* inst = def_use_mgr_->GetDef(type_id);
|
||||||
const auto pointee_type_id = inst->GetSingleWordInOperand(1);
|
const auto pointee_type_id = inst->GetSingleWordInOperand(1);
|
||||||
const auto storage_class = SpvStorageClass(inst->GetSingleWordInOperand(0));
|
const auto storage_class = SpvStorageClass(inst->GetSingleWordInOperand(0));
|
||||||
|
|
||||||
if (pointee_type_id == builtin_position_.struct_type_id) {
|
if (pointee_type_id == builtin_position_.struct_type_id) {
|
||||||
builtin_position_.pointer_type_id = type_id;
|
builtin_position_.pointer_type_id = type_id;
|
||||||
builtin_position_.storage_class = storage_class;
|
builtin_position_.storage_class = storage_class;
|
||||||
|
|
|
@ -123,7 +123,9 @@ class ParserImpl : Reader {
|
||||||
|
|
||||||
/// Converts a SPIR-V type to a Tint type, and saves it for fast lookup.
|
/// 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,
|
/// 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
|
/// On failure, logs an error and returns null. This should only be called
|
||||||
/// after the internal representation of the module has been built.
|
/// after the internal representation of the module has been built.
|
||||||
/// @param type_id the SPIR-V ID of a type.
|
/// @param type_id the SPIR-V ID of a type.
|
||||||
|
|
|
@ -816,6 +816,44 @@ TEST_F(SpvParserTest, ConvertType_PointerToPointer) {
|
||||||
EXPECT_TRUE(p->error().empty());
|
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
|
||||||
} // namespace spirv
|
} // namespace spirv
|
||||||
} // namespace reader
|
} // namespace reader
|
||||||
|
|
Loading…
Reference in New Issue