glsl: fix resizing of the uniform remap table
authorTimothy Arceri <tarceri@itsqueeze.com>
Thu, 6 Feb 2020 01:49:10 +0000 (12:49 +1100)
committerMarge Bot <eric+marge@anholt.net>
Fri, 28 Feb 2020 23:48:46 +0000 (23:48 +0000)
In the NIR linker we were not resizing the remap table correctly
for explicit locations when it was needed.

Reviewed-by: Alejandro PiƱeiro <apinheiro@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/3992>

src/compiler/glsl/gl_nir_link_uniforms.c

index 7196d8b2c1fca2ddc7bfb95afc66fd15906c9fd1..7249829c564197936b2a21028f6366036b10cf9e 100644 (file)
@@ -105,16 +105,20 @@ nir_setup_uniform_remap_tables(struct gl_context *ctx,
       unsigned location =
          link_util_find_empty_block(prog, &prog->data->UniformStorage[i]);
 
-      if (location == -1) {
-         location = prog->NumUniformRemapTable;
+      if (location == -1 || location + entries >= prog->NumUniformRemapTable) {
+         unsigned new_entries = entries;
+         if (location == -1)
+            location = prog->NumUniformRemapTable;
+         else
+            new_entries = location - prog->NumUniformRemapTable + entries;
 
          /* resize remap table to fit new entries */
          prog->UniformRemapTable =
             reralloc(prog,
                      prog->UniformRemapTable,
                      struct gl_uniform_storage *,
-                     prog->NumUniformRemapTable + entries);
-         prog->NumUniformRemapTable += entries;
+                     prog->NumUniformRemapTable + new_entries);
+         prog->NumUniformRemapTable += new_entries;
       }
 
       /* set the base location in remap table for the uniform */