SPV: Scalar smear operation should use type of the scalar to make the
authorRex Xu <rex.xu@amd.com>
Mon, 7 Dec 2015 11:07:17 +0000 (19:07 +0800)
committerRex Xu <rex.xu@amd.com>
Wed, 9 Dec 2015 08:05:06 +0000 (16:05 +0800)
expected vector type when the provided vector type is incompatible with
the scalar.

SPIRV/SpvBuilder.cpp
Test/baseResults/spv.shiftOps.frag.out [new file with mode: 0644]
Test/spv.ShiftOps.frag [new file with mode: 0644]
Test/test-spirv-list

index a46c924..5992d54 100755 (executable)
@@ -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 (file)
index 0000000..e82882e
--- /dev/null
@@ -0,0 +1,66 @@
+spv.shiftOps.frag\r
+Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.\r
+\r
+\r
+Linked fragment stage:\r
+\r
+\r
+// Module Version 10000\r
+// Generated by (magic number): 80001\r
+// Id's are bound by 38\r
+\r
+                              Capability Shader\r
+               1:             ExtInstImport  "GLSL.std.450"\r
+                              MemoryModel Logical GLSL450\r
+                              EntryPoint Fragment 4  "main" 9 25\r
+                              ExecutionMode 4 OriginLowerLeft\r
+                              Source GLSL 450\r
+                              Name 4  "main"\r
+                              Name 9  "icolor"\r
+                              Name 11  "i3"\r
+                              Name 15  "u1"\r
+                              Name 25  "ucolor"\r
+                              Name 27  "u3"\r
+                              Name 30  "i1"\r
+               2:             TypeVoid\r
+               3:             TypeFunction 2\r
+               6:             TypeInt 32 1\r
+               7:             TypeVector 6(int) 3\r
+               8:             TypePointer Output 7(ivec3)\r
+       9(icolor):      8(ptr) Variable Output\r
+              10:             TypePointer UniformConstant 7(ivec3)\r
+          11(i3):     10(ptr) Variable UniformConstant\r
+              13:             TypeInt 32 0\r
+              14:             TypePointer UniformConstant 13(int)\r
+          15(u1):     14(ptr) Variable UniformConstant\r
+              17:             TypeVector 13(int) 3\r
+              20:     13(int) Constant 4\r
+              24:             TypePointer Output 17(ivec3)\r
+      25(ucolor):     24(ptr) Variable Output\r
+              26:             TypePointer UniformConstant 17(ivec3)\r
+          27(u3):     26(ptr) Variable UniformConstant\r
+              29:             TypePointer UniformConstant 6(int)\r
+          30(i1):     29(ptr) Variable UniformConstant\r
+              34:      6(int) Constant 5\r
+         4(main):           2 Function None 3\r
+               5:             Label\r
+              12:    7(ivec3) Load 11(i3)\r
+              16:     13(int) Load 15(u1)\r
+              18:   17(ivec3) CompositeConstruct 16 16 16\r
+              19:    7(ivec3) ShiftLeftLogical 12 18\r
+                              Store 9(icolor) 19\r
+              21:    7(ivec3) Load 9(icolor)\r
+              22:   17(ivec3) CompositeConstruct 20 20 20\r
+              23:    7(ivec3) ShiftLeftLogical 21 22\r
+                              Store 9(icolor) 23\r
+              28:   17(ivec3) Load 27(u3)\r
+              31:      6(int) Load 30(i1)\r
+              32:    7(ivec3) CompositeConstruct 31 31 31\r
+              33:   17(ivec3) ShiftRightLogical 28 32\r
+                              Store 25(ucolor) 33\r
+              35:   17(ivec3) Load 25(ucolor)\r
+              36:    7(ivec3) CompositeConstruct 34 34 34\r
+              37:   17(ivec3) ShiftRightLogical 35 36\r
+                              Store 25(ucolor) 37\r
+                              Return\r
+                              FunctionEnd\r
diff --git a/Test/spv.ShiftOps.frag b/Test/spv.ShiftOps.frag
new file mode 100644 (file)
index 0000000..498d5bd
--- /dev/null
@@ -0,0 +1,19 @@
+#version 450\r
+\r
+uniform int   i1;\r
+uniform uint  u1;\r
+\r
+uniform ivec3 i3;\r
+uniform uvec3 u3;\r
+\r
+out ivec3 icolor;\r
+out uvec3 ucolor;\r
+\r
+void main()\r
+{\r
+    icolor = i3 << u1;\r
+    icolor <<= 4u;\r
+\r
+    ucolor = u3 >> i1;\r
+    ucolor >>= 5;\r
+}\r
index ea3094b..6445b21 100644 (file)
@@ -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