Mesa (master): glsl: error check max user assignable uniform locations

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Apr 18 12:15:31 UTC 2020


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

Author: Timothy Arceri <tarceri at itsqueeze.com>
Date:   Fri Mar  6 10:27:44 2020 +1100

glsl: error check max user assignable uniform locations

This adds the error check to the NIR uniform linker.

Reviewed-by: Alejandro Piñeiro <apinheiro at igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4623>

---

 src/compiler/glsl/gl_nir_link_uniforms.c | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/src/compiler/glsl/gl_nir_link_uniforms.c b/src/compiler/glsl/gl_nir_link_uniforms.c
index 69d7aa57022..de168eb1a3a 100644
--- a/src/compiler/glsl/gl_nir_link_uniforms.c
+++ b/src/compiler/glsl/gl_nir_link_uniforms.c
@@ -48,6 +48,8 @@ static void
 nir_setup_uniform_remap_tables(struct gl_context *ctx,
                                struct gl_shader_program *prog)
 {
+   unsigned total_entries = prog->NumExplicitUniformLocations;
+
    /* For glsl this may have been allocated by reserve_explicit_locations() so
     * that we can keep track of unused uniforms with explicit locations.
     */
@@ -122,6 +124,13 @@ nir_setup_uniform_remap_tables(struct gl_context *ctx,
       /* How many entries for this uniform? */
       const unsigned entries = MAX2(1, uniform->array_elements);
 
+      /* Add new entries to the total amount for checking against MAX_UNIFORM-
+       * _LOCATIONS. This only applies to the default uniform block (-1),
+       * because locations of uniform block entries are not assignable.
+       */
+      if (prog->data->UniformStorage[i].block_index == -1)
+         total_entries += entries;
+
       unsigned location =
          link_util_find_empty_block(prog, &prog->data->UniformStorage[i]);
 
@@ -155,6 +164,15 @@ nir_setup_uniform_remap_tables(struct gl_context *ctx,
       }
    }
 
+   /* Verify that total amount of entries for explicit and implicit locations
+    * is less than MAX_UNIFORM_LOCATIONS.
+    */
+   if (total_entries > ctx->Const.MaxUserAssignableUniformLocations) {
+      linker_error(prog, "count of uniform locations > MAX_UNIFORM_LOCATIONS"
+                   "(%u > %u)", total_entries,
+                   ctx->Const.MaxUserAssignableUniformLocations);
+   }
+
    /* Reserve all the explicit locations of the active subroutine uniforms. */
    for (unsigned i = 0; i < prog->data->NumUniformStorage; i++) {
       struct gl_uniform_storage *uniform = &prog->data->UniformStorage[i];



More information about the mesa-commit mailing list