From ac92c588a46ed662c091c6115dbb72098ddf228c Mon Sep 17 00:00:00 2001 From: Cherser-s <29800876+Cherser-s@users.noreply.github.com> Date: Sun, 7 Nov 2021 13:23:22 +0300 Subject: [PATCH] amdilc: store begin labels for branches and for functions --- src/amdilc/amdilc_compiler.c | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/amdilc/amdilc_compiler.c b/src/amdilc/amdilc_compiler.c index c62512eb..23fa3e29 100644 --- a/src/amdilc/amdilc_compiler.c +++ b/src/amdilc/amdilc_compiler.c @@ -72,12 +72,14 @@ typedef struct { } IlcSampler; typedef struct { + IlcSpvId labelBeginId; IlcSpvId labelElseId; IlcSpvId labelEndId; bool hasElseBlock; } IlcIfElseBlock; typedef struct { + IlcSpvId labelBeginId; IlcSpvId labelHeaderId; IlcSpvId labelContinueId; IlcSpvId labelBreakId; @@ -147,6 +149,7 @@ typedef struct { IlcSampler* samplers; unsigned controlFlowBlockCount; IlcControlFlowBlock* controlFlowBlocks; + IlcSpvId currentFunctionLabelId; unsigned forkPhaseCount; IlcHullPhaseBlock* forkPhases; unsigned joinPhaseCount; @@ -1799,7 +1802,7 @@ static void emitFunc( IlcSpvId voidTypeId = ilcSpvPutVoidType(compiler->module); IlcSpvId funcTypeId = ilcSpvPutFunctionType(compiler->module, voidTypeId, 0, NULL); ilcSpvPutFunction(compiler->module, voidTypeId, id, SpvFunctionControlMaskNone, funcTypeId); - ilcSpvPutLabel(compiler->module, 0); + compiler->currentFunctionLabelId = ilcSpvPutLabel(compiler->module, 0); } static IlcHullPhaseBlock emitHullForkJoinFunction( @@ -1810,7 +1813,7 @@ static IlcHullPhaseBlock emitHullForkJoinFunction( IlcSpvId funcTypeId = ilcSpvPutFunctionType(compiler->module, voidTypeId, 1, &compiler->intId); ilcSpvPutFunction(compiler->module, voidTypeId, funcId, SpvFunctionControlMaskNone, funcTypeId); IlcSpvId paramId = ilcSpvPutFunctionParameter(compiler->module, compiler->intId); - ilcSpvPutLabel(compiler->module, 0);//TODO: handle IL_REGTYPE_SHADER_INSTANCE_ID + compiler->currentFunctionLabelId = ilcSpvPutLabel(compiler->module, 0);//TODO: handle IL_REGTYPE_SHADER_INSTANCE_ID compiler->isInFunction = true; return (IlcHullPhaseBlock) { .functionId = funcId, @@ -1864,7 +1867,7 @@ static void emitHullShaderPhase( IlcSpvId voidTypeId = ilcSpvPutVoidType(compiler->module); IlcSpvId funcTypeId = ilcSpvPutFunctionType(compiler->module, voidTypeId, 0, NULL); ilcSpvPutFunction(compiler->module, voidTypeId, functionId, SpvFunctionControlMaskNone, funcTypeId); - ilcSpvPutLabel(compiler->module, 0); + compiler->currentFunctionLabelId = ilcSpvPutLabel(compiler->module, 0); compiler->isInFunction = true; compiler->controlPointPhase = (IlcHullPhaseBlock){ .type = CONTROL_POINT, @@ -2524,17 +2527,17 @@ static void emitIf( const Instruction* instr) { const IlcIfElseBlock ifElseBlock = { + .labelBeginId = ilcSpvAllocId(compiler->module), .labelElseId = ilcSpvAllocId(compiler->module), .labelEndId = ilcSpvAllocId(compiler->module), .hasElseBlock = false, }; IlcSpvId srcId = loadSource(compiler, &instr->srcs[0], COMP_MASK_XYZW, compiler->int4Id); - IlcSpvId labelBeginId = ilcSpvAllocId(compiler->module); IlcSpvId condId = emitConditionCheck(compiler, srcId, instr->opcode == IL_OP_IF_LOGICALNZ); ilcSpvPutSelectionMerge(compiler->module, ifElseBlock.labelEndId); - ilcSpvPutBranchConditional(compiler->module, condId, labelBeginId, ifElseBlock.labelElseId); - ilcSpvPutLabel(compiler->module, labelBeginId); + ilcSpvPutBranchConditional(compiler->module, condId, ifElseBlock.labelBeginId, ifElseBlock.labelElseId); + ilcSpvPutLabel(compiler->module, ifElseBlock.labelBeginId); const IlcControlFlowBlock block = { .type = BLOCK_IF_ELSE, @@ -2597,6 +2600,7 @@ static void emitWhile( const Instruction* instr) { const IlcLoopBlock loopBlock = { + .labelBeginId = ilcSpvAllocId(compiler->module), .labelHeaderId = ilcSpvAllocId(compiler->module), .labelContinueId = ilcSpvAllocId(compiler->module), .labelBreakId = ilcSpvAllocId(compiler->module), @@ -2607,9 +2611,8 @@ static void emitWhile( ilcSpvPutLoopMerge(compiler->module, loopBlock.labelBreakId, loopBlock.labelContinueId); - IlcSpvId labelBeginId = ilcSpvAllocId(compiler->module); - ilcSpvPutBranch(compiler->module, labelBeginId); - ilcSpvPutLabel(compiler->module, labelBeginId); + ilcSpvPutBranch(compiler->module, loopBlock.labelBeginId); + ilcSpvPutLabel(compiler->module, loopBlock.labelBeginId); const IlcControlFlowBlock block = { .type = BLOCK_LOOP, @@ -4281,6 +4284,7 @@ IlcShader ilcCompileKernel( .samplers = NULL, .controlFlowBlockCount = 0, .controlFlowBlocks = NULL, + .currentFunctionLabelId = 0, .forkPhaseCount = 0, .forkPhases = NULL, .forkPhaseCount = 0,