From 5c4289dd4b3f37bc5b23b24069ee1137a6c1fa32 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 5 Jun 2019 15:15:07 -0700 Subject: [PATCH] freedreno: Only upload the used part of UBO0 to the constant buffer. We were pessimistically uploading all of it in case of indirection, but we can just bump that when we encounter indirection. total constlen in shared programs: 2529623 -> 2485933 (-1.73%) Reviewed-by: Kristian H. Kristensen Reviewed-by: Rob Clark --- src/freedreno/ir3/ir3_compiler_nir.c | 3 ++- src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c | 15 +++++++++++---- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/src/freedreno/ir3/ir3_compiler_nir.c b/src/freedreno/ir3/ir3_compiler_nir.c index e453f33fb91..d84c56b0195 100644 --- a/src/freedreno/ir3/ir3_compiler_nir.c +++ b/src/freedreno/ir3/ir3_compiler_nir.c @@ -1262,7 +1262,8 @@ emit_intrinsic(struct ir3_context *ctx, nir_intrinsic_instr *intr) * since we don't know in the assembler what the max * addr reg value can be: */ - ctx->so->constlen = MAX2(ctx->so->constlen, ctx->s->num_uniforms); + ctx->so->constlen = MAX2(ctx->so->constlen, + ctx->so->shader->ubo_state.size / 16); } break; case nir_intrinsic_load_ubo: diff --git a/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c b/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c index 46216a6f862..b3191a36c14 100644 --- a/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c +++ b/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c @@ -42,14 +42,22 @@ get_ubo_load_range(nir_intrinsic_instr *instr) } static void -gather_ubo_ranges(nir_intrinsic_instr *instr, +gather_ubo_ranges(nir_shader *nir, nir_intrinsic_instr *instr, struct ir3_ubo_analysis_state *state) { if (!nir_src_is_const(instr->src[0])) return; - if (!nir_src_is_const(instr->src[1])) + if (!nir_src_is_const(instr->src[1])) { + if (nir_src_as_uint(instr->src[0]) == 0) { + /* If this is an indirect on UBO 0, we'll still lower it back to + * load_uniform. Set the range to cover all of UBO 0. + */ + state->range[0].end = align(nir->num_uniforms * 16, 16 * 4); + } + return; + } const struct ir3_ubo_range r = get_ubo_load_range(instr); const uint32_t block = nir_src_as_uint(instr->src[0]); @@ -132,7 +140,6 @@ ir3_nir_analyze_ubo_ranges(nir_shader *nir, struct ir3_shader *shader) struct ir3_ubo_analysis_state *state = &shader->ubo_state; memset(state, 0, sizeof(*state)); - state->range[0].end = align(nir->num_uniforms * 16, 16 * 4); /* align to 4*vec4 */ nir_foreach_function(function, nir) { if (function->impl) { @@ -140,7 +147,7 @@ ir3_nir_analyze_ubo_ranges(nir_shader *nir, struct ir3_shader *shader) nir_foreach_instr(instr, block) { if (instr->type == nir_instr_type_intrinsic && nir_instr_as_intrinsic(instr)->intrinsic == nir_intrinsic_load_ubo) - gather_ubo_ranges(nir_instr_as_intrinsic(instr), state); + gather_ubo_ranges(nir, nir_instr_as_intrinsic(instr), state); } } } -- 2.30.2