i965: Allocate temporaries contiguously with other regs in fragment shaders.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_wm_glsl.c
index fd237ee0287330b214a1d9036f411b2dff9c431d..b8a6b7b2339ef588cad2a387cf9b19878a7a613e 100644 (file)
@@ -1,4 +1,4 @@
-#include "macros.h"
+#include "main/macros.h"
 #include "shader/prog_parameter.h"
 #include "brw_context.h"
 #include "brw_eu.h"
@@ -47,13 +47,16 @@ static int get_scalar_dst_index(struct prog_instruction *inst)
 static struct brw_reg alloc_tmp(struct brw_wm_compile *c)
 {
     struct brw_reg reg;
-    reg = brw_vec8_grf(c->tmp_index--, 0);
+    if(c->tmp_index == c->tmp_max)
+       c->tmp_regs[ c->tmp_max++ ] = c->reg_index++;
+    
+    reg = brw_vec8_grf(c->tmp_regs[ c->tmp_index++ ], 0);
     return reg;
 }
 
 static void release_tmps(struct brw_wm_compile *c)
 {
-    c->tmp_index = 127;
+    c->tmp_index = 0;
 }
 
 static struct brw_reg 
@@ -274,10 +277,11 @@ static void emit_delta_xy(struct brw_wm_compile *c,
 
 static void fire_fb_write( struct brw_wm_compile *c,
                            GLuint base_reg,
-                           GLuint nr )
+                           GLuint nr,
+                           GLuint target,
+                           GLuint eot)
 {
     struct brw_compile *p = &c->func;
-
     /* Pass through control information:
      */
     /*  mov (8) m1.0<1>:ud   r1.0<8;8,1>:ud   { Align1 NoMask } */
@@ -294,10 +298,10 @@ static void fire_fb_write( struct brw_wm_compile *c,
            retype(vec8(brw_null_reg()), BRW_REGISTER_TYPE_UW),
            base_reg,
            retype(brw_vec8_grf(0, 0), BRW_REGISTER_TYPE_UW),
-           0,              /* render surface always 0 */
+           target,              
            nr,
            0,
-           1);
+           eot);
 }
 
 static void emit_fb_write(struct brw_wm_compile *c,
@@ -306,7 +310,8 @@ static void emit_fb_write(struct brw_wm_compile *c,
     struct brw_compile *p = &c->func;
     int nr = 2;
     int channel;
-    struct brw_reg src0;//, src1, src2, dst;
+    GLuint target, eot;
+    struct brw_reg src0;
 
     /* Reserve a space for AA - may not be needed:
      */
@@ -337,8 +342,9 @@ static void emit_fb_write(struct brw_wm_compile *c,
 
       nr += 2;
    }
-
-    fire_fb_write(c, 0, nr);
+    target = inst->Sampler >> 1;
+    eot = inst->Sampler & 1;
+    fire_fb_write(c, 0, nr, target, eot);
 }
 
 static void emit_pixel_w( struct brw_wm_compile *c,
@@ -847,20 +853,20 @@ static void emit_sop(struct brw_wm_compile *c,
     struct brw_reg dst, src0, src1;
     int i;
 
-    brw_push_insn_state(p);
     for (i = 0; i < 4; i++) {
        if (mask & (1<<i)) {
            dst = get_dst_reg(c, inst, i, 1);
            src0 = get_src_reg(c, &inst->SrcReg[0], i, 1);
            src1 = get_src_reg(c, &inst->SrcReg[1], i, 1);
+           brw_push_insn_state(p);
            brw_CMP(p, brw_null_reg(), cond, src0, src1);
            brw_set_predicate_control(p, BRW_PREDICATE_NONE);
            brw_MOV(p, dst, brw_imm_f(0.0));
            brw_set_predicate_control(p, BRW_PREDICATE_NORMAL);
            brw_MOV(p, dst, brw_imm_f(1.0));
+           brw_pop_insn_state(p);
        }
     }
-    brw_pop_insn_state(p);
 }
 
 static void emit_slt(struct brw_wm_compile *c,
@@ -975,7 +981,7 @@ static void emit_wpos_xy(struct brw_wm_compile *c,
        brw_ADD(p,
                dst[0],
                retype(src0[0], BRW_REGISTER_TYPE_W),
-               brw_imm_d(- c->key.origin_x));
+               brw_imm_d(- c->key.origin_x));
     }
 
     if (mask & WRITEMASK_Y) {
@@ -983,7 +989,7 @@ static void emit_wpos_xy(struct brw_wm_compile *c,
        brw_ADD(p,
                dst[1],
                negate(retype(src0[1], BRW_REGISTER_TYPE_W)),
-               brw_imm_d(c->key.origin_y + c->key.drawable_height));
+               brw_imm_d(c->key.origin_y + c->key.drawable_height - 1));
     }
 }
 
@@ -995,6 +1001,8 @@ static void emit_txb(struct brw_wm_compile *c,
 {
     struct brw_compile *p = &c->func;
     struct brw_reg dst[4], src[4], payload_reg;
+    GLuint unit = c->fp->program.Base.SamplerUnits[inst->TexSrcUnit];
+
     GLuint i;
     payload_reg = get_reg(c, PROGRAM_PAYLOAD, PAYLOAD_DEPTH, 0, 1, 0, 0);
     for (i = 0; i < 4; i++) 
@@ -1026,8 +1034,8 @@ static void emit_txb(struct brw_wm_compile *c,
            retype(vec8(dst[0]), BRW_REGISTER_TYPE_UW),
            1,
            retype(payload_reg, BRW_REGISTER_TYPE_UW),
-           inst->TexSrcUnit + 1, /* surface */
-           inst->TexSrcUnit,     /* sampler */
+           unit + MAX_DRAW_BUFFERS, /* surface */
+           unit,     /* sampler */
            inst->DstReg.WriteMask,
            BRW_SAMPLER_MESSAGE_SIMD16_SAMPLE_BIAS,
            4,
@@ -1040,10 +1048,12 @@ static void emit_tex(struct brw_wm_compile *c,
 {
     struct brw_compile *p = &c->func;
     struct brw_reg dst[4], src[4], payload_reg;
+    GLuint unit = c->fp->program.Base.SamplerUnits[inst->TexSrcUnit];
+
     GLuint msg_len;
     GLuint i, nr;
     GLuint emit;
-    GLboolean shadow = (c->key.shadowtex_mask & (1<<inst->TexSrcUnit)) ? 1 : 0;
+    GLboolean shadow = (c->key.shadowtex_mask & (1<<unit)) ? 1 : 0;
 
     payload_reg = get_reg(c, PROGRAM_PAYLOAD, PAYLOAD_DEPTH, 0, 1, 0, 0);
 
@@ -1088,8 +1098,8 @@ static void emit_tex(struct brw_wm_compile *c,
            retype(vec8(dst[0]), BRW_REGISTER_TYPE_UW),
            1,
            retype(payload_reg, BRW_REGISTER_TYPE_UW),
-           inst->TexSrcUnit + 1, /* surface */
-           inst->TexSrcUnit,     /* sampler */
+           unit + MAX_DRAW_BUFFERS, /* surface */
+           unit,     /* sampler */
            inst->DstReg.WriteMask,
            BRW_SAMPLER_MESSAGE_SIMD8_SAMPLE,
            4,
@@ -1125,7 +1135,6 @@ static void post_wm_emit( struct brw_wm_compile *c )
 }
 
 static void brw_wm_emit_glsl(struct brw_context *brw, struct brw_wm_compile *c)
-
 {
 #define MAX_IFSN 32
 #define MAX_LOOP_DEPTH 32
@@ -1135,7 +1144,6 @@ static void brw_wm_emit_glsl(struct brw_context *brw, struct brw_wm_compile *c)
     struct brw_compile *p = &c->func;
     struct brw_indirect stack_index = brw_indirect(0, 0);
 
-    brw_init_compile(brw, &c->func);
     c->reg_index = 0;
     prealloc_reg(c);
     brw_set_compression_control(p, BRW_COMPRESSION_NONE);
@@ -1363,7 +1371,6 @@ static void brw_wm_emit_glsl(struct brw_context *brw, struct brw_wm_compile *c)
 void brw_wm_glsl_emit(struct brw_context *brw, struct brw_wm_compile *c)
 {
     brw_wm_pass_fp(c);
-    c->tmp_index = 127;
     brw_wm_emit_glsl(brw, c);
     c->prog_data.total_grf = c->reg_index;
     c->prog_data.total_scratch = 0;