Fix #2264: OpEntryPoint incorrectly including function parameters.
authorJohn Kessenich <cepheus@frii.com>
Wed, 10 Jun 2020 13:15:24 +0000 (07:15 -0600)
committerJohn Kessenich <cepheus@frii.com>
Wed, 10 Jun 2020 13:17:11 +0000 (07:17 -0600)
SPIRV/GlslangToSpv.cpp
Test/baseResults/spv.1.4.OpEntryPoint.opaqueParams.vert.out [new file with mode: 0755]
Test/spv.1.4.OpEntryPoint.opaqueParams.vert [new file with mode: 0644]
gtests/Spv.FromFile.cpp

index 3e420aa..f8a7e49 100644 (file)
@@ -1711,16 +1711,19 @@ void TGlslangToSpvTraverser::visitSymbol(glslang::TIntermSymbol* symbol)
     spv::Id id = getSymbolId(symbol);
 
     if (builder.isPointer(id)) {
-        // Include all "static use" and "linkage only" interface variables on the OpEntryPoint instruction
-        // Consider adding to the OpEntryPoint interface list.
-        // Only looking at structures if they have at least one member.
-        if (!symbol->getType().isStruct() || symbol->getType().getStruct()->size() > 0) {
-            spv::StorageClass sc = builder.getStorageClass(id);
-            // Before SPIR-V 1.4, we only want to include Input and Output.
-            // Starting with SPIR-V 1.4, we want all globals.
-            if ((glslangIntermediate->getSpv().spv >= glslang::EShTargetSpv_1_4 && sc != spv::StorageClassFunction) ||
-                (sc == spv::StorageClassInput || sc == spv::StorageClassOutput)) {
-                iOSet.insert(id);
+        if (!symbol->getType().getQualifier().isParamInput() &&
+            !symbol->getType().getQualifier().isParamOutput()) {
+            // Include all "static use" and "linkage only" interface variables on the OpEntryPoint instruction
+            // Consider adding to the OpEntryPoint interface list.
+            // Only looking at structures if they have at least one member.
+            if (!symbol->getType().isStruct() || symbol->getType().getStruct()->size() > 0) {
+                spv::StorageClass sc = builder.getStorageClass(id);
+                // Before SPIR-V 1.4, we only want to include Input and Output.
+                // Starting with SPIR-V 1.4, we want all globals.
+                if ((glslangIntermediate->getSpv().spv >= glslang::EShTargetSpv_1_4 && sc != spv::StorageClassFunction) ||
+                    (sc == spv::StorageClassInput || sc == spv::StorageClassOutput)) {
+                    iOSet.insert(id);
+                }
             }
         }
 
diff --git a/Test/baseResults/spv.1.4.OpEntryPoint.opaqueParams.vert.out b/Test/baseResults/spv.1.4.OpEntryPoint.opaqueParams.vert.out
new file mode 100755 (executable)
index 0000000..a29ccb8
--- /dev/null
@@ -0,0 +1,72 @@
+spv.1.4.OpEntryPoint.opaqueParams.vert
+// Module Version 10400
+// Generated by (magic number): 80008
+// Id's are bound by 45
+
+                              Capability Shader
+                              Capability ImageQuery
+               1:             ExtInstImport  "GLSL.std.450"
+                              MemoryModel Logical GLSL450
+                              EntryPoint Vertex 4  "main" 41 42 43
+                              Source GLSL 450
+                              Name 4  "main"
+                              Name 18  "funOpaque(s21;t21;p1;"
+                              Name 15  "s2D"
+                              Name 16  "t2D"
+                              Name 17  "s"
+                              Name 40  "size"
+                              Name 41  "s2D"
+                              Name 42  "t2D"
+                              Name 43  "s"
+                              Decorate 41(s2D) DescriptorSet 0
+                              Decorate 41(s2D) Binding 0
+                              Decorate 42(t2D) DescriptorSet 0
+                              Decorate 42(t2D) Binding 1
+                              Decorate 43(s) DescriptorSet 0
+                              Decorate 43(s) Binding 3
+               2:             TypeVoid
+               3:             TypeFunction 2
+               6:             TypeFloat 32
+               7:             TypeImage 6(float) 2D sampled format:Unknown
+               8:             TypeSampledImage 7
+               9:             TypePointer UniformConstant 8
+              10:             TypePointer UniformConstant 7
+              11:             TypeSampler
+              12:             TypePointer UniformConstant 11
+              13:             TypeVector 6(float) 2
+              14:             TypeFunction 13(fvec2) 9(ptr) 10(ptr) 12(ptr)
+              21:             TypeInt 32 1
+              22:     21(int) Constant 0
+              24:             TypeVector 21(int) 2
+              30:    6(float) Constant 1056964608
+              31:   13(fvec2) ConstantComposite 30 30
+              32:             TypeVector 6(float) 4
+              33:    6(float) Constant 0
+              39:             TypePointer Function 13(fvec2)
+         41(s2D):      9(ptr) Variable UniformConstant
+         42(t2D):     10(ptr) Variable UniformConstant
+           43(s):     12(ptr) Variable UniformConstant
+         4(main):           2 Function None 3
+               5:             Label
+        40(size):     39(ptr) Variable Function
+              44:   13(fvec2) FunctionCall 18(funOpaque(s21;t21;p1;) 41(s2D) 42(t2D) 43(s)
+                              Store 40(size) 44
+                              Return
+                              FunctionEnd
+18(funOpaque(s21;t21;p1;):   13(fvec2) Function None 14
+         15(s2D):      9(ptr) FunctionParameter
+         16(t2D):     10(ptr) FunctionParameter
+           17(s):     12(ptr) FunctionParameter
+              19:             Label
+              20:           8 Load 15(s2D)
+              23:           7 Image 20
+              25:   24(ivec2) ImageQuerySizeLod 23 22
+              26:   13(fvec2) ConvertSToF 25
+              27:           7 Load 16(t2D)
+              28:          11 Load 17(s)
+              29:           8 SampledImage 27 28
+              34:   32(fvec4) ImageSampleExplicitLod 29 31 Lod 33
+              35:   13(fvec2) VectorShuffle 34 34 0 1
+              36:   13(fvec2) FMul 26 35
+                              ReturnValue 36
+                              FunctionEnd
diff --git a/Test/spv.1.4.OpEntryPoint.opaqueParams.vert b/Test/spv.1.4.OpEntryPoint.opaqueParams.vert
new file mode 100644 (file)
index 0000000..71c287d
--- /dev/null
@@ -0,0 +1,15 @@
+#version 450\r
+\r
+layout(binding = 0) uniform sampler2D s2D;\r
+layout(binding = 1) uniform texture2D t2D;\r
+layout(binding = 3) uniform sampler s;\r
+\r
+vec2 funOpaque(in sampler2D s2D, texture2D t2D, sampler s)\r
+{\r
+    return textureSize(s2D, 0) * texture(sampler2D(t2D, s), vec2(0.5)).xy;\r
+}\r
+\r
+void main()\r
+{\r
+    vec2 size = funOpaque(s2D, t2D, s);\r
+}
\ No newline at end of file
index 5c9fb9b..e1d9735 100644 (file)
@@ -534,6 +534,7 @@ INSTANTIATE_TEST_CASE_P(
         "spv.1.4.LoopControl.frag",
         "spv.1.4.NonWritable.frag",
         "spv.1.4.OpEntryPoint.frag",
+        "spv.1.4.OpEntryPoint.opaqueParams.vert",
         "spv.1.4.OpSelect.frag",
         "spv.1.4.OpCopyLogical.comp",
         "spv.1.4.OpCopyLogicalBool.comp",