From 505c4b3a39fd038020f984880ace49bbabe819da Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Mon, 17 Jan 2011 22:03:30 +0100 Subject: [PATCH 2/4] r300g: Properly take the sampler view's first_level into account when sampling. Signed-off-by: Brian Paul --- src/gallium/drivers/r300/r300_state_derived.c | 35 ++++++++++++++---------- 1 files changed, 20 insertions(+), 15 deletions(-) diff --git a/src/gallium/drivers/r300/r300_state_derived.c b/src/gallium/drivers/r300/r300_state_derived.c index 95be784..91de113 100644 --- a/src/gallium/drivers/r300/r300_state_derived.c +++ b/src/gallium/drivers/r300/r300_state_derived.c @@ -692,7 +692,7 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) struct r300_sampler_state *sampler; struct r300_sampler_view *view; struct r300_texture *tex; - unsigned min_level, max_level, i, j, size; + unsigned base_level, min_level, level_count, i, j, size; unsigned count = MIN2(state->sampler_view_count, state->sampler_state_count); @@ -724,22 +724,27 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) r300->screen->caps.is_r500); /* determine min/max levels */ - max_level = MIN3(sampler->max_lod + view->base.u.tex.first_level, - tex->desc.b.b.last_level, view->base.u.tex.last_level); - min_level = MIN2(sampler->min_lod + view->base.u.tex.first_level, - max_level); - - if (tex->desc.is_npot && min_level > 0) { - /* Even though we do not implement mipmapping for NPOT - * textures, we should at least honor the minimum level - * which is allowed to be displayed. We do this by setting up - * an i-th mipmap level as the zero level. */ + base_level = view->base.u.tex.first_level; + min_level = sampler->min_lod; + level_count = MIN3(sampler->max_lod, + tex->desc.b.b.last_level - base_level, + view->base.u.tex.last_level - base_level); + + if (base_level + min_level) { + if (tex->desc.is_npot) { + /* Even though we do not implement mipmapping for NPOT + * textures, we should at least honor the minimum level + * which is allowed to be displayed. We do this by setting up + * an i-th mipmap level as the zero level. */ + base_level += min_level; + } + r300_texture_setup_format_state(r300->screen, &tex->desc, - min_level, + base_level, &texstate->format); texstate->format.tile_config |= - tex->desc.offset_in_bytes[min_level] & 0xffffffe0; - assert((tex->desc.offset_in_bytes[min_level] & 0x1f) == 0); + tex->desc.offset_in_bytes[base_level] & 0xffffffe0; + assert((tex->desc.offset_in_bytes[base_level] & 0x1f) == 0); } /* Assign a texture cache region. */ @@ -810,7 +815,7 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300) } } else { /* the MAX_MIP level is the largest (finest) one */ - texstate->format.format0 |= R300_TX_NUM_LEVELS(max_level); + texstate->format.format0 |= R300_TX_NUM_LEVELS(level_count); texstate->filter0 |= R300_TX_MAX_MIP_LEVEL(min_level); } -- 1.7.3.4