mirror of
https://github.com/encounter/dawn-cmake.git
synced 2025-06-05 06:03:34 +00:00
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:
parent
dfcc7b5714
commit
9566742f2a
@ -72,15 +72,21 @@ std::string CommonTypes() {
|
|||||||
)";
|
)";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns the SPIR-V assembly for a vertex shader, optionally
|
// Returns the SPIR-V assembly for capabilities, the memory model,
|
||||||
// with OpName decorations for certain SPIR-V IDs
|
// a vertex shader entry point declaration, and name declarations
|
||||||
std::string PreambleNames(std::vector<std::string> ids) {
|
// for specified IDs.
|
||||||
|
std::string Caps(std::vector<std::string> ids = {}) {
|
||||||
return R"(
|
return R"(
|
||||||
OpCapability Shader
|
OpCapability Shader
|
||||||
OpMemoryModel Logical Simple
|
OpMemoryModel Logical Simple
|
||||||
OpEntryPoint Vertex %100 "main"
|
OpEntryPoint Vertex %100 "main"
|
||||||
)" + Names(ids) +
|
)" + Names(ids);
|
||||||
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) {
|
||||||
|
return Caps(ids) + CommonTypes();
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string Preamble() {
|
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,
|
TEST_F(SpvParserFunctionVarTest,
|
||||||
EmitStatement_CombinatorialValue_Defer_UsedOnceSameConstruct) {
|
EmitStatement_CombinatorialValue_Defer_UsedOnceSameConstruct) {
|
||||||
auto assembly = Preamble() + R"(
|
auto assembly = Preamble() + R"(
|
||||||
|
@ -445,6 +445,9 @@ ast::Decoration* ParserImpl::ConvertMemberDecoration(
|
|||||||
case SpvDecorationColMajor:
|
case SpvDecorationColMajor:
|
||||||
// WGSL only supports column major matrices.
|
// WGSL only supports column major matrices.
|
||||||
return nullptr;
|
return nullptr;
|
||||||
|
case SpvDecorationRelaxedPrecision:
|
||||||
|
// WGSL doesn't support relaxed precision.
|
||||||
|
return nullptr;
|
||||||
case SpvDecorationRowMajor:
|
case SpvDecorationRowMajor:
|
||||||
Fail() << "WGSL does not support row-major matrices: can't "
|
Fail() << "WGSL does not support row-major matrices: can't "
|
||||||
"translate member "
|
"translate member "
|
||||||
|
@ -61,6 +61,18 @@ TEST_F(SpvParserTest, ConvertMemberDecoration_Offset) {
|
|||||||
EXPECT_TRUE(p->error().empty());
|
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) {
|
TEST_F(SpvParserTest, ConvertMemberDecoration_UnhandledDecoration) {
|
||||||
auto p = parser(std::vector<uint32_t>{});
|
auto p = parser(std::vector<uint32_t>{});
|
||||||
|
|
||||||
|
@ -98,6 +98,19 @@ TEST_F(SpvParserGetDecorationsTest,
|
|||||||
EXPECT_TRUE(p->error().empty());
|
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
|
// TODO(dneto): Enable when ArrayStride is handled
|
||||||
TEST_F(SpvParserGetDecorationsTest,
|
TEST_F(SpvParserGetDecorationsTest,
|
||||||
DISABLED_GetDecorationsForMember_OneDecoration) {
|
DISABLED_GetDecorationsForMember_OneDecoration) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user