mesa: add/update comments in _mesa_copy_buffer_subdata()
[mesa.git] / src / mesa / drivers / dri / i965 / brw_wm_fp.c
index 6c9a38eed0a0b7a5ba4411da4b7685e902d54169..1358e749558ab6038ee82dfdb07ed77b4ecefba9 100644 (file)
@@ -215,10 +215,6 @@ static struct prog_instruction * emit_tex_op(struct brw_wm_compile *c,
    assert(tex_src_target < NUM_TEXTURE_TARGETS ||
           tex_src_target == TEX_TARGET_NONE);
 
-   /* update mask of which texture units are referenced by this program */
-   if (tex_src_unit != TEX_UNIT_NONE)
-      c->fp->tex_units_used |= (1 << tex_src_unit);
-
    memset(inst, 0, sizeof(*inst));
 
    inst->Opcode = op;
@@ -669,6 +665,17 @@ static void precalc_tex( struct brw_wm_compile *c,
    struct prog_src_register coord;
    struct prog_dst_register tmpcoord = { 0 };
    const GLuint unit = c->fp->program.Base.SamplerUnits[inst->TexSrcUnit];
+   struct prog_dst_register unswizzled_tmp;
+
+   /* If we are doing EXT_texture_swizzle, we need to write our result into a
+    * temporary, otherwise writemasking of the real dst could lose some of our
+    * channels.
+    */
+   if (c->key.tex.swizzles[unit] != SWIZZLE_NOOP) {
+      unswizzled_tmp = get_temp(c);
+   } else {
+      unswizzled_tmp = inst->DstReg;
+   }
 
    assert(unit < BRW_MAX_TEX_UNIT);
 
@@ -764,9 +771,9 @@ static void precalc_tex( struct brw_wm_compile *c,
     * conversion requires allocating a temporary variable which we
     * don't have the facility to do that late in the compilation.
     */
-   if (c->key.yuvtex_mask & (1 << unit)) {
+   if (c->key.tex.yuvtex_mask & (1 << unit)) {
       /* convert ycbcr to RGBA */
-      bool  swap_uv = c->key.yuvtex_swap_mask & (1<<unit);
+      bool swap_uv = c->key.tex.yuvtex_swap_mask & (1 << unit);
 
       /* 
         CONST C0 = { -.5, -.0625,  -.5, 1.164 }
@@ -780,7 +787,6 @@ static void precalc_tex( struct brw_wm_compile *c,
            RGB.xyz = MAD UYV.xxz, C1,   UYV.y 
         RGB.y   = MAD UYV.z,   C1.w, RGB.y
       */
-      struct prog_dst_register dst = inst->DstReg;
       struct prog_dst_register tmp = get_temp(c);
       struct prog_src_register tmpsrc = src_reg_from_dst(tmp);
       struct prog_src_register C0 = search_or_add_const4f( c,  -.5, -.0625, -.5, 1.164 );
@@ -829,7 +835,7 @@ static void precalc_tex( struct brw_wm_compile *c,
 
       emit_op(c,
              OPCODE_MAD,
-             dst_mask(dst, WRITEMASK_XYZ),
+             dst_mask(unswizzled_tmp, WRITEMASK_XYZ),
              0,
              swap_uv?src_swizzle(tmpsrc, Z,Z,X,X):src_swizzle(tmpsrc, X,X,Z,Z),
              C1,
@@ -839,11 +845,11 @@ static void precalc_tex( struct brw_wm_compile *c,
        */
       emit_op(c,
              OPCODE_MAD,
-             dst_mask(dst, WRITEMASK_Y),
+             dst_mask(unswizzled_tmp, WRITEMASK_Y),
              0,
              src_swizzle1(tmpsrc, Z),
              src_swizzle1(C1, W),
-             src_swizzle1(src_reg_from_dst(dst), Y));
+             src_swizzle1(src_reg_from_dst(unswizzled_tmp), Y));
 
       release_temp(c, tmp);
    }
@@ -851,7 +857,7 @@ static void precalc_tex( struct brw_wm_compile *c,
       /* ordinary RGBA tex instruction */
       emit_tex_op(c, 
                   OPCODE_TEX,
-                  inst->DstReg,
+                  unswizzled_tmp,
                   inst->SaturateMode,
                   unit,
                   inst->TexSrcTarget,
@@ -862,13 +868,13 @@ static void precalc_tex( struct brw_wm_compile *c,
    }
 
    /* For GL_EXT_texture_swizzle: */
-   if (c->key.tex_swizzles[unit] != SWIZZLE_NOOP) {
+   if (c->key.tex.swizzles[unit] != SWIZZLE_NOOP) {
       /* swizzle the result of the TEX instruction */
-      struct prog_src_register tmpsrc = src_reg_from_dst(inst->DstReg);
+      struct prog_src_register tmpsrc = src_reg_from_dst(unswizzled_tmp);
       emit_op(c, OPCODE_SWZ,
               inst->DstReg,
               SATURATE_OFF, /* saturate already done above */
-              src_swizzle4(tmpsrc, c->key.tex_swizzles[unit]),
+              src_swizzle4(tmpsrc, c->key.tex.swizzles[unit]),
               src_undef(),
               src_undef());
    }
@@ -1066,7 +1072,6 @@ void brw_wm_pass_fp( struct brw_wm_compile *c )
    }
    c->pixel_w = src_undef();
    c->nr_fp_insns = 0;
-   c->fp->tex_units_used = 0x0;
 
    /* Emit preamble instructions.  This is where special instructions such as
     * WM_CINTERP, WM_LINTERP, WM_PINTERP and WM_WPOSXY are emitted to