[Mesa-dev] [PATCH 07/53] st/mesa/glsl/i965: move per stage UniformBlocks to gl_program

Lionel Landwerlin lionel.g.landwerlin at intel.com
Tue Jan 3 17:14:37 UTC 2017


Reviewed-by: Lionel Landwerlin <lionel.g.landwerlin at intel.com>

On 03/01/17 02:43, Timothy Arceri wrote:
> This will help allow us to store pointers to gl_program structs in the
> CurrentProgram array resulting in a bunch of code simplifications.
> ---
>   src/compiler/glsl/link_uniforms.cpp              |  4 ++--
>   src/compiler/glsl/linker.cpp                     |  8 ++++----
>   src/compiler/glsl/lower_ubo_reference.cpp        |  2 +-
>   src/mesa/drivers/dri/i965/brw_wm_surface_state.c |  2 +-
>   src/mesa/main/mtypes.h                           |  4 ++--
>   src/mesa/state_tracker/st_atom_constbuf.c        |  2 +-
>   src/mesa/state_tracker/st_glsl_to_tgsi.cpp       | 18 ++++++++----------
>   7 files changed, 19 insertions(+), 21 deletions(-)
>
> diff --git a/src/compiler/glsl/link_uniforms.cpp b/src/compiler/glsl/link_uniforms.cpp
> index fd8331b..f614b9a 100644
> --- a/src/compiler/glsl/link_uniforms.cpp
> +++ b/src/compiler/glsl/link_uniforms.cpp
> @@ -903,7 +903,7 @@ link_update_uniform_buffer_variables(struct gl_linked_shader *shader,
>         unsigned num_blocks = var->data.mode == ir_var_uniform ?
>            shader->Program->info.num_ubos : shader->NumShaderStorageBlocks;
>         struct gl_uniform_block **blks = var->data.mode == ir_var_uniform ?
> -         shader->UniformBlocks : shader->ShaderStorageBlocks;
> +         shader->Program->sh.UniformBlocks : shader->ShaderStorageBlocks;
>   
>         if (var->is_interface_instance()) {
>            const ir_array_refcount_entry *const entry = v.get_variable_entry(var);
> @@ -1332,7 +1332,7 @@ link_assign_uniform_locations(struct gl_shader_program *prog,
>   
>         for (unsigned i = 0; i < sh->Program->info.num_ubos; i++) {
>            sh->num_combined_uniform_components +=
> -            sh->UniformBlocks[i]->UniformBufferSize / 4;
> +            sh->Program->sh.UniformBlocks[i]->UniformBufferSize / 4;
>         }
>      }
>   
> diff --git a/src/compiler/glsl/linker.cpp b/src/compiler/glsl/linker.cpp
> index e5bd235..1c06034 100644
> --- a/src/compiler/glsl/linker.cpp
> +++ b/src/compiler/glsl/linker.cpp
> @@ -1162,7 +1162,7 @@ interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog,
>            sh_blks = sh->ShaderStorageBlocks;
>         } else {
>            sh_num_blocks = prog->_LinkedShaders[i]->Program->info.num_ubos;
> -         sh_blks = sh->UniformBlocks;
> +         sh_blks = sh->Program->sh.UniformBlocks;
>         }
>   
>         for (unsigned int j = 0; j < sh_num_blocks; j++) {
> @@ -1194,7 +1194,7 @@ interstage_cross_validate_uniform_blocks(struct gl_shader_program *prog,
>               struct gl_linked_shader *sh = prog->_LinkedShaders[i];
>   
>               struct gl_uniform_block **sh_blks = validate_ssbo ?
> -               sh->ShaderStorageBlocks : sh->UniformBlocks;
> +               sh->ShaderStorageBlocks : sh->Program->sh.UniformBlocks;
>   
>               blks[j].stageref |= sh_blks[stage_index]->stageref;
>               sh_blks[stage_index] = &blks[j];
> @@ -2272,11 +2272,11 @@ link_intrastage_shaders(void *mem_ctx,
>      }
>   
>      /* Copy ubo blocks to linked shader list */
> -   linked->UniformBlocks =
> +   linked->Program->sh.UniformBlocks =
>         ralloc_array(linked, gl_uniform_block *, num_ubo_blocks);
>      ralloc_steal(linked, ubo_blocks);
>      for (unsigned i = 0; i < num_ubo_blocks; i++) {
> -      linked->UniformBlocks[i] = &ubo_blocks[i];
> +      linked->Program->sh.UniformBlocks[i] = &ubo_blocks[i];
>      }
>      linked->Program->info.num_ubos = num_ubo_blocks;
>   
> diff --git a/src/compiler/glsl/lower_ubo_reference.cpp b/src/compiler/glsl/lower_ubo_reference.cpp
> index 985ecea..5beda45 100644
> --- a/src/compiler/glsl/lower_ubo_reference.cpp
> +++ b/src/compiler/glsl/lower_ubo_reference.cpp
> @@ -293,7 +293,7 @@ lower_ubo_reference_visitor::setup_for_load_or_store(void *mem_ctx,
>         blocks = shader->ShaderStorageBlocks;
>      } else {
>         num_blocks = shader->Program->info.num_ubos;
> -      blocks = shader->UniformBlocks;
> +      blocks = shader->Program->sh.UniformBlocks;
>      }
>      this->uniform_block = NULL;
>      for (unsigned i = 0; i < num_blocks; i++) {
> diff --git a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
> index e3a6033..2140312 100644
> --- a/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
> +++ b/src/mesa/drivers/dri/i965/brw_wm_surface_state.c
> @@ -1385,7 +1385,7 @@ brw_upload_ubo_surfaces(struct brw_context *brw,
>   
>      for (int i = 0; i < shader->Program->info.num_ubos; i++) {
>         struct gl_uniform_buffer_binding *binding =
> -         &ctx->UniformBufferBindings[shader->UniformBlocks[i]->Binding];
> +         &ctx->UniformBufferBindings[shader->Program->sh.UniformBlocks[i]->Binding];
>   
>         if (binding->BufferObject == ctx->Shared->NullBufferObj) {
>            brw->vtbl.emit_null_surface_state(brw, 1, 1, 1, &ubo_surf_offsets[i]);
> diff --git a/src/mesa/main/mtypes.h b/src/mesa/main/mtypes.h
> index 2352bb2..6ddd695 100644
> --- a/src/mesa/main/mtypes.h
> +++ b/src/mesa/main/mtypes.h
> @@ -1999,6 +1999,8 @@ struct gl_program
>             */
>            GLenum ImageAccess[MAX_IMAGE_UNIFORMS];
>   
> +         struct gl_uniform_block **UniformBlocks;
> +
>            union {
>               struct {
>                  /**
> @@ -2382,8 +2384,6 @@ struct gl_linked_shader
>       */
>      unsigned num_combined_uniform_components;
>   
> -   struct gl_uniform_block **UniformBlocks;
> -
>      unsigned NumShaderStorageBlocks;
>      struct gl_uniform_block **ShaderStorageBlocks;
>   
> diff --git a/src/mesa/state_tracker/st_atom_constbuf.c b/src/mesa/state_tracker/st_atom_constbuf.c
> index 30bffa6..45bb885 100644
> --- a/src/mesa/state_tracker/st_atom_constbuf.c
> +++ b/src/mesa/state_tracker/st_atom_constbuf.c
> @@ -252,7 +252,7 @@ static void st_bind_ubos(struct st_context *st,
>         struct gl_uniform_buffer_binding *binding;
>         struct st_buffer_object *st_obj;
>   
> -      binding = &st->ctx->UniformBufferBindings[shader->UniformBlocks[i]->Binding];
> +      binding = &st->ctx->UniformBufferBindings[shader->Program->sh.UniformBlocks[i]->Binding];
>         st_obj = st_buffer_object(binding->BufferObject);
>   
>         cb.buffer = st_obj->buffer;
> diff --git a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> index 7d61b6a..e06c958 100644
> --- a/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> +++ b/src/mesa/state_tracker/st_glsl_to_tgsi.cpp
> @@ -6277,16 +6277,14 @@ st_translate_program(
>         }
>      }
>   
> -   if (program->shader) {
> -      for (i = 0; i < proginfo->info.num_ubos; i++) {
> -         unsigned size = program->shader->UniformBlocks[i]->UniformBufferSize;
> -         unsigned num_const_vecs = (size + 15) / 16;
> -         unsigned first, last;
> -         assert(num_const_vecs > 0);
> -         first = 0;
> -         last = num_const_vecs > 0 ? num_const_vecs - 1 : 0;
> -         ureg_DECL_constant2D(t->ureg, first, last, i + 1);
> -      }
> +   for (i = 0; i < proginfo->info.num_ubos; i++) {
> +      unsigned size = proginfo->sh.UniformBlocks[i]->UniformBufferSize;
> +      unsigned num_const_vecs = (size + 15) / 16;
> +      unsigned first, last;
> +      assert(num_const_vecs > 0);
> +      first = 0;
> +      last = num_const_vecs > 0 ? num_const_vecs - 1 : 0;
> +      ureg_DECL_constant2D(t->ureg, first, last, i + 1);
>      }
>   
>      /* Emit immediate values.




More information about the mesa-dev mailing list