From e5e0f6e37af5ecbc6e7713578ec7449122fd24dc Mon Sep 17 00:00:00 2001 From: John Kessenich <cepheus@frii.com> Date: Sat, 13 Jun 2015 00:48:48 +0000 Subject: [PATCH] glslang -> SPV: swap arguments as needed for OpVectorTimesScalar and OpMatrixTimesScalar, and check for correct types for those as well as OpMatrixTimesVector, OpVectorTimesMatrix, and OpMatrixTimesMatrix. git-svn-id: https://cvs.khronos.org/svn/repos/ogl/trunk/ecosystem/public/sdk/tools/glslang@31486 e7fa87d3-cd2b-0410-9028-fcbf551c1848 --- SPIRV/GlslangToSpv.cpp | 17 +++++++++++++++-- Test/baseResults/spv.100ops.frag.out | 2 +- Test/baseResults/spv.150.geom.out | 4 ++-- Test/baseResults/spv.prepost.frag.out | 2 +- Test/baseResults/spv.structAssignment.frag.out | 2 +- Test/baseResults/spv.structDeref.frag.out | 2 +- Test/baseResults/spv.structure.frag.out | 2 +- .../baseResults/spv.variableArrayIndex.frag.out | 2 +- 8 files changed, 23 insertions(+), 10 deletions(-) diff --git a/SPIRV/GlslangToSpv.cpp b/SPIRV/GlslangToSpv.cpp index b8a2e0f7d..969c091b4 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 f07782c6f..c937419ee 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 bde17299c..b951524eb 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 5064d5a4e..a9031e3e1 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 cc4f3bf49..d8a6a4e96 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 6a9146935..4e58adcc0 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 4cfdd002a..727187d75 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 1b8a8c0e8..ab7ac6247 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) -- GitLab