r600g: implement timestamp query and get_timestamp hook
[mesa.git] / src / gallium / drivers / r600 / r600_shader.c
index cf912c1267d7f3678695d5dddb7e22d1aa15e7c7..ed95f4cdff324d569ca15148b8ac1d1ece788a5c 100644 (file)
@@ -367,31 +367,35 @@ static unsigned r600_fc_from_byte_stream(struct r600_shader_ctx *ctx,
        bytes_read = r600_src_from_byte_stream(bytes, bytes_read, &alu, 0);
        inst = bytes[bytes_read++];
        switch (inst) {
-       case 0:
+       case 0: /* FC_IF */
                llvm_if(ctx, &alu,
                        CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE));
                break;
-       case 1:
+       case 1: /* FC_IF_INT */
+               llvm_if(ctx, &alu,
+                       CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT));
+               break;
+       case 2: /* FC_ELSE */
                tgsi_else(ctx);
                break;
-       case 2:
+       case 3: /* FC_ENDIF */
                tgsi_endif(ctx);
                break;
-       case 3:
+       case 4: /* FC_BGNLOOP */
                tgsi_bgnloop(ctx);
                break;
-       case 4:
+       case 5: /* FC_ENDLOOP */
                tgsi_endloop(ctx);
                break;
-       case 5:
+       case 6: /* FC_BREAK */
                r600_break_from_byte_stream(ctx, &alu,
-                       CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE));
+                       CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT));
                break;
-       case 6:
+       case 7: /* FC_BREAK_NZ_INT */
                r600_break_from_byte_stream(ctx, &alu,
                        CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE_INT));
                break;
-       case 7:
+       case 8: /* FC_CONTINUE */
                {
                        unsigned opcode = TGSI_OPCODE_CONT;
                        if (ctx->bc->chip_class == CAYMAN) {
@@ -407,10 +411,14 @@ static unsigned r600_fc_from_byte_stream(struct r600_shader_ctx *ctx,
                        tgsi_loop_brk_cont(ctx);
                }
                break;
-       case 8:
+       case 9: /* FC_BREAK_Z_INT */
                r600_break_from_byte_stream(ctx, &alu,
                        CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETE_INT));
                break;
+       case 10: /* FC_BREAK_NZ */
+               r600_break_from_byte_stream(ctx, &alu,
+                       CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_PRED_SETNE));
+               break;
        }
 
        return bytes_read;
@@ -1564,6 +1572,7 @@ static int r600_shader_from_tgsi(struct r600_context * rctx, struct r600_pipe_sh
                                        j--;
                                        continue;
                                }
+                               output[j].swizzle_w = rctx->alpha_to_one && rctx->multisample_enable && !rctx->cb0_is_integer ? 5 : 3;
                                output[j].array_base = next_pixel_base++;
                                output[j].type = V_SQ_CF_ALLOC_EXPORT_WORD0_SQ_EXPORT_PIXEL;
                                shader->nr_ps_color_exports++;
@@ -1576,7 +1585,7 @@ static int r600_shader_from_tgsi(struct r600_context * rctx, struct r600_pipe_sh
                                                output[j].swizzle_x = 0;
                                                output[j].swizzle_y = 1;
                                                output[j].swizzle_z = 2;
-                                               output[j].swizzle_w = 3;
+                                               output[j].swizzle_w = rctx->alpha_to_one && rctx->multisample_enable && !rctx->cb0_is_integer ? 5 : 3;
                                                output[j].burst_count = 1;
                                                output[j].barrier = 1;
                                                output[j].array_base = next_pixel_base++;
@@ -3420,7 +3429,7 @@ static int tgsi_f2i(struct r600_shader_ctx *ctx)
                alu.src[0].sel = ctx->temp_reg;
                alu.src[0].chan = i;
 
-               if (i == last_inst)
+               if (i == last_inst || alu.inst == EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_FLT_TO_UINT)
                        alu.last = 1;
                r = r600_bytecode_add_alu(ctx->bc, &alu);
                if (r)
@@ -3736,9 +3745,10 @@ static int tgsi_tex(struct r600_shader_ctx *ctx)
        int opcode;
        /* Texture fetch instructions can only use gprs as source.
         * Also they cannot negate the source or take the absolute value */
-       const boolean src_requires_loading = tgsi_tex_src_requires_loading(ctx, 0);
+       const boolean src_requires_loading = inst->Instruction.Opcode != TGSI_OPCODE_TXQ_LZ &&
+                                             tgsi_tex_src_requires_loading(ctx, 0);
        boolean src_loaded = FALSE;
-       unsigned sampler_src_reg = 1;
+       unsigned sampler_src_reg = inst->Instruction.Opcode == TGSI_OPCODE_TXQ_LZ ? 0 : 1;
        uint8_t offset_x = 0, offset_y = 0, offset_z = 0;
 
        src_gpr = tgsi_tex_get_src_gpr(ctx, 0);
@@ -3871,7 +3881,8 @@ static int tgsi_tex(struct r600_shader_ctx *ctx)
 
        if ((inst->Texture.Texture == TGSI_TEXTURE_CUBE ||
             inst->Texture.Texture == TGSI_TEXTURE_SHADOWCUBE) &&
-           inst->Instruction.Opcode != TGSI_OPCODE_TXQ) {
+           inst->Instruction.Opcode != TGSI_OPCODE_TXQ &&
+           inst->Instruction.Opcode != TGSI_OPCODE_TXQ_LZ) {
 
                static const unsigned src0_swizzle[] = {2, 2, 0, 1};
                static const unsigned src1_swizzle[] = {1, 0, 2, 2};
@@ -4040,7 +4051,13 @@ static int tgsi_tex(struct r600_shader_ctx *ctx)
        tex.dst_sel_y = (inst->Dst[0].Register.WriteMask & 2) ? 1 : 7;
        tex.dst_sel_z = (inst->Dst[0].Register.WriteMask & 4) ? 2 : 7;
        tex.dst_sel_w = (inst->Dst[0].Register.WriteMask & 8) ? 3 : 7;
-       if (src_loaded) {
+
+       if (inst->Instruction.Opcode == TGSI_OPCODE_TXQ_LZ) {
+               tex.src_sel_x = 4;
+               tex.src_sel_y = 4;
+               tex.src_sel_z = 4;
+               tex.src_sel_w = 4;
+       } else if (src_loaded) {
                tex.src_sel_x = 0;
                tex.src_sel_y = 1;
                tex.src_sel_z = 2;
@@ -5299,8 +5316,8 @@ static struct r600_shader_tgsi_instruction r600_shader_tgsi_instruction[] = {
        {TGSI_OPCODE_BGNSUB,    0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {TGSI_OPCODE_ENDLOOP,   0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_endloop},
        {TGSI_OPCODE_ENDSUB,    0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
+       {TGSI_OPCODE_TXQ_LZ,    0, SQ_TEX_INST_GET_TEXTURE_RESINFO, tgsi_tex},
        /* gap */
-       {103,                   0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {104,                   0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {105,                   0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {106,                   0, V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
@@ -5473,8 +5490,8 @@ static struct r600_shader_tgsi_instruction eg_shader_tgsi_instruction[] = {
        {TGSI_OPCODE_BGNSUB,    0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {TGSI_OPCODE_ENDLOOP,   0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_endloop},
        {TGSI_OPCODE_ENDSUB,    0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
+       {TGSI_OPCODE_TXQ_LZ,    0, SQ_TEX_INST_GET_TEXTURE_RESINFO, tgsi_tex},
        /* gap */
-       {103,                   0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {104,                   0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {105,                   0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {106,                   0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
@@ -5647,8 +5664,8 @@ static struct r600_shader_tgsi_instruction cm_shader_tgsi_instruction[] = {
        {TGSI_OPCODE_BGNSUB,    0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {TGSI_OPCODE_ENDLOOP,   0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_endloop},
        {TGSI_OPCODE_ENDSUB,    0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
+       {TGSI_OPCODE_TXQ_LZ,    0, SQ_TEX_INST_GET_TEXTURE_RESINFO, tgsi_tex},
        /* gap */
-       {103,                   0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {104,                   0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {105,                   0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},
        {106,                   0, EG_V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_NOP, tgsi_unsupported},