From: Eric Anholt Date: Tue, 7 Jul 2020 21:13:51 +0000 (-0700) Subject: freedreno/ir3: Merge the redundant immediate_idx/immediates_count fields X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=e873c4da08d883161e572cf7b9d7d24ca12a78b5;p=mesa.git freedreno/ir3: Merge the redundant immediate_idx/immediates_count fields 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: --- diff --git a/src/freedreno/computerator/a6xx.c b/src/freedreno/computerator/a6xx.c index 4cd8e5784f6..baa9b7d8504 100644 --- a/src/freedreno/computerator/a6xx.c +++ b/src/freedreno/computerator/a6xx.c @@ -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); diff --git a/src/freedreno/ir3/ir3_cp.c b/src/freedreno/ir3/ir3_cp.c index 56f6b2b215d..9420116f536 100644 --- a/src/freedreno/ir3/ir3_cp.c +++ b/src/freedreno/ir3/ir3_cp.c @@ -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; diff --git a/src/freedreno/ir3/ir3_parser.y b/src/freedreno/ir3/ir3_parser.y index 6c06f1d3e03..5f79c1b140c 100644 --- a/src/freedreno/ir3/ir3_parser.y +++ b/src/freedreno/ir3/ir3_parser.y @@ -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) diff --git a/src/freedreno/ir3/ir3_shader.c b/src/freedreno/ir3/ir3_shader.c index 99cacbf3301..0e6653a25d4 100644 --- a/src/freedreno/ir3/ir3_shader.c +++ b/src/freedreno/ir3/ir3_shader.c @@ -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], diff --git a/src/freedreno/ir3/ir3_shader.h b/src/freedreno/ir3/ir3_shader.h index f5a73bb2e00..25a4371c52d 100644 --- a/src/freedreno/ir3/ir3_shader.h +++ b/src/freedreno/ir3/ir3_shader.h @@ -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 { diff --git a/src/freedreno/vulkan/tu_pipeline.c b/src/freedreno/vulkan/tu_pipeline.c index 13a8722952f..b8eab8564ac 100644 --- a/src/freedreno/vulkan/tu_pipeline.c +++ b/src/freedreno/vulkan/tu_pipeline.c @@ -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: diff --git a/src/gallium/drivers/freedreno/ir3/ir3_const.h b/src/gallium/drivers/freedreno/ir3/ir3_const.h index d7b50650ea1..7a0386e3f32 100644 --- a/src/gallium/drivers/freedreno/ir3/ir3_const.h +++ b/src/gallium/drivers/freedreno/ir3/ir3_const.h @@ -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: