spirv-reader: limit SpecId to 16 bits
Fixed: tint:883 Change-Id: Ifcbc886421a67452834f3e3d7aae9a8883b435f8 Reviewed-on: https://dawn-review.googlesource.com/c/tint/+/54460 Auto-Submit: David Neto <dneto@google.com> Commit-Queue: James Price <jrprice@google.com> Kokoro: Kokoro <noreply+kokoro@google.com> Reviewed-by: James Price <jrprice@google.com>
This commit is contained in:
parent
ba403cdf8f
commit
906c9cafbb
|
@ -1166,7 +1166,13 @@ bool ParserImpl::EmitScalarSpecConstants() {
|
||||||
ast::DecorationList spec_id_decos;
|
ast::DecorationList spec_id_decos;
|
||||||
for (const auto& deco : GetDecorationsFor(inst.result_id())) {
|
for (const auto& deco : GetDecorationsFor(inst.result_id())) {
|
||||||
if ((deco.size() == 2) && (deco[0] == SpvDecorationSpecId)) {
|
if ((deco.size() == 2) && (deco[0] == SpvDecorationSpecId)) {
|
||||||
auto* cid = create<ast::OverrideDecoration>(Source{}, deco[1]);
|
const uint32_t id = deco[1];
|
||||||
|
if (id > 65535) {
|
||||||
|
return Fail() << "SpecId too large. WGSL override IDs must be "
|
||||||
|
"between 0 and 65535: ID %"
|
||||||
|
<< inst.result_id() << " has SpecId " << id;
|
||||||
|
}
|
||||||
|
auto* cid = create<ast::OverrideDecoration>(Source{}, id);
|
||||||
spec_id_decos.push_back(cid);
|
spec_id_decos.push_back(cid);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -2069,6 +2069,35 @@ TEST_F(
|
||||||
})")) << module_str;
|
})")) << module_str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_Id_TooBig) {
|
||||||
|
// Override IDs must be between 0 and 65535
|
||||||
|
auto p = parser(test::Assemble(Preamble() + FragMain() + R"(
|
||||||
|
OpDecorate %1 SpecId 65536
|
||||||
|
%bool = OpTypeBool
|
||||||
|
%1 = OpSpecConstantTrue %bool
|
||||||
|
%void = OpTypeVoid
|
||||||
|
%voidfn = OpTypeFunction %void
|
||||||
|
)" + MainBody()));
|
||||||
|
EXPECT_FALSE(p->Parse());
|
||||||
|
EXPECT_EQ(p->error(),
|
||||||
|
"SpecId too large. WGSL override IDs must be between 0 and 65535: "
|
||||||
|
"ID %1 has SpecId 65536");
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_F(SpvModuleScopeVarParserTest,
|
||||||
|
ScalarSpecConstant_DeclareConst_Id_MaxValid) {
|
||||||
|
// Override IDs must be between 0 and 65535
|
||||||
|
auto p = parser(test::Assemble(Preamble() + FragMain() + R"(
|
||||||
|
OpDecorate %1 SpecId 65535
|
||||||
|
%bool = OpTypeBool
|
||||||
|
%1 = OpSpecConstantTrue %bool
|
||||||
|
%void = OpTypeVoid
|
||||||
|
%voidfn = OpTypeFunction %void
|
||||||
|
)" + MainBody()));
|
||||||
|
EXPECT_TRUE(p->Parse());
|
||||||
|
EXPECT_EQ(p->error(), "");
|
||||||
|
}
|
||||||
|
|
||||||
TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_True) {
|
TEST_F(SpvModuleScopeVarParserTest, ScalarSpecConstant_DeclareConst_True) {
|
||||||
auto p = parser(test::Assemble(Preamble() + FragMain() + R"(
|
auto p = parser(test::Assemble(Preamble() + FragMain() + R"(
|
||||||
OpName %c "myconst"
|
OpName %c "myconst"
|
||||||
|
|
Loading…
Reference in New Issue