HLSL: Refactor attribute implementation.
- make it sharable with GLSL
- correct the case insensitivity
- remove the map; queries are not needed, all entries need processing
- make it easier to build bottom up (will help GLSL parsing)
- support semantic checking and reporting
- allow front-end dependent semantics and attribute name mapping
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index 64bce35..b7b6597 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -129,8 +129,9 @@
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::SelectionControlMask TranslateSelectionControl(const glslang::TIntermSelection&) const;
+ spv::SelectionControlMask TranslateSwitchControl(const glslang::TIntermSwitch&) const;
+ spv::LoopControlMask TranslateLoopControl(const glslang::TIntermLoop&) const;
spv::StorageClass TranslateStorageClass(const glslang::TType&);
spv::Id createSpvVariable(const glslang::TIntermSymbol*);
spv::Id getSampledType(const glslang::TSampler&);
@@ -748,26 +749,34 @@
}
}
-spv::SelectionControlMask TGlslangToSpvTraverser::TranslateSelectionControl(glslang::TSelectionControl selectionControl) const
+spv::SelectionControlMask TGlslangToSpvTraverser::TranslateSelectionControl(const glslang::TIntermSelection& selectionNode) 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;
- }
+ if (selectionNode.getFlatten())
+ return spv::SelectionControlFlattenMask;
+ if (selectionNode.getDontFlatten())
+ return spv::SelectionControlDontFlattenMask;
+ return spv::SelectionControlMaskNone;
}
-spv::LoopControlMask TGlslangToSpvTraverser::TranslateLoopControl(glslang::TLoopControl loopControl) const
+spv::SelectionControlMask TGlslangToSpvTraverser::TranslateSwitchControl(const glslang::TIntermSwitch& switchNode) const
{
- switch (loopControl) {
- case glslang::ELoopControlNone: return spv::LoopControlMaskNone;
- case glslang::ELoopControlUnroll: return spv::LoopControlUnrollMask;
- case glslang::ELoopControlDontUnroll: return spv::LoopControlDontUnrollMask;
- // TODO: DependencyInfinite
- // TODO: DependencyLength
- default: return spv::LoopControlMaskNone;
- }
+ if (switchNode.getFlatten())
+ return spv::SelectionControlFlattenMask;
+ if (switchNode.getDontFlatten())
+ return spv::SelectionControlDontFlattenMask;
+ return spv::SelectionControlMaskNone;
+}
+
+spv::LoopControlMask TGlslangToSpvTraverser::TranslateLoopControl(const glslang::TIntermLoop& loopNode) const
+{
+ spv::LoopControlMask control = spv::LoopControlMaskNone;
+
+ if (loopNode.getDontUnroll())
+ control = control | spv::LoopControlDontUnrollMask;
+ if (loopNode.getUnroll())
+ control = control | spv::LoopControlUnrollMask;
+
+ return control;
}
// Translate glslang type to SPIR-V storage class.
@@ -2026,7 +2035,7 @@
node->getCondition()->traverse(this);
// Selection control:
- const spv::SelectionControlMask control = TranslateSelectionControl(node->getSelectionControl());
+ const spv::SelectionControlMask control = TranslateSelectionControl(*node);
// make an "if" based on the value created by the condition
spv::Builder::If ifBuilder(accessChainLoad(node->getCondition()->getType()), control, builder);
@@ -2068,7 +2077,7 @@
spv::Id selector = accessChainLoad(node->getCondition()->getAsTyped()->getType());
// Selection control:
- const spv::SelectionControlMask control = TranslateSelectionControl(node->getSelectionControl());
+ const spv::SelectionControlMask control = TranslateSwitchControl(*node);
// browse the children to sort out code segments
int defaultSegment = -1;
@@ -2128,7 +2137,7 @@
builder.createBranch(&blocks.head);
// Loop control:
- const spv::LoopControlMask control = TranslateLoopControl(node->getLoopControl());
+ const spv::LoopControlMask control = TranslateLoopControl(*node);
// TODO: dependency length