i965: Allocate temporaries contiguously with other regs in fragment shaders.
[mesa.git] / src / mesa / drivers / dri / i965 / brw_wm_glsl.c
index 305100f8833993321ba7dedba147d909aae0de14..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 
@@ -850,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,
@@ -1368,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;