vc4: Add support for the FACE semantic.
[mesa.git] / src / gallium / drivers / vc4 / vc4_qir.c
index ef8a4e54d2427268a6b36a6dbe7a8a2a57f981ac..432fb1bf55569e280d1dd4f06f7b624db1102ad4 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "util/u_memory.h"
 #include "util/u_simple_list.h"
+#include "util/ralloc.h"
 
 #include "vc4_qir.h"
 #include "vc4_qpu.h"
@@ -76,7 +77,8 @@ static const struct qir_op_info qir_op_info[] = {
         [QOP_VPM_WRITE] = { "vpm_write", 0, 1, true },
         [QOP_VPM_READ] = { "vpm_read", 0, 1, true },
         [QOP_TLB_DISCARD_SETUP] = { "discard", 0, 1, true },
-        [QOP_TLB_PASSTHROUGH_Z_WRITE] = { "tlb_passthrough_z", 0, 0, true },
+        [QOP_TLB_STENCIL_SETUP] = { "tlb_stencil_setup", 0, 1, true },
+        [QOP_TLB_Z_WRITE] = { "tlb_z", 0, 1, true },
         [QOP_TLB_COLOR_WRITE] = { "tlb_color", 0, 1, true },
         [QOP_TLB_COLOR_READ] = { "tlb_color_read", 1, 0, true },
         [QOP_VARY_ADD_C] = { "vary_add_c", 1, 1 },
@@ -84,7 +86,8 @@ static const struct qir_op_info qir_op_info[] = {
         [QOP_FRAG_X] = { "frag_x", 1, 0 },
         [QOP_FRAG_Y] = { "frag_y", 1, 0 },
         [QOP_FRAG_Z] = { "frag_z", 1, 0 },
-        [QOP_FRAG_RCP_W] = { "frag_rcp_w", 1, 0 },
+        [QOP_FRAG_W] = { "frag_w", 1, 0 },
+        [QOP_FRAG_REV_FLAG] = { "frag_rev_flag", 1, 0 },
 
         [QOP_TEX_S] = { "tex_s", 0, 2 },
         [QOP_TEX_T] = { "tex_t", 0, 2 },
@@ -95,6 +98,10 @@ static const struct qir_op_info qir_op_info[] = {
         [QOP_R4_UNPACK_B] = { "r4_unpack_b", 1, 1 },
         [QOP_R4_UNPACK_C] = { "r4_unpack_c", 1, 1 },
         [QOP_R4_UNPACK_D] = { "r4_unpack_d", 1, 1 },
+        [QOP_UNPACK_8A] = { "unpack_8a", 1, 1 },
+        [QOP_UNPACK_8B] = { "unpack_8b", 1, 1 },
+        [QOP_UNPACK_8C] = { "unpack_8c", 1, 1 },
+        [QOP_UNPACK_8D] = { "unpack_8d", 1, 1 },
 };
 
 static const char *
@@ -119,8 +126,7 @@ bool
 qir_has_side_effects(struct qinst *inst)
 {
         for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
-                if (inst->src[i].file == QFILE_VARY ||
-                    inst->src[i].file == QFILE_UNIF)
+                if (inst->src[i].file == QFILE_VARY)
                         return true;
         }
 
@@ -176,7 +182,7 @@ qir_reads_r4(struct qinst *inst)
 }
 
 static void
-qir_print_reg(struct qreg reg)
+qir_print_reg(struct vc4_compile *c, struct qreg reg)
 {
         const char *files[] = {
                 [QFILE_TEMP] = "t",
@@ -188,17 +194,24 @@ qir_print_reg(struct qreg reg)
                 fprintf(stderr, "null");
         else
                 fprintf(stderr, "%s%d", files[reg.file], reg.index);
+
+        if (reg.file == QFILE_UNIF &&
+            c->uniform_contents[reg.index] == QUNIFORM_CONSTANT) {
+                fprintf(stderr, " (0x%08x / %f)",
+                        c->uniform_data[reg.index],
+                        uif(c->uniform_data[reg.index]));
+        }
 }
 
 void
-qir_dump_inst(struct qinst *inst)
+qir_dump_inst(struct vc4_compile *c, struct qinst *inst)
 {
         fprintf(stderr, "%s ", qir_get_op_name(inst->op));
 
-        qir_print_reg(inst->dst);
+        qir_print_reg(c, inst->dst);
         for (int i = 0; i < qir_get_op_nsrc(inst->op); i++) {
                 fprintf(stderr, ", ");
-                qir_print_reg(inst->src[i]);
+                qir_print_reg(c, inst->src[i]);
         }
 }
 
@@ -209,7 +222,7 @@ qir_dump(struct vc4_compile *c)
 
         foreach(node, &c->instructions) {
                 struct qinst *inst = (struct qinst *)node;
-                qir_dump_inst(inst);
+                qir_dump_inst(c, inst);
                 fprintf(stderr, "\n");
         }
 }
@@ -274,17 +287,34 @@ qir_reg_equals(struct qreg a, struct qreg b)
 struct vc4_compile *
 qir_compile_init(void)
 {
-        struct vc4_compile *c = CALLOC_STRUCT(vc4_compile);
+        struct vc4_compile *c = rzalloc(NULL, struct vc4_compile);
 
         make_empty_list(&c->instructions);
 
+        c->output_position_index = -1;
+        c->output_color_index = -1;
+
         return c;
 }
 
+void
+qir_remove_instruction(struct qinst *qinst)
+{
+        remove_from_list(&qinst->link);
+        free(qinst->src);
+        free(qinst);
+}
+
 void
 qir_compile_destroy(struct vc4_compile *c)
 {
-        free(c);
+        while (!is_empty_list(&c->instructions)) {
+                struct qinst *qinst =
+                        (struct qinst *)first_elem(&c->instructions);
+                qir_remove_instruction(qinst);
+        }
+
+        ralloc_free(c);
 }
 
 const char *