SPV: Protect getStorageClass() with a test that the thing is pointer.
authorJohn Kessenich <cepheus@frii.com>
Wed, 9 Dec 2015 03:48:49 +0000 (20:48 -0700)
committerJohn Kessenich <cepheus@frii.com>
Wed, 9 Dec 2015 03:48:49 +0000 (20:48 -0700)
SPIRV/GlslangToSpv.cpp
SPIRV/spvIR.h
Test/baseResults/spv.bool.vert.out [new file with mode: 0644]
Test/spv.bool.vert [new file with mode: 0644]
Test/test-spirv-list
glslang/Include/revision.h

index 7d0d3ab..5e43286 100755 (executable)
@@ -599,9 +599,11 @@ void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol)
             builder.setAccessChainLValue(id);
     } else {
         // finish off the entry-point SPV instruction by adding the Input/Output <id>
-        spv::StorageClass sc = builder.getStorageClass(id);
-        if (sc == spv::StorageClassInput || sc == spv::StorageClassOutput)
-            entryPoint->addIdOperand(id);
+        if (builder.isPointer(id)) {
+            spv::StorageClass sc = builder.getStorageClass(id);
+            if (sc == spv::StorageClassInput || sc == spv::StorageClassOutput)
+                entryPoint->addIdOperand(id);
+        }
     }
 }
 
index 6736a13..9291185 100755 (executable)
@@ -293,7 +293,12 @@ public:
 
     Instruction* getInstruction(Id id) const { return idToInstruction[id]; }
     spv::Id getTypeId(Id resultId) const { return idToInstruction[resultId]->getTypeId(); }
-    StorageClass getStorageClass(Id typeId) const { return (StorageClass)idToInstruction[typeId]->getImmediateOperand(0); }
+    StorageClass getStorageClass(Id typeId) const
+    {
+        assert(idToInstruction[typeId]->getOpCode() == spv::OpTypePointer);
+        return (StorageClass)idToInstruction[typeId]->getImmediateOperand(0);
+    }
+
     void dump(std::vector<unsigned int>& out) const
     {
         for (int f = 0; f < (int)functions.size(); ++f)
diff --git a/Test/baseResults/spv.bool.vert.out b/Test/baseResults/spv.bool.vert.out
new file mode 100644 (file)
index 0000000..04aff36
--- /dev/null
@@ -0,0 +1,98 @@
+spv.bool.vert\r
+Warning, version 450 is not yet complete; most version-specific features are present, but some are missing.\r
+\r
+\r
+Linked vertex stage:\r
+\r
+\r
+// Module Version 10000\r
+// Generated by (magic number): 80001\r
+// Id's are bound by 49\r
+\r
+                              Capability Shader\r
+               1:             ExtInstImport  "GLSL.std.450"\r
+                              MemoryModel Logical GLSL450\r
+                              EntryPoint Vertex 4  "main" 23 47 48\r
+                              Source GLSL 450\r
+                              Name 4  "main"\r
+                              Name 10  "foo(b1;"\r
+                              Name 9  "b"\r
+                              Name 21  "gl_PerVertex"\r
+                              MemberName 21(gl_PerVertex) 0  "gl_Position"\r
+                              MemberName 21(gl_PerVertex) 1  "gl_PointSize"\r
+                              MemberName 21(gl_PerVertex) 2  "gl_ClipDistance"\r
+                              MemberName 21(gl_PerVertex) 3  "gl_CullDistance"\r
+                              Name 23  ""\r
+                              Name 28  "ubname"\r
+                              MemberName 28(ubname) 0  "b"\r
+                              Name 30  "ubinst"\r
+                              Name 31  "param"\r
+                              Name 47  "gl_VertexID"\r
+                              Name 48  "gl_InstanceID"\r
+                              MemberDecorate 21(gl_PerVertex) 0 BuiltIn Position\r
+                              MemberDecorate 21(gl_PerVertex) 1 BuiltIn PointSize\r
+                              MemberDecorate 21(gl_PerVertex) 2 BuiltIn ClipDistance\r
+                              MemberDecorate 21(gl_PerVertex) 3 BuiltIn CullDistance\r
+                              Decorate 21(gl_PerVertex) Block\r
+                              Decorate 28(ubname) GLSLShared\r
+                              Decorate 28(ubname) Block\r
+                              Decorate 47(gl_VertexID) BuiltIn VertexId\r
+                              Decorate 48(gl_InstanceID) BuiltIn InstanceId\r
+               2:             TypeVoid\r
+               3:             TypeFunction 2\r
+               6:             TypeBool\r
+               7:             TypePointer Function 6(bool)\r
+               8:             TypeFunction 6(bool) 7(ptr)\r
+              13:     6(bool) ConstantFalse\r
+              16:             TypeFloat 32\r
+              17:             TypeVector 16(float) 4\r
+              18:             TypeInt 32 0\r
+              19:     18(int) Constant 1\r
+              20:             TypeArray 16(float) 19\r
+21(gl_PerVertex):             TypeStruct 17(fvec4) 16(float) 20 20\r
+              22:             TypePointer Output 21(gl_PerVertex)\r
+              23:     22(ptr) Variable Output\r
+              24:             TypeInt 32 1\r
+              25:     24(int) Constant 0\r
+              26:             TypePointer Function 17(fvec4)\r
+      28(ubname):             TypeStruct 6(bool)\r
+              29:             TypePointer Uniform 28(ubname)\r
+      30(ubinst):     29(ptr) Variable Uniform\r
+              32:             TypePointer Uniform 6(bool)\r
+              38:   16(float) Constant 0\r
+              39:   17(fvec4) ConstantComposite 38 38 38 38\r
+              41:   16(float) Constant 1065353216\r
+              42:   17(fvec4) ConstantComposite 41 41 41 41\r
+              44:             TypePointer Output 17(fvec4)\r
+              46:             TypePointer Input 24(int)\r
+ 47(gl_VertexID):     46(ptr) Variable Input\r
+48(gl_InstanceID):     46(ptr) Variable Input\r
+         4(main):           2 Function None 3\r
+               5:             Label\r
+              27:     26(ptr) Variable Function\r
+       31(param):      7(ptr) Variable Function\r
+              33:     32(ptr) AccessChain 30(ubinst) 25\r
+              34:     6(bool) Load 33\r
+                              Store 31(param) 34\r
+              35:     6(bool) FunctionCall 10(foo(b1;) 31(param)\r
+                              SelectionMerge 37 None\r
+                              BranchConditional 35 36 40\r
+              36:               Label\r
+                                Store 27 39\r
+                                Branch 37\r
+              40:               Label\r
+                                Store 27 42\r
+                                Branch 37\r
+              37:             Label\r
+              43:   17(fvec4) Load 27\r
+              45:     44(ptr) AccessChain 23 25\r
+                              Store 45 43\r
+                              Return\r
+                              FunctionEnd\r
+     10(foo(b1;):     6(bool) Function None 8\r
+            9(b):      7(ptr) FunctionParameter\r
+              11:             Label\r
+              12:     6(bool) Load 9(b)\r
+              14:     6(bool) INotEqual 12 13\r
+                              ReturnValue 14\r
+                              FunctionEnd\r
diff --git a/Test/spv.bool.vert b/Test/spv.bool.vert
new file mode 100644 (file)
index 0000000..f58bc55
--- /dev/null
@@ -0,0 +1,17 @@
+#version 450\r
+\r
+const bool condition = false;\r
+\r
+uniform ubname {\r
+    bool b;\r
+} ubinst;\r
+\r
+bool foo(bool b)\r
+{\r
+       return b != condition;\r
+}\r
+\r
+void main()\r
+{\r
+    gl_Position = foo(ubinst.b) ? vec4(0.0) : vec4(1.0);\r
+}\r
index 136a9a6..ea3094b 100644 (file)
@@ -30,6 +30,7 @@ spv.accessChain.frag
 spv.aggOps.frag
 spv.always-discard.frag
 spv.always-discard2.frag
+spv.bool.vert
 spv.conditionalDiscard.frag
 spv.conversion.frag
 spv.dataOut.frag
index a21eb50..b14834f 100644 (file)
@@ -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 "SPIRV99.830"
+#define GLSLANG_REVISION "SPIRV99.831"
 #define GLSLANG_DATE "08-Dec-2015"