diff --git a/src/sksl/SkSLIRGenerator.cpp b/src/sksl/SkSLIRGenerator.cpp index ea9901d0ad..3a64211edc 100644 --- a/src/sksl/SkSLIRGenerator.cpp +++ b/src/sksl/SkSLIRGenerator.cpp @@ -725,17 +725,18 @@ std::unique_ptr IRGenerator::applyInvocationIDWorkaround(std::unique_ptr< std::vector(), fContext.fVoid_Type.get(), fIsBuiltinCode)); - fProgramElements->push_back(std::make_unique(/*offset=*/-1, - invokeDecl, fIsBuiltinCode, - std::move(main))); - + auto invokeDef = std::make_unique(/*offset=*/-1, invokeDecl, fIsBuiltinCode, + std::move(main)); + invokeDecl->setDefinition(invokeDef.get()); + fProgramElements->push_back(std::move(invokeDef)); std::vector> variables; const Variable* loopIdx = &(*fSymbolTable)["sk_InvocationID"]->as(); - auto test = std::make_unique(/*offset=*/-1, - std::make_unique(/*offset=*/-1, loopIdx), - Token::Kind::TK_LT, - std::make_unique(fContext, /*offset=*/-1, fInvocations), - fContext.fBool_Type.get()); + auto test = std::make_unique( + /*offset=*/-1, + std::make_unique(/*offset=*/-1, loopIdx), + Token::Kind::TK_LT, + std::make_unique(fContext, /*offset=*/-1, fInvocations), + fContext.fBool_Type.get()); auto next = std::make_unique( std::make_unique(/*offset=*/-1, loopIdx, VariableReference::RefKind::kReadWrite), @@ -746,18 +747,19 @@ std::unique_ptr IRGenerator::applyInvocationIDWorkaround(std::unique_ptr< StatementArray loopBody; loopBody.reserve_back(2); - loopBody.push_back(std::make_unique(this->call( - /*offset=*/-1, *invokeDecl, - ExpressionArray{}))); - loopBody.push_back(std::make_unique(this->call( - /*offset=*/-1, std::move(endPrimitive), - ExpressionArray{}))); - auto assignment = std::make_unique(/*offset=*/-1, - std::make_unique(/*offset=*/-1, loopIdx, - VariableReference::RefKind::kWrite), - Token::Kind::TK_EQ, - std::make_unique(fContext, /*offset=*/-1, /*value=*/0), - fContext.fInt_Type.get()); + loopBody.push_back(std::make_unique(this->call(/*offset=*/-1, + *invokeDecl, + ExpressionArray{}))); + loopBody.push_back(std::make_unique(this->call(/*offset=*/-1, + std::move(endPrimitive), + ExpressionArray{}))); + auto assignment = std::make_unique( + /*offset=*/-1, + std::make_unique(/*offset=*/-1, loopIdx, + VariableReference::RefKind::kWrite), + Token::Kind::TK_EQ, + std::make_unique(fContext, /*offset=*/-1, /*value=*/0), + fContext.fInt_Type.get()); auto initializer = std::make_unique(std::move(assignment)); auto loop = std::make_unique(/*offset=*/-1, std::move(initializer), @@ -766,7 +768,7 @@ std::unique_ptr IRGenerator::applyInvocationIDWorkaround(std::unique_ptr< fSymbolTable); StatementArray children; children.push_back(std::move(loop)); - return std::make_unique(-1, std::move(children)); + return std::make_unique(/*offset=*/-1, std::move(children)); } std::unique_ptr IRGenerator::getNormalizeSkPositionCode() { diff --git a/tests/sksl/shared/golden/GeometryNoGSInvocations.asm.geom b/tests/sksl/shared/golden/GeometryNoGSInvocations.asm.geom index 5f7b84d4c7..ed86496007 100644 --- a/tests/sksl/shared/golden/GeometryNoGSInvocations.asm.geom +++ b/tests/sksl/shared/golden/GeometryNoGSInvocations.asm.geom @@ -1,7 +1,7 @@ OpCapability Geometry %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint Geometry %main "main" %4 %9 +OpEntryPoint Geometry %main "main" %3 %8 OpExecutionMode %main InputPoints OpExecutionMode %main OutputLineStrip OpExecutionMode %main OutputVertices 4 @@ -10,7 +10,6 @@ OpName %sk_PerVertex "sk_PerVertex" OpMemberName %sk_PerVertex 0 "sk_Position" OpMemberName %sk_PerVertex 1 "sk_PointSize" OpName %sk_InvocationID "sk_InvocationID" -OpName %_invoke "_invoke" OpName %main "main" OpMemberDecorate %sk_PerVertex 0 BuiltIn Position OpMemberDecorate %sk_PerVertex 1 BuiltIn PointSize @@ -19,66 +18,61 @@ OpDecorate %_arr_sk_PerVertex_int_1 ArrayStride 32 %v4float = OpTypeVector %float 4 %sk_PerVertex = OpTypeStruct %v4float %float %_ptr_Output_sk_PerVertex = OpTypePointer Output %sk_PerVertex -%4 = OpVariable %_ptr_Output_sk_PerVertex Output +%3 = OpVariable %_ptr_Output_sk_PerVertex Output %int = OpTypeInt 32 1 %int_1 = OpConstant %int 1 %_arr_sk_PerVertex_int_1 = OpTypeArray %sk_PerVertex %int_1 %_ptr_Input__arr_sk_PerVertex_int_1 = OpTypePointer Input %_arr_sk_PerVertex_int_1 -%9 = OpVariable %_ptr_Input__arr_sk_PerVertex_int_1 Input +%8 = OpVariable %_ptr_Input__arr_sk_PerVertex_int_1 Input %_ptr_Private_int = OpTypePointer Private %int %sk_InvocationID = OpVariable %_ptr_Private_int Private %void = OpTypeVoid -%17 = OpTypeFunction %void +%16 = OpTypeFunction %void %int_0 = OpConstant %int 0 +%int_2 = OpConstant %int 2 +%bool = OpTypeBool %_ptr_Input_v4float = OpTypePointer Input %v4float %float_0_5 = OpConstant %float 0.5 %float_0 = OpConstant %float 0 %_ptr_Output_v4float = OpTypePointer Output %v4float %float_n0_5 = OpConstant %float -0.5 -%int_2 = OpConstant %int 2 -%bool = OpTypeBool -%_invoke = OpFunction %void None %17 -%18 = OpLabel -%20 = OpAccessChain %_ptr_Input_v4float %9 %int_0 %int_0 -%22 = OpLoad %v4float %20 -%26 = OpLoad %int %sk_InvocationID -%25 = OpConvertSToF %float %26 -%27 = OpCompositeConstruct %v4float %float_0_5 %float_0 %float_0 %25 -%28 = OpFAdd %v4float %22 %27 -%29 = OpAccessChain %_ptr_Output_v4float %4 %int_0 -OpStore %29 %28 -OpEmitVertex -%32 = OpAccessChain %_ptr_Input_v4float %9 %int_0 %int_0 -%33 = OpLoad %v4float %32 -%36 = OpLoad %int %sk_InvocationID -%35 = OpConvertSToF %float %36 -%37 = OpCompositeConstruct %v4float %float_n0_5 %float_0 %float_0 %35 -%38 = OpFAdd %v4float %33 %37 -%39 = OpAccessChain %_ptr_Output_v4float %4 %int_0 -OpStore %39 %38 -OpEmitVertex -OpReturn -OpFunctionEnd -%main = OpFunction %void None %17 -%41 = OpLabel +%main = OpFunction %void None %16 +%17 = OpLabel OpStore %sk_InvocationID %int_0 -OpBranch %42 -%42 = OpLabel -OpLoopMerge %46 %45 None -OpBranch %43 -%43 = OpLabel -%47 = OpLoad %int %sk_InvocationID -%49 = OpSLessThan %bool %47 %int_2 -OpBranchConditional %49 %44 %46 -%44 = OpLabel -%51 = OpFunctionCall %void %_invoke +OpBranch %19 +%19 = OpLabel +OpLoopMerge %23 %22 None +OpBranch %20 +%20 = OpLabel +%24 = OpLoad %int %sk_InvocationID +%26 = OpSLessThan %bool %24 %int_2 +OpBranchConditional %26 %21 %23 +%21 = OpLabel +%28 = OpAccessChain %_ptr_Input_v4float %8 %int_0 %int_0 +%30 = OpLoad %v4float %28 +%34 = OpLoad %int %sk_InvocationID +%33 = OpConvertSToF %float %34 +%35 = OpCompositeConstruct %v4float %float_0_5 %float_0 %float_0 %33 +%36 = OpFAdd %v4float %30 %35 +%37 = OpAccessChain %_ptr_Output_v4float %3 %int_0 +OpStore %37 %36 +OpEmitVertex +%40 = OpAccessChain %_ptr_Input_v4float %8 %int_0 %int_0 +%41 = OpLoad %v4float %40 +%44 = OpLoad %int %sk_InvocationID +%43 = OpConvertSToF %float %44 +%45 = OpCompositeConstruct %v4float %float_n0_5 %float_0 %float_0 %43 +%46 = OpFAdd %v4float %41 %45 +%47 = OpAccessChain %_ptr_Output_v4float %3 %int_0 +OpStore %47 %46 +OpEmitVertex OpEndPrimitive -OpBranch %45 -%45 = OpLabel -%53 = OpLoad %int %sk_InvocationID -%54 = OpIAdd %int %53 %int_1 -OpStore %sk_InvocationID %54 -OpBranch %42 -%46 = OpLabel +OpBranch %22 +%22 = OpLabel +%50 = OpLoad %int %sk_InvocationID +%51 = OpIAdd %int %50 %int_1 +OpStore %sk_InvocationID %51 +OpBranch %19 +%23 = OpLabel OpReturn OpFunctionEnd diff --git a/tests/sksl/shared/golden/GeometryNoGSInvocations.glsl b/tests/sksl/shared/golden/GeometryNoGSInvocations.glsl index 3b8fd9551a..08d9d4f05c 100644 --- a/tests/sksl/shared/golden/GeometryNoGSInvocations.glsl +++ b/tests/sksl/shared/golden/GeometryNoGSInvocations.glsl @@ -2,16 +2,14 @@ int sk_InvocationID; layout (points) in ; layout (line_strip, max_vertices = 4) out ; -void _invoke() { - gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.0, 0.0, float(sk_InvocationID)); - EmitVertex(); - - gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(sk_InvocationID)); - EmitVertex(); -} void main() { for (sk_InvocationID = 0;sk_InvocationID < 2; sk_InvocationID++) { - _invoke(); + gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.0, 0.0, float(sk_InvocationID)); + EmitVertex(); + + gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(sk_InvocationID)); + EmitVertex(); + EndPrimitive(); } } diff --git a/tests/sksl/shared/golden/GeometryNoGSInvocationsReorder.asm.geom b/tests/sksl/shared/golden/GeometryNoGSInvocationsReorder.asm.geom index a389176646..4f8f61b765 100644 --- a/tests/sksl/shared/golden/GeometryNoGSInvocationsReorder.asm.geom +++ b/tests/sksl/shared/golden/GeometryNoGSInvocationsReorder.asm.geom @@ -1,7 +1,7 @@ OpCapability Geometry %1 = OpExtInstImport "GLSL.std.450" OpMemoryModel Logical GLSL450 -OpEntryPoint Geometry %main "main" %4 %9 +OpEntryPoint Geometry %main "main" %3 %8 OpExecutionMode %main InputPoints OpExecutionMode %main OutputLineStrip OpExecutionMode %main OutputVertices 2 @@ -10,7 +10,6 @@ OpName %sk_PerVertex "sk_PerVertex" OpMemberName %sk_PerVertex 0 "sk_Position" OpMemberName %sk_PerVertex 1 "sk_PointSize" OpName %sk_InvocationID "sk_InvocationID" -OpName %_invoke "_invoke" OpName %main "main" OpMemberDecorate %sk_PerVertex 0 BuiltIn Position OpMemberDecorate %sk_PerVertex 1 BuiltIn PointSize @@ -19,66 +18,61 @@ OpDecorate %_arr_sk_PerVertex_int_1 ArrayStride 32 %v4float = OpTypeVector %float 4 %sk_PerVertex = OpTypeStruct %v4float %float %_ptr_Output_sk_PerVertex = OpTypePointer Output %sk_PerVertex -%4 = OpVariable %_ptr_Output_sk_PerVertex Output +%3 = OpVariable %_ptr_Output_sk_PerVertex Output %int = OpTypeInt 32 1 %int_1 = OpConstant %int 1 %_arr_sk_PerVertex_int_1 = OpTypeArray %sk_PerVertex %int_1 %_ptr_Input__arr_sk_PerVertex_int_1 = OpTypePointer Input %_arr_sk_PerVertex_int_1 -%9 = OpVariable %_ptr_Input__arr_sk_PerVertex_int_1 Input +%8 = OpVariable %_ptr_Input__arr_sk_PerVertex_int_1 Input %_ptr_Private_int = OpTypePointer Private %int %sk_InvocationID = OpVariable %_ptr_Private_int Private %void = OpTypeVoid -%17 = OpTypeFunction %void +%16 = OpTypeFunction %void %int_0 = OpConstant %int 0 +%int_2 = OpConstant %int 2 +%bool = OpTypeBool %_ptr_Input_v4float = OpTypePointer Input %v4float %float_0_5 = OpConstant %float 0.5 %float_0 = OpConstant %float 0 %_ptr_Output_v4float = OpTypePointer Output %v4float %float_n0_5 = OpConstant %float -0.5 -%int_2 = OpConstant %int 2 -%bool = OpTypeBool -%_invoke = OpFunction %void None %17 -%18 = OpLabel -%20 = OpAccessChain %_ptr_Input_v4float %9 %int_0 %int_0 -%22 = OpLoad %v4float %20 -%26 = OpLoad %int %sk_InvocationID -%25 = OpConvertSToF %float %26 -%27 = OpCompositeConstruct %v4float %float_0_5 %float_0 %float_0 %25 -%28 = OpFAdd %v4float %22 %27 -%29 = OpAccessChain %_ptr_Output_v4float %4 %int_0 -OpStore %29 %28 -OpEmitVertex -%32 = OpAccessChain %_ptr_Input_v4float %9 %int_0 %int_0 -%33 = OpLoad %v4float %32 -%36 = OpLoad %int %sk_InvocationID -%35 = OpConvertSToF %float %36 -%37 = OpCompositeConstruct %v4float %float_n0_5 %float_0 %float_0 %35 -%38 = OpFAdd %v4float %33 %37 -%39 = OpAccessChain %_ptr_Output_v4float %4 %int_0 -OpStore %39 %38 -OpEmitVertex -OpReturn -OpFunctionEnd -%main = OpFunction %void None %17 -%41 = OpLabel +%main = OpFunction %void None %16 +%17 = OpLabel OpStore %sk_InvocationID %int_0 -OpBranch %42 -%42 = OpLabel -OpLoopMerge %46 %45 None -OpBranch %43 -%43 = OpLabel -%47 = OpLoad %int %sk_InvocationID -%49 = OpSLessThan %bool %47 %int_2 -OpBranchConditional %49 %44 %46 -%44 = OpLabel -%51 = OpFunctionCall %void %_invoke +OpBranch %19 +%19 = OpLabel +OpLoopMerge %23 %22 None +OpBranch %20 +%20 = OpLabel +%24 = OpLoad %int %sk_InvocationID +%26 = OpSLessThan %bool %24 %int_2 +OpBranchConditional %26 %21 %23 +%21 = OpLabel +%28 = OpAccessChain %_ptr_Input_v4float %8 %int_0 %int_0 +%30 = OpLoad %v4float %28 +%34 = OpLoad %int %sk_InvocationID +%33 = OpConvertSToF %float %34 +%35 = OpCompositeConstruct %v4float %float_0_5 %float_0 %float_0 %33 +%36 = OpFAdd %v4float %30 %35 +%37 = OpAccessChain %_ptr_Output_v4float %3 %int_0 +OpStore %37 %36 +OpEmitVertex +%40 = OpAccessChain %_ptr_Input_v4float %8 %int_0 %int_0 +%41 = OpLoad %v4float %40 +%44 = OpLoad %int %sk_InvocationID +%43 = OpConvertSToF %float %44 +%45 = OpCompositeConstruct %v4float %float_n0_5 %float_0 %float_0 %43 +%46 = OpFAdd %v4float %41 %45 +%47 = OpAccessChain %_ptr_Output_v4float %3 %int_0 +OpStore %47 %46 +OpEmitVertex OpEndPrimitive -OpBranch %45 -%45 = OpLabel -%53 = OpLoad %int %sk_InvocationID -%54 = OpIAdd %int %53 %int_1 -OpStore %sk_InvocationID %54 -OpBranch %42 -%46 = OpLabel +OpBranch %22 +%22 = OpLabel +%50 = OpLoad %int %sk_InvocationID +%51 = OpIAdd %int %50 %int_1 +OpStore %sk_InvocationID %51 +OpBranch %19 +%23 = OpLabel OpReturn OpFunctionEnd diff --git a/tests/sksl/shared/golden/GeometryNoGSInvocationsReorder.glsl b/tests/sksl/shared/golden/GeometryNoGSInvocationsReorder.glsl index 8ab2e5f6fd..176a02ca58 100644 --- a/tests/sksl/shared/golden/GeometryNoGSInvocationsReorder.glsl +++ b/tests/sksl/shared/golden/GeometryNoGSInvocationsReorder.glsl @@ -2,16 +2,14 @@ int sk_InvocationID; layout (points) in ; layout (line_strip, max_vertices = 2) out ; -void _invoke() { - gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.0, 0.0, float(sk_InvocationID)); - EmitVertex(); - - gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(sk_InvocationID)); - EmitVertex(); -} void main() { for (sk_InvocationID = 0;sk_InvocationID < 2; sk_InvocationID++) { - _invoke(); + gl_Position = gl_in[0].gl_Position + vec4(0.5, 0.0, 0.0, float(sk_InvocationID)); + EmitVertex(); + + gl_Position = gl_in[0].gl_Position + vec4(-0.5, 0.0, 0.0, float(sk_InvocationID)); + EmitVertex(); + EndPrimitive(); } }