spirv-reader: ignore RelaxedPrecision on struct members

Bug: tint:737
Change-Id: Ic9a37e70ad1e6c1aa49aa49fe37a842361e306e1
Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/53440
Auto-Submit: David Neto <dneto@google.com>
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
David Neto 2021-06-07 20:36:54 +00:00 committed by Tint LUCI CQ
parent dfcc7b5714
commit 9566742f2a
4 changed files with 110 additions and 5 deletions

View File

@ -72,15 +72,21 @@ std::string CommonTypes() {
)";
}
// Returns the SPIR-V assembly for a vertex shader, optionally
// with OpName decorations for certain SPIR-V IDs
std::string PreambleNames(std::vector<std::string> ids) {
// Returns the SPIR-V assembly for capabilities, the memory model,
// a vertex shader entry point declaration, and name declarations
// for specified IDs.
std::string Caps(std::vector<std::string> ids = {}) {
return R"(
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint Vertex %100 "main"
)" + Names(ids) +
CommonTypes();
)" + Names(ids);
}
// Returns the SPIR-V assembly for a vertex shader, optionally
// with OpName decorations for certain SPIR-V IDs
std::string PreambleNames(std::vector<std::string> ids) {
return Caps(ids) + CommonTypes();
}
std::string Preamble() {
@ -680,6 +686,77 @@ TEST_F(SpvParserFunctionVarTest, EmitFunctionVariables_StructInitializer_Null) {
)"));
}
TEST_F(SpvParserFunctionVarTest,
EmitFunctionVariables_Decorate_RelaxedPrecision) {
// RelaxedPrecisionis dropped
auto p = parser(test::Assemble(Caps({"myvar"}) + R"(
OpDecorate %myvar RelaxedPrecision
%float = OpTypeFloat 32
%ptr = OpTypePointer Function %float
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%100 = OpFunction %void None %voidfn
%entry = OpLabel
%myvar = OpVariable %ptr Function
OpReturn
OpFunctionEnd
)"));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions());
auto fe = p->function_emitter(100);
EXPECT_TRUE(fe.EmitFunctionVariables());
const auto got = ToString(p->builder(), fe.ast_body());
EXPECT_EQ(got, R"(VariableDeclStatement{
Variable{
myvar
none
undefined
__f32
}
}
)") << got;
}
TEST_F(SpvParserFunctionVarTest,
EmitFunctionVariables_MemberDecorate_RelaxedPrecision) {
// RelaxedPrecisionis dropped
const auto assembly = Caps({"myvar", "strct"}) + R"(
OpMemberDecorate %strct 0 RelaxedPrecision
%float = OpTypeFloat 32
%strct = OpTypeStruct %float
%ptr = OpTypePointer Function %strct
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%100 = OpFunction %void None %voidfn
%entry = OpLabel
%myvar = OpVariable %ptr Function
OpReturn
OpFunctionEnd
)";
auto p = parser(test::Assemble(assembly));
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions())
<< assembly << p->error() << std::endl;
auto fe = p->function_emitter(100);
EXPECT_TRUE(fe.EmitFunctionVariables());
const auto got = ToString(p->builder(), fe.ast_body());
EXPECT_EQ(got, R"(VariableDeclStatement{
Variable{
myvar
none
undefined
__type_name_strct
}
}
)") << got;
}
TEST_F(SpvParserFunctionVarTest,
EmitStatement_CombinatorialValue_Defer_UsedOnceSameConstruct) {
auto assembly = Preamble() + R"(

View File

@ -445,6 +445,9 @@ ast::Decoration* ParserImpl::ConvertMemberDecoration(
case SpvDecorationColMajor:
// WGSL only supports column major matrices.
return nullptr;
case SpvDecorationRelaxedPrecision:
// WGSL doesn't support relaxed precision.
return nullptr;
case SpvDecorationRowMajor:
Fail() << "WGSL does not support row-major matrices: can't "
"translate member "

View File

@ -61,6 +61,18 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Offset) {
EXPECT_TRUE(p->error().empty());
}
TEST_F(SpvParserTest, ConvertMemberDecoration_RelaxedPrecision) {
// WGSL does not support relaxed precision. Drop it.
// It's functionally correct to use full precision f32 instead of
// relaxed precision f32.
auto p = parser(std::vector<uint32_t>{});
auto* result =
p->ConvertMemberDecoration(1, 1, {SpvDecorationRelaxedPrecision});
EXPECT_EQ(result, nullptr);
EXPECT_TRUE(p->error().empty());
}
TEST_F(SpvParserTest, ConvertMemberDecoration_UnhandledDecoration) {
auto p = parser(std::vector<uint32_t>{});

View File

@ -98,6 +98,19 @@ TEST_F(SpvParserGetDecorationsTest,
EXPECT_TRUE(p->error().empty());
}
TEST_F(SpvParserGetDecorationsTest, GetDecorationsForMember_RelaxedPrecision) {
auto p = parser(test::Assemble(R"(
OpMemberDecorate %10 0 RelaxedPrecision
%float = OpTypeFloat 32
%10 = OpTypeStruct %float
)"));
EXPECT_TRUE(p->BuildAndParseInternalModule()) << p->error();
auto decorations = p->GetDecorationsForMember(10, 0);
EXPECT_THAT(decorations,
UnorderedElementsAre(Decoration{SpvDecorationRelaxedPrecision}));
EXPECT_TRUE(p->error().empty());
}
// TODO(dneto): Enable when ArrayStride is handled
TEST_F(SpvParserGetDecorationsTest,
DISABLED_GetDecorationsForMember_OneDecoration) {