HLSL: Translate directive [flatten] and [branch] to SPV control mask.
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index 50806d0..138a2cd 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -122,6 +122,7 @@
spv::Decoration TranslateAuxiliaryStorageDecoration(const glslang::TQualifier& qualifier);
spv::BuiltIn TranslateBuiltInDecoration(glslang::TBuiltInVariable, bool memberDeclaration);
spv::ImageFormat TranslateImageFormat(const glslang::TType& type);
+ spv::SelectionControlMask TranslateSelectionControl(glslang::TSelectionControl) const;
spv::LoopControlMask TranslateLoopControl(glslang::TLoopControl) const;
spv::StorageClass TranslateStorageClass(const glslang::TType&);
spv::Id createSpvVariable(const glslang::TIntermSymbol*);
@@ -741,6 +742,16 @@
}
}
+spv::SelectionControlMask TGlslangToSpvTraverser::TranslateSelectionControl(glslang::TSelectionControl selectionControl) const
+{
+ switch (selectionControl) {
+ case glslang::ESelectionControlNone: return spv::SelectionControlMaskNone;
+ case glslang::ESelectionControlFlatten: return spv::SelectionControlFlattenMask;
+ case glslang::ESelectionControlDontFlatten: return spv::SelectionControlDontFlattenMask;
+ default: return spv::SelectionControlMaskNone;
+ }
+}
+
spv::LoopControlMask TGlslangToSpvTraverser::TranslateLoopControl(glslang::TLoopControl loopControl) const
{
switch (loopControl) {
@@ -1941,8 +1952,7 @@
return false;
}
- // Instead, emit control flow...
-
+ // Instead, emit control flow...
// Don't handle results as temporaries, because there will be two names
// and better to leave SSA to later passes.
spv::Id result = (node->getBasicType() == glslang::EbtVoid)
@@ -1952,8 +1962,11 @@
// emit the condition before doing anything with selection
node->getCondition()->traverse(this);
+ // Selection control:
+ const spv::SelectionControlMask control = TranslateSelectionControl(node->getSelectionControl());
+
// make an "if" based on the value created by the condition
- spv::Builder::If ifBuilder(accessChainLoad(node->getCondition()->getType()), builder);
+ spv::Builder::If ifBuilder(accessChainLoad(node->getCondition()->getType()), control, builder);
// emit the "then" statement
if (node->getTrueBlock() != nullptr) {
@@ -1991,6 +2004,9 @@
node->getCondition()->traverse(this);
spv::Id selector = accessChainLoad(node->getCondition()->getAsTyped()->getType());
+ // Selection control:
+ const spv::SelectionControlMask control = TranslateSelectionControl(node->getSelectionControl());
+
// browse the children to sort out code segments
int defaultSegment = -1;
std::vector<TIntermNode*> codeSegments;
@@ -2016,7 +2032,7 @@
// make the switch statement
std::vector<spv::Block*> segmentBlocks; // returned, as the blocks allocated in the call
- builder.makeSwitch(selector, (int)codeSegments.size(), caseValues, valueIndexToSegment, defaultSegment, segmentBlocks);
+ builder.makeSwitch(selector, control, (int)codeSegments.size(), caseValues, valueIndexToSegment, defaultSegment, segmentBlocks);
// emit all the code in the segments
breakForLoop.push(false);
@@ -5707,7 +5723,7 @@
leftId = builder.createUnaryOp(spv::OpLogicalNot, boolTypeId, leftId);
// make an "if" based on the left value
- spv::Builder::If ifBuilder(leftId, builder);
+ spv::Builder::If ifBuilder(leftId, spv::SelectionControlMaskNone, builder);
// emit right operand as the "then" part of the "if"
builder.clearAccessChain();