spirv-reader: Error on multiple Position built-ins

Produce a meaningful error instead of just crashing.

Bug: oss-fuzz:55170
Change-Id: I09d94a910835839ce9407849446cf2928231a114
Reviewed-on: https://dawn-review.googlesource.com/c/dawn/+/128540
Kokoro: Kokoro <noreply+kokoro@google.com>
Commit-Queue: James Price <jrprice@google.com>
Reviewed-by: David Neto <dneto@google.com>
This commit is contained in:
James Price 2023-04-24 19:48:23 +00:00 committed by Dawn LUCI CQ
parent bdc2d24900
commit d36740509f
2 changed files with 35 additions and 0 deletions

View File

@ -1438,6 +1438,12 @@ bool ParserImpl::EmitModuleScopeVariables() {
if ((type_id == builtin_position_.pointer_type_id) && if ((type_id == builtin_position_.pointer_type_id) &&
((spirv_storage_class == spv::StorageClass::Input) || ((spirv_storage_class == spv::StorageClass::Input) ||
(spirv_storage_class == spv::StorageClass::Output))) { (spirv_storage_class == spv::StorageClass::Output))) {
// TODO(crbug.com/tint/103): Support modules that contain multiple Position built-ins.
if (builtin_position_.per_vertex_var_id != 0) {
return Fail()
<< "unsupported: multiple Position built-in variables in the same module";
}
// Skip emitting gl_PerVertex. // Skip emitting gl_PerVertex.
builtin_position_.per_vertex_var_id = var.result_id(); builtin_position_.per_vertex_var_id = var.result_id();
builtin_position_.per_vertex_var_init_id = builtin_position_.per_vertex_var_init_id =

View File

@ -4132,6 +4132,35 @@ fn main() -> main_out {
EXPECT_EQ(got, expected) << got; EXPECT_EQ(got, expected) << got;
} }
TEST_F(SpvModuleScopeVarParserTest, BuiltinPosition_MultiplePerVertexVariables) {
// This is not currently supported, so just make sure we produce a meaningful error instead of
// crashing.
const std::string assembly = R"(
OpCapability Shader
OpMemoryModel Logical Simple
OpEntryPoint Vertex %main "main" %1
OpDecorate %struct Block
OpMemberDecorate %struct 0 BuiltIn Position
%void = OpTypeVoid
%voidfn = OpTypeFunction %void
%f32 = OpTypeFloat 32
%vec4f = OpTypeVector %f32 4
%struct = OpTypeStruct %vec4f
%struct_out_ptr = OpTypePointer Output %struct
%1 = OpVariable %struct_out_ptr Output
%2 = OpVariable %struct_out_ptr Output
%main = OpFunction %void None %voidfn
%entry = OpLabel
OpReturn
OpFunctionEnd
)";
auto p = parser(test::Assemble(assembly));
EXPECT_FALSE(p->Parse());
EXPECT_FALSE(p->success());
EXPECT_EQ(p->error(), "unsupported: multiple Position built-in variables in the same module");
}
TEST_F(SpvModuleScopeVarParserTest, Input_FlattenArray_OneLevel) { TEST_F(SpvModuleScopeVarParserTest, Input_FlattenArray_OneLevel) {
const std::string assembly = R"( const std::string assembly = R"(
OpCapability Shader OpCapability Shader