From: Rob Clark Date: Mon, 15 Jun 2020 18:43:36 +0000 (-0700) Subject: freedreno/ir3: un-embed const_state X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=00926954c30aabbb67fe839924e433bd30001c9d;p=mesa.git freedreno/ir3: un-embed const_state Make it an rzalloc'd ptr instead of embedded struct, so it can serve as the mem ctx for immediates. This gets rid of needing to explicitly free the immediates, so one less thing to deal with when moving const_state. (Also, after we move const_state to the shader variant, we won't need one for binning pass variants) Signed-off-by: Rob Clark Part-of: --- diff --git a/src/freedreno/ir3/ir3_assembler.c b/src/freedreno/ir3/ir3_assembler.c index 005f52859a8..e81eda6e9ae 100644 --- a/src/freedreno/ir3/ir3_assembler.c +++ b/src/freedreno/ir3/ir3_assembler.c @@ -37,6 +37,7 @@ ir3_parse_asm(struct ir3_compiler *c, struct ir3_kernel_info *info, FILE *in) struct ir3_shader *shader = rzalloc_size(NULL, sizeof(*shader)); shader->compiler = c; shader->type = MESA_SHADER_COMPUTE; + shader->const_state = rzalloc_size(shader, sizeof(*shader->const_state)); mtx_init(&shader->variants_lock, mtx_plain); struct ir3_shader_variant *v = rzalloc_size(shader, sizeof(*v)); diff --git a/src/freedreno/ir3/ir3_cp.c b/src/freedreno/ir3/ir3_cp.c index a9562af25aa..e739f792cf8 100644 --- a/src/freedreno/ir3/ir3_cp.c +++ b/src/freedreno/ir3/ir3_cp.c @@ -199,9 +199,12 @@ lower_immed(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr, unsigned n, /* Reallocate for 4 more elements whenever it's necessary */ struct ir3_const_state *const_state = ir3_const_state(ctx->so); if (const_state->immediate_idx == const_state->immediates_size * 4) { + const_state->immediates = rerzalloc(const_state, + const_state->immediates, + __typeof__(const_state->immediates[0]), + const_state->immediates_size, + const_state->immediates_size + 4); const_state->immediates_size += 4; - const_state->immediates = realloc (const_state->immediates, - const_state->immediates_size * sizeof(const_state->immediates[0])); for (int i = const_state->immediate_idx; i < const_state->immediates_size * 4; i++) const_state->immediates[i / 4].val[i % 4] = 0xd0d0d0d0; diff --git a/src/freedreno/ir3/ir3_nir.c b/src/freedreno/ir3/ir3_nir.c index 2df5715f51c..de76cb70e55 100644 --- a/src/freedreno/ir3/ir3_nir.c +++ b/src/freedreno/ir3/ir3_nir.c @@ -277,7 +277,7 @@ ir3_optimize_nir(struct ir3_shader *shader, nir_shader *s) * const_state layout setup. This should be done after ubo range * analysis. */ - ir3_setup_const_state(shader, s, &shader->const_state); + ir3_setup_const_state(shader, s, shader->const_state); } void diff --git a/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c b/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c index b41bfe48772..0ae11a3512a 100644 --- a/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c +++ b/src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c @@ -304,7 +304,8 @@ instr_is_load_ubo(nir_instr *instr) bool ir3_nir_analyze_ubo_ranges(nir_shader *nir, struct ir3_shader *shader) { - struct ir3_ubo_analysis_state *state = &shader->const_state.ubo_state; + struct ir3_const_state *const_state = shader->const_state; + struct ir3_ubo_analysis_state *state = &const_state->ubo_state; memset(state, 0, sizeof(*state)); for (int i = 0; i < IR3_MAX_UBO_PUSH_RANGES; i++) { diff --git a/src/freedreno/ir3/ir3_parser.y b/src/freedreno/ir3/ir3_parser.y index 2e89d773fc9..27c52bd21e9 100644 --- a/src/freedreno/ir3/ir3_parser.y +++ b/src/freedreno/ir3/ir3_parser.y @@ -157,9 +157,12 @@ static void add_const(unsigned reg, unsigned c0, unsigned c1, unsigned c2, unsig assert((reg & 0x7) == 0); int idx = reg >> (1 + 2); /* low bit is half vs full, next two bits are swiz */ if (const_state->immediate_idx == const_state->immediates_size * 4) { + const_state->immediates = rerzalloc(const_state, + const_state->immediates, + __typeof__(const_state->immediates[0]), + const_state->immediates_size, + const_state->immediates_size + 4); const_state->immediates_size += 4; - const_state->immediates = realloc (const_state->immediates, - const_state->immediates_size * sizeof(const_state->immediates[0])); } const_state->immediates[idx].val[0] = c0; const_state->immediates[idx].val[1] = c1; diff --git a/src/freedreno/ir3/ir3_shader.c b/src/freedreno/ir3/ir3_shader.c index c7d06a99fc2..66f72c98dc1 100644 --- a/src/freedreno/ir3/ir3_shader.c +++ b/src/freedreno/ir3/ir3_shader.c @@ -271,7 +271,6 @@ ir3_shader_get_variant(struct ir3_shader *shader, const struct ir3_shader_key *k void ir3_shader_destroy(struct ir3_shader *shader) { - free(shader->const_state.immediates); ralloc_free(shader->nir); mtx_destroy(&shader->variants_lock); ralloc_free(shader); @@ -346,6 +345,7 @@ ir3_shader_from_nir(struct ir3_compiler *compiler, nir_shader *nir, if (stream_output) memcpy(&shader->stream_output, stream_output, sizeof(shader->stream_output)); shader->num_reserved_user_consts = reserved_user_consts; + shader->const_state = rzalloc_size(shader, sizeof(*shader->const_state)); if (nir->info.stage == MESA_SHADER_GEOMETRY) NIR_PASS_V(nir, ir3_nir_lower_gs); diff --git a/src/freedreno/ir3/ir3_shader.h b/src/freedreno/ir3/ir3_shader.h index b9dd4a42317..ff131cc1838 100644 --- a/src/freedreno/ir3/ir3_shader.h +++ b/src/freedreno/ir3/ir3_shader.h @@ -621,7 +621,7 @@ struct ir3_shader { struct ir3_compiler *compiler; - struct ir3_const_state const_state; + struct ir3_const_state *const_state; unsigned num_reserved_user_consts; struct nir_shader *nir; @@ -644,7 +644,7 @@ struct ir3_shader { static inline struct ir3_const_state * ir3_const_state(const struct ir3_shader_variant *v) { - return &v->shader->const_state; + return v->shader->const_state; } void * ir3_shader_assemble(struct ir3_shader_variant *v); diff --git a/src/freedreno/vulkan/tu_clear_blit.c b/src/freedreno/vulkan/tu_clear_blit.c index df2359f3bb0..e6e7daf1bfe 100644 --- a/src/freedreno/vulkan/tu_clear_blit.c +++ b/src/freedreno/vulkan/tu_clear_blit.c @@ -321,7 +321,10 @@ static void r3d_common(struct tu_cmd_buffer *cmd, struct tu_cs *cs, bool blit, uint32_t num_rts, bool layered_clear) { - struct ir3_shader dummy_shader = {}; + struct ir3_const_state dummy_const_state = {}; + struct ir3_shader dummy_shader = { + .const_state = &dummy_const_state, + }; struct ir3_shader_variant vs = { .type = MESA_SHADER_VERTEX,