gallivm: some bits of seamless cube filtering implementation
authorRoland Scheidegger <sroland@vmware.com>
Fri, 13 Sep 2013 17:52:09 +0000 (19:52 +0200)
committerRoland Scheidegger <sroland@vmware.com>
Tue, 17 Sep 2013 22:00:37 +0000 (00:00 +0200)
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).

v2: fix s/t wrap not r/s...

Reviewed-by: Brian Paul <brianp@vmware.com>
Reviewed-by: Jose Fonseca <jfonseca@vmware.com>
src/gallium/auxiliary/gallivm/lp_bld_sample.c
src/gallium/auxiliary/gallivm/lp_bld_sample.h
src/gallium/auxiliary/gallivm/lp_bld_sample_soa.c

index 9b0a92c9cb9564de20d34223601eefe48ca3f5b9..c7753829f3f96c29589c7b048d63b3dcca327fe2 100644 (file)
@@ -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;
index e6b9f30d7bb85434854cbbd0774a4273f498c3b4..803a99e3b0c4009e5b2395d739ee45eb97406d4e 100644 (file)
@@ -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;
index 7e98919204d840dc8f0b11814dac5fee31d16068..355e97d76a68f48e7f9b7a9bec00acf520cb5504 100644 (file)
@@ -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_s = PIPE_TEX_WRAP_CLAMP_TO_EDGE;
+      derived_sampler_state.wrap_t = 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,