freedreno/ir3: Merge the redundant immediate_idx/immediates_count fields
authorEric Anholt <eric@anholt.net>
Tue, 7 Jul 2020 21:13:51 +0000 (14:13 -0700)
committerMarge Bot <eric+marge@anholt.net>
Wed, 5 Aug 2020 23:06:55 +0000 (23:06 +0000)
I got tripped up again with the index vs count vs size fields and I'd
rather we didn't store the redundant info.  Settle on immediates_count as
"how many dwords of immediates we have"

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/5990>

src/freedreno/computerator/a6xx.c
src/freedreno/ir3/ir3_cp.c
src/freedreno/ir3/ir3_parser.y
src/freedreno/ir3/ir3_shader.c
src/freedreno/ir3/ir3_shader.h
src/freedreno/vulkan/tu_pipeline.c
src/gallium/drivers/freedreno/ir3/ir3_const.h

index 4cd8e5784f6d0ca7d318554c6c63ae375d3282b4..baa9b7d8504840848c59a056f9b80bc4557582d1 100644 (file)
@@ -220,7 +220,7 @@ cs_const_emit(struct fd_ringbuffer *ring, struct kernel *kernel, uint32_t grid[3
 
        const struct ir3_const_state *const_state = ir3_const_state(v);
        uint32_t base = const_state->offsets.immediate;
-       int size = const_state->immediates_count;
+       int size = DIV_ROUND_UP(const_state->immediates_count, 4);
 
        if (ir3_kernel->info.numwg != INVALID_REG) {
                assert((ir3_kernel->info.numwg & 0x3) == 0);
index 56f6b2b215d90e6b61dda8a885179b9559f223c2..9420116f536d28bcbf61c30cff60ab4f53bc9c43 100644 (file)
@@ -198,7 +198,7 @@ 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) {
+       if (const_state->immediates_count == const_state->immediates_size * 4) {
                const_state->immediates = rerzalloc(const_state,
                                const_state->immediates,
                                __typeof__(const_state->immediates[0]),
@@ -206,11 +206,11 @@ lower_immed(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr, unsigned n,
                                const_state->immediates_size + 4);
                const_state->immediates_size += 4;
 
-               for (int i = const_state->immediate_idx; i < const_state->immediates_size * 4; i++)
+               for (int i = const_state->immediates_count; i < const_state->immediates_size * 4; i++)
                        const_state->immediates[i / 4].val[i % 4] = 0xd0d0d0d0;
        }
 
-       for (i = 0; i < const_state->immediate_idx; i++) {
+       for (i = 0; i < const_state->immediates_count; i++) {
                swiz = i % 4;
                idx  = i / 4;
 
@@ -219,11 +219,11 @@ lower_immed(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr, unsigned n,
                }
        }
 
-       if (i == const_state->immediate_idx) {
+       if (i == const_state->immediates_count) {
                /* Add on a new immediate to be pushed, if we have space left in the
                 * constbuf.
                 */
-               if (const_state->offsets.immediate + const_state->immediate_idx / 4 >=
+               if (const_state->offsets.immediate + const_state->immediates_count / 4 >=
                                ir3_max_const(ctx->so))
                        return false;
 
@@ -231,8 +231,7 @@ lower_immed(struct ir3_cp_ctx *ctx, struct ir3_instruction *instr, unsigned n,
                idx  = i / 4;
 
                const_state->immediates[idx].val[swiz] = reg->uim_val;
-               const_state->immediates_count = idx + 1;
-               const_state->immediate_idx++;
+               const_state->immediates_count++;
        }
 
        reg->flags = new_flags;
index 6c06f1d3e03157ed5fecfa4ca23837993ea8e893..5f79c1b140ccdf7f45097b7e074fcdba5e337d11 100644 (file)
@@ -156,7 +156,7 @@ static void add_const(unsigned reg, unsigned c0, unsigned c1, unsigned c2, unsig
        struct ir3_const_state *const_state = ir3_const_state(variant);
        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) {
+       if (const_state->immediates_count == const_state->immediates_size * 4) {
                const_state->immediates = rerzalloc(const_state,
                                const_state->immediates,
                                __typeof__(const_state->immediates[0]),
@@ -168,8 +168,7 @@ static void add_const(unsigned reg, unsigned c0, unsigned c1, unsigned c2, unsig
        const_state->immediates[idx].val[1] = c1;
        const_state->immediates[idx].val[2] = c2;
        const_state->immediates[idx].val[3] = c3;
-       const_state->immediates_count = idx + 1;
-       const_state->immediate_idx++;
+       const_state->immediates_count++;
 }
 
 static void add_sysval(unsigned reg, unsigned compmask, gl_system_value sysval)
index 99cacbf3301308dc8f0b536a99d62244520e46f4..0e6653a25d4888c733f2d3c6649dcb84aaca9159 100644 (file)
@@ -571,7 +571,7 @@ ir3_shader_disasm(struct ir3_shader_variant *so, uint32_t *bin, FILE *out)
        }
 
        const struct ir3_const_state *const_state = ir3_const_state(so);
-       for (i = 0; i < const_state->immediates_count; i++) {
+       for (i = 0; i < DIV_ROUND_UP(const_state->immediates_count, 4); i++) {
                fprintf(out, "@const(c%d.x)\t", const_state->offsets.immediate + i);
                fprintf(out, "0x%08x, 0x%08x, 0x%08x, 0x%08x\n",
                                const_state->immediates[i].val[0],
index f5a73bb2e005d0b5bda0aaf81fa9ebc2df480725..25a4371c52de5edf02264c633d0ed386863f3849 100644 (file)
@@ -191,7 +191,6 @@ struct ir3_const_state {
                uint32_t off[IR3_MAX_SHADER_IMAGES];
        } image_dims;
 
-       unsigned immediate_idx;
        unsigned immediates_count;
        unsigned immediates_size;
        struct {
index 13a8722952f93b48036cd76d1813ceedcc49f07d..b8eab8564ac56a23ac7c8eab10470f26c5ec20da 100644 (file)
@@ -445,7 +445,7 @@ tu6_emit_xs_config(struct tu_cs *cs,
 
    const struct ir3_const_state *const_state = ir3_const_state(xs);
    uint32_t base = const_state->offsets.immediate;
-   int size = const_state->immediates_count;
+   int size = DIV_ROUND_UP(const_state->immediates_count, 4);
 
    /* truncate size to avoid writing constants that shader
     * does not use:
index d7b50650ea12bebd853e0bf51a2ab06ccc83a7d9..7a0386e3f3246239ad0305141bf1347d33aff211 100644 (file)
@@ -259,7 +259,7 @@ ir3_emit_immediates(struct fd_screen *screen, const struct ir3_shader_variant *v
 {
        const struct ir3_const_state *const_state = ir3_const_state(v);
        uint32_t base = const_state->offsets.immediate;
-       int size = const_state->immediates_count;
+       int size = DIV_ROUND_UP(const_state->immediates_count, 4);
 
        /* truncate size to avoid writing constants that shader
         * does not use: