gallium: Add TEX_FILTER_ANISO img filter
authorKeith Whitwell <keith@tungstengraphics.com>
Wed, 12 Mar 2008 10:39:25 +0000 (10:39 +0000)
committerKeith Whitwell <keith@tungstengraphics.com>
Wed, 12 Mar 2008 10:42:49 +0000 (10:42 +0000)
Hardware almost universally expects us to set a special filtering mode
when anisotropic filtering is enabled, as opposed to varying a max-aniso
values.  Do this once in the state tracker & simplify the driver code.

src/gallium/drivers/i915simple/i915_state.c
src/gallium/drivers/i965simple/brw_wm_sampler_state.c
src/gallium/drivers/softpipe/sp_tex_sample.c
src/gallium/include/pipe/p_defines.h
src/mesa/state_tracker/st_atom_sampler.c

index d9ab483bfca9a08df7bab3e4a2630f3351d8f1c6..57b195ea8d7ca23426cde9dec5f7114104d7ca86 100644 (file)
@@ -71,6 +71,8 @@ static unsigned translate_img_filter( unsigned filter )
       return FILTER_NEAREST;
    case PIPE_TEX_FILTER_LINEAR:
       return FILTER_LINEAR;
+   case PIPE_TEX_FILTER_ANISO:
+      return FILTER_ANISOTROPIC;
    default:
       assert(0);
       return FILTER_NEAREST;
@@ -84,7 +86,7 @@ static unsigned translate_mip_filter( unsigned filter )
       return MIPFILTER_NONE;
    case PIPE_TEX_MIPFILTER_NEAREST:
       return MIPFILTER_NEAREST;
-   case PIPE_TEX_FILTER_LINEAR:
+   case PIPE_TEX_MIPFILTER_LINEAR:
       return MIPFILTER_LINEAR;
    default:
       assert(0);
@@ -211,16 +213,11 @@ i915_create_sampler_state(struct pipe_context *pipe,
    cso->templ = sampler;
 
    mipFilt = translate_mip_filter(sampler->min_mip_filter);
-   if (sampler->max_anisotropy > 1.0) {
-      minFilt = FILTER_ANISOTROPIC;
-      magFilt = FILTER_ANISOTROPIC;
-      if (sampler->max_anisotropy > 2.0) {
-         cso->state[0] |= SS2_MAX_ANISO_4;
-      }
-   }
-   else {
-      minFilt = translate_img_filter( sampler->min_img_filter );
-      magFilt = translate_img_filter( sampler->mag_img_filter );
+   minFilt = translate_img_filter( sampler->min_img_filter );
+   magFilt = translate_img_filter( sampler->mag_img_filter );
+   
+   if (sampler->max_anisotropy > 2.0) {
+      cso->state[0] |= SS2_MAX_ANISO_4;
    }
 
    {
index ff5ba7e7c7a4a4a1f0a34f60af16939f727e8b44..b9eaee56ee87d10e78abf246c9b9a5a1dedd173a 100644 (file)
@@ -136,6 +136,9 @@ static void brw_update_sampler_state( const struct pipe_sampler_state *pipe_samp
    case PIPE_TEX_FILTER_LINEAR:
       sampler->ss0.min_filter = BRW_MAPFILTER_LINEAR;
       break;
+   case PIPE_TEX_FILTER_ANISO:
+      sampler->ss0.min_filter = BRW_MAPFILTER_ANISOTROPIC;
+      break;
    default:
       break;
    }
@@ -155,26 +158,23 @@ static void brw_update_sampler_state( const struct pipe_sampler_state *pipe_samp
    }
    /* Set Anisotropy:
     */
-   if (pipe_sampler->max_anisotropy > 1.0) {
-      sampler->ss0.min_filter = BRW_MAPFILTER_ANISOTROPIC;
-      sampler->ss0.mag_filter = BRW_MAPFILTER_ANISOTROPIC;
-
-      if (pipe_sampler->max_anisotropy > 2.0) {
-        sampler->ss3.max_aniso = MAX2((pipe_sampler->max_anisotropy - 2) / 2,
-                                      BRW_ANISORATIO_16);
-      }
+   switch (pipe_sampler->mag_img_filter) {
+   case PIPE_TEX_FILTER_NEAREST:
+      sampler->ss0.mag_filter = BRW_MAPFILTER_NEAREST;
+      break;
+   case PIPE_TEX_FILTER_LINEAR:
+      sampler->ss0.mag_filter = BRW_MAPFILTER_LINEAR;
+      break;
+   case PIPE_TEX_FILTER_ANISO:
+      sampler->ss0.mag_filter = BRW_MAPFILTER_LINEAR;
+      break;
+   default:
+      break;
    }
-   else {
-      switch (pipe_sampler->mag_img_filter) {
-      case PIPE_TEX_FILTER_NEAREST:
-        sampler->ss0.mag_filter = BRW_MAPFILTER_NEAREST;
-        break;
-      case PIPE_TEX_FILTER_LINEAR:
-        sampler->ss0.mag_filter = BRW_MAPFILTER_LINEAR;
-        break;
-      default:
-        break;
-      }
+
+   if (pipe_sampler->max_anisotropy > 2.0) {
+      sampler->ss3.max_aniso = MAX2((pipe_sampler->max_anisotropy - 2) / 2,
+                                    BRW_ANISORATIO_16);
    }
 
    sampler->ss1.s_wrap_mode = translate_wrap_mode(pipe_sampler->wrap_s);
index 0ced585c7f3676343d3e78116ef146060ada2dfa..34da6356d70f82cc6cb6954d1a29d52d110137e6 100644 (file)
@@ -714,6 +714,7 @@ sp_get_samples_2d_common(struct tgsi_sampler *sampler,
       }
       break;
    case PIPE_TEX_FILTER_LINEAR:
+   case PIPE_TEX_FILTER_ANISO:
       for (j = 0; j < QUAD_SIZE; j++) {
          float tx[4][4], a, b;
          int x0, y0, x1, y1, c;
@@ -846,6 +847,7 @@ sp_get_samples_3d(struct tgsi_sampler *sampler,
       }
       break;
    case PIPE_TEX_FILTER_LINEAR:
+   case PIPE_TEX_FILTER_ANISO:
       for (j = 0; j < QUAD_SIZE; j++) {
          float texel0[4][4], texel1[4][4];
          float xw, yw, zw; /* interpolation weights */
@@ -972,6 +974,7 @@ sp_get_samples_rect(struct tgsi_sampler *sampler,
       }
       break;
    case PIPE_TEX_FILTER_LINEAR:
+   case PIPE_TEX_FILTER_ANISO:
       for (j = 0; j < QUAD_SIZE; j++) {
          float tx[4][4], a, b;
          int x0, y0, x1, y1, c;
index 0c662d651795618ffb7a3df1453b16b84b9cd6bc..bc938ba25388cf51bb12ba75b83fc6fd6a072f0f 100644 (file)
@@ -152,7 +152,7 @@ enum pipe_texture_target {
  */
 #define PIPE_TEX_FILTER_NEAREST      0
 #define PIPE_TEX_FILTER_LINEAR       1
-/* #define PIPE_TEX_FILTER_ANISO        2 */
+#define PIPE_TEX_FILTER_ANISO        2 
 
 
 #define PIPE_TEX_COMPARE_NONE          0
index 1babba9b4fa411cb1dbdfd4e4f6e317f6b5f4614..d376480c9150d20c1b3aab2de10ce201747fd404 100644 (file)
@@ -160,6 +160,10 @@ update_samplers(struct st_context *st)
 #endif
 
         sampler->max_anisotropy = texobj->MaxAnisotropy;
+         if (sampler->max_anisotropy > 1.0) {
+            sampler->min_img_filter = PIPE_TEX_FILTER_ANISO;
+            sampler->mag_img_filter = PIPE_TEX_FILTER_ANISO;
+         }
 
          /* only care about ARB_shadow, not SGI shadow */
          if (texobj->CompareMode == GL_COMPARE_R_TO_TEXTURE) {