diff options
| author | jsmall-nvidia <jsmall@nvidia.com> | 2023-06-22 15:07:31 -0400 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-06-22 15:07:31 -0400 |
| commit | 769c7fdd19ea579770baac7b6d5e16d6406a8013 (patch) | |
| tree | a0f04c668911a2b3b58e0fc89f5bb765540226bd /source | |
| parent | ac541d45fafde340b141172cf76d003ff70d471e (diff) | |
[branch] and [flatten] support (#2928)
* #include an absolute path didn't work - because paths were taken to always be relative.
* Small fixes and improvements around reflection tool.
* Make PrettyWriter printing a class.
* Add HLSL output support for [flatten] and [branch]
* Handle [branch] on switch.
Diffstat (limited to 'source')
| -rw-r--r-- | source/slang/slang-emit-c-like.cpp | 4 | ||||
| -rw-r--r-- | source/slang/slang-emit-c-like.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-emit-hlsl.cpp | 20 | ||||
| -rw-r--r-- | source/slang/slang-emit-hlsl.h | 3 | ||||
| -rw-r--r-- | source/slang/slang-ir-inst-defs.h | 2 | ||||
| -rw-r--r-- | source/slang/slang-lower-to-ir.cpp | 23 |
6 files changed, 52 insertions, 3 deletions
diff --git a/source/slang/slang-emit-c-like.cpp b/source/slang/slang-emit-c-like.cpp index c7ea3a09a..872a7a8b2 100644 --- a/source/slang/slang-emit-c-like.cpp +++ b/source/slang/slang-emit-c-like.cpp @@ -2792,6 +2792,8 @@ void CLikeSourceEmitter::emitRegion(Region* inRegion) { auto ifRegion = (IfRegion*) region; + emitIfDecorationsImpl(ifRegion->ifElseInst); + // TODO: consider simplifying the code in // the case where `ifRegion == null` // so that we output `if(!condition) { elseRegion }` @@ -2858,6 +2860,8 @@ void CLikeSourceEmitter::emitRegion(Region* inRegion) { auto switchRegion = (SwitchRegion*) region; + emitSwitchDecorationsImpl(switchRegion->switchInst); + // Emit the start of our statement. m_writer->emit("switch("); emitOperand(switchRegion->getCondition(), getInfo(EmitOp::General)); diff --git a/source/slang/slang-emit-c-like.h b/source/slang/slang-emit-c-like.h index 636faad46..47eff1ac4 100644 --- a/source/slang/slang-emit-c-like.h +++ b/source/slang/slang-emit-c-like.h @@ -521,6 +521,9 @@ public: virtual void emitIntrinsicCallExprImpl(IRCall* inst, IRTargetIntrinsicDecoration* targetIntrinsic, EmitOpInfo const& inOuterPrec); virtual void emitFunctionPreambleImpl(IRInst* inst) { SLANG_UNUSED(inst); } virtual void emitLoopControlDecorationImpl(IRLoopControlDecoration* decl) { SLANG_UNUSED(decl); } + virtual void emitIfDecorationsImpl(IRIfElse* ifInst) { SLANG_UNUSED(ifInst); } + virtual void emitSwitchDecorationsImpl(IRSwitch* switchInst) { SLANG_UNUSED(switchInst); } + virtual void emitFuncDecorationImpl(IRDecoration* decoration) { SLANG_UNUSED(decoration); } virtual void emitLivenessImpl(IRInst* inst); diff --git a/source/slang/slang-emit-hlsl.cpp b/source/slang/slang-emit-hlsl.cpp index 3f6e79f4a..76300c18b 100644 --- a/source/slang/slang-emit-hlsl.cpp +++ b/source/slang/slang-emit-hlsl.cpp @@ -766,6 +766,26 @@ static bool _canEmitExport(const Profile& profile) Super::emitFuncDecorationsImpl(func); } +void HLSLSourceEmitter::emitIfDecorationsImpl(IRIfElse* ifInst) +{ + if (ifInst->findDecorationImpl(kIROp_BranchDecoration)) + { + m_writer->emit("[branch]\n"); + } + else if (ifInst->findDecorationImpl(kIROp_FlattenDecoration)) + { + m_writer->emit("[flatten]\n"); + } +} + +void HLSLSourceEmitter::emitSwitchDecorationsImpl(IRSwitch* switchInst) +{ + if (switchInst->findDecorationImpl(kIROp_BranchDecoration)) + { + m_writer->emit("[branch]\n"); + } +} + void HLSLSourceEmitter::emitFuncDecorationImpl(IRDecoration* decoration) { switch( decoration->getOp() ) diff --git a/source/slang/slang-emit-hlsl.h b/source/slang/slang-emit-hlsl.h index 2e4eb29b9..f2440fe38 100644 --- a/source/slang/slang-emit-hlsl.h +++ b/source/slang/slang-emit-hlsl.h @@ -53,6 +53,9 @@ protected: virtual void emitFuncDecorationImpl(IRDecoration* decoration) SLANG_OVERRIDE; virtual void emitFuncDecorationsImpl(IRFunc* func) SLANG_OVERRIDE; + virtual void emitSwitchDecorationsImpl(IRSwitch* switchInst) SLANG_OVERRIDE; + virtual void emitIfDecorationsImpl(IRIfElse* ifInst) SLANG_OVERRIDE; + virtual void handleRequiredCapabilitiesImpl(IRInst* inst) SLANG_OVERRIDE; virtual void emitGlobalInstImpl(IRInst* inst) SLANG_OVERRIDE; diff --git a/source/slang/slang-ir-inst-defs.h b/source/slang/slang-ir-inst-defs.h index fc020403d..0c5afb4af 100644 --- a/source/slang/slang-ir-inst-defs.h +++ b/source/slang/slang-ir-inst-defs.h @@ -624,6 +624,8 @@ INST(AllocateOpaqueHandle, allocateOpaqueHandle, 0, 0) INST(HighLevelDeclDecoration, highLevelDecl, 1, 0) INST(LayoutDecoration, layout, 1, 0) + INST(BranchDecoration, branch, 0, 0) + INST(FlattenDecoration, flatten, 0, 0) INST(LoopControlDecoration, loopControl, 1, 0) INST(LoopMaxItersDecoration, loopMaxIters, 1, 0) INST(LoopInferredMaxItersDecoration, loopInferredMaxIters, 2, 0) diff --git a/source/slang/slang-lower-to-ir.cpp b/source/slang/slang-lower-to-ir.cpp index 937262758..5df1db03b 100644 --- a/source/slang/slang-lower-to-ir.cpp +++ b/source/slang/slang-lower-to-ir.cpp @@ -5075,13 +5075,15 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor> auto irCond = getSimpleVal(context, lowerRValueExpr(context, condExpr)); + IRInst* ifInst = nullptr; + if (elseStmt) { auto thenBlock = createBlock(); auto elseBlock = createBlock(); auto afterBlock = createBlock(); - builder->emitIfElse(irCond, thenBlock, elseBlock, afterBlock); + ifInst = builder->emitIfElse(irCond, thenBlock, elseBlock, afterBlock); insertBlock(thenBlock); lowerStmt(context, thenStmt); @@ -5097,13 +5099,22 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor> auto thenBlock = createBlock(); auto afterBlock = createBlock(); - builder->emitIf(irCond, thenBlock, afterBlock); + ifInst = builder->emitIf(irCond, thenBlock, afterBlock); insertBlock(thenBlock); lowerStmt(context, thenStmt); insertBlock(afterBlock); } + + if (stmt->findModifier<FlattenAttribute>()) + { + builder->addDecoration(ifInst, kIROp_FlattenDecoration); + } + if (stmt->findModifier<BranchAttribute>()) + { + builder->addDecoration(ifInst, kIROp_BranchDecoration); + } } void addLoopDecorations( @@ -5828,7 +5839,7 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor> // prepared to emit the `switch` instruction // itself. builder->setInsertInto(initialBlock); - builder->emitSwitch( + auto switchInst = builder->emitSwitch( conditionVal, breakLabel, defaultLabel, @@ -5840,6 +5851,12 @@ struct StmtLoweringVisitor : StmtVisitor<StmtLoweringVisitor> // This is the block that subsequent code will go into. insertBlock(breakLabel); context->shared->breakLabels.remove(stmt); + + // If there is the branch attribute output the IR decoration + if (stmt->hasModifier<BranchAttribute>()) + { + builder->addDecoration(switchInst, kIROp_BranchDecoration); + } } }; |
