brw: Allocate brw_inst::src with ralloc

In the few cases we have to _increase_ the number of sources, the new
code will not attempt to recollect the memory, i.e. it delays freeing
the old smaller one source array.  For the instructions that may need
this (when making a SEND into a SEND_GATHER), this is not expected to
happen more than once.

Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/36730>
This commit is contained in:
Caio Oliveira 2025-08-09 15:03:49 -07:00 committed by Marge Bot
parent 29c12bbebf
commit 858162a2fc
2 changed files with 3 additions and 13 deletions

View file

@ -81,17 +81,11 @@ brw_inst::brw_inst(const brw_inst &that)
initialize_sources(this, that.src, that.sources);
}
brw_inst::~brw_inst()
{
if (this->src != this->builtin_src)
delete[] this->src;
}
static void
initialize_sources(brw_inst *inst, const brw_reg src[], uint8_t num_sources)
{
if (num_sources > ARRAY_SIZE(inst->builtin_src))
inst->src = new brw_reg[num_sources];
inst->src = ralloc_array(inst, brw_reg, num_sources);
else
inst->src = inst->builtin_src;
@ -114,7 +108,7 @@ brw_inst::resize_sources(uint8_t num_sources)
if (old_src == this->builtin_src) {
if (num_sources > builtin_size) {
new_src = new brw_reg[num_sources];
new_src = ralloc_array(this, brw_reg, num_sources);
for (unsigned i = 0; i < this->sources; i++)
new_src[i] = old_src[i];
@ -132,13 +126,10 @@ brw_inst::resize_sources(uint8_t num_sources)
new_src = old_src;
} else {
new_src = new brw_reg[num_sources];
new_src = ralloc_array(this, brw_reg, num_sources);
for (unsigned i = 0; i < this->sources; i++)
new_src[i] = old_src[i];
}
if (old_src != new_src)
delete[] old_src;
}
this->sources = num_sources;

View file

@ -51,7 +51,6 @@ public:
brw_inst(enum opcode opcode, uint8_t exec_size, const brw_reg &dst,
const brw_reg src[], unsigned sources);
brw_inst(const brw_inst &that);
~brw_inst();
void resize_sources(uint8_t num_sources);