compiler/glsl: explicitly store NumUniformBlocks
authorErik Faye-Lund <erik.faye-lund@collabora.com>
Tue, 28 Apr 2020 11:28:16 +0000 (13:28 +0200)
committerMarge Bot <eric+marge@anholt.net>
Tue, 5 May 2020 09:17:51 +0000 (09:17 +0000)
It's not great to use shader_info for this information, because it
might have gone through lowering of uniforms to UBOs, which can change
the number of UBOs. So let's make sure we know the size of the
UniformBlocks array from when the shader was linked instead.

Reviewed-by: Alyssa Rosenzweig <alyssa@collabora.com>
Reviewed-by: Eric Anholt <eric@anholt.net>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4734>

src/compiler/glsl/gl_nir_link_uniform_blocks.c
src/compiler/glsl/linker.cpp
src/compiler/glsl/serialize.cpp
src/mesa/main/mtypes.h

index 53f03fe2a80e5b5164e9e7ed7287068a55dda022..07f1614a40c99322b673127f4aa9c42045d8975a 100644 (file)
@@ -302,8 +302,10 @@ nir_interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog,
 
    if (block_type == BLOCK_SSBO)
       prog->data->ShaderStorageBlocks = blks;
-   else
+   else {
+      prog->data->NumUniformBlocks = *num_blks;
       prog->data->UniformBlocks = blks;
+   }
 
    return true;
 }
@@ -610,6 +612,7 @@ gl_nir_link_uniform_blocks(struct gl_context *ctx,
       linked->Program->sh.UniformBlocks =
          ralloc_array(linked, struct gl_uniform_block *, num_ubo_blocks);
       ralloc_steal(linked, ubo_blocks);
+      linked->Program->sh.NumUniformBlocks = num_ubo_blocks;
       for (unsigned i = 0; i < num_ubo_blocks; i++) {
          linked->Program->sh.UniformBlocks[i] = &ubo_blocks[i];
       }
index b3175090c717c3dc5199531b00cb34d413edd494..a49c5e6ccc201dcc29ac7a0f0ae13019f3d66365 100644 (file)
@@ -2568,6 +2568,7 @@ link_intrastage_shaders(void *mem_ctx,
    for (unsigned i = 0; i < num_ubo_blocks; i++) {
       linked->Program->sh.UniformBlocks[i] = &ubo_blocks[i];
    }
+   linked->Program->sh.NumUniformBlocks = num_ubo_blocks;
    linked->Program->info.num_ubos = num_ubo_blocks;
 
    /* Copy ssbo blocks to linked shader list */
index d4aacc1cb95b40933a0cc3068626a40a3152f6c3..2f68d1b97853ed20ca3f9f52a9e85032cdfec686 100644 (file)
@@ -139,10 +139,10 @@ write_buffer_blocks(struct blob *metadata, struct gl_shader_program *prog)
 
       struct gl_program *glprog = sh->Program;
 
-      blob_write_uint32(metadata, glprog->info.num_ubos);
+      blob_write_uint32(metadata, glprog->sh.NumUniformBlocks);
       blob_write_uint32(metadata, glprog->info.num_ssbos);
 
-      for (unsigned j = 0; j < glprog->info.num_ubos; j++) {
+      for (unsigned j = 0; j < glprog->sh.NumUniformBlocks; j++) {
          uint32_t offset =
             glprog->sh.UniformBlocks[j] - prog->data->UniformBlocks;
          blob_write_uint32(metadata, offset);
@@ -215,15 +215,15 @@ read_buffer_blocks(struct blob_reader *metadata,
 
       struct gl_program *glprog = sh->Program;
 
-      glprog->info.num_ubos = blob_read_uint32(metadata);
+      glprog->sh.NumUniformBlocks = blob_read_uint32(metadata);
       glprog->info.num_ssbos = blob_read_uint32(metadata);
 
       glprog->sh.UniformBlocks =
-         rzalloc_array(glprog, gl_uniform_block *, glprog->info.num_ubos);
+         rzalloc_array(glprog, gl_uniform_block *, glprog->sh.NumUniformBlocks);
       glprog->sh.ShaderStorageBlocks =
          rzalloc_array(glprog, gl_uniform_block *, glprog->info.num_ssbos);
 
-      for (unsigned j = 0; j < glprog->info.num_ubos; j++) {
+      for (unsigned j = 0; j < glprog->sh.NumUniformBlocks; j++) {
          uint32_t offset = blob_read_uint32(metadata);
          glprog->sh.UniformBlocks[j] = prog->data->UniformBlocks + offset;
       }
index e334de0672dc53349b9d507181b508d48717b162..a46eb72da9ae7be2b1baa3b90851dcf78d058e66 100644 (file)
@@ -2182,6 +2182,7 @@ struct gl_program
           */
          GLenum16 ImageAccess[MAX_IMAGE_UNIFORMS];
 
+         GLuint NumUniformBlocks;
          struct gl_uniform_block **UniformBlocks;
          struct gl_uniform_block **ShaderStorageBlocks;