Merge branch 'gallium-polygon-stipple'
[mesa.git] / src / gallium / drivers / r300 / r300_state_derived.c
index e943f1a715f4ae4fd77330dd1be33a9ce7de5c7b..f63114e7eb74a67cbd3227717aa5f6c2e34f603c 100644 (file)
@@ -438,7 +438,7 @@ static void r300_update_rs_block(struct r300_context *r300)
 
     /* Rasterize texture coordinates. */
     for (i = 0; i < ATTR_GENERIC_COUNT && tex_count < 8; i++) {
-       bool sprite_coord = false;
+       boolean sprite_coord = false;
 
        if (fs_inputs->generic[i] != ATTR_UNUSED) {
            sprite_coord = !!(r300->sprite_coord_enable & (1 << i));
@@ -741,25 +741,6 @@ static uint32_t r300_get_border_color(enum pipe_format format,
     return uc.ui;
 }
 
-static boolean util_format_is_float(enum pipe_format format)
-{
-    const struct util_format_description *desc = util_format_description(format);
-    unsigned i;
-
-    if (!format)
-       return FALSE;
-
-    /* Find the first non-void channel. */
-    for (i = 0; i < 4; i++)
-        if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID)
-            break;
-
-    if (i == 4)
-        return FALSE;
-
-    return desc->channel[i].type == UTIL_FORMAT_TYPE_FLOAT ? TRUE : FALSE;
-}
-
 static void r300_merge_textures_and_samplers(struct r300_context* r300)
 {
     struct r300_textures_state *state =
@@ -768,9 +749,10 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300)
     struct r300_sampler_state *sampler;
     struct r300_sampler_view *view;
     struct r300_resource *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);
+    boolean has_us_format = r300->screen->caps.has_us_format;
 
     /* The KIL opcode fix, see below. */
     if (!count && !r300->screen->caps.is_r500)
@@ -800,21 +782,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->b.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->tex.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
-                 * the i-th mipmap level as the zero level. */
-                unsigned offset = tex->tex_offset +
-                                  tex->tex.offset_in_bytes[min_level];
+            base_level = view->base.u.tex.first_level;
+            min_level = sampler->min_lod;
+            level_count = MIN3(sampler->max_lod,
+                               tex->b.b.b.last_level - base_level,
+                               view->base.u.tex.last_level - base_level);
+
+            if (base_level + min_level) {
+                unsigned offset;
+
+                if (tex->tex.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;
+                }
+                offset = tex->tex_offset +
+                         tex->tex.offset_in_bytes[base_level];
 
                 r300_texture_setup_format_state(r300->screen, tex,
-                                                min_level,
+                                                base_level,
                                                 &texstate->format);
                 texstate->format.tile_config |= offset & 0xffffffe0;
                 assert((offset & 0x1f) == 0);
@@ -866,6 +854,12 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300)
                 texstate->filter0 |= R300_TX_WRAP_T(R300_TX_CLAMP_TO_EDGE);
             }
 
+            /* The hardware doesn't like CLAMP and CLAMP_TO_BORDER
+             * for the 3rd coordinate if the texture isn't 3D. */
+            if (tex->b.b.b.target != PIPE_TEXTURE_3D) {
+                texstate->filter0 &= ~R300_TX_WRAP_R_MASK;
+            }
+
             if (tex->tex.is_npot) {
                 /* NPOT textures don't support mip filter, unfortunately.
                  * This prevents incorrect rendering. */
@@ -891,7 +885,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);
             }
 
@@ -923,7 +917,7 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300)
 
             texstate->filter0 |= i << 28;
 
-            size += 16;
+            size += 16 + (has_us_format ? 2 : 0);
             state->count = i+1;
         } else {
             /* For the KIL opcode to work on r3xx-r4xx, the texture unit
@@ -952,7 +946,7 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300)
                 texstate->border_color = 0;
 
                 texstate->filter0 |= i << 28;
-                size += 16;
+                size += 16 + (has_us_format ? 2 : 0);
                 state->count = i+1;
             }
         }
@@ -977,7 +971,7 @@ static void r300_decompress_depth_textures(struct r300_context *r300)
                           state->sampler_state_count);
     unsigned i;
 
-    if (!r300->hyperz_locked || !r300->locked_zbuffer) {
+    if (!r300->locked_zbuffer) {
         return;
     }