mesa/shader_query: Fix LOCATION_INDEX query (ARB_gl_spirv)
authorAntia Puentes <apuentes@igalia.com>
Fri, 14 Sep 2018 06:55:24 +0000 (08:55 +0200)
committerAlejandro Piñeiro <apinheiro@igalia.com>
Fri, 12 Jul 2019 21:42:41 +0000 (23:42 +0200)
When querying GL_LOCATION_INDEX using glGetProgramResourceiv
we already know the index of the resource, we do not need to find
it using the name, which is convenient for shaders coming from
SPIR-V binaries where names are optional.

Reviewed-by: Caio Marcelo de Oliveira Filho <caio.oliveira@intel.com>
src/mesa/main/shader_query.cpp

index a3365107648291bd1b47e2b3d36f11e8da216760..e9b39b7ff8f496425741caaf11f2f663e5c11225 100644 (file)
@@ -938,17 +938,9 @@ _mesa_program_resource_location(struct gl_shader_program *shProg,
    return program_resource_location(res, array_index);
 }
 
-/**
- * Function implements following index queries:
- *    glGetFragDataIndex
- */
-GLint
-_mesa_program_resource_location_index(struct gl_shader_program *shProg,
-                                      GLenum programInterface, const char *name)
+static GLint
+_get_resource_location_index(struct gl_program_resource *res)
 {
-   struct gl_program_resource *res =
-      _mesa_program_resource_find_name(shProg, programInterface, name, NULL);
-
    /* Non-existent variable or resource is not referenced by fragment stage. */
    if (!res || !(res->StageReferences & (1 << MESA_SHADER_FRAGMENT)))
       return -1;
@@ -963,6 +955,20 @@ _mesa_program_resource_location_index(struct gl_shader_program *shProg,
    return RESOURCE_VAR(res)->index;
 }
 
+/**
+ * Function implements following index queries:
+ *    glGetFragDataIndex
+ */
+GLint
+_mesa_program_resource_location_index(struct gl_shader_program *shProg,
+                                      GLenum programInterface, const char *name)
+{
+   struct gl_program_resource *res =
+      _mesa_program_resource_find_name(shProg, programInterface, name, NULL);
+
+   return _get_resource_location_index(res);
+}
+
 static uint8_t
 stage_from_enum(GLenum ref)
 {
@@ -1320,8 +1326,7 @@ _mesa_program_resource_prop(struct gl_shader_program *shProg,
       if (tmp == -1)
          *val = -1;
       else
-         *val = _mesa_program_resource_location_index(shProg, res->Type,
-                                                      RESOURCE_VAR(res)->name);
+         *val = _get_resource_location_index(res);
       return 1;
    }
    case GL_NUM_COMPATIBLE_SUBROUTINES: