[PATCH] i965: make sure hardware choose the right filter mode

Yuanhan Liu yuanhan.liu at linux.intel.com
Wed Nov 2 19:01:25 PDT 2011


Here I quoted Eric's words:
  the min/mag decision is based on the computed LOD of the sample,
  and if we clamp the LOD to BaseLevel by not including the other
  levels, it will always choose the mag filter even if minification
  should have occurred

And here is how the hardware do the min/mag decision in a formula way:

  MagMode = (LOD - Base <= 0)

where LOD is computed in a way like the following if preClamp is enabled:
  if (preClamp is enabled)
    LOD = min(min(MIPCnt, MAX_LOD), pre-computed_LOD);
  else
    LOD = per-computed_LOD;

So, if have just one level(the baselevel), just don't enable preclamp to
make hardware choose the right filter mode.

This would fix all oglc filtercubemin subcase fail and introduce no oglc
regression.

Signed-off-by: Yuanhan Liu <yuanhan.liu at linux.intel.com>
---
 src/mesa/drivers/dri/i965/brw_wm_sampler_state.c |    9 +++++++++
 1 files changed, 9 insertions(+), 0 deletions(-)

diff --git a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c
index 6104afc..f102573 100644
--- a/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c
+++ b/src/mesa/drivers/dri/i965/brw_wm_sampler_state.c
@@ -164,8 +164,10 @@ static void brw_update_sampler_state(struct brw_context *brw,
    struct gl_context *ctx = &intel->ctx;
    struct gl_texture_unit *texUnit = &ctx->Texture.Unit[unit];
    struct gl_texture_object *texObj = texUnit->_Current;
+   struct intel_texture_object *intelObj = intel_texture_object(texObj);
    struct gl_sampler_object *gl_sampler = _mesa_get_samplerobj(ctx, unit);
    bool using_nearest = false;
+   int mip_cnt = intelObj->_MaxLevel - texObj->BaseLevel;
 
    switch (gl_sampler->MinFilter) {
    case GL_NEAREST:
@@ -275,6 +277,13 @@ static void brw_update_sampler_state(struct brw_context *brw,
 					 gl_sampler->LodBias, -16, 15), 6);
 
    sampler->ss0.lod_preclamp = 1; /* OpenGL mode */
+   /*
+    * Workaround: if mip count is set to 0 and preclamp is enabled,
+    * this would clamp * the final lod to 0 and then hardware would
+    * always choose mag filter.
+    */
+   if (gl_sampler->MinFilter != gl_sampler->MagFilter && mip_cnt == 0)
+      sampler->ss0.lod_preclamp = 0;
    sampler->ss0.default_color_mode = 0; /* OpenGL/DX10 mode */
 
    /* Set BaseMipLevel, MaxLOD, MinLOD: 
-- 
1.7.4.4


More information about the mesa-dev mailing list