mesa/shader_query: Fix NAME_LENGTH queries (ARB_gl_spirv)
authorAntia Puentes <apuentes@igalia.com>
Mon, 13 Aug 2018 16:48:37 +0000 (18:48 +0200)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Fri, 12 Jul 2019 21:42:41 +0000 (23:42 +0200)
For shaders constructed from SPIR-V binaries, it is possible that
no name reflection information is available. In that case,

 - glGetProgramInterfaceiv(.., pname=MAX_NAME_LENGTH, ..)
 - gletProgramResourceiv(.., props=NAME_LENGTH, ..)

should return 1.

Signed-off-by: Antia Puentes <apuentes@igalia.com>
Signed-off-by: Andres Gomez <agomez@igalia.com>
Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
src/mesa/main/shader_query.cpp

index 3fcd4fcedc5bbb0e8bc7eef8c787d860eea307cb..a3365107648291bd1b47e2b3d36f11e8da216760 100644 (file)
@@ -778,7 +778,15 @@ add_index_to_name(struct gl_program_resource *res)
 extern unsigned
 _mesa_program_resource_name_len(struct gl_program_resource *res)
 {
-   unsigned length = strlen(_mesa_program_resource_name(res));
+   const char* name = _mesa_program_resource_name(res);
+
+   /* For shaders constructed from SPIR-V binaries, variables may not
+    * have names associated with them.
+    */
+   if (!name)
+      return 0;
+
+   unsigned length = strlen(name);
    if (_mesa_program_resource_array_size(res) && add_index_to_name(res))
       length += 3;
    return length;
@@ -819,7 +827,11 @@ _mesa_get_program_resource_name(struct gl_shader_program *shProg,
 
    _mesa_copy_string(name, bufSize, length, _mesa_program_resource_name(res));
 
-   if (_mesa_program_resource_array_size(res) && add_index_to_name(res)) {
+   /* The resource name can be NULL for shaders constructed from SPIR-V
+    * binaries. In that case, we do not add the '[0]'.
+    */
+   if (name && name[0] != '\0' &&
+       _mesa_program_resource_array_size(res) && add_index_to_name(res)) {
       int i;
 
       /* The comparison is strange because *length does *NOT* include the