[Mesa-dev] [PATCH v2 27/28] mesa: add NULL name check for several length queries

Alejandro PiƱeiro apinheiro at igalia.com
Thu Sep 27 09:52:06 UTC 2018


Since ARB_gl_spirv it is possible to miss a lot of name reflection
information, so it is needed to add NULL name checks for several
queries, and return a specific value on those cases. This commit add
them for ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH,
ACTIVE_ATTRIBUTE_MAX_LENGTH and ACTIVE_UNIFORM_MAX_LENGTH.

>From ARB_gl_spirv spec:
   "If pname is ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, the length of
    the longest active uniform block name, including the null
    terminator, is returned. If no active uniform blocks exist, zero
    is returned. If no name reflection information is available, one
    is returned.

    If pname is ACTIVE_ATTRIBUTE_MAX_LENGTH, the length of the longest
    active attribute name, including a null terminator, is returned.
    If no active attributes exist, zero is returned. If no name
    reflection information is available, one is returned.

    If pname is ACTIVE_UNIFORM_MAX_LENGTH, the length of the longest
    active uniform name, including a null terminator, is returned. If
    no active uniforms exist, zero is returned. If no name reflection
    information is available, one is returned."
---
 src/mesa/main/shader_query.cpp | 12 ++++++++++--
 src/mesa/main/shaderapi.c      | 26 ++++++++++++++++++++++----
 2 files changed, 32 insertions(+), 6 deletions(-)

diff --git a/src/mesa/main/shader_query.cpp b/src/mesa/main/shader_query.cpp
index b775b4231c2..0a85e183a0c 100644
--- a/src/mesa/main/shader_query.cpp
+++ b/src/mesa/main/shader_query.cpp
@@ -244,9 +244,17 @@ _mesa_longest_attribute_name_length(struct gl_shader_program *shProg)
       if (res->Type == GL_PROGRAM_INPUT &&
           res->StageReferences & (1 << MESA_SHADER_VERTEX)) {
 
-          const size_t length = strlen(RESOURCE_VAR(res)->name);
+         /* From ARB_gl_spirv spec:
+          *   "If pname is ACTIVE_ATTRIBUTE_MAX_LENGTH, the length of the
+          *    longest active attribute name, including a null terminator, is
+          *    returned.  If no active attributes exist, zero is returned. If
+          *    no name reflection information is available, one is returned."
+          */
+          const size_t length = RESOURCE_VAR(res)->name != NULL ?
+             strlen(RESOURCE_VAR(res)->name) : 1;
+
           if (length >= longest)
-             longest = length + 1;
+             longest = RESOURCE_VAR(res)->name != NULL ? length + 1 : length;
       }
    }
 
diff --git a/src/mesa/main/shaderapi.c b/src/mesa/main/shaderapi.c
index 2ea8d965aba..3e532c1b41e 100644
--- a/src/mesa/main/shaderapi.c
+++ b/src/mesa/main/shaderapi.c
@@ -728,11 +728,22 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname,
          if (shProg->data->UniformStorage[i].is_shader_storage)
             continue;
 
+         /* From ARB_gl_spirv spec:
+          *   "If pname is ACTIVE_UNIFORM_MAX_LENGTH, the length of the
+          *    longest active uniform name, including a null terminator, is
+          *    returned. If no active uniforms exist, zero is returned. If no
+          *    name reflection information is available, one is returned."
+          *
+          * We are setting 0 here, as below it will add 1 for the NUL character.
+          */
+         const GLint base_len = shProg->data->UniformStorage[i].name != NULL ?
+            strlen(shProg->data->UniformStorage[i].name) : 0;
+
 	 /* Add one for the terminating NUL character for a non-array, and
 	  * 4 for the "[0]" and the NUL for an array.
 	  */
-         const GLint len = strlen(shProg->data->UniformStorage[i].name) + 1 +
-             ((shProg->data->UniformStorage[i].array_elements != 0) ? 3 : 0);
+         const GLint len = base_len + 1 +
+            ((shProg->data->UniformStorage[i].array_elements != 0) ? 3 : 0);
 
 	 if (len > max_len)
 	    max_len = len;
@@ -810,9 +821,16 @@ get_programiv(struct gl_context *ctx, GLuint program, GLenum pname,
          break;
 
       for (i = 0; i < shProg->data->NumUniformBlocks; i++) {
-	 /* Add one for the terminating NUL character.
+	 /* Add one for the terminating NUL character. Name can be NULL, in
+          * that case, from ARB_gl_spirv:
+          *   "If pname is ACTIVE_UNIFORM_BLOCK_MAX_NAME_LENGTH, the length of
+          *    the longest active uniform block name, including the null
+          *    terminator, is returned. If no active uniform blocks exist,
+          *    zero is returned. If no name reflection information is
+          *    available, one is returned."
 	  */
-         const GLint len = strlen(shProg->data->UniformBlocks[i].Name) + 1;
+         const GLint len = shProg->data->UniformBlocks[i].Name ?
+            strlen(shProg->data->UniformBlocks[i].Name) + 1 : 1;
 
 	 if (len > max_len)
 	    max_len = len;
-- 
2.14.1



More information about the mesa-dev mailing list