From 2068b0143027a9f61011f3cac6b620414c85c8f6 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Wed, 20 May 2020 13:40:29 -0700 Subject: [PATCH] freedreno/ir3: Refactor out IBO source references. All the users of the unsigned result just wanted an ir3_instruction to reference. Move a6xx's helpers to ir3_image.c and inline the old unsigned results version. Part-of: --- src/freedreno/ir3/ir3_a4xx.c | 26 +++++++++--------------- src/freedreno/ir3/ir3_a6xx.c | 38 ++++++----------------------------- src/freedreno/ir3/ir3_image.c | 26 ++++++++++++++++++------ src/freedreno/ir3/ir3_image.h | 4 ++-- 4 files changed, 37 insertions(+), 57 deletions(-) diff --git a/src/freedreno/ir3/ir3_a4xx.c b/src/freedreno/ir3/ir3_a4xx.c index e460cd0b629..04dec6c027f 100644 --- a/src/freedreno/ir3/ir3_a4xx.c +++ b/src/freedreno/ir3/ir3_a4xx.c @@ -42,8 +42,7 @@ emit_intrinsic_load_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr, struct ir3_block *b = ctx->block; struct ir3_instruction *ldgb, *src0, *src1, *byte_offset, *offset; - /* can this be non-const buffer_index? how do we handle that? */ - int ibo_idx = ir3_ssbo_to_ibo(ctx->so->shader, nir_src_as_uint(intr->src[0])); + struct ir3_instruction *ssbo = ir3_ssbo_to_ibo(ctx, intr->src[0]); byte_offset = ir3_get_src(ctx, &intr->src[1])[0]; offset = ir3_get_src(ctx, &intr->src[2])[0]; @@ -55,7 +54,7 @@ emit_intrinsic_load_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr, }, 2); src1 = offset; - ldgb = ir3_LDGB(b, create_immed(b, ibo_idx), 0, + ldgb = ir3_LDGB(b, ssbo, 0, src0, 0, src1, 0); ldgb->regs[0]->wrmask = MASK(intr->num_components); ldgb->cat6.iim_val = intr->num_components; @@ -78,8 +77,7 @@ emit_intrinsic_store_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr) assert(wrmask == BITFIELD_MASK(intr->num_components)); - /* can this be non-const buffer_index? how do we handle that? */ - int ibo_idx = ir3_ssbo_to_ibo(ctx->so->shader, nir_src_as_uint(intr->src[1])); + struct ir3_instruction *ssbo = ir3_ssbo_to_ibo(ctx, intr->src[1]); byte_offset = ir3_get_src(ctx, &intr->src[2])[0]; offset = ir3_get_src(ctx, &intr->src[3])[0]; @@ -94,7 +92,7 @@ emit_intrinsic_store_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr) create_immed(b, 0), }, 2); - stgb = ir3_STGB(b, create_immed(b, ibo_idx), 0, src0, 0, src1, 0, src2, 0); + stgb = ir3_STGB(b, ssbo, 0, src0, 0, src1, 0, src2, 0); stgb->cat6.iim_val = ncomp; stgb->cat6.d = 4; stgb->cat6.type = TYPE_U32; @@ -129,9 +127,7 @@ emit_intrinsic_atomic_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr) *offset; type_t type = TYPE_U32; - /* can this be non-const buffer_index? how do we handle that? */ - int ibo_idx = ir3_ssbo_to_ibo(ctx->so->shader, nir_src_as_uint(intr->src[0])); - ssbo = create_immed(b, ibo_idx); + ssbo = ir3_ssbo_to_ibo(ctx, intr->src[0]); byte_offset = ir3_get_src(ctx, &intr->src[1])[0]; offset = ir3_get_src(ctx, &intr->src[3])[0]; @@ -257,9 +253,8 @@ emit_intrinsic_store_image(struct ir3_context *ctx, nir_intrinsic_instr *intr) struct ir3_instruction *stib, *offset; struct ir3_instruction * const *value = ir3_get_src(ctx, &intr->src[3]); struct ir3_instruction * const *coords = ir3_get_src(ctx, &intr->src[1]); + struct ir3_instruction * ibo = ir3_image_to_ibo(ctx, intr->src[0]); unsigned ncoords = ir3_get_image_coords(intr, NULL); - unsigned slot = nir_src_as_uint(intr->src[0]); - unsigned ibo_idx = ir3_image_to_ibo(ctx->so->shader, slot); unsigned ncomp = ir3_get_num_components_for_image_format(nir_intrinsic_format(intr)); /* src0 is value @@ -274,7 +269,7 @@ emit_intrinsic_store_image(struct ir3_context *ctx, nir_intrinsic_instr *intr) * one over the other in various cases. */ - stib = ir3_STIB(b, create_immed(b, ibo_idx), 0, + stib = ir3_STIB(b, ibo, 0, ir3_create_collect(ctx, value, ncomp), 0, ir3_create_collect(ctx, coords, ncoords), 0, offset, 0); @@ -293,13 +288,10 @@ static struct ir3_instruction * emit_intrinsic_atomic_image(struct ir3_context *ctx, nir_intrinsic_instr *intr) { struct ir3_block *b = ctx->block; - struct ir3_instruction *atomic, *image, *src0, *src1, *src2; + struct ir3_instruction *atomic, *src0, *src1, *src2; struct ir3_instruction * const *coords = ir3_get_src(ctx, &intr->src[1]); + struct ir3_instruction * image = ir3_image_to_ibo(ctx, intr->src[0]); unsigned ncoords = ir3_get_image_coords(intr, NULL); - unsigned slot = nir_src_as_uint(intr->src[0]); - unsigned ibo_idx = ir3_image_to_ibo(ctx->so->shader, slot); - - image = create_immed(b, ibo_idx); /* src0 is value (or uvec2(value, compare)) * src1 is coords diff --git a/src/freedreno/ir3/ir3_a6xx.c b/src/freedreno/ir3/ir3_a6xx.c index 6160a855771..cef7a78dad5 100644 --- a/src/freedreno/ir3/ir3_a6xx.c +++ b/src/freedreno/ir3/ir3_a6xx.c @@ -48,32 +48,6 @@ handle_bindless_cat6(struct ir3_instruction *instr, nir_src rsrc) instr->cat6.base = nir_intrinsic_desc_set(intrin); } -static struct ir3_instruction * -ssbo_idx(struct ir3_context *ctx, nir_src src) -{ - if (ir3_bindless_resource(src)) { - ctx->so->bindless_ibo = true; - return ir3_get_src(ctx, &src)[0]; - } else { - /* can this be non-const buffer_index? how do we handle that? */ - int ibo_idx = ir3_ssbo_to_ibo(ctx->so->shader, nir_src_as_uint(src)); - return create_immed(ctx->block, ibo_idx); - } -} - -static struct ir3_instruction * -image_idx(struct ir3_context *ctx, nir_src src) -{ - if (ir3_bindless_resource(src)) { - ctx->so->bindless_ibo = true; - return ir3_get_src(ctx, &src)[0]; - } else { - /* can this be non-const buffer_index? how do we handle that? */ - int ibo_idx = ir3_image_to_ibo(ctx->so->shader, nir_src_as_uint(src)); - return create_immed(ctx->block, ibo_idx); - } -} - /* src[] = { buffer_index, offset }. No const_index */ static void emit_intrinsic_load_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr, @@ -85,7 +59,7 @@ emit_intrinsic_load_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr, offset = ir3_get_src(ctx, &intr->src[2])[0]; - ldib = ir3_LDIB(b, ssbo_idx(ctx, intr->src[0]), 0, offset, 0); + ldib = ir3_LDIB(b, ir3_ssbo_to_ibo(ctx, intr->src[0]), 0, offset, 0); ldib->regs[0]->wrmask = MASK(intr->num_components); ldib->cat6.iim_val = intr->num_components; ldib->cat6.d = 1; @@ -113,7 +87,7 @@ emit_intrinsic_store_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr) val = ir3_create_collect(ctx, ir3_get_src(ctx, &intr->src[0]), ncomp); offset = ir3_get_src(ctx, &intr->src[3])[0]; - stib = ir3_STIB(b, ssbo_idx(ctx, intr->src[1]), 0, offset, 0, val, 0); + stib = ir3_STIB(b, ir3_ssbo_to_ibo(ctx, intr->src[1]), 0, offset, 0, val, 0); stib->cat6.iim_val = ncomp; stib->cat6.d = 1; stib->cat6.type = intr->src[0].ssa->bit_size == 16 ? TYPE_U16 : TYPE_U32; @@ -148,7 +122,7 @@ emit_intrinsic_atomic_ssbo(struct ir3_context *ctx, nir_intrinsic_instr *intr) struct ir3_instruction *atomic, *ibo, *src0, *src1, *data, *dummy; type_t type = TYPE_U32; - ibo = ssbo_idx(ctx, intr->src[0]); + ibo = ir3_ssbo_to_ibo(ctx, intr->src[0]); data = ir3_get_src(ctx, &intr->src[2])[0]; @@ -241,7 +215,7 @@ emit_intrinsic_load_image(struct ir3_context *ctx, nir_intrinsic_instr *intr, struct ir3_instruction * const *coords = ir3_get_src(ctx, &intr->src[1]); unsigned ncoords = ir3_get_image_coords(intr, NULL); - ldib = ir3_LDIB(b, image_idx(ctx, intr->src[0]), 0, + ldib = ir3_LDIB(b, ir3_image_to_ibo(ctx, intr->src[0]), 0, ir3_create_collect(ctx, coords, ncoords), 0); ldib->regs[0]->wrmask = MASK(intr->num_components); ldib->cat6.iim_val = intr->num_components; @@ -269,7 +243,7 @@ emit_intrinsic_store_image(struct ir3_context *ctx, nir_intrinsic_instr *intr) /* src0 is offset, src1 is value: */ - stib = ir3_STIB(b, image_idx(ctx, intr->src[0]), 0, + stib = ir3_STIB(b, ir3_image_to_ibo(ctx, intr->src[0]), 0, ir3_create_collect(ctx, coords, ncoords), 0, ir3_create_collect(ctx, value, ncomp), 0); stib->cat6.iim_val = ncomp; @@ -293,7 +267,7 @@ emit_intrinsic_atomic_image(struct ir3_context *ctx, nir_intrinsic_instr *intr) struct ir3_instruction *value = ir3_get_src(ctx, &intr->src[3])[0]; unsigned ncoords = ir3_get_image_coords(intr, NULL); - ibo = image_idx(ctx, intr->src[0]); + ibo = ir3_image_to_ibo(ctx, intr->src[0]); /* So this gets a bit creative: * diff --git a/src/freedreno/ir3/ir3_image.c b/src/freedreno/ir3/ir3_image.c index 09ee833de11..b89f74d5de9 100644 --- a/src/freedreno/ir3/ir3_image.c +++ b/src/freedreno/ir3/ir3_image.c @@ -39,10 +39,17 @@ ir3_ibo_mapping_init(struct ir3_ibo_mapping *mapping, unsigned num_textures) mapping->tex_base = num_textures; } -unsigned -ir3_ssbo_to_ibo(struct ir3_shader *shader, unsigned ssbo) +struct ir3_instruction * +ir3_ssbo_to_ibo(struct ir3_context *ctx, nir_src src) { - return ssbo; + if (ir3_bindless_resource(src)) { + ctx->so->bindless_ibo = true; + return ir3_get_src(ctx, &src)[0]; + } else { + /* can this be non-const buffer_index? how do we handle that? */ + int ssbo_idx = nir_src_as_uint(src); + return create_immed(ctx->block, ssbo_idx); + } } unsigned @@ -56,10 +63,17 @@ ir3_ssbo_to_tex(struct ir3_ibo_mapping *mapping, unsigned ssbo) return mapping->ssbo_to_tex[ssbo] + mapping->tex_base; } -unsigned -ir3_image_to_ibo(struct ir3_shader *shader, unsigned image) +struct ir3_instruction * +ir3_image_to_ibo(struct ir3_context *ctx, nir_src src) { - return shader->nir->info.num_ssbos + image; + if (ir3_bindless_resource(src)) { + ctx->so->bindless_ibo = true; + return ir3_get_src(ctx, &src)[0]; + } else { + /* can this be non-const buffer_index? how do we handle that? */ + int image_idx = nir_src_as_uint(src); + return create_immed(ctx->block, ctx->s->info.num_ssbos + image_idx); + } } unsigned diff --git a/src/freedreno/ir3/ir3_image.h b/src/freedreno/ir3/ir3_image.h index ff798694713..d2c1f2338e5 100644 --- a/src/freedreno/ir3/ir3_image.h +++ b/src/freedreno/ir3/ir3_image.h @@ -31,9 +31,9 @@ void ir3_ibo_mapping_init(struct ir3_ibo_mapping *mapping, unsigned num_textures); -unsigned ir3_ssbo_to_ibo(struct ir3_shader *shader, unsigned ssbo); +struct ir3_instruction *ir3_ssbo_to_ibo(struct ir3_context *ctx, nir_src src); unsigned ir3_ssbo_to_tex(struct ir3_ibo_mapping *mapping, unsigned ssbo); -unsigned ir3_image_to_ibo(struct ir3_shader *shader, unsigned image); +struct ir3_instruction *ir3_image_to_ibo(struct ir3_context *ctx, nir_src src); unsigned ir3_image_to_tex(struct ir3_ibo_mapping *mapping, unsigned image); unsigned ir3_get_image_coords(const nir_intrinsic_instr *instr, unsigned *flagsp); -- 2.30.2