diff --git a/src/imagination/g5p/pco_g5p_general.c b/src/imagination/g5p/pco_g5p_general.c index a92dad2ba2a..26b0f05dbb7 100644 --- a/src/imagination/g5p/pco_g5p_general.c +++ b/src/imagination/g5p/pco_g5p_general.c @@ -267,6 +267,15 @@ struct gctx { bool compact_vs; /* last retry: compact movable bank1 values between instructions */ bool vs_bank0; /* VS pressure retry: temps in bank 0, outputs in bank 1 (vs-two-bank-allocator.md) */ bool vs_evict; /* last VS retry: held bank-1 values move to bank 0 to keep room for bank-1-only forms */ + bool evict_ladder; /* the retry after it: the whole ladder again, vs_evict in every two-bank attempt */ + /* vs_evict, inside one qualified vertex texture (vtex_lend_run()): bank-1 registers lent to the recipe; their + * values wait in bank 0 and return before the next instruction */ + bool vtex_lend; + nir_tex_instr *vtex_tex; /* the texture whose recipe borrows them */ + unsigned vtex_park_need; /* bank-0 registers the result's components are parked in */ + unsigned nvtex_lent; + uint64_t vtex_lent_mask; /* the lent bank-1 registers: neither lent again nor evicted until returned */ + struct { uint8_t bank1, bank0; } vtex_lent[NUM_DWORDS]; nir_intrinsic_instr *vend_store; /* eager: the output component written by the final vend */ unsigned vend_comp; /* common store */ @@ -464,6 +473,10 @@ static int alloc_bank0(struct gctx *c) return -1; } +static void evict_vertex_bank1_n(struct gctx *c, unsigned n, bool aligned); +static void vs_park_bank1_def(struct gctx *c, nir_def *def, unsigned dst, unsigned n); +static int vtex_lend_run(struct gctx *c, unsigned n); + static unsigned alloc_run(struct gctx *c, unsigned n, const char *why) { if (c->vs && c->tex_bank0) { @@ -495,6 +508,18 @@ static unsigned alloc_run(struct gctx *c, unsigned n, const char *why) return r; } } + if (c->vs && c->vs_evict && !c->cf_depth && !c->tex_bank0) { + evict_vertex_bank1_n(c, n, false); + for (unsigned r = 0; r + n <= NUM_DWORDS; r++) { + uint64_t mask = BITFIELD64_RANGE(r, n); + if (!((c->busy | c->reserved | c->tex_coord_pending | c->tex_pending) & mask)) { + c->busy |= mask; + c->max_dword = MAX2(c->max_dword, r + n); + c->max_written = MAX2(c->max_written, r + n); + return r; + } + } + } if (n == 1 && c->vs && c->vs_bank0) { int r = alloc_bank0(c); if (r >= 0) @@ -506,6 +531,11 @@ static unsigned alloc_run(struct gctx *c, unsigned n, const char *why) tex_flush(c); return alloc_run(c, n, why); } + if (c->vtex_lend) { + int r = vtex_lend_run(c, n); + if (r >= 0) + return r; + } c->need = n; refuse(c, "register pressure: %s needs %u dword(s), %u of %u in use", why, n, util_bitcount64((c->busy | c->reserved | c->tex_coord_pending | c->tex_pending) & BITFIELD64_MASK(NUM_DWORDS)), NUM_DWORDS); @@ -4004,7 +4034,7 @@ static void emit_alu_body(struct gctx *c, nir_alu_instr *a); static void emit_alu(struct gctx *c, nir_alu_instr *a) { - c->alloc_out = c->vs && c->vs_bank0 && vs_feeds_output(c, &a->def); + c->alloc_out = c->vs && c->vs_bank0 && !c->vs_evict && vs_feeds_output(c, &a->def); emit_alu_body(c, a); c->alloc_out = false; } @@ -4663,13 +4693,37 @@ static void emit_dyn_ubo(struct gctx *c, nir_intrinsic_instr *in) put(c, raw, g5p_usc_wait(raw, 0), "wait"); /* the load has completed (wait): the element's unused tail is free */ c->busy &= ~BITFIELD64_RANGE(dst + n, loaded - n); + vs_park_bank1_def(c, &in->def, dst, n); + c->p->evidence |= PCO_G5P_EV_DYN_UBO; +} + +/* Park a completed bank-1 load run in bank 0 under vs_evict so bank 1 stays + * open for coupled vertex texture recipes and addressed loads. */ +static void vs_park_bank1_def(struct gctx *c, nir_def *def, unsigned dst, unsigned n) +{ + uint8_t raw[G5P_USC_MAX]; for (unsigned k = 0; k < n; k++) { - struct val *v = V(c, &in->def, k); + struct val *v = V(c, def, k); + if (c->vs && c->vs_evict) { + if (!v->uses) { + c->busy &= ~BITFIELD64_BIT(dst + k); + continue; + } + int parked = alloc_bank0(c); + if (parked >= 0) { + put(c, raw, g5p_usc_move(raw, H(c, parked), H(c, dst + k), 0, 1, 0x21), + "vertex load result to bank0"); + c->busy &= ~BITFIELD64_BIT(dst + k); + v->state = VAL_REG; + v->reg = parked; + v->held = true; + continue; + } + } v->state = VAL_REG; v->reg = dst + k; v->held = true; } - c->p->evidence |= PCO_G5P_EV_DYN_UBO; } /* A constant-offset load from a UBO range whose contiguous span would not @@ -4706,6 +4760,12 @@ static void emit_memory_ubo(struct gctx *c, nir_intrinsic_instr *in, for (pair = 0; pair + 2 <= NUM_DWORDS; pair += 2) if (!((c->busy | c->reserved | c->tex_coord_pending | c->tex_pending) & BITFIELD64_RANGE(pair, 2))) break; + if (pair + 2 > NUM_DWORDS && c->vs && c->vs_evict && !c->cf_depth) { + evict_vertex_bank1_n(c, 2, true); + for (pair = 0; pair + 2 <= NUM_DWORDS; pair += 2) + if (!((c->busy | c->reserved | c->tex_coord_pending | c->tex_pending) & BITFIELD64_RANGE(pair, 2))) + break; + } if (pair + 2 > NUM_DWORDS) refuse(c, "memory UBO load: register pressure for address pair"); c->busy |= BITFIELD64_RANGE(pair, 2); @@ -4731,12 +4791,7 @@ static void emit_memory_ubo(struct gctx *c, nir_intrinsic_instr *in, free_scratch(c); } - for (unsigned k = 0; k < n; k++) { - struct val *v = V(c, &in->def, k); - v->state = VAL_REG; - v->reg = dst + k; - v->held = true; - } + vs_park_bank1_def(c, &in->def, dst, n); c->p->evidence |= PCO_G5P_EV_DYN_UBO; } @@ -4859,6 +4914,12 @@ static void emit_address_ssbo_load(struct gctx *c, nir_intrinsic_instr *in, unsi for (pair = 0; pair + 2 <= NUM_DWORDS; pair += 2) if (!((c->busy | c->reserved | c->tex_coord_pending | c->tex_pending) & BITFIELD64_RANGE(pair, 2))) break; + if (pair + 2 > NUM_DWORDS && c->vs && c->vs_evict && !c->cf_depth) { + evict_vertex_bank1_n(c, 2, true); + for (pair = 0; pair + 2 <= NUM_DWORDS; pair += 2) + if (!((c->busy | c->reserved | c->tex_coord_pending | c->tex_pending) & BITFIELD64_RANGE(pair, 2))) + break; + } if (pair + 2 > NUM_DWORDS) refuse(c, "load_ssbo: register pressure for an address pair"); c->busy |= BITFIELD64_RANGE(pair, 2); @@ -4878,12 +4939,7 @@ static void emit_address_ssbo_load(struct gctx *c, nir_intrinsic_instr *in, unsi put(c, raw, g5p_usc_wait(raw, 0), "wait"); c->busy &= ~BITFIELD64_RANGE(pair, 2); free_scratch(c); - for (unsigned k = 0; k < n; k++) { - struct val *v = V(c, &in->def, k); - v->state = VAL_REG; - v->reg = dst + k; - v->held = true; - } + vs_park_bank1_def(c, &in->def, dst, n); c->p->evidence |= PCO_G5P_EV_BUFFER_LOAD; } @@ -5041,7 +5097,7 @@ static void emit_intrinsic(struct gctx *c, nir_intrinsic_instr *in) break; unsigned g = vgrp(c, (struct ref){decl, 0, false, false}); /* vertex: a read that an output stores goes to bank 1 */ - c->alloc_out = c->vs && c->vs_bank0 && vs_feeds_output(c, &in->def); + c->alloc_out = c->vs && c->vs_bank0 && !c->vs_evict && vs_feeds_output(c, &in->def); unsigned dst = alloc_reg(c, -1); c->alloc_out = false; put(c, raw, g5p_usc_move(raw, H(c, dst), H(c, dv->reg), vbank(c, dst), g, @@ -5349,10 +5405,111 @@ static void vertex_qualified_copy(struct gctx *c, unsigned dst, nir_def *def, un vhdr(c, 0x21, src, -1, -1)), "qualified vertex texture copy"); } +/* + * The last vertex retry (vs_evict), a qualified vertex texture whose bank-1 recipe run (coordinates, level or + * derivatives, compare/offset extras, the result) finds no free run, also where evict_vertex_bank1_n() may not + * move a value for good (inside control flow, where another path would not take the move; a decl's register). + * The registers of the run are lent to the recipe for this instruction only: each held value is moved into a + * free bank-0 register (the move evict_vertex_bank1_n() emits) and moved back into its own bank-1 register once + * the result has been parked in bank 0 (vtex_return(), the bank-0-to-bank-1 move of vertex_qualified_copy()). + * Every value ends the instruction in the register it started in, so it is valid at any control-flow depth. + * Never lent: the texture's own sources, the recipe's registers, reserved and pending ones, a busy register + * without a value. Bank 0 must keep room for the result's parked components (vtex_park_need). + */ +static uint64_t vtex_source_regs(struct gctx *c, nir_tex_instr *t) +{ + uint64_t m = 0; + for (unsigned i = 0; i < t->num_srcs; i++) { + if (t->src[i].src_type == nir_tex_src_texture_deref || t->src[i].src_type == nir_tex_src_sampler_deref) + continue; + for (unsigned k = 0; k < t->src[i].src.ssa->num_components; k++) { + struct ref r = resolve_value(c, t->src[i].src.ssa, k); + struct val *v = V(c, r.def, r.comp); + if (v->held) + m |= BITFIELD64_BIT(v->reg); + } + } + return m; +} + +static bool vtex_lendable(struct gctx *c, unsigned r) +{ + for (unsigned i = 0; i < c->nvals; i++) + if (c->vals[i].held && c->vals[i].reg == r) + return true; + return false; /* a busy register with no value (a pair, a persistent constant) stays */ +} + +static int vtex_lend_run(struct gctx *c, unsigned n) +{ + const uint64_t used = c->busy | c->reserved | c->tex_coord_pending | c->tex_pending; + const uint64_t fixed = c->reserved | c->scratch | c->tex_coord_pending | c->tex_pending | c->vtex_lent_mask | + (c->vtex_tex ? vtex_source_regs(c, c->vtex_tex) : ~UINT64_C(0)); + const unsigned free0 = util_bitcount64(~used & BITFIELD64_RANGE(VS_BANK0, NUM_DWORDS)); + int best = -1; + unsigned best_cost = UINT_MAX; + for (unsigned r = 0; r + n <= NUM_DWORDS; r++) { + unsigned cost = 0; + bool ok = true; + for (unsigned k = r; k < r + n && ok; k++) { + if (!(used & BITFIELD64_BIT(k))) + continue; + ok = !(fixed & BITFIELD64_BIT(k)) && vtex_lendable(c, k); + cost++; + } + if (ok && cost < best_cost) { + best = r; + best_cost = cost; + } + } + if (best < 0 || c->nvtex_lent + best_cost > NUM_DWORDS || free0 < best_cost + c->vtex_park_need) + return -1; + uint8_t raw[G5P_USC_MAX]; + u_foreach_bit64(src, BITFIELD64_RANGE(best, n) & used) { + int dst = alloc_bank0(c); + if (dst < 0) + refuse(c, "register pressure: no bank-0 register to lend a bank-1 register from"); + put(c, raw, g5p_usc_move(raw, H(c, dst), H(c, src), 0, 1, 0x21), "lent bank-1 register's value into bank 0"); + c->vtex_lent[c->nvtex_lent].bank1 = src; + c->vtex_lent[c->nvtex_lent].bank0 = dst; + c->nvtex_lent++; + c->vtex_lent_mask |= BITFIELD64_BIT(src); + c->busy &= ~BITFIELD64_BIT(src); + } + c->busy |= BITFIELD64_RANGE(best, n); + c->max_dword = MAX2(c->max_dword, best + n); + c->max_written = MAX2(c->max_written, best + n); + return best; +} + +/* The lent registers' values back into their own bank-1 registers (vtex_lend_run()). */ +static void vtex_return(struct gctx *c) +{ + uint8_t raw[G5P_USC_MAX]; + for (unsigned i = 0; i < c->nvtex_lent; i++) { + const unsigned b1 = c->vtex_lent[i].bank1, b0 = c->vtex_lent[i].bank0; + if ((c->busy | c->reserved) & BITFIELD64_BIT(b1)) + refuse(c, "register pressure: a lent bank-1 register is still in use after the vertex texture"); + put(c, raw, g5p_usc_move(raw, H(c, b1), H(c, b0), 1, 1, vhdr(c, 0x21, b0, -1, -1)), + "lent bank-1 register's value back from bank 0"); + c->busy = (c->busy & ~BITFIELD64_BIT(b0)) | BITFIELD64_BIT(b1); + } + c->nvtex_lent = 0; + c->vtex_lent_mask = 0; +} + static void emit_vertex_qualified_texture(struct gctx *c, nir_tex_instr *t) { uint8_t raw[G5P_USC_MAX]; struct tex_bind *b = tex_for(c, t); + /* the last vertex retry: the recipe may borrow held bank-1 registers (vtex_lend_run()) */ + c->vtex_lend = c->vs && c->vs_bank0 && c->vs_evict; + c->nvtex_lent = 0; + c->vtex_park_need = 0; + c->vtex_tex = t; + if (c->vtex_lend) + for (unsigned k = 0; k < (t->is_shadow ? 1u : 4u); k++) + c->vtex_park_need += V(c, &t->def, k)->uses != 0; bool read = t->op == nir_texop_txf, array = t->is_array; bool compare = t->is_shadow; bool cube = t->sampler_dim == GLSL_SAMPLER_DIM_CUBE; @@ -5430,7 +5587,17 @@ static void emit_vertex_qualified_texture(struct gctx *c, nir_tex_instr *t) if (packed >= 0) put(c, raw, xyz ? g5p_usc_half_immediate_xyz(raw, offset_half, packed, 1) : g5p_usc_vertex_half_immediate(raw, offset_half, packed), "qualified vertex packed offset"); + /* All SSA sources have been copied into the recipe's bank-1 scratch; release + * dying sources before allocating the 4-dword result run. */ + if (c->vs_bank0) { + for (unsigned i = 0; i < t->num_srcs; i++) + for (unsigned k = 0; k < t->src[i].src.ssa->num_components; k++) { + struct ref r = resolve_value(c, t->src[i].src.ssa, k); + free_dying(c, &r, 1); + } + } unsigned nresult = compare ? 1 : 4; + c->scratch |= scratch; unsigned dst = alloc_bank1_run(c, nresult, "qualified vertex texture result"); struct g5p_tex_ext x = { .dst_half=H(c,dst), .image_qword=b->image/2, @@ -5449,17 +5616,10 @@ static void emit_vertex_qualified_texture(struct gctx *c, nir_tex_instr *t) }; put(c, raw, g5p_usc_sample_ext(raw,&x), "qualified vertex sample/read recipe"); put(c, raw, g5p_usc_wait(raw,0), "wait"); - c->scratch |= scratch; if (c->vs_bank0) { /* All TPU operands have been consumed and WDF has retired the read. - * Release the recipe tuple and dying SSA sources before parking its - * results. Loop-extended last uses remain held by mark(). */ + * Release the recipe tuple before parking its results. */ free_scratch(c); - for (unsigned i = 0; i < t->num_srcs; i++) - for (unsigned k = 0; k < t->src[i].src.ssa->num_components; k++) { - struct ref r = resolve_value(c, t->src[i].src.ssa, k); - free_dying(c, &r, 1); - } } for (unsigned k=0;kdef,k); @@ -5494,6 +5654,9 @@ static void emit_vertex_qualified_texture(struct gctx *c, nir_tex_instr *t) c->busy &= ~BITFIELD64_BIT(dst + k); } } + c->vtex_lend = false; + c->vtex_tex = NULL; + vtex_return(c); c->p->evidence |= PCO_G5P_EV_TEX_TYPES; } @@ -6615,6 +6778,8 @@ static void eager_outputs(struct gctx *c, int idx) if (c->vout[i].at == idx) { unsigned r = c->vs_bank0 ? vs_out_reg(c, c->vout[i].r) : reg_of(c, c->vout[i].r, "vertex output"); put(c, raw, g5p_usc_vout(raw, H(c, r), c->vout[i].slot, vbank(c, r), false), "vertex output"); + if (c->vs_bank0) + free_scratch(c); } } @@ -8179,7 +8344,7 @@ static void decl_alloc(struct gctx *c, int ip) } v->state = VAL_REG; const bool out = c->alloc_out; - c->alloc_out = c->vs && c->vs_bank0 && c->decl_out[i]; + c->alloc_out = c->vs && c->vs_bank0 && !c->vs_evict && c->decl_out[i]; hold(c, v, alloc_reg(c, -1)); c->alloc_out = out; } @@ -8281,6 +8446,8 @@ static void emit_break(struct gctx *c, bool when_true) static void emit_if_else(struct gctx *c, nir_if *nif, bool sense) { + if (c->vs && c->vs_evict && !c->cf_depth) + evict_vertex_bank1_n(c, 12, false); stack_op(c, G5P_ST_PUSH, !sense, 1); c->cf_depth++; c->pushes++; @@ -8334,6 +8501,8 @@ static void emit_loop(struct gctx *c, nir_loop *l) tex_flush(c); c->now = nir_loop_first_block(l)->start_ip; decl_alloc(c, c->now); + if (c->vs && c->vs_evict && !c->cf_depth) + evict_vertex_bank1_n(c, 12, false); stack_op(c, G5P_ST_LOOP, false, 2); unsigned first_exit = c->nexits, body = c->size, pushes = c->pushes; c->cf_depth++; @@ -8396,15 +8565,15 @@ static void compact_vertex_bank1(struct gctx *c) * cf_operand() and the vertex texture park already emit. */ static bool evict_movable(struct gctx *c, unsigned r) { - if ((c->reserved | c->scratch | c->tex_pending | c->tex_coord_pending) & BITFIELD64_BIT(r)) + if ((c->reserved | c->scratch | c->tex_pending | c->tex_coord_pending | c->vtex_lent_mask) & BITFIELD64_BIT(r)) return false; if (!(c->busy & BITFIELD64_BIT(r))) return true; bool owned = false; for (unsigned i = 0; i < c->nvals; i++) if (c->vals[i].held && c->vals[i].reg == r) { - if (c->vals[i].last <= c->now) - return false; /* an operand of this instruction stays where it is */ + if (c->vals[i].decl || c->vals[i].last <= c->now) + return false; /* decls and operands of this instruction stay where they are */ owned = true; } return owned; /* a busy register with no value (a pair, a persistent constant) stays */ @@ -8419,12 +8588,13 @@ static int evict_last(struct gctx *c, unsigned r) return last; } -/* The aligned run of n bank-1 registers that is cheapest to free (fewest - * moves, then the latest nearest read), or -1. */ -static int evict_run(struct gctx *c, unsigned n) +/* The run of n bank-1 registers that is cheapest to free (fewest moves, then + * the latest nearest read), or -1. */ +static int evict_run(struct gctx *c, unsigned n, bool aligned) { + const unsigned step = aligned ? n : 1; int best = -1, best_cost = INT_MAX, best_near = -1; - for (unsigned r = 0; r + n <= NUM_DWORDS; r += n) { + for (unsigned r = 0; r + n <= NUM_DWORDS; r += step) { int cost = 0, near = INT_MAX; bool ok = true; for (unsigned k = r; k < r + n && ok; k++) { @@ -8443,13 +8613,13 @@ static int evict_run(struct gctx *c, unsigned n) return best; } -static void evict_vertex_bank1(struct gctx *c) +static void evict_vertex_bank1_n(struct gctx *c, unsigned n, bool aligned) { - int run = evict_run(c, 8); + int run = evict_run(c, n, aligned); if (run < 0) return; uint8_t raw[G5P_USC_MAX]; - u_foreach_bit64(src, BITFIELD64_RANGE(run, 8) & c->busy) { + u_foreach_bit64(src, BITFIELD64_RANGE(run, n) & c->busy) { int dst = alloc_bank0(c); if (dst < 0) return; /* bank 0 is full too: the instruction refuses as before */ @@ -8461,6 +8631,11 @@ static void evict_vertex_bank1(struct gctx *c) } } +static void evict_vertex_bank1(struct gctx *c) +{ + evict_vertex_bank1_n(c, 8, true); +} + static void emit_block(struct gctx *c, nir_block *block) { nir_foreach_instr(ins, block) { @@ -8471,7 +8646,7 @@ static void emit_block(struct gctx *c, nir_block *block) decl_alloc(c, c->now); if (c->vs && c->vs_bank0 && c->compact_vs && !c->cf) compact_vertex_bank1(c); - if (c->vs && c->vs_bank0 && c->vs_evict && !c->cf) + if (c->vs && c->vs_bank0 && c->vs_evict && !c->cf_depth) evict_vertex_bank1(c); switch (ins->type) { case nir_instr_type_alu: @@ -8549,6 +8724,10 @@ static bool codegen(struct gctx *c) memset(c->decl_held, 0, c->ndecls * sizeof(*c->decl_held)); c->stack_used = false; c->cf_depth = c->nexits = c->pushes = 0; + c->vtex_tex = NULL; + c->vtex_lend = false; + c->nvtex_lent = 0; + c->vtex_lent_mask = 0; plan_saturate(c); plan_bools(c); if (c->vs) @@ -8703,6 +8882,8 @@ static bool two_pass(struct gctx *c) for (unsigned i = 0; i < c->impl->ssa_alloc * 4; i++) c->lastput[i] = -1; c->klast[0] = c->klast[1] = c->klast[2] = -1; + if (c->evict_ladder) + c->vs_evict = c->vs && c->vs_bank0; /* Control flow always takes Apple's last-read groups (a read inside a * loop is never the last), and the count pass places the mask stack. */ if (!c->vs && !(c->key->last_read_groups || c->cf)) @@ -9116,7 +9297,8 @@ bool pco_g5p_compile_general_key(nir_shader *nir, bool half_output, const uint8_ static bool compile_general_link(nir_shader *nir, bool half_output, const uint8_t *attrib_components, const struct pco_g5p_fs_key *key, const struct pco_g5p_vs_link *link, - struct pco_g5p_program *out, bool preserve_cf, bool evict, bool last) + struct pco_g5p_program *out, bool preserve_cf, bool evict, bool last, + bool evict_ladder) { static const struct pco_g5p_fs_key default_key = {.write_mask = 0xf}; memset(out, 0, sizeof(*out)); @@ -9248,13 +9430,21 @@ static bool compile_general_link(nir_shader *nir, bool half_output, const uint8_ refuse(c, "out of memory"); memset(c->home, -1, c->impl->ssa_alloc * 4); schedule_texture_batches(c); + if (evict_ladder) { + /* pco_g5p_compile_general_link()'s retry after the eviction retry: every two-bank attempt below evicts + * (two_pass()), in the program's own order and in the orders the ladder makes */ + if (!c->vs || impl_has_side_effects(c->impl)) + refuse(c, "register pressure: bank-1 eviction is a vertex retry without stores"); + c->evict_ladder = true; + } if (evict) { - /* pco_g5p_compile_general_link()'s last vertex retry: the program's own order, temps in bank 0, attributes - * moved out of bank 1 where a bank-1-only form needs room (evict_vertex_bank1()) */ - /* as the other between-instruction mover (compact_vs): straight-line programs without stores */ - if (!c->vs || c->cf || impl_has_side_effects(c->impl)) - refuse(c, "register pressure: bank-1 eviction is a straight-line vertex retry without stores"); - c->vs_bank0 = c->remat = c->eager_vout = c->vs_evict = true; + /* pco_g5p_compile_general_link()'s last vertex retry: the program's own order, temps and outputs in bank 0, + * attributes and loaded values moved out of bank 1 where a bank-1-only form needs room + * (evict_vertex_bank1_n()) */ + if (!c->vs || impl_has_side_effects(c->impl)) + refuse(c, "register pressure: bank-1 eviction is a vertex retry without stores"); + c->vs_bank0 = c->remat = c->vs_evict = true; + c->eager_vout = !c->cf; ok = two_pass(c); goto done; } @@ -9417,6 +9607,20 @@ static bool compile_general_link(nir_shader *nir, bool half_output, const uint8_ return ok; } +/* out->refusal = @first, then @sep and the refusal now in out->refusal (cut at the buffer's end) */ +static void follow_refusal(struct pco_g5p_program *out, const char *first, const char *sep) +{ + char last[sizeof(out->refusal)]; + memcpy(last, out->refusal, sizeof(last)); + memcpy(out->refusal, first, sizeof(out->refusal)); + size_t len = strnlen(out->refusal, sizeof(out->refusal) - 1); + for (const char *s = sep; *s && len + 1 < sizeof(out->refusal); s++) + out->refusal[len++] = *s; + for (const char *s = last; *s && len + 1 < sizeof(out->refusal); s++) + out->refusal[len++] = *s; + out->refusal[len] = '\0'; +} + bool pco_g5p_compile_general_link(nir_shader *nir, bool half_output, const uint8_t *attrib_components, const struct pco_g5p_fs_key *key, const struct pco_g5p_vs_link *link, struct pco_g5p_program *out) @@ -9429,6 +9633,13 @@ bool pco_g5p_compile_general_link(nir_shader *nir, bool half_output, const uint8 * from its own order, before the scheduling retries reordered it, with the * attributes moved out of bank 1 where a bank-1-only form needs room * (evict_vertex_bank1()). Programs that compile today never get there. */ + /* A vertex program the eviction retry refused too goes through the whole + * ladder once more with the eviction in every two-bank attempt, so also in + * the orders the scheduling retries make. In its own order the evicted + * values can fill bank 0 before the program ends (Google Maps: bank 0 full, + * bank 1 free only in scattered registers, at a qualified vertex texture); + * the pressure-driven order holds fewer values at once. Programs that + * compile today never get there either. */ /* A fragment program every attempt below refused for pressure is compiled * a last time (compile_general_link()'s last): its own control flow with * the if/else chains' phi webs coalesced, and the registers above r31 @@ -9438,7 +9649,8 @@ bool pco_g5p_compile_general_link(nir_shader *nir, bool half_output, const uint8 const bool fs = nir->info.stage == MESA_SHADER_FRAGMENT; const bool fs_cf = fs && cf_left(nir); nir_shader *original = fs_cf || nir->info.stage == MESA_SHADER_VERTEX ? nir_shader_clone(NULL, nir) : NULL; - bool ok = compile_general_link(nir, half_output, attrib_components, key, link, out, false, false, fs && !fs_cf); + bool ok = compile_general_link(nir, half_output, attrib_components, key, link, out, false, false, fs && !fs_cf, + false); nir_shader *final = NULL; if (!ok && fs_cf && strstr(out->refusal, "register pressure")) final = nir_shader_clone(NULL, original); @@ -9446,12 +9658,21 @@ bool pco_g5p_compile_general_link(nir_shader *nir, bool half_output, const uint8 char first[sizeof(out->refusal)]; memcpy(first, out->refusal, sizeof(first)); const bool vs = nir->info.stage == MESA_SHADER_VERTEX; - ok = compile_general_link(original, half_output, attrib_components, key, link, out, !vs, vs, false); - if (!ok && vs) /* the ladder's own reason stays the one reported */ - memcpy(out->refusal, first, sizeof(first)); + nir_shader *again = vs ? nir_shader_clone(NULL, original) : NULL; + ok = compile_general_link(original, half_output, attrib_components, key, link, out, !vs, vs, false, false); + if (!ok && vs) { + /* the ladder's own reason stays the one reported first; the eviction retry's follows it, then the + * eviction ladder's */ + follow_refusal(out, first, "; bank-1 eviction retry: "); + memcpy(first, out->refusal, sizeof(first)); + ok = compile_general_link(again, half_output, attrib_components, key, link, out, false, false, false, true); + if (!ok) + follow_refusal(out, first, "; eviction ladder: "); + } + ralloc_free(again); } if (!ok && final && strstr(out->refusal, "register pressure")) - ok = compile_general_link(final, half_output, attrib_components, key, link, out, true, false, true); + ok = compile_general_link(final, half_output, attrib_components, key, link, out, true, false, true, false); ralloc_free(final); ralloc_free(original); return ok;