brw: Use live->max_vgrf_size in pre-RA scheduling

Post-RA scheduling doesn't use liveness analysis, so we continue using
MAX_VGRF_SIZE(devinfo).  But for pre-RA scheduling, we now use
live->max_vgrf_size.

This helps get us to a place where we can emit arbitrarily large VGRFs
early on in compilation, but which will be split and cleaned up prior to
register allocation.  It may also allocate smaller arrays in practice
since MAX_VGRF_SIZE(devinfo) assumes the worst case scenario for things
we actually could need to allocate.

Cc: mesa-stable
Reviewed-by: Matt Turner <mattst88@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/34461>
(cherry picked from commit a45583f078)
This commit is contained in:
Kenneth Graunke 2025-04-09 16:04:26 -07:00 committed by Eric Engestrom
parent 0d1e83ca6a
commit 7a588a5a8e
2 changed files with 11 additions and 8 deletions

View file

@ -1384,7 +1384,7 @@
"description": "brw: Use live->max_vgrf_size in pre-RA scheduling",
"nominated": true,
"nomination_type": 1,
"resolution": 0,
"resolution": 1,
"main_sha": null,
"because_sha": null,
"notes": null

View file

@ -643,6 +643,7 @@ public:
bool post_reg_alloc;
int grf_count;
unsigned max_vgrf_size;
const fs_visitor *s;
/**
@ -708,9 +709,6 @@ brw_instruction_scheduler::brw_instruction_scheduler(void *mem_ctx, const fs_vis
this->grf_count = grf_count;
this->post_reg_alloc = post_reg_alloc;
const unsigned grf_write_scale = MAX_VGRF_SIZE(s->devinfo);
this->last_grf_write = linear_zalloc_array(lin_ctx, schedule_node *, grf_count * grf_write_scale);
this->nodes_len = s->cfg->last_block()->end_ip + 1;
this->nodes = linear_zalloc_array(lin_ctx, schedule_node, this->nodes_len);
@ -774,8 +772,11 @@ brw_instruction_scheduler::brw_instruction_scheduler(void *mem_ctx, const fs_vis
this->written = NULL;
this->reads_remaining = NULL;
this->hw_reads_remaining = NULL;
this->max_vgrf_size = MAX_VGRF_SIZE(s->devinfo);
}
this->last_grf_write = linear_zalloc_array(lin_ctx, schedule_node *, grf_count * this->max_vgrf_size);
foreach_block(block, s->cfg) {
set_current_block(block);
@ -876,6 +877,8 @@ brw_instruction_scheduler::setup_liveness(cfg_t *cfg)
}
}
this->max_vgrf_size = live.max_vgrf_size;
ralloc_free(payload_last_use_ip);
}
@ -1212,13 +1215,13 @@ brw_instruction_scheduler::clear_last_grf_write()
if (inst->dst.file == VGRF) {
/* Don't bother being careful with regs_written(), quicker to just clear 2 cachelines. */
memset(&last_grf_write[inst->dst.nr * MAX_VGRF_SIZE(s->devinfo)], 0,
sizeof(*last_grf_write) * MAX_VGRF_SIZE(s->devinfo));
memset(&last_grf_write[inst->dst.nr * max_vgrf_size], 0,
sizeof(*last_grf_write) * max_vgrf_size);
}
}
} else {
memset(last_grf_write, 0,
sizeof(*last_grf_write) * grf_count * MAX_VGRF_SIZE(s->devinfo));
sizeof(*last_grf_write) * grf_count * max_vgrf_size);
}
}
@ -1227,7 +1230,7 @@ brw_instruction_scheduler::grf_index(const brw_reg &reg)
{
if (post_reg_alloc)
return reg.nr;
return reg.nr * MAX_VGRF_SIZE(s->devinfo) + reg.offset / REG_SIZE;
return reg.nr * max_vgrf_size + reg.offset / REG_SIZE;
}
void