glsl: move calculate_subroutine_compat() to shared linker code
authorTimothy Arceri <tarceri@itsqueeze.com>
Tue, 7 Jan 2020 02:43:05 +0000 (13:43 +1100)
committerTimothy Arceri <tarceri@itsqueeze.com>
Fri, 10 Jan 2020 00:41:20 +0000 (00:41 +0000)
We will make use of this in the nir linker in the following patch.

Reviewed-by: Tapani Pälli <tapani.palli@intel.com>
src/compiler/glsl/linker.cpp
src/compiler/glsl/linker_util.cpp
src/compiler/glsl/linker_util.h

index ce0ab7ac32232e846e3f7c28313e8f03bb7b1c89..ef77389add4ec377af3544ca4ddcea6a44296503 100644 (file)
@@ -3321,42 +3321,6 @@ store_fragdepth_layout(struct gl_shader_program *prog)
    }
 }
 
-static void
-link_calculate_subroutine_compat(struct gl_shader_program *prog)
-{
-   unsigned mask = prog->data->linked_stages;
-   while (mask) {
-      const int i = u_bit_scan(&mask);
-      struct gl_program *p = prog->_LinkedShaders[i]->Program;
-
-      for (unsigned j = 0; j < p->sh.NumSubroutineUniformRemapTable; j++) {
-         if (p->sh.SubroutineUniformRemapTable[j] == INACTIVE_UNIFORM_EXPLICIT_LOCATION)
-            continue;
-
-         struct gl_uniform_storage *uni = p->sh.SubroutineUniformRemapTable[j];
-
-         if (!uni)
-            continue;
-
-         int count = 0;
-         if (p->sh.NumSubroutineFunctions == 0) {
-            linker_error(prog, "subroutine uniform %s defined but no valid functions found\n", uni->type->name);
-            continue;
-         }
-         for (unsigned f = 0; f < p->sh.NumSubroutineFunctions; f++) {
-            struct gl_subroutine_function *fn = &p->sh.SubroutineFunctions[f];
-            for (int k = 0; k < fn->num_compat_types; k++) {
-               if (fn->types[k] == uni->type) {
-                  count++;
-                  break;
-               }
-            }
-         }
-         uni->num_compatible_subroutines = count;
-      }
-   }
-}
-
 /**
  * Validate shader image resources.
  */
@@ -4440,7 +4404,7 @@ link_and_validate_uniforms(struct gl_context *ctx,
    if (prog->data->LinkStatus == LINKING_FAILURE)
       return;
 
-   link_calculate_subroutine_compat(prog);
+   link_util_calculate_subroutine_compat(prog);
 
    if (!ctx->Const.UseNIRGLSLLinker) {
       link_util_check_uniform_resources(ctx, prog);
index bd4043df2dbdb70c197ed1f535b98c189ddbb04c..80c9f2872f98dec34c48b83b92c8683680704013 100644 (file)
@@ -22,6 +22,7 @@
  *
  */
 #include "main/mtypes.h"
+#include "glsl_types.h"
 #include "linker_util.h"
 #include "util/bitscan.h"
 #include "util/set.h"
@@ -250,3 +251,39 @@ link_util_check_uniform_resources(struct gl_context *ctx,
       }
    }
 }
+
+void
+link_util_calculate_subroutine_compat(struct gl_shader_program *prog)
+{
+   unsigned mask = prog->data->linked_stages;
+   while (mask) {
+      const int i = u_bit_scan(&mask);
+      struct gl_program *p = prog->_LinkedShaders[i]->Program;
+
+      for (unsigned j = 0; j < p->sh.NumSubroutineUniformRemapTable; j++) {
+         if (p->sh.SubroutineUniformRemapTable[j] == INACTIVE_UNIFORM_EXPLICIT_LOCATION)
+            continue;
+
+         struct gl_uniform_storage *uni = p->sh.SubroutineUniformRemapTable[j];
+
+         if (!uni)
+            continue;
+
+         int count = 0;
+         if (p->sh.NumSubroutineFunctions == 0) {
+            linker_error(prog, "subroutine uniform %s defined but no valid functions found\n", uni->type->name);
+            continue;
+         }
+         for (unsigned f = 0; f < p->sh.NumSubroutineFunctions; f++) {
+            struct gl_subroutine_function *fn = &p->sh.SubroutineFunctions[f];
+            for (int k = 0; k < fn->num_compat_types; k++) {
+               if (fn->types[k] == uni->type) {
+                  count++;
+                  break;
+               }
+            }
+         }
+         uni->num_compatible_subroutines = count;
+      }
+   }
+}
index 7d355d10659a46932bb414eb714acd5b58cb2b35..53e0ca315a53598e38fff1c5e17dcf29b5d48e32 100644 (file)
@@ -78,6 +78,9 @@ void
 link_util_check_uniform_resources(struct gl_context *ctx,
                                   struct gl_shader_program *prog);
 
+void
+link_util_calculate_subroutine_compat(struct gl_shader_program *prog);
+
 #ifdef __cplusplus
 }
 #endif