freedreno/computerator: Decouple ir3 assembler
authorKristian H. Kristensen <hoegsberg@google.com>
Wed, 22 Apr 2020 23:52:46 +0000 (16:52 -0700)
committerMarge Bot <eric+marge@anholt.net>
Sat, 25 Apr 2020 00:03:43 +0000 (00:03 +0000)
Specifically, don't include ir3_asm.h in the parser as that's
computerator specific.

Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/4741>

src/freedreno/computerator/a6xx.c
src/freedreno/computerator/ir3_asm.c
src/freedreno/computerator/ir3_asm.h
src/freedreno/computerator/ir3_parser.y

index 3484d3636de1901c271e5bf4993245259ea89398..b02718bc8494957579af6f1cfc82ea387bed988c 100644 (file)
@@ -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];
index 11cc7ee06f74d7f05f33e25b2a892d935f2942b2..46e213474072ef1f9d2fecc41d6cb127ea4067bf 100644 (file)
@@ -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;
index 576623e0236a8437d777893e3577f151b9661713..5bb19c096452e716056d6caf8fd7d4b34b6a15ee 100644 (file)
 #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);
 
index e4b02cca9ed6390f97ab7b865a95a7095d85be79..f12222e7a5cb8f5af39c047eec551c4c7719cb50 100644 (file)
  */
 
 %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);
 }