Explicitly declare gl_PerVertex block
authorMaciej Jesionowski <maciej.jesionowski@mobica.com>
Thu, 16 Jun 2016 12:02:45 +0000 (14:02 +0200)
committerMaciej Jesionowski <maciej.jesionowski@mobica.com>
Thu, 16 Jun 2016 13:25:29 +0000 (15:25 +0200)
This fixes SPIR-V validation error in shaders generated from GLSL (not ES)
due to missing ClipDistance capability.

external/vulkancts/data/vulkan/draw/VertexFetch.vert
external/vulkancts/data/vulkan/draw/VertexFetchInstanced.vert
external/vulkancts/data/vulkan/draw/VertexFetchInstancedFirstInstance.vert
external/vulkancts/modules/vulkan/binding_model/vktBindingShaderAccessTests.cpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineEarlyFragmentTests.cpp
external/vulkancts/modules/vulkan/pipeline/vktPipelineSpecConstantTests.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 da65f4b..8d3a5f2 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 12ca3b8..8028556 100644 (file)
@@ -50,6 +50,10 @@ using namespace vk;
 namespace
 {
 
+static const char* const s_perVertexBlock =    "gl_PerVertex {\n"
+                                                                                       "    vec4 gl_Position;\n"
+                                                                                       "}";
+
 //! Raw memory storage for values used in test cases.
 //! We use it to simplify test case definitions where different types are expected in the result.
 class GenericValue
@@ -289,6 +293,8 @@ void SpecConstantTest::initPrograms (SourceCollections& programCollection) const
                src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
                        << "layout(location = 0) in highp vec4 position;\n"
                        << "\n"
+                       << "out " << s_perVertexBlock << ";\n"
+                       << "\n"
                        << (useSpecConst ? generateSpecConstantCode(m_caseDef.specConstants) : "")
                        << (useSpecConst ? generateSSBOCode(m_caseDef.ssboCode) : "")
                        << (useSpecConst ? m_caseDef.globalCode + "\n" : "")
@@ -327,6 +333,10 @@ void SpecConstantTest::initPrograms (SourceCollections& programCollection) const
                src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
                        << "layout(vertices = 3) out;\n"
                        << "\n"
+                       << "in " << s_perVertexBlock << " gl_in[gl_MaxPatchVertices];\n"
+                       << "\n"
+                       << "out " << s_perVertexBlock << " gl_out[];\n"
+                       << "\n"
                        << (useSpecConst ? generateSpecConstantCode(m_caseDef.specConstants) : "")
                        << (useSpecConst ? generateSSBOCode(m_caseDef.ssboCode) : "")
                        << (useSpecConst ? m_caseDef.globalCode + "\n" : "")
@@ -353,6 +363,10 @@ void SpecConstantTest::initPrograms (SourceCollections& programCollection) const
                src << glu::getGLSLVersionDeclaration(glu::GLSL_VERSION_440) << "\n"
                        << "layout(triangles, equal_spacing, ccw) in;\n"
                        << "\n"
+                       << "in " << s_perVertexBlock << " gl_in[gl_MaxPatchVertices];\n"
+                       << "\n"
+                       << "out " << s_perVertexBlock << ";\n"
+                       << "\n"
                        << (useSpecConst ? generateSpecConstantCode(m_caseDef.specConstants) : "")
                        << (useSpecConst ? generateSSBOCode(m_caseDef.ssboCode) : "")
                        << (useSpecConst ? m_caseDef.globalCode + "\n" : "")
@@ -376,6 +390,10 @@ void SpecConstantTest::initPrograms (SourceCollections& programCollection) const
                        << "layout(triangles) in;\n"
                        << "layout(triangle_strip, max_vertices = 3) out;\n"
                        << "\n"
+                       << "in " << s_perVertexBlock << " gl_in[];\n"
+                       << "\n"
+                       << "out " << s_perVertexBlock << ";\n"
+                       << "\n"
                        << (useSpecConst ? generateSpecConstantCode(m_caseDef.specConstants) : "")
                        << (useSpecConst ? generateSSBOCode(m_caseDef.ssboCode) : "")
                        << (useSpecConst ? m_caseDef.globalCode + "\n" : "")