i965: Always handle GL_DEPTH_TEXTURE_MODE through the shader.
authorEric Anholt <eric@anholt.net>
Fri, 18 Nov 2011 01:01:58 +0000 (17:01 -0800)
committerEric Anholt <eric@anholt.net>
Wed, 30 Nov 2011 00:44:51 +0000 (16:44 -0800)
We were already doing it through the shader (layered underneath
GL_EXT_texture_swizzle) in the shadow compare case.  This avoids
having per-format logic for switching out the surface format dependent
on the depth mode.

v2: Also do the swizzling for DEPTH_STENCIL.  oops.

Reviewed-by: Ian Romanick <idr@freedesktop.org>
Reviewed-by: Kenneth Graunke <kenneth@whitecape.org>
src/mesa/drivers/dri/i965/brw_wm.c
src/mesa/drivers/dri/i965/brw_wm_surface_state.c

index 377b8ba2231aa6b18bb31da65398044b286db097..207ffd6c63994c81961ead4fa17f3cfbfab98a46 100644 (file)
@@ -420,25 +420,40 @@ static void brw_wm_populate_key( struct brw_context *brw,
            SWIZZLE_NIL
         };
 
-        /* GL_DEPTH_TEXTURE_MODE is normally handled through
-         * brw_wm_surface_state, but it applies to shadow compares as
-         * well and our shadow compares always return the result in
-         * all 4 channels.
-         */
-        if (sampler->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB) {
-           key->compare_funcs[i] = sampler->CompareFunc;
-
-           if (sampler->DepthMode == GL_ALPHA) {
+        if (img->_BaseFormat == GL_DEPTH_COMPONENT ||
+            img->_BaseFormat == GL_DEPTH_STENCIL) {
+           if (sampler->CompareMode == GL_COMPARE_R_TO_TEXTURE_ARB)
+              key->compare_funcs[i] = sampler->CompareFunc;
+
+           /* 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 (sampler->DepthMode) {
+           case GL_ALPHA:
               swizzles[0] = SWIZZLE_ZERO;
               swizzles[1] = SWIZZLE_ZERO;
               swizzles[2] = SWIZZLE_ZERO;
-           } else if (sampler->DepthMode == GL_LUMINANCE) {
+              swizzles[3] = SWIZZLE_X;
+              break;
+           case GL_LUMINANCE:
+              swizzles[0] = SWIZZLE_X;
+              swizzles[1] = SWIZZLE_X;
+              swizzles[2] = SWIZZLE_X;
               swizzles[3] = SWIZZLE_ONE;
-           } else if (sampler->DepthMode == GL_RED) {
-              /* See table 3.23 of the GL 3.0 spec. */
+              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;
            }
         }
 
index 5a6896e63b422c8ec699e24c7a2727e59bda73f7..0f6abe2e54e7559bd0bab19cc0e60616f0bdcd4c 100644 (file)
@@ -568,29 +568,12 @@ translate_tex_format(gl_format mesa_format,
    switch( mesa_format ) {
 
    case MESA_FORMAT_Z16:
-      if (depth_mode == GL_INTENSITY) 
-         return BRW_SURFACEFORMAT_I16_UNORM;
-      else if (depth_mode == GL_ALPHA)
-         return BRW_SURFACEFORMAT_A16_UNORM;
-      else if (depth_mode == GL_RED)
-         return BRW_SURFACEFORMAT_R16_UNORM;
-      else
-         return BRW_SURFACEFORMAT_L16_UNORM;
+      return BRW_SURFACEFORMAT_I16_UNORM;
 
    case MESA_FORMAT_S8_Z24:
    case MESA_FORMAT_X8_Z24:
-      /* XXX: these different surface formats don't seem to
-       * make any difference for shadow sampler/compares.
-       */
-      if (depth_mode == GL_INTENSITY) 
-         return BRW_SURFACEFORMAT_I24X8_UNORM;
-      else if (depth_mode == GL_ALPHA)
-         return BRW_SURFACEFORMAT_A24X8_UNORM;
-      else if (depth_mode == GL_RED)
-         return BRW_SURFACEFORMAT_R24_UNORM_X8_TYPELESS;
-      else
-         return BRW_SURFACEFORMAT_L24X8_UNORM;
-      
+      return BRW_SURFACEFORMAT_I24X8_UNORM;
+
    case MESA_FORMAT_SARGB8:
    case MESA_FORMAT_SLA8:
    case MESA_FORMAT_SL8: