From 231333a20d88336cd0474c573b46a2509b43245e Mon Sep 17 00:00:00 2001 From: Timothy Arceri Date: Fri, 9 Mar 2018 12:30:01 +1100 Subject: [PATCH] st: add uniform packing support to lower_uniforms_to_ubo() MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Reviewed-by: Marek Olšák --- src/mesa/state_tracker/st_glsl_to_nir.cpp | 2 +- src/mesa/state_tracker/st_nir.h | 3 ++- .../state_tracker/st_nir_lower_uniforms_to_ubo.c | 16 +++++++++++----- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/mesa/state_tracker/st_glsl_to_nir.cpp b/src/mesa/state_tracker/st_glsl_to_nir.cpp index 2ca64231e0d..9006650517b 100644 --- a/src/mesa/state_tracker/st_glsl_to_nir.cpp +++ b/src/mesa/state_tracker/st_glsl_to_nir.cpp @@ -762,7 +762,7 @@ st_finalize_nir(struct st_context *st, struct gl_program *prog, PIPE_SHADER_CAP_MAX_INSTRUCTIONS) > 0) { NIR_PASS_V(nir, nir_lower_io, nir_var_uniform, type_size, (nir_lower_io_options)0); - NIR_PASS_V(nir, st_nir_lower_uniforms_to_ubo); + NIR_PASS_V(nir, st_nir_lower_uniforms_to_ubo, prog->Parameters); } if (screen->get_param(screen, PIPE_CAP_NIR_SAMPLERS_AS_DEREF)) diff --git a/src/mesa/state_tracker/st_nir.h b/src/mesa/state_tracker/st_nir.h index 1c2e32a5e6f..3dd78fb1155 100644 --- a/src/mesa/state_tracker/st_nir.h +++ b/src/mesa/state_tracker/st_nir.h @@ -36,7 +36,8 @@ struct nir_shader; void st_nir_lower_builtin(struct nir_shader *shader); void st_nir_lower_tex_src_plane(struct nir_shader *shader, unsigned free_slots, unsigned lower_2plane, unsigned lower_3plane); -bool st_nir_lower_uniforms_to_ubo(struct nir_shader *shader); +bool st_nir_lower_uniforms_to_ubo(struct nir_shader *shader, + const struct gl_program_parameter_list *params); void st_finalize_nir(struct st_context *st, struct gl_program *prog, struct gl_shader_program *shader_program, diff --git a/src/mesa/state_tracker/st_nir_lower_uniforms_to_ubo.c b/src/mesa/state_tracker/st_nir_lower_uniforms_to_ubo.c index 1d2cca065b8..e2a477ecc74 100644 --- a/src/mesa/state_tracker/st_nir_lower_uniforms_to_ubo.c +++ b/src/mesa/state_tracker/st_nir_lower_uniforms_to_ubo.c @@ -33,8 +33,11 @@ #include "nir_builder.h" #include "st_nir.h" +#include "program/prog_parameter.h" + static bool -lower_instr(nir_intrinsic_instr *instr, nir_builder *b) +lower_instr(nir_intrinsic_instr *instr, nir_builder *b, + const struct gl_program_parameter_list *params) { b->cursor = nir_before_instr(&instr->instr); @@ -47,10 +50,12 @@ lower_instr(nir_intrinsic_instr *instr, nir_builder *b) } if (instr->intrinsic == nir_intrinsic_load_uniform) { + unsigned pvo = params->ParameterValueOffset[nir_intrinsic_base(instr)]; + nir_ssa_def *ubo_idx = nir_imm_int(b, 0); nir_ssa_def *ubo_offset = - nir_imul(b, nir_imm_int(b, 16), - nir_iadd(b, nir_imm_int(b, nir_intrinsic_base(instr)), + nir_iadd(b, nir_imm_int(b, 4 * pvo), + nir_imul(b, nir_imm_int(b, 4), nir_ssa_for_src(b, instr->src[0], 1))); nir_intrinsic_instr *load = @@ -72,7 +77,8 @@ lower_instr(nir_intrinsic_instr *instr, nir_builder *b) } bool -st_nir_lower_uniforms_to_ubo(nir_shader *shader) +st_nir_lower_uniforms_to_ubo(nir_shader *shader, + const struct gl_program_parameter_list *params) { bool progress = false; @@ -84,7 +90,7 @@ st_nir_lower_uniforms_to_ubo(nir_shader *shader) nir_foreach_instr_safe(instr, block) { if (instr->type == nir_instr_type_intrinsic) progress |= lower_instr(nir_instr_as_intrinsic(instr), - &builder); + &builder, params); } } -- 2.30.2