SPV OpAtomicCompareSwap: Generate correct operand order and number of operands.
diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp
index 37ee52f..3dffceb 100755
--- a/SPIRV/GlslangToSpv.cpp
+++ b/SPIRV/GlslangToSpv.cpp
@@ -2526,14 +2526,21 @@
// Sort out the operands
// - mapping from glslang -> SPV
// - there are extra SPV operands with no glslang source
+ // - compare-exchange swaps the value and comparator
+ // - compare-exchange has an extra memory semantics
std::vector<spv::Id> spvAtomicOperands; // hold the spv operands
auto opIt = operands.begin(); // walk the glslang operands
spvAtomicOperands.push_back(*(opIt++));
spvAtomicOperands.push_back(builder.makeUintConstant(spv::ScopeDevice)); // TBD: what is the correct scope?
spvAtomicOperands.push_back(builder.makeUintConstant(spv::MemorySemanticsMaskNone)); // TBD: what are the correct memory semantics?
+ if (opCode == spv::OpAtomicCompareExchange) {
+ spvAtomicOperands.push_back(builder.makeUintConstant(spv::MemorySemanticsMaskNone)); // TBD: what are the correct memory semantics?
+ spvAtomicOperands.push_back(*(opIt + 1));
+ spvAtomicOperands.push_back(*opIt);
+ opIt += 2;
+ }
- // Add the rest of the operands, skipping the first one, which was dealt with above.
- // For some ops, there are none, for some 1, for compare-exchange, 2.
+ // Add the rest of the operands, skipping any that were dealt with above.
for (; opIt != operands.end(); ++opIt)
spvAtomicOperands.push_back(*opIt);
diff --git a/Test/baseResults/spv.atomic.comp.out b/Test/baseResults/spv.atomic.comp.out
index 359d8da..55052ae 100755
--- a/Test/baseResults/spv.atomic.comp.out
+++ b/Test/baseResults/spv.atomic.comp.out
@@ -120,7 +120,7 @@
Store 38(origi) 64
65: 6(int) Load 46(atomu)
67: 6(int) Load 48(value)
- 68: 6(int) AtomicCompareExchange 65 15 16 66 67
+ 68: 6(int) AtomicCompareExchange 65 15 16 16 67 66
Store 44(origu) 68
Return
FunctionEnd
diff --git a/glslang/Include/revision.h b/glslang/Include/revision.h
index a223c3a..480cdc1 100644
--- a/glslang/Include/revision.h
+++ b/glslang/Include/revision.h
@@ -2,5 +2,5 @@
// For the version, it uses the latest git tag followed by the number of commits.
// For the date, it uses the current date (when then script is run).
-#define GLSLANG_REVISION "3.0.753"
+#define GLSLANG_REVISION "3.0.754"
#define GLSLANG_DATE "14-Sep-2015"