[Mesa-dev] [PATCH] gallivm: some bits of seamless cube filtering implementation

sroland at vmware.com sroland at vmware.com
Fri Sep 13 09:06:03 PDT 2013


From: Roland Scheidegger <sroland at vmware.com>

Simply adjust wrap mode to clamp_to_edge. This is all that's needed for a
correct implementation for nearest filtering, and it's way better than
using repeat wrap for instance for linear filtering (though obviously this
doesn't actually do seamless filtering).
---
 src/gallium/auxiliary/gallivm/lp_bld_sample.c     |    1 +
 src/gallium/auxiliary/gallivm/lp_bld_sample.h     |    1 +
 src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c |   41 ++++++++++++++-------
 3 files changed, 29 insertions(+), 14 deletions(-)

diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.c b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
index 9b0a92c..c775382 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.c
@@ -155,6 +155,7 @@ lp_sampler_static_sampler_state(struct lp_static_sampler_state *state,
    state->wrap_r            = sampler->wrap_r;
    state->min_img_filter    = sampler->min_img_filter;
    state->mag_img_filter    = sampler->mag_img_filter;
+   state->seamless_cube_map = sampler->seamless_cube_map;
 
    if (sampler->max_lod > 0.0f) {
       state->min_mip_filter = sampler->min_mip_filter;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample.h b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
index e6b9f30..803a99e 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample.h
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample.h
@@ -114,6 +114,7 @@ struct lp_static_sampler_state
    unsigned lod_bias_non_zero:1;
    unsigned apply_min_lod:1;  /**< min_lod > 0 ? */
    unsigned apply_max_lod:1;  /**< max_lod < last_level ? */
+   unsigned seamless_cube_map:1;
 
    /* Hacks */
    unsigned force_nearest_s:1;
diff --git a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
index 7e98919..1b564d9 100644
--- a/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
+++ b/src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c
@@ -2123,8 +2123,21 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
       debug_printf("  .min_mip_filter = %u\n", derived_sampler_state.min_mip_filter);
    }
 
-   min_img_filter = static_sampler_state->min_img_filter;
-   mag_img_filter = static_sampler_state->mag_img_filter;
+   if ((static_texture_state->target == PIPE_TEXTURE_CUBE ||
+        static_texture_state->target == PIPE_TEXTURE_CUBE_ARRAY) &&
+       static_sampler_state->seamless_cube_map)
+   {
+      /*
+       * Seamless filtering ignores wrap modes.
+       * Setting to CLAMP_TO_EDGE is correct for nearest filtering, for
+       * bilinear it's not correct but way better than using for instance repeat.
+       */
+      derived_sampler_state.wrap_r = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+      derived_sampler_state.wrap_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+   }
+
+   min_img_filter = derived_sampler_state.min_img_filter;
+   mag_img_filter = derived_sampler_state.mag_img_filter;
 
 
    /*
@@ -2260,16 +2273,16 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
       LLVMValueRef ilevel0 = NULL, ilevel1 = NULL;
       boolean use_aos = util_format_fits_8unorm(bld.format_desc) &&
                         /* not sure this is strictly needed or simply impossible */
-                        static_sampler_state->compare_mode == PIPE_TEX_COMPARE_NONE &&
-                        lp_is_simple_wrap_mode(static_sampler_state->wrap_s);
+                        derived_sampler_state.compare_mode == PIPE_TEX_COMPARE_NONE &&
+                        lp_is_simple_wrap_mode(derived_sampler_state.wrap_s);
 
       use_aos &= bld.num_lods <= num_quads ||
-                 static_sampler_state->min_img_filter ==
-                    static_sampler_state->mag_img_filter;
+                 derived_sampler_state.min_img_filter ==
+                    derived_sampler_state.mag_img_filter;
       if (dims > 1) {
-         use_aos &= lp_is_simple_wrap_mode(static_sampler_state->wrap_t);
+         use_aos &= lp_is_simple_wrap_mode(derived_sampler_state.wrap_t);
          if (dims > 2) {
-            use_aos &= lp_is_simple_wrap_mode(static_sampler_state->wrap_r);
+            use_aos &= lp_is_simple_wrap_mode(derived_sampler_state.wrap_r);
          }
       }
 
@@ -2278,12 +2291,12 @@ lp_build_sample_soa(struct gallivm_state *gallivm,
          debug_printf("%s: using floating point linear filtering for %s\n",
                       __FUNCTION__, bld.format_desc->short_name);
          debug_printf("  min_img %d  mag_img %d  mip %d  wraps %d  wrapt %d  wrapr %d\n",
-                      static_sampler_state->min_img_filter,
-                      static_sampler_state->mag_img_filter,
-                      static_sampler_state->min_mip_filter,
-                      static_sampler_state->wrap_s,
-                      static_sampler_state->wrap_t,
-                      static_sampler_state->wrap_r);
+                      derived_sampler_state.min_img_filter,
+                      derived_sampler_state.mag_img_filter,
+                      derived_sampler_state.min_mip_filter,
+                      derived_sampler_state.wrap_s,
+                      derived_sampler_state.wrap_t,
+                      derived_sampler_state.wrap_r);
       }
 
       lp_build_sample_common(&bld, texture_index, sampler_index,
-- 
1.7.9.5


More information about the mesa-dev mailing list