summaryrefslogtreecommitdiff
path: root/source/slang/slang-emit-spirv.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'source/slang/slang-emit-spirv.cpp')
-rw-r--r--source/slang/slang-emit-spirv.cpp18
1 files changed, 17 insertions, 1 deletions
diff --git a/source/slang/slang-emit-spirv.cpp b/source/slang/slang-emit-spirv.cpp
index fc2505d63..b17ccf483 100644
--- a/source/slang/slang-emit-spirv.cpp
+++ b/source/slang/slang-emit-spirv.cpp
@@ -1473,7 +1473,20 @@ struct SPIRVEmitContext
//
for( auto irBlock : irFunc->getBlocks() )
{
- emitInst(spvFunc, irBlock, SpvOpLabel, kResultID);
+ auto spvBlock = emitInst(spvFunc, irBlock, SpvOpLabel, kResultID);
+ if (irBlock == irFunc->getFirstBlock())
+ {
+ // OpVariable
+ // All variables used in the function must be declared before anything else.
+ for (auto block : irFunc->getBlocks())
+ {
+ for (auto inst : block->getChildren())
+ {
+ if (as<IRVar>(inst))
+ emitLocalInst(spvBlock, inst);
+ }
+ }
+ }
// In addition to normal basic blocks,
// all loops gets a header block.
@@ -1517,6 +1530,9 @@ struct SPIRVEmitContext
// Any instructions local to the block will be emitted as children
// of the block.
//
+ // Skip vars because they are already emitted.
+ if (as<IRVar>(irInst))
+ continue;
emitLocalInst(spvBlock, irInst);
if (irInst->getOp() == kIROp_loop)
pendingLoopInsts.add(as<IRLoop>(irInst));