Merge branch 'gallium-0.1' into gallium-0.2
[mesa.git] / src / mesa / drivers / dri / i965 / brw_wm_glsl.c
index e738086fefb06fe43b445892a05117bc0f3302be..305100f8833993321ba7dedba147d909aae0de14 100644 (file)
@@ -5,7 +5,7 @@
 #include "brw_wm.h"
 
 /* Only guess, need a flag in gl_fragment_program later */
-GLboolean brw_wm_is_glsl(struct gl_fragment_program *fp)
+GLboolean brw_wm_is_glsl(const struct gl_fragment_program *fp)
 {
     int i;
     for (i = 0; i < fp->Base.NumInstructions; i++) {
@@ -274,10 +274,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 +295,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 +307,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 +339,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,
@@ -967,21 +970,23 @@ static void emit_wpos_xy(struct brw_wm_compile *c,
     src0[0] = get_src_reg(c, &inst->SrcReg[0], 0, 1);
     src0[1] = get_src_reg(c, &inst->SrcReg[0], 1, 1);
 
-    /* Calc delta X,Y by subtracting origin in r1 from the pixel
-     * centers.
+    /* Calculate the pixel offset from window bottom left into destination
+     * X and Y channels.
      */
     if (mask & WRITEMASK_X) {
-       brw_MOV(p,
+       /* X' = X - origin_x */
+       brw_ADD(p,
                dst[0],
-               retype(src0[0], BRW_REGISTER_TYPE_UW));
+               retype(src0[0], BRW_REGISTER_TYPE_W),
+               brw_imm_d(0 - c->key.origin_x));
     }
 
     if (mask & WRITEMASK_Y) {
-       /* TODO -- window_height - Y */
-       brw_MOV(p,
+       /* Y' = height - (Y - origin_y) = height + origin_y - Y */
+       brw_ADD(p,
                dst[1],
-               retype(src0[1], BRW_REGISTER_TYPE_UW));
-
+               negate(retype(src0[1], BRW_REGISTER_TYPE_W)),
+               brw_imm_d(c->key.origin_y + c->key.drawable_height - 1));
     }
 }
 
@@ -993,6 +998,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++) 
@@ -1024,8 +1031,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,
@@ -1038,10 +1045,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);
 
@@ -1086,8 +1095,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,
@@ -1122,8 +1131,7 @@ static void post_wm_emit( struct brw_wm_compile *c )
     }
 }
 
-static void brw_wm_emit_glsl(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
@@ -1133,7 +1141,6 @@ static void brw_wm_emit_glsl(struct brw_wm_compile *c)
     struct brw_compile *p = &c->func;
     struct brw_indirect stack_index = brw_indirect(0, 0);
 
-    brw_init_compile(&c->func);
     c->reg_index = 0;
     prealloc_reg(c);
     brw_set_compression_control(p, BRW_COMPRESSION_NONE);
@@ -1358,11 +1365,11 @@ static void brw_wm_emit_glsl(struct brw_wm_compile *c)
        c->fp->program.Base.Instructions[i].Data = NULL;
 }
 
-void brw_wm_glsl_emit(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(c);
+    brw_wm_emit_glsl(brw, c);
     c->prog_data.total_grf = c->reg_index;
     c->prog_data.total_scratch = 0;
 }