Cherry-pick SPIR-V ClipDistance validation fixes
authorPyry Haulos <phaulos@google.com>
Wed, 23 Nov 2016 00:13:32 +0000 (16:13 -0800)
committerPyry Haulos <phaulos@google.com>
Tue, 29 Nov 2016 23:22:54 +0000 (15:22 -0800)
These fixes are needed in order for SPIR-V validation to pass when
shaders are compiled with a newer glslang version.

Bug: 33041922

Explicitly declare gl_PerVertex block

This fixes SPIR-V validation error in shaders generated from GLSL (not ES)
due to missing ClipDistance capability.

(cherry picked from commit 0a6fe1448b303a6a4e4ab48712eaf1c0b16d75b1)

Explicitly declare gl_PerVertex in push constant tests

(cherry picked from commit cba5d02d184b771bc4a21b8aecbbde3377d86167)

Change tes/geom shaders in timestamp tests use 310 es

Vertex and fragment shaders were already using that GLSL version.

(cherry picked from commit d47309690aa9b2e685b267ea6395e88b32c855a8)

Change ubo and ssbo tests to use 310 es shaders

(cherry picked from commit 4d36051923691c5f92cf3615e82d30d54ed3b09b)

Explicitly declare gl_PerVertex in dynamic viewport state tests

(cherry picked from commit 816c46d518d08a4ff321ca93780f2786fa86ba60)

Explicitly declare gl_PerVertex in occlusion query tests

(cherry picked from commit a1257f69aa6008d4e5a22148a43d59692eb24822)

Change-Id: Ib53b245d25c6cbc345a88e8b247f01ac7cf8a541

12 files changed:
external/vulkancts/data/vulkan/draw/VertexFetch.vert
external/vulkancts/data/vulkan/draw/VertexFetchInstanced.vert
external/vulkancts/data/vulkan/draw/VertexFetchInstancedFirstInstance.vert
external/vulkancts/data/vulkan/dynamic_state/VertexFetch.vert
external/vulkancts/data/vulkan/dynamic_state/ViewportArray.geom
external/vulkancts/modules/vulkan/binding_model/vktBindingShaderAccessTests.cpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineEarlyFragmentTests.cpp
external/vulkancts/modules/vulkan/pipeline/vktPipelinePushConstantTests.cpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineTimestampTests.cpp
external/vulkancts/modules/vulkan/query_pool/vktQueryPoolOcclusionTests.cpp
external/vulkancts/modules/vulkan/ssbo/vktSSBOLayoutCase.cpp
external/vulkancts/modules/vulkan/ubo/vktUniformBlockCase.cpp

index 1730f5f..7f070f5 100644 (file)
@@ -5,6 +5,10 @@ layout(location = 1) in vec4 in_color;
 
 layout(location = 0) out vec4 out_color;
 
+out gl_PerVertex {
+    vec4 gl_Position;
+};
+
 void main() {
        gl_Position = in_position;
        out_color = in_color;
index e694f60..1576892 100644 (file)
@@ -5,6 +5,10 @@ layout(location = 1) in vec4 in_color;
 
 layout(location = 0) out vec4 out_color;
 
+out gl_PerVertex {
+    vec4 gl_Position;
+};
+
 void main() {
        vec2 perVertex = vec2(in_position.x, in_position.y);
        vec2 perInstance[6]     = vec2[6](vec2(0.0, 0.0), vec2(0.3, 0.0), vec2(0.0, -0.3),vec2(0.3, -0.3), vec2(0.7, -0.7), vec2(-0.75, 0.8));
index 2e76fe9..f3e4a1a 100644 (file)
@@ -5,6 +5,10 @@ layout(location = 1) in vec4 in_color;
 
 layout(location = 0) out vec4 out_color;
 
+out gl_PerVertex {
+    vec4 gl_Position;
+};
+
 void main() {
        vec2 perVertex = vec2(in_position.x, in_position.y);
        vec2 perInstance[6]     = vec2[6](vec2(0.7, -0.7), vec2(-0.75, 0.8), vec2(0.0, 0.0), vec2(0.3, 0.0), vec2(0.0, -0.3),vec2(0.3, -0.3) );
index 2b97bd9..2387227 100644 (file)
@@ -1,10 +1,11 @@
-#version 310 es
+#version 450
 precision highp float;
 
 layout(location = 0) in vec4 in_position;
 layout(location = 1) in vec4 in_color;
 
 layout(location = 0) out vec4 out_color;
+out gl_PerVertex { vec4 gl_Position; };
 
 void main() {
        gl_Position = in_position;
index ebf6821..eb3c3f2 100644 (file)
@@ -1,7 +1,9 @@
-#version 430
+#version 450
 layout(triangles) in;
 layout(triangle_strip, max_vertices = 3) out;
 
+in gl_PerVertex { vec4 gl_Position; } gl_in[];
+out gl_PerVertex { vec4 gl_Position; };
 layout(location = 0) in vec4 in_color[];
 layout(location = 0) out vec4 out_color;
 
index 270f2fb..8cf3d92 100644 (file)
@@ -75,6 +75,43 @@ static const char* const s_quadrantGenVertexPosSource =      "       highp int quadPhase =
                                                                                                                "       quadrant_id = gl_VertexIndex / 6;\n"
                                                                                                                "       result_position = vec4(float(quadOriginX + quadXcoord - 1), float(quadOriginY + quadYcoord - 1), 0.0, 1.0);\n";
 
+std::string genPerVertexBlock (const vk::VkShaderStageFlagBits stage, const glu::GLSLVersion version)
+{
+       static const char* const block = "gl_PerVertex {\n"
+                                                                        "    vec4  gl_Position;\n"
+                                                                        "    float gl_PointSize;\n"    // not used, but for compatibility with how implicit block is declared in ES
+                                                                        "}";
+       std::ostringstream str;
+
+       if (!glu::glslVersionIsES(version))
+               switch (stage)
+               {
+                       case vk::VK_SHADER_STAGE_VERTEX_BIT:
+                               str << "out " << block << ";\n";
+                               break;
+
+                       case vk::VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT:
+                               str << "in " << block << " gl_in[gl_MaxPatchVertices];\n"
+                                       << "out " << block << " gl_out[];\n";
+                               break;
+
+                       case vk::VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT:
+                               str << "in " << block << " gl_in[gl_MaxPatchVertices];\n"
+                                       << "out " << block << ";\n";
+                               break;
+
+                       case vk::VK_SHADER_STAGE_GEOMETRY_BIT:
+                               str << "in " << block << " gl_in[];\n"
+                                       << "out " << block << ";\n";
+                               break;
+
+                       default:
+                               break;
+               }
+
+       return str.str();
+}
+
 bool isUniformDescriptorType (vk::VkDescriptorType type)
 {
        return type == vk::VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER ||
@@ -2247,6 +2284,7 @@ std::string QuadrantRendederCase::genVertexSource (void) const
                        << genResourceDeclarations(vk::VK_SHADER_STAGE_VERTEX_BIT, 0)
                        << "layout(location = 0) out highp vec4 " << nextStageName << "_color;\n"
                        << (onlyVS ? "" : "layout(location = 1) flat out highp int " + de::toString(nextStageName) + "_quadrant_id;\n")
+                       << genPerVertexBlock(vk::VK_SHADER_STAGE_VERTEX_BIT, m_glslVersion)
                        << "void main (void)\n"
                        << "{\n"
                        << "    highp vec4 result_position;\n"
@@ -2266,6 +2304,7 @@ std::string QuadrantRendederCase::genVertexSource (void) const
                buf << versionDecl << "\n"
                        << genExtensionDeclarations(vk::VK_SHADER_STAGE_VERTEX_BIT)
                        << "layout(location = 1) flat out highp int " << nextStageName << "_quadrant_id;\n"
+                       << genPerVertexBlock(vk::VK_SHADER_STAGE_VERTEX_BIT, m_glslVersion)
                        << "void main (void)\n"
                        << "{\n"
                        << "    highp vec4 result_position;\n"
@@ -2299,6 +2338,7 @@ std::string QuadrantRendederCase::genTessCtrlSource (void) const
                        << genResourceDeclarations(vk::VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, 0)
                        << "layout(location = 1) flat in highp int tsc_quadrant_id[];\n"
                        << "layout(location = 0) out highp vec4 tes_color[];\n"
+                       << genPerVertexBlock(vk::VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, m_glslVersion)
                        << "void main (void)\n"
                        << "{\n"
                        << "    highp vec4 result_color;\n"
@@ -2332,6 +2372,7 @@ std::string QuadrantRendederCase::genTessCtrlSource (void) const
                        << "layout(vertices=3) out;\n"
                        << "layout(location = 1) flat in highp int tsc_quadrant_id[];\n"
                        << "layout(location = 1) flat out highp int tes_quadrant_id[];\n"
+                       << genPerVertexBlock(vk::VK_SHADER_STAGE_TESSELLATION_CONTROL_BIT, m_glslVersion)
                        << "void main (void)\n"
                        << "{\n"
                        << "    tes_quadrant_id[gl_InvocationID] = tsc_quadrant_id[0];\n"
@@ -2382,6 +2423,7 @@ std::string QuadrantRendederCase::genTessEvalSource (void) const
                        << genResourceDeclarations(vk::VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, 0)
                        << "layout(location = 1) flat in highp int tes_quadrant_id[];\n"
                        << "layout(location = 0) out highp vec4 frag_color;\n"
+                       << genPerVertexBlock(vk::VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, m_glslVersion)
                        << "void main (void)\n"
                        << "{\n"
                        << "    highp vec4 result_color;\n"
@@ -2403,6 +2445,7 @@ std::string QuadrantRendederCase::genTessEvalSource (void) const
                        << "layout(triangles) in;\n"
                        << "layout(location = 0) in highp vec4 tes_color[];\n"
                        << "layout(location = 0) out highp vec4 frag_color;\n"
+                       << genPerVertexBlock(vk::VK_SHADER_STAGE_TESSELLATION_EVALUATION_BIT, m_glslVersion)
                        << "void main (void)\n"
                        << "{\n"
                        << "    frag_color = tes_color[0];\n"
@@ -2439,6 +2482,7 @@ std::string QuadrantRendederCase::genGeometrySource (void) const
                        << genResourceDeclarations(vk::VK_SHADER_STAGE_GEOMETRY_BIT, 0)
                        << "layout(location = 1) flat in highp int geo_quadrant_id[];\n"
                        << "layout(location = 0) out highp vec4 frag_color;\n"
+                       << genPerVertexBlock(vk::VK_SHADER_STAGE_GEOMETRY_BIT, m_glslVersion)
                        << "void main (void)\n"
                        << "{\n"
                        << "    highp int quadrant_id;\n"
index b2731f5..c5fe5b1 100644 (file)
@@ -759,6 +759,10 @@ void EarlyFragmentTest::initPrograms (SourceCollections& programCollection) cons
                        << "\n"
                        << "layout(location = 0) in highp vec4 position;\n"
                        << "\n"
+                       << "out gl_PerVertex {\n"
+                       << "   vec4 gl_Position;\n"
+                       << "};\n"
+                       << "\n"
                        << "void main (void)\n"
                        << "{\n"
                        << "    gl_Position = position;\n"
index 1e3e967..fdd6fd2 100644 (file)
@@ -228,6 +228,7 @@ void PushConstantGraphicsTest::initPrograms (SourceCollections& sourceCollection
                                          << "layout(location = 0) in highp vec4 position;\n"
                                          << "layout(location = 1) in highp vec4 color;\n"
                                          << "layout(location = 0) out highp vec4 vtxColor;\n"
+                                         << "out gl_PerVertex { vec4 gl_Position; };\n"
                                          << "layout(push_constant) uniform Material {\n";
 
                        switch (getRangeSizeCase(m_pushConstantRange[rangeNdx].range.size))
@@ -314,6 +315,8 @@ void PushConstantGraphicsTest::initPrograms (SourceCollections& sourceCollection
                                                   << "} tessLevel;\n"
                                                   << "layout(location = 0) in highp vec4 color[];\n"
                                                   << "layout(location = 0) out highp vec4 vtxColor[];\n"
+                                                  << "in gl_PerVertex { vec4 gl_Position; } gl_in[gl_MaxPatchVertices];\n"
+                                                  << "out gl_PerVertex { vec4 gl_Position; } gl_out[];\n"
                                                   << "void main()\n"
                                                   << "{\n"
                                                   << "  gl_TessLevelInner[0] = tessLevel.level;\n"
@@ -336,6 +339,8 @@ void PushConstantGraphicsTest::initPrograms (SourceCollections& sourceCollection
                                                          << "} matInst;\n"
                                                          << "layout(location = 0) in highp vec4 color[];\n"
                                                          << "layout(location = 0) out highp vec4 vtxColor;\n"
+                                                         << "in gl_PerVertex { vec4 gl_Position; } gl_in[gl_MaxPatchVertices];\n"
+                                                         << "out gl_PerVertex { vec4 gl_Position; };\n"
                                                          << "void main()\n"
                                                          << "{\n"
                                                          << "  gl_Position = gl_TessCoord.x * gl_in[0].gl_Position + gl_TessCoord.y * gl_in[1].gl_Position + gl_TessCoord.z * gl_in[2].gl_Position;\n"
@@ -355,6 +360,8 @@ void PushConstantGraphicsTest::initPrograms (SourceCollections& sourceCollection
                                                << "} matInst;\n"
                                                << "layout(location = 0) in highp vec4 color[];\n"
                                                << "layout(location = 0) out highp vec4 vtxColor;\n"
+                                               << "in gl_PerVertex { vec4 gl_Position; } gl_in[];\n"
+                                               << "out gl_PerVertex { vec4 gl_Position; };\n"
                                                << "void main()\n"
                                                << "{\n"
                                                << "  for(int i=0; i<3; i++)\n"
index 744c84a..692367e 100644 (file)
@@ -1367,7 +1367,8 @@ void AdvGraphicsTest::initPrograms(SourceCollections& programCollection) const
        BasicGraphicsTest::initPrograms(programCollection);
 
        programCollection.glslSources.add("dummy_geo") << glu::GeometrySource(
-               "#version 450 \n"
+               "#version 310 es\n"
+               "#extension GL_EXT_geometry_shader : enable\n"
                "layout(triangles) in;\n"
                "layout(triangle_strip, max_vertices = 3) out;\n"
                "layout(location = 0) in highp vec4 in_vtxColor[];\n"
@@ -1384,7 +1385,8 @@ void AdvGraphicsTest::initPrograms(SourceCollections& programCollection) const
                "}\n");
 
        programCollection.glslSources.add("basic_tcs") << glu::TessellationControlSource(
-               "#version 450 \n"
+               "#version 310 es\n"
+               "#extension GL_EXT_tessellation_shader : enable\n"
                "layout(vertices = 3) out;\n"
                "layout(location = 0) in highp vec4 color[];\n"
                "layout(location = 0) out highp vec4 vtxColor[];\n"
@@ -1399,7 +1401,8 @@ void AdvGraphicsTest::initPrograms(SourceCollections& programCollection) const
                "}\n");
 
        programCollection.glslSources.add("basic_tes") << glu::TessellationEvaluationSource(
-               "#version 450 \n"
+               "#version 310 es\n"
+               "#extension GL_EXT_tessellation_shader : enable\n"
                "layout(triangles, fractional_even_spacing, ccw) in;\n"
                "layout(location = 0) in highp vec4 colors[];\n"
                "layout(location = 0) out highp vec4 vtxColor;\n"
index 22feecc..74a9742 100644 (file)
@@ -1005,9 +1005,10 @@ private:
                                                                                                                                           "}\n");
 
                programCollection.glslSources.add("vert") << glu::VertexSource("#version 430\n"
-                                                                                                                                                "layout(location = 0) in vec4 in_Postion;\n"
+                                                                                                                                                "layout(location = 0) in vec4 in_Position;\n"
+                                                                                                                                                "out gl_PerVertex { vec4 gl_Position; float gl_PointSize; };\n"
                                                                                                                                                 "void main() {\n"
-                                                                                                                                                "      gl_Position  = in_Postion;\n"
+                                                                                                                                                "      gl_Position  = in_Position;\n"
                                                                                                                                                 "      gl_PointSize = 1.0;\n"
                                                                                                                                                 "}\n");
        }
index ca02de0..f56c50b 100644 (file)
@@ -1201,7 +1201,7 @@ string generateComputeShader (const ShaderInterface& interface, const BufferLayo
 {
        std::ostringstream src;
 
-       src << "#version 450\n";
+       src << "#version 310 es\n";
        src << "layout(local_size_x = 1) in;\n";
        src << "\n";
 
index 35805fb..6dee37d 100644 (file)
@@ -1052,7 +1052,7 @@ void generateCompareSrc (std::ostringstream& src, const char* resultVar, const S
 std::string generateVertexShader (const ShaderInterface& interface, const UniformLayout& layout, const std::map<int, void*>& blockPointers)
 {
        std::ostringstream src;
-       src << "#version 450\n";
+       src << "#version 310 es\n";
 
        src << "layout(location = 0) in highp vec4 a_position;\n";
        src << "layout(location = 0) out mediump float v_vtxResult;\n";
@@ -1092,7 +1092,7 @@ std::string generateVertexShader (const ShaderInterface& interface, const Unifor
 std::string generateFragmentShader (const ShaderInterface& interface, const UniformLayout& layout, const std::map<int, void*>& blockPointers)
 {
        std::ostringstream src;
-       src << "#version 450\n";
+       src << "#version 310 es\n";
 
        src << "layout(location = 0) in mediump float v_vtxResult;\n";
        src << "layout(location = 0) out mediump vec4 dEQP_FragColor;\n";