freedreno/ir3: move immediates to const_state
authorRob Clark <robdclark@chromium.org>
Mon, 6 May 2019 23:02:19 +0000 (16:02 -0700)
committerRob Clark <robdclark@chromium.org>
Tue, 7 May 2019 14:26:00 +0000 (07:26 -0700)
They are really part of the constant state, and it will moving things
from ir3_shader_variant to ir3_shader if we combine them.

Signed-off-by: Rob Clark <robdclark@chromium.org>
src/freedreno/ir3/ir3_cp.c
src/freedreno/ir3/ir3_shader.c
src/freedreno/ir3/ir3_shader.h
src/freedreno/vulkan/tu_shader.c
src/gallium/drivers/freedreno/ir3/ir3_gallium.c

index 983c5fa61f289712fb43af658391af5d4d594a4c..5d46b19d6e5d680fb20a8293cf3ad9f37098333c 100644 (file)
@@ -37,7 +37,6 @@
 struct ir3_cp_ctx {
        struct ir3 *shader;
        struct ir3_shader_variant *so;
-       unsigned immediate_idx;
 };
 
 /* is it a type preserving mov, with ok flags? */
@@ -299,32 +298,31 @@ lower_immed(struct ir3_cp_ctx *ctx, struct ir3_register *reg, unsigned new_flags
        }
 
        /* Reallocate for 4 more elements whenever it's necessary */
-       if (ctx->immediate_idx == ctx->so->immediates_size * 4) {
-               ctx->so->immediates_size += 4;
-               ctx->so->immediates = realloc (ctx->so->immediates,
-                       ctx->so->immediates_size * sizeof (ctx->so->immediates[0]));
+       struct ir3_const_state *const_state = &ctx->so->const_state;
+       if (const_state->immediate_idx == 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 (i = 0; i < ctx->immediate_idx; i++) {
+       for (i = 0; i < const_state->immediate_idx; i++) {
                swiz = i % 4;
                idx  = i / 4;
 
-               if (ctx->so->immediates[idx].val[swiz] == reg->uim_val) {
+               if (const_state->immediates[idx].val[swiz] == reg->uim_val) {
                        break;
                }
        }
 
-       if (i == ctx->immediate_idx) {
+       if (i == const_state->immediate_idx) {
                /* need to generate a new immediate: */
                swiz = i % 4;
                idx  = i / 4;
-               ctx->so->immediates[idx].val[swiz] = reg->uim_val;
-               ctx->so->immediates_count = idx + 1;
-               ctx->immediate_idx++;
+               const_state->immediates[idx].val[swiz] = reg->uim_val;
+               const_state->immediates_count = idx + 1;
+               const_state->immediate_idx++;
        }
 
-       struct ir3_const_state *const_state = &ctx->so->const_state;
-
        new_flags &= ~IR3_REG_IMMED;
        new_flags |= IR3_REG_CONST;
        reg->flags = new_flags;
index 63cad3ee4147f0ed769467129a2273e7766d7e7e..29f7fa05f0c913671ea4a2c4f825827e93a35b5c 100644 (file)
@@ -47,8 +47,8 @@ delete_variant(struct ir3_shader_variant *v)
                ir3_destroy(v->ir);
        if (v->bo)
                fd_bo_del(v->bo);
-       if (v->immediates)
-               free(v->immediates);
+       if (v->const_state.immediates)
+               free(v->const_state.immediates);
        free(v);
 }
 
@@ -351,13 +351,13 @@ ir3_shader_disasm(struct ir3_shader_variant *so, uint32_t *bin, FILE *out)
        }
 
        struct ir3_const_state *const_state = &so->const_state;
-       for (i = 0; i < so->immediates_count; i++) {
+       for (i = 0; i < const_state->immediates_count; i++) {
                fprintf(out, "@const(c%d.x)\t", const_state->offsets.immediate + i);
                fprintf(out, "0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
-                               so->immediates[i].val[0],
-                               so->immediates[i].val[1],
-                               so->immediates[i].val[2],
-                               so->immediates[i].val[3]);
+                               const_state->immediates[i].val[0],
+                               const_state->immediates[i].val[1],
+                               const_state->immediates[i].val[2],
+                               const_state->immediates[i].val[3]);
        }
 
        disasm_a3xx(bin, so->info.sizedwords, 0, out, ir->compiler->gpu_id);
index 448f60521940dfd76cada9c339fa1270863a1c09..a4386d7762d1f154a1dce779a1e68ac32d3c7214 100644 (file)
@@ -148,6 +148,13 @@ struct ir3_const_state {
                 */
                uint32_t off[IR3_MAX_SHADER_IMAGES];
        } image_dims;
+
+       unsigned immediate_idx;
+       unsigned immediates_count;
+       unsigned immediates_size;
+       struct {
+               uint32_t val[4];
+       } *immediates;
 };
 
 /**
@@ -490,12 +497,6 @@ struct ir3_shader_variant {
 
        bool per_samp;
 
-       unsigned immediates_count;
-       unsigned immediates_size;
-       struct {
-               uint32_t val[4];
-       } *immediates;
-
        /* for astc srgb workaround, the number/base of additional
         * alpha tex states we need, and index of original tex states
         */
index c2fdff9953e1e9d2cfe4a151c47f32a696f22bc1..62f8f91c7f3320d93cf82a37139a9b7d4e3aade7 100644 (file)
@@ -196,8 +196,8 @@ tu_shader_destroy(struct tu_device *dev,
    for (uint32_t i = 0; i < 1 + shader->has_binning_pass; i++) {
       if (shader->variants[i].ir)
          ir3_destroy(shader->variants[i].ir);
-      if (shader->variants[i].immediates)
-         free(shader->variants[i].immediates);
+      if (shader->variants[i].const_state.immediates)
+         free(shader->variants[i].const_state.immediates);
    }
 
    if (shader->binary)
index 3bb29daf9b8d10fdfa55c24e725814b9ee21dae1..08a7c90aab34991d704cca521353ea8803934f82 100644 (file)
@@ -388,7 +388,7 @@ emit_immediates(struct fd_context *ctx, const struct ir3_shader_variant *v,
 {
        const struct ir3_const_state *const_state = &v->const_state;
        uint32_t base = const_state->offsets.immediate;
-       int size = v->immediates_count;
+       int size = const_state->immediates_count;
 
        /* truncate size to avoid writing constants that shader
         * does not use:
@@ -402,7 +402,7 @@ emit_immediates(struct fd_context *ctx, const struct ir3_shader_variant *v,
        if (size > 0) {
                ring_wfi(ctx->batch, ring);
                ctx->emit_const(ring, v->type, base,
-                       0, size, v->immediates[0].val, NULL);
+                       0, size, const_state->immediates[0].val, NULL);
        }
 }