r600g: fix up vs export handling
[mesa.git] / src / gallium / drivers / r600 / r600_shader.c
index de49d212a587c11a3bcca92b37023b6c8ad1fb0e..fc56656f55d034340315824f3eacac0e3810e584 100644 (file)
@@ -332,6 +332,12 @@ static int tgsi_declaration(struct r600_shader_ctx *ctx)
                ctx->shader->output[i].sid = d->Semantic.Index;
                ctx->shader->output[i].gpr = ctx->file_offset[TGSI_FILE_OUTPUT] + i;
                ctx->shader->output[i].interpolate = d->Declaration.Interpolate;
+               if (ctx->type == TGSI_PROCESSOR_VERTEX) {
+                       /* these don't count as vertex param exports */
+                       if ((ctx->shader->output[i].name == TGSI_SEMANTIC_POSITION) ||
+                           (ctx->shader->output[i].name == TGSI_SEMANTIC_PSIZE))
+                               ctx->shader->npos++;
+               }
                break;
        case TGSI_FILE_CONSTANT:
        case TGSI_FILE_TEMPORARY:
@@ -658,9 +664,9 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
                ctx.file_offset[TGSI_FILE_INPUT] = evergreen_gpr_count(&ctx);
        }
        ctx.file_offset[TGSI_FILE_OUTPUT] = ctx.file_offset[TGSI_FILE_INPUT] +
-                                               ctx.info.file_count[TGSI_FILE_INPUT];
+                                               ctx.info.file_max[TGSI_FILE_INPUT] + 1;
        ctx.file_offset[TGSI_FILE_TEMPORARY] = ctx.file_offset[TGSI_FILE_OUTPUT] +
-                                               ctx.info.file_count[TGSI_FILE_OUTPUT];
+                                               ctx.info.file_max[TGSI_FILE_OUTPUT] + 1;
 
        /* Outside the GPR range. This will be translated to one of the
         * kcache banks later. */
@@ -668,7 +674,7 @@ static int r600_shader_from_tgsi(struct r600_pipe_context * rctx, struct r600_pi
 
        ctx.file_offset[TGSI_FILE_IMMEDIATE] = V_SQ_ALU_SRC_LITERAL;
        ctx.ar_reg = ctx.file_offset[TGSI_FILE_TEMPORARY] +
-                       ctx.info.file_count[TGSI_FILE_TEMPORARY];
+                       ctx.info.file_max[TGSI_FILE_TEMPORARY] + 1;
        ctx.temp_reg = ctx.ar_reg + 1;
 
        ctx.nliterals = 0;
@@ -1370,6 +1376,22 @@ static int tgsi_lit(struct r600_shader_ctx *ctx)
        struct r600_bc_alu alu;
        int r;
 
+       /* tmp.x = max(src.y, 0.0) */
+       memset(&alu, 0, sizeof(struct r600_bc_alu));
+       alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_MAX);
+       r600_bc_src(&alu.src[0], &ctx->src[0], 1);
+       alu.src[1].sel  = V_SQ_ALU_SRC_0; /*0.0*/
+       alu.src[1].chan = 1;
+
+       alu.dst.sel = ctx->temp_reg;
+       alu.dst.chan = 0;
+       alu.dst.write = 1;
+
+       alu.last = 1;
+       r = r600_bc_add_alu(ctx->bc, &alu);
+       if (r)
+               return r;
+
        if (inst->Dst[0].Register.WriteMask & (1 << 2))
        {
                int chan;
@@ -1378,11 +1400,13 @@ static int tgsi_lit(struct r600_shader_ctx *ctx)
 
                if (ctx->bc->chip_class == CAYMAN) {
                        for (i = 0; i < 3; i++) {
-                               /* dst.z = log(src.y) */
+                               /* tmp.z = log(tmp.x) */
                                memset(&alu, 0, sizeof(struct r600_bc_alu));
                                alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED);
-                               r600_bc_src(&alu.src[0], &ctx->src[0], 1);
-                               tgsi_dst(ctx, &inst->Dst[0], i, &alu.dst);
+                               alu.src[0].sel = ctx->temp_reg;
+                               alu.src[0].chan = 0;
+                               alu.dst.sel = ctx->temp_reg;
+                               alu.dst.chan = i;
                                if (i == 2) {
                                        alu.dst.write = 1;
                                        alu.last = 1;
@@ -1394,10 +1418,11 @@ static int tgsi_lit(struct r600_shader_ctx *ctx)
                                        return r;
                        }
                } else {
-                       /* tmp.z = log(src.y) */
+                       /* tmp.z = log(tmp.x) */
                        memset(&alu, 0, sizeof(struct r600_bc_alu));
                        alu.inst = CTX_INST(V_SQ_ALU_WORD1_OP2_SQ_OP2_INST_LOG_CLAMPED);
-                       r600_bc_src(&alu.src[0], &ctx->src[0], 1);
+                       alu.src[0].sel = ctx->temp_reg;
+                       alu.src[0].chan = 0;
                        alu.dst.sel = ctx->temp_reg;
                        alu.dst.chan = 2;
                        alu.dst.write = 1;