[Mesa-dev] [PATCH] gallivm: add a horrible hack for stencil texturing with border

sroland at vmware.com sroland at vmware.com
Tue Dec 15 20:37:58 PST 2015


From: Roland Scheidegger <sroland at vmware.com>

mesa/st doesn't give us a useful swizzle when stencil texturing. Moreover,
it's not even obvious what the swizzle actually should be - the channel which
is used for the fetch (Y) is not the same as the one which must be used for
the border component (X), which is due to a mismatch between GL and gallium
interface. (On top of that, I have no idea what GL expects in YZW channels in
the end.)
So add some special case for stencil texturing with border, to fetch the right
border component. Though it seems there has to be some better solution...
This fixes piglit texwrap GL_ARB_texture_stencil8 bordercolor (only the fixed
version).
---
 src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c | 28 +++++++++++++++++++++--
 1 file changed, 26 insertions(+), 2 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
index e21933f..efba5a8 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
@@ -187,9 +187,33 @@ lp_build_sample_texel_soa(struct lp_build_sample_context *bld,
       border_type.length = 4;
       /*
        * Only replace channels which are actually present. The others should
-       * get optimized away eventually by sampler_view swizzle anyway but it's
-       * easier too.
+       * get optimized away eventually by sampler_view swizzle in most cases...
+       * If not, for "ordinary" color textures, fetch will have placed the
+       * correct default values there, since missing channels must use default
+       * values regardless of border.
+       * We do, however, some horrendous hack for stencil textures. We won't
+       * get a useful swizzle, and furthermore the channel to fetch (Y) doesn't
+       * match the channel for the border color (X).
        */
+      if (util_format_has_stencil(format_desc) &&
+            !util_format_has_depth(format_desc)) {
+         LLVMValueRef zero = lp_build_const_int32(bld->gallivm, 0);
+         LLVMValueRef border_col;
+         border_col = lp_build_extract_broadcast(bld->gallivm,
+                                                 border_type,
+                                                 bld->texel_type,
+                                                 bld->border_color_clamped,
+                                                 zero);
+         /*
+          * Replace first 3 chans (match what fetch did).
+          */
+         for (chan = 0; chan < 3; chan++) {
+            texel_out[chan] = lp_build_select(&bld->texel_bld, use_border,
+                                              border_col, texel_out[chan]);
+         }
+         return;
+      }
+
       for (chan = 0; chan < 4; chan++) {
          unsigned chan_s;
          /* reverse-map channel... */
-- 
2.1.4



More information about the mesa-dev mailing list