Mesa (master): glsl: add check_image_resources() for the nir linker

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Mon Jan 6 23:11:26 UTC 2020


Module: Mesa
Branch: master
Commit: feffd1fa65d36e34499f29b39f8b18655c2b979f
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=feffd1fa65d36e34499f29b39f8b18655c2b979f

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Fri Jan  3 15:09:20 2020 +1100

glsl: add check_image_resources() for the nir linker

This is adapted from the GLSL IR code but doesn't need to
iterate over the IR. I believe this also fixes a potential bug in
the GLSL IR code which potentially counts the same output twice.

Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>

---

 src/compiler/glsl/gl_nir_linker.c | 38 ++++++++++++++++++++++++++++++++++++++
 1 file changed, 38 insertions(+)

diff --git a/src/compiler/glsl/gl_nir_linker.c b/src/compiler/glsl/gl_nir_linker.c
index 65d3e162a3c..b3832e5629f 100644
--- a/src/compiler/glsl/gl_nir_linker.c
+++ b/src/compiler/glsl/gl_nir_linker.c
@@ -582,6 +582,44 @@ gl_nir_link_spirv(struct gl_context *ctx, struct gl_shader_program *prog,
    return true;
 }
 
+/**
+ * Validate shader image resources.
+ */
+static void
+check_image_resources(struct gl_context *ctx, struct gl_shader_program *prog)
+{
+   unsigned total_image_units = 0;
+   unsigned fragment_outputs = 0;
+   unsigned total_shader_storage_blocks = 0;
+
+   if (!ctx->Extensions.ARB_shader_image_load_store)
+      return;
+
+   for (unsigned i = 0; i < MESA_SHADER_STAGES; i++) {
+      struct gl_linked_shader *sh = prog->_LinkedShaders[i];
+      if (!sh)
+         continue;
+
+      total_image_units += sh->Program->info.num_images;
+      total_shader_storage_blocks += sh->Program->info.num_ssbos;
+   }
+
+   if (total_image_units > ctx->Const.MaxCombinedImageUniforms)
+      linker_error(prog, "Too many combined image uniforms\n");
+
+   struct gl_linked_shader *frag_sh =
+      prog->_LinkedShaders[MESA_SHADER_FRAGMENT];
+   if (frag_sh) {
+      uint64_t frag_outputs_written = frag_sh->Program->info.outputs_written;
+      fragment_outputs = util_bitcount64(frag_outputs_written);
+   }
+
+   if (total_image_units + fragment_outputs + total_shader_storage_blocks >
+       ctx->Const.MaxCombinedShaderOutputResources)
+      linker_error(prog, "Too many combined image uniforms, shader storage "
+                         " buffers and fragment outputs\n");
+}
+
 bool
 gl_nir_link_glsl(struct gl_context *ctx, struct gl_shader_program *prog)
 {




More information about the mesa-commit mailing list