[Mesa-dev] [PATCH 3/3] i965: Fix shadow sampling with DEPTH_TEXTURE_MODE = GL_ALPHA on Haswell.

Kenneth Graunke kenneth at whitecape.org
Mon Sep 10 14:15:43 PDT 2012


Our code generation for the GLSL 1.30+-style shadow sampling functions
(which return a float rather than a vec4) always returns the R channel.

This poses a problem for handling DEPTH_TEXTURE_MODE with surface state
swizzling: the R channel would have 0 (while A would have the result).
Since the same sampler could theoretically be accessed with both the
old-style and new-style sampling functions, we can't decide whether to
set up the surface swizzling mode as 000R or R???.  We have to emit
instructions.

Tempted to leave this broken, as nobody outside a conformance suite will
likely notice.  However, the overhead should be minimal unless you're
actually using GL_ALPHA, in which case you deserve the poor performance.

Signed-off-by: Kenneth Graunke <kenneth at whitecape.org>
---
 src/mesa/drivers/dri/i965/brw_wm.c                | 8 +++++---
 src/mesa/drivers/dri/i965/gen7_wm_surface_state.c | 9 ++++-----
 2 files changed, 9 insertions(+), 8 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_wm.c b/src/mesa/drivers/dri/i965/brw_wm.c
index 55fb14a..609ac9e 100644
--- a/src/mesa/drivers/dri/i965/brw_wm.c
+++ b/src/mesa/drivers/dri/i965/brw_wm.c
@@ -508,10 +508,13 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
 
       const struct gl_texture_image *img = t->Image[0][t->BaseLevel];
 
+      const bool is_depth = img->_BaseFormat == GL_DEPTH_COMPONENT ||
+                            img->_BaseFormat == GL_DEPTH_STENCIL;
+
       /* Handle EXT_texture_swizzle and DEPTH_TEXTURE_MODE swizzling for
        * hardware that doesn't natively support it.
        */
-      if (!intel->is_haswell) {
+      if (!intel->is_haswell || (t->DepthMode == GL_ALPHA && is_depth)) {
 	 int swizzles[SWIZZLE_NIL + 1] = {
 	    SWIZZLE_X,
 	    SWIZZLE_Y,
@@ -522,8 +525,7 @@ brw_populate_sampler_prog_key_data(struct gl_context *ctx,
 	    SWIZZLE_NIL
 	 };
 
-	 if (img->_BaseFormat == GL_DEPTH_COMPONENT ||
-	     img->_BaseFormat == GL_DEPTH_STENCIL) {
+	 if (is_depth) {
 	    /* 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.
diff --git a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
index 5e71260..0466a25 100644
--- a/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
+++ b/src/mesa/drivers/dri/i965/gen7_wm_surface_state.c
@@ -374,11 +374,10 @@ gen7_update_texture_surface(struct gl_context *ctx,
          /* Handle legacy DEPTH_TEXTURE_MODE swizzling. */
          switch (tObj->DepthMode) {
          case GL_ALPHA:
-            surf->ss7.shader_channel_select_r = HSW_SCS_ZERO;
-            surf->ss7.shader_channel_select_g = HSW_SCS_ZERO;
-            surf->ss7.shader_channel_select_b = HSW_SCS_ZERO;
-            surf->ss7.shader_channel_select_a = HSW_SCS_RED;
-            break;
+            /* Handling GL_ALPHA as a surface format override breaks 1.30+
+             * style lookups that return a float, as these only look at the
+             * .x channel (which is always 0 for GL_ALPHA).
+             */
          case GL_LUMINANCE:
             surf->ss7.shader_channel_select_r = HSW_SCS_RED;
             surf->ss7.shader_channel_select_g = HSW_SCS_RED;
-- 
1.7.11.4



More information about the mesa-dev mailing list