Skip to content

Commit 362ce7c

Browse files
authored
Allow more levels of arrays with component decoration (#5820)
Fixes #5819 * Allow multiple levels of arrays in a variable with component decoration
1 parent 2484975 commit 362ce7c

File tree

2 files changed

+74
-1
lines changed

2 files changed

+74
-1
lines changed

source/val/validate_decorations.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1876,7 +1876,7 @@ spv_result_t CheckComponentDecoration(ValidationState_t& vstate,
18761876

18771877
if (spvIsVulkanEnv(vstate.context()->target_env)) {
18781878
// Strip the array, if present.
1879-
if (vstate.GetIdOpcode(type_id) == spv::Op::OpTypeArray) {
1879+
while (vstate.GetIdOpcode(type_id) == spv::Op::OpTypeArray) {
18801880
type_id = vstate.FindDef(type_id)->word(2u);
18811881
}
18821882

test/val/val_decoration_test.cpp

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10364,6 +10364,79 @@ OpFunctionEnd
1036410364
HasSubstr("member 0 is missing an Offset decoration"));
1036510365
}
1036610366

10367+
TEST_F(ValidateDecorations, ComponentMultipleArrays) {
10368+
const std::string spirv = R"(
10369+
OpCapability Tessellation
10370+
%1 = OpExtInstImport "GLSL.std.450"
10371+
OpMemoryModel Logical GLSL450
10372+
OpEntryPoint TessellationEvaluation %main "main" %_ %FOO %FOO0
10373+
OpExecutionMode %main Triangles
10374+
OpExecutionMode %main SpacingEqual
10375+
OpExecutionMode %main VertexOrderCcw
10376+
OpSource GLSL 460
10377+
OpSourceExtension "GL_EXT_nonuniform_qualifier"
10378+
OpName %main "main"
10379+
OpName %gl_PerVertex "gl_PerVertex"
10380+
OpMemberName %gl_PerVertex 0 "gl_Position"
10381+
OpMemberName %gl_PerVertex 1 "gl_PointSize"
10382+
OpMemberName %gl_PerVertex 2 "gl_ClipDistance"
10383+
OpMemberName %gl_PerVertex 3 "gl_CullDistance"
10384+
OpName %_ ""
10385+
OpName %FOO "FOO"
10386+
OpMemberDecorate %gl_PerVertex 0 BuiltIn Position
10387+
OpMemberDecorate %gl_PerVertex 1 BuiltIn PointSize
10388+
OpMemberDecorate %gl_PerVertex 2 BuiltIn ClipDistance
10389+
OpMemberDecorate %gl_PerVertex 3 BuiltIn CullDistance
10390+
OpDecorate %gl_PerVertex Block
10391+
OpDecorate %FOO Component 2
10392+
OpDecorate %FOO Location 1
10393+
OpDecorate %FOO0 Location 1
10394+
OpDecorate %FOO0 Component 0
10395+
%void = OpTypeVoid
10396+
%3 = OpTypeFunction %void
10397+
%float = OpTypeFloat 32
10398+
%v4float = OpTypeVector %float 4
10399+
%uint = OpTypeInt 32 0
10400+
%uint_1 = OpConstant %uint 1
10401+
%_arr_float_uint_1 = OpTypeArray %float %uint_1
10402+
%gl_PerVertex = OpTypeStruct %v4float %float %_arr_float_uint_1 %_arr_float_uint_1
10403+
%_ptr_Output_gl_PerVertex = OpTypePointer Output %gl_PerVertex
10404+
%_ = OpVariable %_ptr_Output_gl_PerVertex Output
10405+
%int = OpTypeInt 32 1
10406+
%int_0 = OpConstant %int 0
10407+
%v2float = OpTypeVector %float 2
10408+
%uint_2 = OpConstant %uint 2
10409+
%_arr_v2float_uint_2 = OpTypeArray %v2float %uint_2
10410+
%uint_32 = OpConstant %uint 32
10411+
%_arr__arr_v2float_uint_2_uint_32 = OpTypeArray %_arr_v2float_uint_2 %uint_32
10412+
%_ptr_Input__arr__arr_v2float_uint_2_uint_32 = OpTypePointer Input %_arr__arr_v2float_uint_2_uint_32
10413+
%FOO = OpVariable %_ptr_Input__arr__arr_v2float_uint_2_uint_32 Input
10414+
%FOO0 = OpVariable %_ptr_Input__arr__arr_v2float_uint_2_uint_32 Input
10415+
%_ptr_Input_v2float = OpTypePointer Input %v2float
10416+
%int_1 = OpConstant %int 1
10417+
%uint_0 = OpConstant %uint 0
10418+
%_ptr_Output_float = OpTypePointer Output %float
10419+
%main = OpFunction %void None %3
10420+
%5 = OpLabel
10421+
%24 = OpAccessChain %_ptr_Input_v2float %FOO %int_0 %int_0
10422+
%25 = OpLoad %v2float %24
10423+
%27 = OpAccessChain %_ptr_Input_v2float %FOO0 %int_1 %int_1
10424+
%28 = OpLoad %v2float %27
10425+
%29 = OpFAdd %v2float %25 %28
10426+
%32 = OpAccessChain %_ptr_Output_float %_ %int_0 %uint_0
10427+
%33 = OpCompositeExtract %float %29 0
10428+
OpStore %32 %33
10429+
%34 = OpAccessChain %_ptr_Output_float %_ %int_0 %uint_1
10430+
%35 = OpCompositeExtract %float %29 1
10431+
OpStore %34 %35
10432+
OpReturn
10433+
OpFunctionEnd
10434+
)";
10435+
10436+
CompileSuccessfully(spirv, SPV_ENV_VULKAN_1_0);
10437+
EXPECT_EQ(SPV_SUCCESS, ValidateInstructions(SPV_ENV_VULKAN_1_0));
10438+
}
10439+
1036710440
} // namespace
1036810441
} // namespace val
1036910442
} // namespace spvtools

0 commit comments

Comments
 (0)