diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index b8a2e0f7d3337b017d5f488bed880911ea5362c8..969c091b4780093d53567d5c52db100306c0d318 100644 --- a/SPIRV/GlslangToSpv.cpp +++ b/SPIRV/GlslangToSpv.cpp @@ -1684,9 +1684,10 @@ spv::Id TGlslangToSpvTraverser::handleUserFunctionCall(const glslang::TIntermAgg return result; } +// Translate AST operation to SPV operation, already having SPV-based operands/types. spv::Id TGlslangToSpvTraverser::createBinaryOperation(glslang::TOperator op, spv::Decoration precision, - spv::Id typeId, spv::Id left, spv::Id right, - glslang::TBasicType typeProxy, bool reduceComparison) + spv::Id typeId, spv::Id left, spv::Id right, + glslang::TBasicType typeProxy, bool reduceComparison) { bool isUnsigned = typeProxy == glslang::EbtUint; bool isFloat = typeProxy == glslang::EbtFloat || typeProxy == glslang::EbtDouble; @@ -1719,22 +1720,34 @@ spv::Id TGlslangToSpvTraverser::createBinaryOperation(glslang::TOperator op, spv break; case glslang::EOpVectorTimesScalar: case glslang::EOpVectorTimesScalarAssign: + if (builder.isVector(right)) + std::swap(left, right); + assert(builder.isScalar(right)); binOp = spv::OpVectorTimesScalar; needsPromotion = false; break; case glslang::EOpVectorTimesMatrix: case glslang::EOpVectorTimesMatrixAssign: + assert(builder.isVector(left)); + assert(builder.isMatrix(right)); binOp = spv::OpVectorTimesMatrix; break; case glslang::EOpMatrixTimesVector: + assert(builder.isMatrix(left)); + assert(builder.isVector(right)); binOp = spv::OpMatrixTimesVector; break; case glslang::EOpMatrixTimesScalar: case glslang::EOpMatrixTimesScalarAssign: + if (builder.isMatrix(right)) + std::swap(left, right); + assert(builder.isScalar(right)); binOp = spv::OpMatrixTimesScalar; break; case glslang::EOpMatrixTimesMatrix: case glslang::EOpMatrixTimesMatrixAssign: + assert(builder.isMatrix(left)); + assert(builder.isMatrix(right)); binOp = spv::OpMatrixTimesMatrix; break; case glslang::EOpOuterProduct: diff --git a/Test/baseResults/spv.100ops.frag.out b/Test/baseResults/spv.100ops.frag.out index f07782c6f7bc9d8231727ae53ceb92015a01acd5..c937419eebe7820b8b7eaa96f40dd289d41943f8 100644 --- a/Test/baseResults/spv.100ops.frag.out +++ b/Test/baseResults/spv.100ops.frag.out @@ -73,7 +73,7 @@ Linked fragment stage: 39: 16(int) Load 18(z) 40: 7(float) ConvertSToF 39 41: 35(fvec4) CompositeConstruct 40 40 40 40 - 42: 35(fvec4) VectorTimesScalar 38 41 + 42: 35(fvec4) VectorTimesScalar 41 38 43: 7(float) FunctionCall 9(foo() 44: 35(fvec4) CompositeConstruct 43 43 43 43 45: 35(fvec4) FAdd 42 44 diff --git a/Test/baseResults/spv.150.geom.out b/Test/baseResults/spv.150.geom.out index bde17299c81e409541d264c8a145b8288217cdbd..b951524ebe26392cda0bf818fa3a5c2a5d06a240 100644 --- a/Test/baseResults/spv.150.geom.out +++ b/Test/baseResults/spv.150.geom.out @@ -127,12 +127,12 @@ Linked geometry stage: EmitVertex 55: 20(ptr) AccessChain 19(fromV) 13 13 56: 8(fvec3) Load 55 - 57: 8(fvec3) VectorTimesScalar 54 56 + 57: 8(fvec3) VectorTimesScalar 56 54 58: 23(ptr) AccessChain 11 13 Store 58 57 59: 35(ptr) AccessChain 34(gl_in) 13 13 60: 25(fvec4) Load 59 - 61: 25(fvec4) VectorTimesScalar 54 60 + 61: 25(fvec4) VectorTimesScalar 60 54 62: 38(ptr) AccessChain 30 13 Store 62 61 63: 42(ptr) AccessChain 34(gl_in) 41 40 diff --git a/Test/baseResults/spv.prepost.frag.out b/Test/baseResults/spv.prepost.frag.out index 5064d5a4e895ca2c761508098e5e06d83c4a8d29..a9031e3e1a97490db797e319d093e97b0d4e1367 100644 --- a/Test/baseResults/spv.prepost.frag.out +++ b/Test/baseResults/spv.prepost.frag.out @@ -145,7 +145,7 @@ Linked fragment stage: Store 74(v) 91 94: 11(float) Load 67(z) 95: 72(fvec4) Load 74(v) - 96: 72(fvec4) VectorTimesScalar 94 95 + 96: 72(fvec4) VectorTimesScalar 95 94 Store 93(gl_FragColor) 96 Branch 6 6: Label diff --git a/Test/baseResults/spv.structAssignment.frag.out b/Test/baseResults/spv.structAssignment.frag.out index cc4f3bf49b591a53ae9447260b4aa51d0efc632e..d8a6a4e96013af7bde1db72fb7922548e89b01aa 100644 --- a/Test/baseResults/spv.structAssignment.frag.out +++ b/Test/baseResults/spv.structAssignment.frag.out @@ -90,7 +90,7 @@ Linked fragment stage: 41: 38 Load 40(sampler) 45: 42(fvec2) Load 44(coord) 46: 30(fvec4) TextureSample 41 45 - 47: 30(fvec4) VectorTimesScalar 37 46 + 47: 30(fvec4) VectorTimesScalar 46 37 Store 32(gl_FragColor) 47 Branch 6 6: Label diff --git a/Test/baseResults/spv.structDeref.frag.out b/Test/baseResults/spv.structDeref.frag.out index 6a914693507da5a29474289e1a9439fc6b48a5e5..4e58adcc0e30a2461b5bf4a5c12fce182ca975e1 100644 --- a/Test/baseResults/spv.structDeref.frag.out +++ b/Test/baseResults/spv.structDeref.frag.out @@ -185,7 +185,7 @@ Linked fragment stage: 114: 111 Load 113(sampler) 115: 60(fvec2) Load 62(coord) 116: 95(fvec4) TextureSample 114 115 - 117: 95(fvec4) VectorTimesScalar 110 116 + 117: 95(fvec4) VectorTimesScalar 116 110 Store 97(gl_FragColor) 117 Branch 6 6: Label diff --git a/Test/baseResults/spv.structure.frag.out b/Test/baseResults/spv.structure.frag.out index 4cfdd002aa8b7071152624d31ce2f97dcb3bea89..727187d7514c213ce389b0254522eec0ed1ef147 100644 --- a/Test/baseResults/spv.structure.frag.out +++ b/Test/baseResults/spv.structure.frag.out @@ -97,7 +97,7 @@ Linked fragment stage: 52: 49 Load 51(sampler) 56: 53(fvec2) Load 55(coord) 57: 17(fvec4) TextureSample 52 56 - 58: 17(fvec4) VectorTimesScalar 48 57 + 58: 17(fvec4) VectorTimesScalar 57 48 Store 47(gl_FragColor) 58 Branch 6 6: Label diff --git a/Test/baseResults/spv.variableArrayIndex.frag.out b/Test/baseResults/spv.variableArrayIndex.frag.out index 1b8a8c0e83cab1ec3922eff5c3f38d9a5f155b22..ab7ac6247c48d971bd7e51bdb172a12bb89912b4 100644 --- a/Test/baseResults/spv.variableArrayIndex.frag.out +++ b/Test/baseResults/spv.variableArrayIndex.frag.out @@ -118,7 +118,7 @@ Linked fragment stage: 60: 57 Load 59(sampler) 64: 61(fvec2) Load 63(coord) 65: 53(fvec4) TextureSample 60 64 - 66: 53(fvec4) VectorTimesScalar 56 65 + 66: 53(fvec4) VectorTimesScalar 65 56 Store 55(gl_FragColor) 66 70: 61(fvec2) Load 63(coord) 71: 13(float) Load 31(scale)