i965: Refactor texture swizzle generation into a helper.
authorKenneth Graunke <kenneth@whitecape.org>
Fri, 7 Sep 2012 20:24:16 +0000 (13:24 -0700)
committerKenneth Graunke <kenneth@whitecape.org>
Thu, 27 Sep 2012 05:58:30 +0000 (22:58 -0700)
It's going to be reused in a second place soon.

Reviewed-by: Eric Anholt <eric@anholt.net>
Signed-off-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_state.h
src/mesa/drivers/dri/i965/brw_wm.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c

index 99fa088a90f865df82d05525601e3c0855f4e9dc..48dd4ba76bb4e3cb945a24e239c1389938034b6b 100644 (file)
@@ -202,6 +202,8 @@ GLuint translate_tex_format(gl_format mesa_format,
                            GLenum depth_mode,
                            GLenum srgb_decode);
 
+int brw_get_texture_swizzle(const struct gl_texture_object *t);
+
 /* gen7_wm_surface_state.c */
 void gen7_set_surface_tiling(struct gen7_surface_state *surf, uint32_t tiling);
 void gen7_set_surface_msaa(struct gen7_surface_state *surf,
index 995e8f3fa2190f3ae33218de1a1f6e639eefa6a2..0f115259867f8d9fd4e314b1182986e62506512c 100644 (file)
@@ -504,49 +504,8 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
         const struct gl_texture_object *t = unit->_Current;
         const struct gl_texture_image *img = t->Image[0][t->BaseLevel];
         struct gl_sampler_object *sampler = _mesa_get_samplerobj(ctx, unit_id);
-        int swizzles[SWIZZLE_NIL + 1] = {
-           SWIZZLE_X,
-           SWIZZLE_Y,
-           SWIZZLE_Z,
-           SWIZZLE_W,
-           SWIZZLE_ZERO,
-           SWIZZLE_ONE,
-           SWIZZLE_NIL
-        };
-
-        if (img->_BaseFormat == GL_DEPTH_COMPONENT ||
-            img->_BaseFormat == GL_DEPTH_STENCIL) {
-           /* We handle GL_DEPTH_TEXTURE_MODE here instead of as surface
-            * format overrides because shadow comparison always returns the
-            * result of the comparison in all channels anyway.
-            */
-           switch (t->DepthMode) {
-           case GL_ALPHA:
-              swizzles[0] = SWIZZLE_ZERO;
-              swizzles[1] = SWIZZLE_ZERO;
-              swizzles[2] = SWIZZLE_ZERO;
-              swizzles[3] = SWIZZLE_X;
-              break;
-           case GL_LUMINANCE:
-              swizzles[0] = SWIZZLE_X;
-              swizzles[1] = SWIZZLE_X;
-              swizzles[2] = SWIZZLE_X;
-              swizzles[3] = SWIZZLE_ONE;
-              break;
-           case GL_INTENSITY:
-              swizzles[0] = SWIZZLE_X;
-              swizzles[1] = SWIZZLE_X;
-              swizzles[2] = SWIZZLE_X;
-              swizzles[3] = SWIZZLE_X;
-              break;
-           case GL_RED:
-              swizzles[0] = SWIZZLE_X;
-              swizzles[1] = SWIZZLE_ZERO;
-              swizzles[2] = SWIZZLE_ZERO;
-              swizzles[3] = SWIZZLE_ONE;
-              break;
-           }
-        }
+
+        key->swizzles[s] = brw_get_texture_swizzle(t);
 
         if (img->InternalFormat == GL_YCBCR_MESA) {
            key->yuvtex_mask |= 1 << s;
@@ -554,12 +513,6 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
                key->yuvtex_swap_mask |= 1 << s;
         }
 
-        key->swizzles[s] =
-           MAKE_SWIZZLE4(swizzles[GET_SWZ(t->_Swizzle, 0)],
-                         swizzles[GET_SWZ(t->_Swizzle, 1)],
-                         swizzles[GET_SWZ(t->_Swizzle, 2)],
-                         swizzles[GET_SWZ(t->_Swizzle, 3)]);
-
         if (sampler->MinFilter != GL_NEAREST &&
             sampler->MagFilter != GL_NEAREST) {
            if (sampler->WrapS == GL_CLAMP)
index 582e2399a15d1a923a2fe3cb5c813a403af43205..abdcb8478bae79dc5b22986b362bd2d362c2da31 100644 (file)
@@ -653,6 +653,62 @@ brw_get_surface_num_multisamples(unsigned num_samples)
 }
 
 
+/**
+ * Compute the combination of DEPTH_TEXTURE_MODE and EXT_texture_swizzle
+ * swizzling.
+ */
+int
+brw_get_texture_swizzle(const struct gl_texture_object *t)
+{
+   const struct gl_texture_image *img = t->Image[0][t->BaseLevel];
+
+   int swizzles[SWIZZLE_NIL + 1] = {
+      SWIZZLE_X,
+      SWIZZLE_Y,
+      SWIZZLE_Z,
+      SWIZZLE_W,
+      SWIZZLE_ZERO,
+      SWIZZLE_ONE,
+      SWIZZLE_NIL
+   };
+
+   if (img->_BaseFormat == GL_DEPTH_COMPONENT ||
+       img->_BaseFormat == GL_DEPTH_STENCIL) {
+      switch (t->DepthMode) {
+      case GL_ALPHA:
+         swizzles[0] = SWIZZLE_ZERO;
+         swizzles[1] = SWIZZLE_ZERO;
+         swizzles[2] = SWIZZLE_ZERO;
+         swizzles[3] = SWIZZLE_X;
+         break;
+      case GL_LUMINANCE:
+         swizzles[0] = SWIZZLE_X;
+         swizzles[1] = SWIZZLE_X;
+         swizzles[2] = SWIZZLE_X;
+         swizzles[3] = SWIZZLE_ONE;
+         break;
+      case GL_INTENSITY:
+         swizzles[0] = SWIZZLE_X;
+         swizzles[1] = SWIZZLE_X;
+         swizzles[2] = SWIZZLE_X;
+         swizzles[3] = SWIZZLE_X;
+         break;
+      case GL_RED:
+         swizzles[0] = SWIZZLE_X;
+         swizzles[1] = SWIZZLE_ZERO;
+         swizzles[2] = SWIZZLE_ZERO;
+         swizzles[3] = SWIZZLE_ONE;
+         break;
+      }
+   }
+
+   return MAKE_SWIZZLE4(swizzles[GET_SWZ(t->_Swizzle, 0)],
+                        swizzles[GET_SWZ(t->_Swizzle, 1)],
+                        swizzles[GET_SWZ(t->_Swizzle, 2)],
+                        swizzles[GET_SWZ(t->_Swizzle, 3)]);
+}
+
+
 static void
 brw_update_buffer_texture_surface(struct gl_context *ctx,
                                   unsigned unit,