radeonsi: don't use lp_build_if for the wrapping if block in merged shaders
[mesa.git] / src / gallium / drivers / r600 / r600_asm.c
index f333e7769a0ff288d6241bf3f84cb27f79a0eccd..4ba77c535f9b05cd44bb48ddb51094bd8608ea71 100644 (file)
@@ -43,7 +43,7 @@ static inline bool alu_writes(struct r600_bytecode_alu *alu)
        return alu->dst.write || alu->is_op3;
 }
 
-static inline unsigned int r600_bytecode_get_num_operands(struct r600_bytecode_alu *alu)
+static inline unsigned int r600_bytecode_get_num_operands(const struct r600_bytecode_alu *alu)
 {
        return r600_isa_alu(alu->op)->src_count;
 }
@@ -231,6 +231,25 @@ int r600_bytecode_add_output(struct r600_bytecode *bc,
        return 0;
 }
 
+int r600_bytecode_add_pending_output(struct r600_bytecode *bc,
+               const struct r600_bytecode_output *output)
+{
+       assert(bc->n_pending_outputs + 1 < ARRAY_SIZE(bc->pending_outputs));
+       bc->pending_outputs[bc->n_pending_outputs++] = *output;
+
+       return 0;
+}
+
+void r600_bytecode_need_wait_ack(struct r600_bytecode *bc, boolean need_wait_ack)
+{
+       bc->need_wait_ack = need_wait_ack;
+}
+
+boolean r600_bytecode_get_need_wait_ack(struct r600_bytecode *bc)
+{
+       return bc->need_wait_ack;
+}
+
 /* alu instructions that can ony exits once per group */
 static int is_alu_once_inst(struct r600_bytecode_alu *alu)
 {
@@ -402,7 +421,8 @@ static int reserve_gpr(struct alu_bank_swizzle *bs, unsigned sel, unsigned chan,
        return 0;
 }
 
-static int reserve_cfile(struct r600_bytecode *bc, struct alu_bank_swizzle *bs, unsigned sel, unsigned chan)
+static int reserve_cfile(const struct r600_bytecode *bc,
+                        struct alu_bank_swizzle *bs, unsigned sel, unsigned chan)
 {
        int res, num_res = 4;
        if (bc->chip_class >= R700) {
@@ -444,7 +464,7 @@ static int is_const(int sel)
                sel <= V_SQ_ALU_SRC_LITERAL);
 }
 
-static int check_vector(struct r600_bytecode *bc, struct r600_bytecode_alu *alu,
+static int check_vector(const struct r600_bytecode *bc, const struct r600_bytecode_alu *alu,
                        struct alu_bank_swizzle *bs, int bank_swizzle)
 {
        int r, src, num_src, sel, elem, cycle;
@@ -474,7 +494,7 @@ static int check_vector(struct r600_bytecode *bc, struct r600_bytecode_alu *alu,
        return 0;
 }
 
-static int check_scalar(struct r600_bytecode *bc, struct r600_bytecode_alu *alu,
+static int check_scalar(const struct r600_bytecode *bc, const struct r600_bytecode_alu *alu,
                        struct alu_bank_swizzle *bs, int bank_swizzle)
 {
        int r, src, num_src, const_count, sel, elem, cycle;
@@ -520,7 +540,7 @@ static int check_scalar(struct r600_bytecode *bc, struct r600_bytecode_alu *alu,
        return 0;
 }
 
-static int check_and_set_bank_swizzle(struct r600_bytecode *bc,
+static int check_and_set_bank_swizzle(const struct r600_bytecode *bc,
                                      struct r600_bytecode_alu *slots[5])
 {
        struct alu_bank_swizzle bs;
@@ -1007,6 +1027,7 @@ static int r600_bytecode_alloc_inst_kcache_lines(struct r600_bytecode *bc,
                        continue;
 
                bank = alu->src[i].kc_bank;
+               assert(bank < R600_MAX_HW_CONST_BUFFERS);
                line = (sel-512)>>4;
                index_mode = alu->src[i].kc_rel ? 1 : 0; // V_SQ_CF_INDEX_0 / V_SQ_CF_INDEX_NONE
 
@@ -1299,6 +1320,15 @@ int r600_bytecode_add_alu_type(struct r600_bytecode *bc,
        if (nalu->dst.rel && bc->r6xx_nop_after_rel_dst)
                insert_nop_r6xx(bc);
 
+       /* Might need to insert spill write ops after current clause */
+       if (nalu->last && bc->n_pending_outputs) {
+               while (bc->n_pending_outputs) {
+                       r = r600_bytecode_add_output(bc, &bc->pending_outputs[--bc->n_pending_outputs]);
+                       if (r)
+                               return r;
+               }
+       }
+
        return 0;
 }
 
@@ -1491,6 +1521,13 @@ int r600_bytecode_add_gds(struct r600_bytecode *bc, const struct r600_bytecode_g
 int r600_bytecode_add_cfinst(struct r600_bytecode *bc, unsigned op)
 {
        int r;
+
+       /* Emit WAIT_ACK before control flow to ensure pending writes are always acked. */
+       if (op != CF_OP_MEM_SCRATCH && bc->need_wait_ack) {
+               bc->need_wait_ack = false;
+               r = r600_bytecode_add_cfinst(bc, CF_OP_WAIT_ACK);
+       }
+
        r = r600_bytecode_add_cf(bc);
        if (r)
                return r;
@@ -1508,7 +1545,10 @@ int cm_bytecode_add_cf_end(struct r600_bytecode *bc)
 /* common to all 3 families */
 static int r600_bytecode_vtx_build(struct r600_bytecode *bc, struct r600_bytecode_vtx *vtx, unsigned id)
 {
-       bc->bytecode[id] = S_SQ_VTX_WORD0_BUFFER_ID(vtx->buffer_id) |
+       if (r600_isa_fetch(vtx->op)->flags & FF_MEM)
+               return r700_bytecode_fetch_mem_build(bc, vtx, id);
+       bc->bytecode[id] = S_SQ_VTX_WORD0_VTX_INST(r600_isa_fetch_opcode(bc->isa->hw_class, vtx->op)) |
+                       S_SQ_VTX_WORD0_BUFFER_ID(vtx->buffer_id) |
                        S_SQ_VTX_WORD0_FETCH_TYPE(vtx->fetch_type) |
                        S_SQ_VTX_WORD0_SRC_GPR(vtx->src_gpr) |
                        S_SQ_VTX_WORD0_SRC_SEL_X(vtx->src_sel_x);
@@ -1624,7 +1664,8 @@ static void r600_bytecode_cf_vtx_build(uint32_t *bytecode, const struct r600_byt
        *bytecode++ = S_SQ_CF_WORD0_ADDR(cf->addr >> 1);
        *bytecode++ = S_SQ_CF_WORD1_CF_INST(r600_isa_cf_opcode(ISA_CC_R600, cf->op)) |
                        S_SQ_CF_WORD1_BARRIER(1) |
-                       S_SQ_CF_WORD1_COUNT((cf->ndw / 4) - 1);
+                       S_SQ_CF_WORD1_COUNT((cf->ndw / 4) - 1)|
+                       S_SQ_CF_WORD1_END_OF_PROGRAM(cf->end_of_program);
 }
 
 /* common for r600/r700 - eg in eg_asm.c */
@@ -1968,6 +2009,21 @@ static int print_src(struct r600_bytecode_alu *alu, unsigned idx)
                        o += fprintf(stderr, "LDS_OQ_B_POP");
                        need_chan = 1;
                        break;
+               case EG_V_SQ_ALU_SRC_TIME_LO:
+                       o += fprintf(stderr, "TIME_LO");
+                       break;
+               case EG_V_SQ_ALU_SRC_TIME_HI:
+                       o += fprintf(stderr, "TIME_HI");
+                       break;
+               case EG_V_SQ_ALU_SRC_SE_ID:
+                       o += fprintf(stderr, "SE_ID");
+                       break;
+               case EG_V_SQ_ALU_SRC_SIMD_ID:
+                       o += fprintf(stderr, "SIMD_ID");
+                       break;
+               case EG_V_SQ_ALU_SRC_HW_WAVE_ID:
+                       o += fprintf(stderr, "HW_WAVE_ID");
+                       break;
                case V_SQ_ALU_SRC_PS:
                        o += fprintf(stderr, "PS");
                        break;
@@ -2086,7 +2142,12 @@ void r600_bytecode_disasm(struct r600_bytecode *bc)
                                fprintf(stderr, "%04d %08X %08X  %s ", id, bc->bytecode[id],
                                                bc->bytecode[id + 1], cfop->name);
                                fprintf(stderr, "%d @%d ", cf->ndw / 4, cf->addr);
+                               if (cf->vpm)
+                                       fprintf(stderr, "VPM ");
+                               if (cf->end_of_program)
+                                       fprintf(stderr, "EOP ");
                                fprintf(stderr, "\n");
+
                        } else if (cfop->flags & CF_EXP) {
                                int o = 0;
                                const char *exp_type[] = {"PIXEL", "POS  ", "PARAM"};
@@ -2115,6 +2176,8 @@ void r600_bytecode_disasm(struct r600_bytecode *bc)
                                print_indent(o, 67);
 
                                fprintf(stderr, " ES:%X ", cf->output.elem_size);
+                               if (cf->mark)
+                                       fprintf(stderr, "MARK ");
                                if (!cf->barrier)
                                        fprintf(stderr, "NO_BARRIER ");
                                if (cf->end_of_program)
@@ -2128,6 +2191,15 @@ void r600_bytecode_disasm(struct r600_bytecode *bc)
                                                bc->bytecode[id], bc->bytecode[id + 1], cfop->name);
                                o += print_indent(o, 43);
                                o += fprintf(stderr, "%s ", exp_type[cf->output.type]);
+
+                               if (r600_isa_cf(cf->op)->flags & CF_RAT) {
+                                       o += fprintf(stderr, "RAT%d", cf->rat.id);
+                                       if (cf->rat.index_mode) {
+                                               o += fprintf(stderr, "[IDX%d]", cf->rat.index_mode - 1);
+                                       }
+                                       o += fprintf(stderr, " INST: %d ", cf->rat.inst);
+                               }
+
                                if (cf->output.burst_count > 1) {
                                        o += fprintf(stderr, "%d-%d ", cf->output.array_base,
                                                        cf->output.array_base + cf->output.burst_count - 1);
@@ -2155,10 +2227,16 @@ void r600_bytecode_disasm(struct r600_bytecode *bc)
                                fprintf(stderr, " ES:%i ", cf->output.elem_size);
                                if (cf->output.array_size != 0xFFF)
                                        fprintf(stderr, "AS:%i ", cf->output.array_size);
+                               if (cf->mark)
+                                       fprintf(stderr, "MARK ");
                                if (!cf->barrier)
                                        fprintf(stderr, "NO_BARRIER ");
                                if (cf->end_of_program)
                                        fprintf(stderr, "EOP ");
+
+                               if (cf->output.mark)
+                                       fprintf(stderr, "MARK ");
+
                                fprintf(stderr, "\n");
                        } else {
                                fprintf(stderr, "%04d %08X %08X  %s ", id, bc->bytecode[id],
@@ -2170,6 +2248,8 @@ void r600_bytecode_disasm(struct r600_bytecode *bc)
                                        fprintf(stderr, "POP:%X ", cf->pop_count);
                                if (cf->count && (cfop->flags & CF_EMIT))
                                        fprintf(stderr, "STREAM%d ", cf->count);
+                               if (cf->vpm)
+                                       fprintf(stderr, "VPM ");
                                if (cf->end_of_program)
                                        fprintf(stderr, "EOP ");
                                fprintf(stderr, "\n");
@@ -2290,6 +2370,8 @@ void r600_bytecode_disasm(struct r600_bytecode *bc)
 
                        o += fprintf(stderr, ", R%d.", vtx->src_gpr);
                        o += print_swizzle(vtx->src_sel_x);
+                       if (r600_isa_fetch(vtx->op)->flags & FF_MEM)
+                               o += print_swizzle(vtx->src_sel_y);
 
                        if (vtx->offset)
                                fprintf(stderr, " +%db", vtx->offset);
@@ -2306,6 +2388,19 @@ void r600_bytecode_disasm(struct r600_bytecode *bc)
                        if (bc->chip_class >= EVERGREEN && vtx->buffer_index_mode)
                                fprintf(stderr, "SQ_%s ", index_mode[vtx->buffer_index_mode]);
 
+                       if (r600_isa_fetch(vtx->op)->flags & FF_MEM) {
+                               if (vtx->uncached)
+                                       fprintf(stderr, "UNCACHED ");
+                               if (vtx->indexed)
+                                       fprintf(stderr, "INDEXED:%d ", vtx->indexed);
+
+                               fprintf(stderr, "ELEM_SIZE:%d ", vtx->elem_size);
+                               if (vtx->burst_count)
+                                       fprintf(stderr, "BURST_COUNT:%d ", vtx->burst_count);
+                               fprintf(stderr, "ARRAY_BASE:%d ", vtx->array_base);
+                               fprintf(stderr, "ARRAY_SIZE:%d ", vtx->array_size);
+                       }
+
                        fprintf(stderr, "UCF:%d ", vtx->use_const_fields);
                        fprintf(stderr, "FMT(DTA:%d ", vtx->data_format);
                        fprintf(stderr, "NUM:%d ", vtx->num_format_all);
@@ -2375,6 +2470,17 @@ void r600_vertex_data_type(enum pipe_format pformat,
                return;
        }
 
+       if (pformat == PIPE_FORMAT_B5G5R5A1_UNORM) {
+               *format = FMT_1_5_5_5;
+               *endian = r600_endian_swap(16);
+               return;
+       }
+
+       if (pformat == PIPE_FORMAT_A1B5G5R5_UNORM) {
+               *format = FMT_5_5_5_1;
+               return;
+       }
+
        desc = util_format_description(pformat);
        if (desc->layout != UTIL_FORMAT_LAYOUT_PLAIN) {
                goto out_unknown;
@@ -2432,6 +2538,16 @@ void r600_vertex_data_type(enum pipe_format pformat,
                /* Signed ints */
        case UTIL_FORMAT_TYPE_SIGNED:
                switch (desc->channel[i].size) {
+               case 4:
+                       switch (desc->nr_channels) {
+                       case 2:
+                               *format = FMT_4_4;
+                               break;
+                       case 4:
+                               *format = FMT_4_4_4_4;
+                               break;
+                       }
+                       break;
                case 8:
                        switch (desc->nr_channels) {
                        case 1:
@@ -2656,7 +2772,9 @@ void *r600_create_vertex_fetch_shader(struct pipe_context *ctx,
                return NULL;
        }
 
-       bytecode = r600_buffer_map_sync_with_rings(&rctx->b, shader->buffer, PIPE_TRANSFER_WRITE | PIPE_TRANSFER_UNSYNCHRONIZED);
+       bytecode = r600_buffer_map_sync_with_rings
+               (&rctx->b, shader->buffer,
+               PIPE_TRANSFER_WRITE | PIPE_TRANSFER_UNSYNCHRONIZED | RADEON_TRANSFER_TEMPORARY);
        bytecode += shader->offset / 4;
 
        if (R600_BIG_ENDIAN) {