[spirv-reader] Support Location on module vars
Bug: tint:3 Change-Id: If7fc85251cbffab477b0b4f86c204de6c6a853f6 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/25103 Reviewed-by: dan sinclair <dsinclair@chromium.org>
This commit is contained in:
parent
d8a4d4b06f
commit
3c3d2275fe
|
@ -942,6 +942,15 @@ std::unique_ptr<ast::Variable> ParserImpl::MakeVariable(uint32_t id,
|
||||||
ast_decorations.emplace_back(
|
ast_decorations.emplace_back(
|
||||||
std::make_unique<ast::BuiltinDecoration>(ast_builtin));
|
std::make_unique<ast::BuiltinDecoration>(ast_builtin));
|
||||||
}
|
}
|
||||||
|
if (deco[0] == SpvDecorationLocation) {
|
||||||
|
if (deco.size() != 2) {
|
||||||
|
Fail() << "malformed Location decoration on ID " << id
|
||||||
|
<< ": requires one literal operand";
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
ast_decorations.emplace_back(
|
||||||
|
std::make_unique<ast::LocationDecoration>(deco[1]));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (!ast_decorations.empty()) {
|
if (!ast_decorations.empty()) {
|
||||||
auto decorated_var =
|
auto decorated_var =
|
||||||
|
|
|
@ -1117,6 +1117,57 @@ TEST_F(SpvParserTest, ModuleScopeVar_StructUndefInitializer) {
|
||||||
<< module_str;
|
<< module_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvParserTest, ModuleScopeVar_LocationDecoration_Valid) {
|
||||||
|
auto* p = parser(test::Assemble(R"(
|
||||||
|
OpName %myvar "myvar"
|
||||||
|
OpDecorate %myvar Location 3
|
||||||
|
)" + CommonTypes() + R"(
|
||||||
|
%ptr = OpTypePointer Input %uint
|
||||||
|
%myvar = OpVariable %ptr Input
|
||||||
|
)"));
|
||||||
|
ASSERT_TRUE(p->BuildAndParseInternalModuleExceptFunctions()) << p->error();
|
||||||
|
EXPECT_TRUE(p->error().empty());
|
||||||
|
const auto module_str = p->module().to_str();
|
||||||
|
EXPECT_THAT(module_str, HasSubstr(R"(
|
||||||
|
DecoratedVariable{
|
||||||
|
Decorations{
|
||||||
|
LocationDecoration{3}
|
||||||
|
}
|
||||||
|
myvar
|
||||||
|
in
|
||||||
|
__u32
|
||||||
|
})"))
|
||||||
|
<< module_str;
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvParserTest,
|
||||||
|
ModuleScopeVar_LocationDecoration_MissingOperandWontAssemble) {
|
||||||
|
const auto assembly = R"(
|
||||||
|
OpName %myvar "myvar"
|
||||||
|
OpDecorate %myvar Location
|
||||||
|
)" + CommonTypes() + R"(
|
||||||
|
%ptr = OpTypePointer Input %uint
|
||||||
|
%myvar = OpVariable %ptr Input
|
||||||
|
)";
|
||||||
|
EXPECT_THAT(test::AssembleFailure(assembly),
|
||||||
|
Eq("4:4: Expected operand, found next instruction instead."));
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvParserTest,
|
||||||
|
ModuleScopeVar_LocationDecoration_TwoOperandsWontAssemble) {
|
||||||
|
const auto assembly = R"(
|
||||||
|
OpName %myvar "myvar"
|
||||||
|
OpDecorate %myvar Location 3 4
|
||||||
|
)" + CommonTypes() + R"(
|
||||||
|
%ptr = OpTypePointer Input %uint
|
||||||
|
%myvar = OpVariable %ptr Input
|
||||||
|
)";
|
||||||
|
EXPECT_THAT(
|
||||||
|
test::AssembleFailure(assembly),
|
||||||
|
Eq("2:34: Expected <opcode> or <result-id> at the beginning of an "
|
||||||
|
"instruction, found '4'."));
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
} // namespace spirv
|
} // namespace spirv
|
||||||
} // namespace reader
|
} // namespace reader
|
||||||
|
|
Loading…
Reference in New Issue