glsl: add subroutine support to nir_build_program_resource_list()
authorTimothy Arceri <tarceri@itsqueeze.com>
Wed, 23 Oct 2019 02:43:34 +0000 (13:43 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Fri, 13 Dec 2019 00:07:19 +0000 (00:07 +0000)
This is required so we can use the NIR linker to link GLSL in
addition to spirv.

Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
src/compiler/glsl/gl_nir_linker.c

index b6ad926bf582981dcd8bd21c6e6e157fbc1c357b..2664942662a918d0aa6fbc46b7eabe71582446f1 100644 (file)
@@ -26,6 +26,7 @@
 #include "gl_nir_linker.h"
 #include "linker_util.h"
 #include "main/mtypes.h"
+#include "main/shaderobj.h"
 #include "ir_uniform.h" /* for gl_uniform_storage */
 
 /* This file included general link methods, using NIR, instead of IR as
@@ -475,9 +476,22 @@ nir_build_program_resource_list(struct gl_context *ctx,
    for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
       struct gl_uniform_storage *uniform = &prog->data->UniformStorage[i];
 
-      /* Do not add uniforms internally used by Mesa. */
-      if (uniform->hidden)
+      if (uniform->hidden) {
+         for (int j = MESA_SHADER_VERTEX; j < MESA_SHADER_STAGES; j++) {
+            if (!uniform->opaque[j].active ||
+                glsl_get_base_type(uniform->type) != GLSL_TYPE_SUBROUTINE)
+               continue;
+
+            GLenum type =
+               _mesa_shader_stage_to_subroutine_uniform((gl_shader_stage)j);
+            /* add shader subroutines */
+            if (!link_util_add_program_resource(prog, resource_set,
+                                                type, uniform, 0))
+               return;
+         }
+
          continue;
+      }
 
       if (!link_util_should_add_buffer_variable(prog, uniform,
                                                 top_level_array_base_offset,
@@ -533,6 +547,21 @@ nir_build_program_resource_list(struct gl_context *ctx,
          return;
    }
 
+   unsigned mask = prog->data->linked_stages;
+   while (mask) {
+      const int i = u_bit_scan(&mask);
+      struct gl_program *p = prog->_LinkedShaders[i]->Program;
+
+      GLuint type = _mesa_shader_stage_to_subroutine((gl_shader_stage)i);
+      for (unsigned j = 0; j < p->sh.NumSubroutineFunctions; j++) {
+         if (!link_util_add_program_resource(prog, resource_set,
+                                             type,
+                                             &p->sh.SubroutineFunctions[j],
+                                             0))
+            return;
+      }
+   }
+
    _mesa_set_destroy(resource_set, NULL);
 }