freedreno/ir3: un-embed const_state
authorRob Clark <robdclark@chromium.org>
Mon, 15 Jun 2020 18:43:36 +0000 (11:43 -0700)
committerMarge Bot <eric+marge@anholt.net>
Fri, 19 Jun 2020 13:16:57 +0000 (13:16 +0000)
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 <robdclark@chromium.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5508>

src/freedreno/ir3/ir3_assembler.c
src/freedreno/ir3/ir3_cp.c
src/freedreno/ir3/ir3_nir.c
src/freedreno/ir3/ir3_nir_analyze_ubo_ranges.c
src/freedreno/ir3/ir3_parser.y
src/freedreno/ir3/ir3_shader.c
src/freedreno/ir3/ir3_shader.h
src/freedreno/vulkan/tu_clear_blit.c

index 005f52859a8e2f2a743415001b9b378136d61600..e81eda6e9ae75e8a4c1f21ba1a7274673c780600 100644 (file)
@@ -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));
index a9562af25aa0cc23050e7167d2ca9c9945e4c149..e739f792cf80ac3e3872157e72b199d77c16b94d 100644 (file)
@@ -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;
index 2df5715f51c0768a8c2c24f798b518e66741556d..de76cb70e55f8f543b9aac8a9fd119375eedf696 100644 (file)
@@ -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
index b41bfe487726c97829146e55af0eed067bacb395..0ae11a3512abef643a2815d708f9e756440ba033 100644 (file)
@@ -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++) {
index 2e89d773fc9955987c4bfb2aa65d138d7b85246d..27c52bd21e91aeb0097a38d4de44c08aff258300 100644 (file)
@@ -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;
index c7d06a99fc2502f1ba98433f0adf913182c881cc..66f72c98dc1f4a8939b29b23db7757ca533b4e62 100644 (file)
@@ -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);
index b9dd4a423172dc0f7f4204f3b187859f431d345d..ff131cc1838684b7602616bf47bdb3251c1b49ee 100644 (file)
@@ -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);
index df2359f3bb0888d25c3ef676a3c33014a925218d..e6e7daf1bfeb1838f8f3424ade565cf2b587db04 100644 (file)
@@ -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,