From 869d86e664a02de0dc9a7f31defaffaa8ef07f91 Mon Sep 17 00:00:00 2001 From: "Kristian H. Kristensen" Date: Wed, 22 Apr 2020 16:52:46 -0700 Subject: [PATCH] freedreno/computerator: Decouple ir3 assembler Specifically, don't include ir3_asm.h in the parser as that's computerator specific. Part-of: --- src/freedreno/computerator/a6xx.c | 6 ++-- src/freedreno/computerator/ir3_asm.c | 8 +++-- src/freedreno/computerator/ir3_asm.h | 5 ++-- src/freedreno/computerator/ir3_parser.y | 40 +++++++++++++++---------- 4 files changed, 36 insertions(+), 23 deletions(-) diff --git a/src/freedreno/computerator/a6xx.c b/src/freedreno/computerator/a6xx.c index 3484d3636de..b02718bc849 100644 --- a/src/freedreno/computerator/a6xx.c +++ b/src/freedreno/computerator/a6xx.c @@ -211,9 +211,9 @@ cs_const_emit(struct fd_ringbuffer *ring, struct kernel *kernel, uint32_t grid[3 uint32_t base = const_state->offsets.immediate; int size = const_state->immediates_count; - if (ir3_kernel->numwg != INVALID_REG) { - assert((ir3_kernel->numwg & 0x3) == 0); - int idx = ir3_kernel->numwg >> 2; + if (ir3_kernel->info.numwg != INVALID_REG) { + assert((ir3_kernel->info.numwg & 0x3) == 0); + int idx = ir3_kernel->info.numwg >> 2; const_state->immediates[idx].val[0] = grid[0]; const_state->immediates[idx].val[1] = grid[1]; const_state->immediates[idx].val[2] = grid[2]; diff --git a/src/freedreno/computerator/ir3_asm.c b/src/freedreno/computerator/ir3_asm.c index 11cc7ee06f7..46e21347407 100644 --- a/src/freedreno/computerator/ir3_asm.c +++ b/src/freedreno/computerator/ir3_asm.c @@ -41,14 +41,18 @@ ir3_asm_assemble(struct ir3_compiler *c, FILE *in) kernel->v = v; - kernel->numwg = INVALID_REG; + kernel->info.numwg = INVALID_REG; - v->ir = ir3_parse(kernel, in); + v->ir = ir3_parse(v, &kernel->info, in); if (!v->ir) errx(-1, "parse failed"); ir3_debug_print(v->ir, "AFTER PARSING"); + memcpy(kernel->base.local_size, kernel->info.local_size, sizeof(kernel->base.local_size)); + kernel->base.num_bufs = kernel->info.num_bufs; + memcpy(kernel->base.buf_sizes, kernel->info.buf_sizes, sizeof(kernel->base.buf_sizes)); + kernel->bin = ir3_shader_assemble(v, c->gpu_id); unsigned sz = v->info.sizedwords * 4; diff --git a/src/freedreno/computerator/ir3_asm.h b/src/freedreno/computerator/ir3_asm.h index 576623e0236..5bb19c09645 100644 --- a/src/freedreno/computerator/ir3_asm.h +++ b/src/freedreno/computerator/ir3_asm.h @@ -27,15 +27,14 @@ #include "main.h" #include "ir3/ir3_shader.h" +#include "ir3_parser.h" struct ir3_kernel { struct kernel base; + struct ir3_kernel_info info; struct backend *backend; struct ir3_shader_variant *v; void *bin; - - /* driver-param uniforms: */ - unsigned numwg; }; define_cast(kernel, ir3_kernel); diff --git a/src/freedreno/computerator/ir3_parser.y b/src/freedreno/computerator/ir3_parser.y index e4b02cca9ed..f12222e7a5c 100644 --- a/src/freedreno/computerator/ir3_parser.y +++ b/src/freedreno/computerator/ir3_parser.y @@ -22,8 +22,20 @@ */ %code requires { -struct ir3_kernel; -struct ir3 * ir3_parse(struct ir3_kernel *k, FILE *f); + +#define MAX_BUFS 4 + +struct ir3_kernel_info { + uint32_t local_size[3]; + uint32_t num_bufs; + uint32_t buf_sizes[MAX_BUFS]; /* size in dwords */ + + /* driver-param uniforms: */ + unsigned numwg; +}; + +struct ir3 * ir3_parse(struct ir3_shader_variant *v, + struct ir3_kernel_info *k, FILE *f); } %{ @@ -41,7 +53,6 @@ struct ir3 * ir3_parse(struct ir3_kernel *k, FILE *f); #include "ir3/instr-a3xx.h" #include "ir3_parser.h" -#include "ir3_asm.h" /* ir3 treats the abs/neg flags as separate flags for float vs integer, * but in the instruction encoding they are the same thing. Tracking @@ -51,7 +62,7 @@ struct ir3 * ir3_parse(struct ir3_kernel *k, FILE *f); #define IR3_REG_ABS IR3_REG_FABS #define IR3_REG_NEGATE IR3_REG_FNEG -static struct ir3_kernel *kernel; +static struct ir3_kernel_info *info; static struct ir3_shader_variant *variant; /* NOTE the assembler doesn't really use the ir3_block construction * like the compiler does. Everything is treated as one large block. @@ -193,14 +204,15 @@ static void yyerror(const char *error) fprintf(stderr, "error at line %d: %s\n", ir3_yyget_lineno(), error); } -struct ir3 * ir3_parse(struct ir3_kernel *k, FILE *f) +struct ir3 * ir3_parse(struct ir3_shader_variant *v, + struct ir3_kernel_info *k, FILE *f) { ir3_yyin = f; #ifdef YYDEBUG yydebug = 1; #endif - kernel = k; - variant = k->v; + info = k; + variant = v; if (yyparse()) { ir3_destroy(variant->ir); variant->ir = NULL; @@ -501,10 +513,9 @@ const_val: T_FLOAT { $$ = fui($1); } | T_HEX { $$ = $1; } localsize_header: T_A_LOCALSIZE const_val ',' const_val ',' const_val { - struct kernel *k = &kernel->base; - k->local_size[0] = $2; - k->local_size[1] = $4; - k->local_size[2] = $6; + info->local_size[0] = $2; + info->local_size[1] = $4; + info->local_size[2] = $6; } const_header: T_A_CONST '(' T_CONSTANT ')' const_val ',' const_val ',' const_val ',' const_val { @@ -512,10 +523,9 @@ const_header: T_A_CONST '(' T_CONSTANT ')' const_val ',' const_val ',' cons } buf_header: T_A_BUF const_val { - struct kernel *k = &kernel->base; - int idx = k->num_bufs++; + int idx = info->num_bufs++; assert(idx < MAX_BUFS); - k->buf_sizes[idx] = $2; + info->buf_sizes[idx] = $2; } invocationid_header: T_A_INVOCATIONID '(' T_REGISTER ')' { @@ -534,7 +544,7 @@ wgid_header: T_A_WGID '(' T_REGISTER ')' { numwg_header: T_A_NUMWG '(' T_CONSTANT ')' { assert(($3 & 0x1) == 0); /* half-reg not allowed */ unsigned reg = $3 >> 1; - kernel->numwg = reg; + info->numwg = reg; /* reserve space in immediates for the actual value to be plugged in later: */ add_const($3, 0, 0, 0, 0); } -- 2.30.2