Mesa (master): i965: implement GL_EXT_texture_swizzle

Brian Paul brianp at kemper.freedesktop.org
Wed Jan 28 22:07:15 UTC 2009


Module: Mesa
Branch: master
Commit: c0d3b7679aa90e1a0dca2db152205efaec088b90
URL:    http://cgit.freedesktop.org/mesa/mesa/commit/?id=c0d3b7679aa90e1a0dca2db152205efaec088b90

Author: Brian Paul <brianp at vmware.com>
Date:   Wed Jan 28 14:50:03 2009 -0700

i965: implement GL_EXT_texture_swizzle

If the texture swizzle is not XYZW (no-op) add an extra MOV instruction
after the TEX instruction to rearrange the components.

---

 src/mesa/drivers/dri/i965/brw_wm.c            |    5 +++++
 src/mesa/drivers/dri/i965/brw_wm.h            |    2 ++
 src/mesa/drivers/dri/i965/brw_wm_fp.c         |   19 +++++++++++++++++++
 src/mesa/drivers/dri/intel/intel_extensions.c |    1 +
 4 files changed, 27 insertions(+), 0 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index 1683308..3ee0ead 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -242,6 +242,11 @@ static void brw_wm_populate_key( struct brw_context *brw,
 	    if (img->TexFormat->MesaFormat == MESA_FORMAT_YCBCR)
 		key->yuvtex_swap_mask |= 1 << i;
 	 }
+
+         key->tex_swizzles[i] = t->_Swizzle;
+      }
+      else {
+         key->tex_swizzles[i] = SWIZZLE_NOOP;
       }
    }
 
diff --git a/src/mesa/drivers/dri/i965/brw_wm.h b/src/mesa/drivers/dri/i965/brw_wm.h
index 388c6f7..0f46a25 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.h
+++ b/src/mesa/drivers/dri/i965/brw_wm.h
@@ -70,6 +70,8 @@ struct brw_wm_prog_key {
    GLuint yuvtex_mask:16;
    GLuint yuvtex_swap_mask:16;	/* UV swaped */
 
+   GLuint tex_swizzles[BRW_MAX_TEX_UNIT];
+
    GLuint program_string_id:32;
    GLuint origin_x, origin_y;
    GLuint drawable_height;
diff --git a/src/mesa/drivers/dri/i965/brw_wm_fp.c b/src/mesa/drivers/dri/i965/brw_wm_fp.c
index fdacad0..6b3f51d 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_fp.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_fp.c
@@ -111,6 +111,12 @@ static struct prog_src_register src_swizzle1( struct prog_src_register reg, int
    return src_swizzle(reg, x, x, x, x);
 }
 
+static struct prog_src_register src_swizzle4( struct prog_src_register reg, uint swizzle )
+{
+   reg.Swizzle = swizzle;
+   return reg;
+}
+
 
 /***********************************************************************
  * Dest regs
@@ -751,6 +757,19 @@ static void precalc_tex( struct brw_wm_compile *c,
 	      src_undef());
    }
 
+   /* For GL_EXT_texture_swizzle: */
+   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);
+      emit_op(c, OPCODE_MOV,
+              inst->DstReg,
+              SATURATE_OFF, /* saturate already done above */
+              0, 0,   /* tex unit, target N/A */
+              src_swizzle4(tmpsrc, c->key.tex_swizzles[unit]),
+              src_undef(),
+              src_undef());
+   }
+
    if ((inst->TexSrcTarget == TEXTURE_RECT_INDEX) ||
        (inst->TexSrcTarget == TEXTURE_CUBE_INDEX))
       release_temp(c, tmpcoord);
diff --git a/src/mesa/drivers/dri/intel/intel_extensions.c b/src/mesa/drivers/dri/intel/intel_extensions.c
index 2395501..8f09f8d 100644
--- a/src/mesa/drivers/dri/intel/intel_extensions.c
+++ b/src/mesa/drivers/dri/intel/intel_extensions.c
@@ -137,6 +137,7 @@ static const struct dri_extension brw_extensions[] = {
    { "GL_EXT_shadow_funcs",               NULL },
    { "GL_EXT_stencil_two_side",           GL_EXT_stencil_two_side_functions },
    { "GL_EXT_texture_sRGB",		  NULL },
+   { "GL_EXT_texture_swizzle",		  NULL },
    { "GL_EXT_vertex_array_bgra",	  NULL },
    { "GL_ATI_separate_stencil",           GL_ATI_separate_stencil_functions },
    { "GL_ATI_texture_env_combine3",       NULL },




More information about the mesa-commit mailing list