Fix locations in enhanced layouts tests
authorIago Toral Quiroga <itoral@igalia.com>
Fri, 22 Sep 2017 09:06:50 +0000 (11:06 +0200)
committerAlexander Galazin <Alexander.Galazin@arm.com>
Sun, 1 Oct 2017 14:36:53 +0000 (10:36 -0400)
Some of the tests query the last output location in
each shader stage and write an output to them that is
then read in the next shader stage, but they do not
consider if that location exists in the next shader
stage.

Fix this by selecting the maximum output location to
use as the minimum between the stage's maximum output
location and the next stage's maximum input location.

The same issue applies to the maximum input location
available in each shader stage.

Components: OpenGL
VK-GL-CTS issue: 708

Affects:
KHR-GL45.enhanced_layouts.varying_components
KHR-GL45.enhanced_layouts.varying_locations
KHR-GL45.enhanced_layouts.varying_location_limit
KHR-GL46.enhanced_layouts.varying_components
KHR-GL46.enhanced_layouts.varying_locations
KHR-GL46.enhanced_layouts.varying_location_limit

Change-Id: Iacf84bd3eeb33eadaf5a9a816f7ebb7205492af5

external/openglcts/modules/gl/gl4cEnhancedLayoutsTests.cpp

index 4ef77c4..22b9389 100644 (file)
@@ -5068,24 +5068,30 @@ tcu::TestNode::IterateResult TestBase::iterate()
  **/
 GLint TestBase::getLastInputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
 {
-       GLint  divide = 4; /* 4 components per location */
-       GLint  param  = 0;
-       GLenum pname  = 0;
+       GLint  divide           = 4; /* 4 components per location */
+       GLint  param            = 0;
+       GLenum pname            = 0;
+       GLint  paramPrev        = 0;
+       GLenum pnamePrev        = 0;
 
        /* Select pnmae */
        switch (stage)
        {
        case Utils::Shader::FRAGMENT:
                pname = GL_MAX_FRAGMENT_INPUT_COMPONENTS;
+               pnamePrev = GL_MAX_GEOMETRY_OUTPUT_COMPONENTS;
                break;
        case Utils::Shader::GEOMETRY:
                pname = GL_MAX_GEOMETRY_INPUT_COMPONENTS;
+               pnamePrev = GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS;
                break;
        case Utils::Shader::TESS_CTRL:
                pname = GL_MAX_TESS_CONTROL_INPUT_COMPONENTS;
+               pnamePrev = GL_MAX_VERTEX_OUTPUT_COMPONENTS;
                break;
        case Utils::Shader::TESS_EVAL:
                pname = GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS;
+               pnamePrev = GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS;
                break;
        case Utils::Shader::VERTEX:
                pname  = GL_MAX_VERTEX_ATTRIBS;
@@ -5108,6 +5114,14 @@ GLint TestBase::getLastInputLocation(Utils::Shader::STAGES stage, const Utils::T
        gl.getIntegerv(pname, &param);
        GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
 
+       if (pnamePrev) {
+               gl.getIntegerv(pnamePrev, &paramPrev);
+               GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
+
+               /* Don't read from a location that doesn't exist in the previous stage */
+               param = de::min(param, paramPrev);
+       }
+
 /* Calculate */
 #if WRKARD_VARYINGLOCATIONSTEST
 
@@ -5124,7 +5138,7 @@ GLint TestBase::getLastInputLocation(Utils::Shader::STAGES stage, const Utils::T
        return n_avl_locations - n_req_location; /* last is max - 1 */
 }
 
-/** Get last input location available for given type at specific stage
+/** Get last output location available for given type at specific stage
  *
  * @param stage        Shader stage
  * @param type         Input type
@@ -5134,23 +5148,29 @@ GLint TestBase::getLastInputLocation(Utils::Shader::STAGES stage, const Utils::T
  **/
 GLint TestBase::getLastOutputLocation(Utils::Shader::STAGES stage, const Utils::Type& type, GLuint array_length)
 {
-       GLint  param = 0;
-       GLenum pname = 0;
+       GLint  param            = 0;
+       GLenum pname            = 0;
+       GLint  paramNext        = 0;
+       GLenum pnameNext        = 0;
 
-       /* Select pnmae */
+       /* Select pname */
        switch (stage)
        {
        case Utils::Shader::GEOMETRY:
                pname = GL_MAX_GEOMETRY_OUTPUT_COMPONENTS;
+               pnameNext = GL_MAX_FRAGMENT_INPUT_COMPONENTS;
                break;
        case Utils::Shader::TESS_CTRL:
                pname = GL_MAX_TESS_CONTROL_OUTPUT_COMPONENTS;
+               pnameNext = GL_MAX_TESS_EVALUATION_INPUT_COMPONENTS;
                break;
        case Utils::Shader::TESS_EVAL:
                pname = GL_MAX_TESS_EVALUATION_OUTPUT_COMPONENTS;
+               pnameNext = GL_MAX_GEOMETRY_INPUT_COMPONENTS;
                break;
        case Utils::Shader::VERTEX:
                pname = GL_MAX_VERTEX_OUTPUT_COMPONENTS;
+               pnameNext = GL_MAX_TESS_CONTROL_INPUT_COMPONENTS;
                break;
        default:
                TCU_FAIL("Invalid enum");
@@ -5169,6 +5189,9 @@ GLint TestBase::getLastOutputLocation(Utils::Shader::STAGES stage, const Utils::
        gl.getIntegerv(pname, &param);
        GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
 
+       gl.getIntegerv(pnameNext, &paramNext);
+       GLU_EXPECT_NO_ERROR(gl.getError(), "GetIntegerv");
+
 /* Calculate */
 #if WRKARD_VARYINGLOCATIONSTEST
 
@@ -5176,6 +5199,9 @@ GLint TestBase::getLastOutputLocation(Utils::Shader::STAGES stage, const Utils::
 
 #else
 
+       /* Don't write to a location that doesn't exist in the next stage */
+       param = de::min(param, paramNext);
+
        const GLint n_avl_locations = param / 4; /* 4 components per location */
 
 #endif