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 <hoegsberg@google.com>
Reviewed-by: Rob Clark <robdclark@gmail.com>
This commit is contained in:
Eric Anholt 2019-06-05 15:15:07 -07:00
parent 852704976a
commit 5c4289dd4b
2 changed files with 13 additions and 5 deletions

View File

@ -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:

View File

@ -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);
}
}
}