freedreno,computerator: support initialization of buffers

The following syntax can now be used to set the initial content of
buffers:

@buf size (reg) val0, val1, ...

If the buffer is not fully initialized, remaining values will be set to
zero.

Signed-off-by: Job Noorman <jnoorman@igalia.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/28625>
This commit is contained in:
Job Noorman 2024-04-08 10:38:31 +02:00 committed by Marge Bot
parent b3e65c77c4
commit 8d55b6155c
6 changed files with 42 additions and 1 deletions

View File

@ -0,0 +1,9 @@
@localsize 8, 1, 1
@buf 8 1, 2, 3, 4, 5, 6, 7, 8
@invocationid(r0.x)
ldib.b.untyped.1d.u32.4.imm r1.x, r0.x, 0
(sy)add.u r1.x, r1.x, 5
(rpt5)nop
stib.b.untyped.1d.u32.4.imm r1.x, r0.x, 0
end

View File

@ -46,6 +46,8 @@ ir3_asm_assemble(struct ir3_compiler *c, FILE *in)
sizeof(kernel->base.buf_sizes));
memcpy(kernel->base.buf_addr_regs, kernel->info.buf_addr_regs,
sizeof(kernel->base.buf_addr_regs));
memcpy(kernel->base.buf_init_data, kernel->info.buf_init_data,
sizeof(kernel->base.buf_init_data));
unsigned sz = v->info.size;

View File

@ -269,6 +269,13 @@ main(int argc, char **argv)
for (int i = 0; i < kernel->num_bufs; i++) {
printf("buf[%d]: size=%u\n", i, kernel->buf_sizes[i]);
kernel->bufs[i] = fd_bo_new(dev, kernel->buf_sizes[i] * 4, 0, "buf[%d]", i);
if (kernel->buf_init_data[i]) {
fd_bo_cpu_prep(kernel->bufs[i], pipe, FD_BO_PREP_WRITE);
void *map = fd_bo_map(kernel->bufs[i]);
memcpy(map, kernel->buf_init_data[i], kernel->buf_sizes[i] * 4);
free(kernel->buf_init_data[i]);
}
}
if (disasm)

View File

@ -42,6 +42,7 @@ struct kernel {
uint32_t num_bufs;
uint32_t buf_sizes[MAX_BUFS]; /* size in dwords */
uint32_t buf_addr_regs[MAX_BUFS];
uint32_t *buf_init_data[MAX_BUFS];
/* filled in by frontend before launching grid: */
struct fd_bo *bufs[MAX_BUFS];

View File

@ -37,6 +37,8 @@ struct ir3_kernel_info {
uint32_t num_bufs;
uint32_t buf_sizes[MAX_BUFS]; /* size in dwords */
uint32_t buf_addr_regs[MAX_BUFS];
uint32_t *buf_init_data[MAX_BUFS];
uint32_t buf_init_data_sizes[MAX_BUFS];
uint64_t shader_print_buffer_iova;

View File

@ -236,6 +236,21 @@ static void add_const(unsigned reg, unsigned c0, unsigned c1, unsigned c2, unsig
const_state->immediates[idx * 4 + 3] = c3;
}
static void add_buf_init_val(uint32_t val)
{
assert(info->num_bufs > 0);
unsigned idx = info->num_bufs - 1;
if (!info->buf_init_data[idx]) {
unsigned sz = info->buf_sizes[idx] * 4;
info->buf_init_data[idx] = malloc(sz);
memset(info->buf_init_data[idx], 0, sz);
}
assert(info->buf_init_data_sizes[idx] < info->buf_sizes[idx]);
info->buf_init_data[idx][info->buf_init_data_sizes[idx]++] = val;
}
static void add_sysval(unsigned reg, unsigned compmask, gl_system_value sysval)
{
unsigned n = variant->inputs_count++;
@ -752,6 +767,11 @@ const_header: T_A_CONST '(' T_CONSTANT ')' const_val ',' const_val ',' cons
add_const($3, $5, $7, $9, $11);
}
buf_header_init_val: const_val { add_buf_init_val($1); }
buf_header_init_vals: buf_header_init_val
| buf_header_init_val ',' buf_header_init_vals
|
buf_header_addr_reg:
'(' T_CONSTANT ')' {
assert(($2 & 0x1) == 0); /* half-reg not allowed */
@ -767,7 +787,7 @@ buf_header: T_A_BUF const_val {
int idx = info->num_bufs++;
assert(idx < MAX_BUFS);
info->buf_sizes[idx] = $2;
} buf_header_addr_reg
} buf_header_addr_reg buf_header_init_vals
invocationid_header: T_A_INVOCATIONID '(' T_REGISTER ')' {
assert(($3 & 0x1) == 0); /* half-reg not allowed */