From e723b45bcad4b115c42850c534e3ffa50c20519a Mon Sep 17 00:00:00 2001 From: Rex Xu Date: Mon, 7 Dec 2015 19:07:17 +0800 Subject: [PATCH] SPV: Scalar smear operation should use type of the scalar to make the expected vector type when the provided vector type is incompatible with the scalar. --- SPIRV/SpvBuilder.cpp | 4 +++ Test/baseResults/spv.shiftOps.frag.out | 66 ++++++++++++++++++++++++++++++++++ Test/spv.ShiftOps.frag | 19 ++++++++++ Test/test-spirv-list | 1 + 4 files changed, 90 insertions(+) create mode 100644 Test/baseResults/spv.shiftOps.frag.out create mode 100644 Test/spv.ShiftOps.frag diff --git a/SPIRV/SpvBuilder.cpp b/SPIRV/SpvBuilder.cpp index a46c924..5992d54 100755 --- a/SPIRV/SpvBuilder.cpp +++ b/SPIRV/SpvBuilder.cpp @@ -1190,6 +1190,10 @@ Id Builder::smearScalar(Decoration /*precision*/, Id scalar, Id vectorType) if (numComponents == 1) return scalar; + // Make new vector type if the provided one is incompatible with type of the scalar + if (getTypeId(scalar) != getScalarTypeId(vectorType)) + vectorType = makeVectorType(getTypeId(scalar), numComponents); + Instruction* smear = new Instruction(getUniqueId(), vectorType, OpCompositeConstruct); for (int c = 0; c < numComponents; ++c) smear->addIdOperand(scalar); diff --git a/Test/baseResults/spv.shiftOps.frag.out b/Test/baseResults/spv.shiftOps.frag.out new file mode 100644 index 0000000..e82882e --- /dev/null +++ b/Test/baseResults/spv.shiftOps.frag.out @@ -0,0 +1,66 @@ +spv.shiftOps.frag +Warning, version 450 is not yet complete; most version-specific features are present, but some are missing. + + +Linked fragment stage: + + +// Module Version 10000 +// Generated by (magic number): 80001 +// Id's are bound by 38 + + Capability Shader + 1: ExtInstImport "GLSL.std.450" + MemoryModel Logical GLSL450 + EntryPoint Fragment 4 "main" 9 25 + ExecutionMode 4 OriginLowerLeft + Source GLSL 450 + Name 4 "main" + Name 9 "icolor" + Name 11 "i3" + Name 15 "u1" + Name 25 "ucolor" + Name 27 "u3" + Name 30 "i1" + 2: TypeVoid + 3: TypeFunction 2 + 6: TypeInt 32 1 + 7: TypeVector 6(int) 3 + 8: TypePointer Output 7(ivec3) + 9(icolor): 8(ptr) Variable Output + 10: TypePointer UniformConstant 7(ivec3) + 11(i3): 10(ptr) Variable UniformConstant + 13: TypeInt 32 0 + 14: TypePointer UniformConstant 13(int) + 15(u1): 14(ptr) Variable UniformConstant + 17: TypeVector 13(int) 3 + 20: 13(int) Constant 4 + 24: TypePointer Output 17(ivec3) + 25(ucolor): 24(ptr) Variable Output + 26: TypePointer UniformConstant 17(ivec3) + 27(u3): 26(ptr) Variable UniformConstant + 29: TypePointer UniformConstant 6(int) + 30(i1): 29(ptr) Variable UniformConstant + 34: 6(int) Constant 5 + 4(main): 2 Function None 3 + 5: Label + 12: 7(ivec3) Load 11(i3) + 16: 13(int) Load 15(u1) + 18: 17(ivec3) CompositeConstruct 16 16 16 + 19: 7(ivec3) ShiftLeftLogical 12 18 + Store 9(icolor) 19 + 21: 7(ivec3) Load 9(icolor) + 22: 17(ivec3) CompositeConstruct 20 20 20 + 23: 7(ivec3) ShiftLeftLogical 21 22 + Store 9(icolor) 23 + 28: 17(ivec3) Load 27(u3) + 31: 6(int) Load 30(i1) + 32: 7(ivec3) CompositeConstruct 31 31 31 + 33: 17(ivec3) ShiftRightLogical 28 32 + Store 25(ucolor) 33 + 35: 17(ivec3) Load 25(ucolor) + 36: 7(ivec3) CompositeConstruct 34 34 34 + 37: 17(ivec3) ShiftRightLogical 35 36 + Store 25(ucolor) 37 + Return + FunctionEnd diff --git a/Test/spv.ShiftOps.frag b/Test/spv.ShiftOps.frag new file mode 100644 index 0000000..498d5bd --- /dev/null +++ b/Test/spv.ShiftOps.frag @@ -0,0 +1,19 @@ +#version 450 + +uniform int i1; +uniform uint u1; + +uniform ivec3 i3; +uniform uvec3 u3; + +out ivec3 icolor; +out uvec3 ucolor; + +void main() +{ + icolor = i3 << u1; + icolor <<= 4u; + + ucolor = u3 >> i1; + ucolor >>= 5; +} diff --git a/Test/test-spirv-list b/Test/test-spirv-list index ea3094b..6445b21 100644 --- a/Test/test-spirv-list +++ b/Test/test-spirv-list @@ -61,6 +61,7 @@ spv.intOps.vert spv.precision.frag spv.prepost.frag spv.qualifiers.vert +spv.shiftOps.frag spv.simpleFunctionCall.frag spv.simpleMat.vert spv.structAssignment.frag -- 2.7.4