r300g: fix texture border color once again
authorMarek Olšák <maraeo@gmail.com>
Mon, 29 Nov 2010 02:40:04 +0000 (03:40 +0100)
committerMarek Olšák <maraeo@gmail.com>
Tue, 30 Nov 2010 22:31:16 +0000 (23:31 +0100)
I made the texwrap test be more thorough and realized that this driver code
had not been quite right. This commit fixes the border color for depth
textures, compressed textures, and 16-bits-per-channel textures
with up to 2 channels (R16, RG16).

NOTE: This is a candidate for the 7.9 branch.

src/gallium/drivers/r300/r300_state_derived.c

index 1cff3483b50c6a1e0ad9f9c0708851dce259762b..c4cd291d75dffd132aedf03c61d502138e0b0990 100644 (file)
@@ -592,7 +592,8 @@ static void r300_update_rs_block(struct r300_context *r300)
 }
 
 static uint32_t r300_get_border_color(enum pipe_format format,
-                                      const float border[4])
+                                      const float border[4],
+                                      boolean is_r500)
 {
     const struct util_format_description *desc;
     float border_swizzled[4] = {0};
@@ -601,6 +602,24 @@ static uint32_t r300_get_border_color(enum pipe_format format,
 
     desc = util_format_description(format);
 
+    /* Do depth formats first. */
+    if (util_format_is_depth_or_stencil(format)) {
+        switch (format) {
+        case PIPE_FORMAT_Z16_UNORM:
+            return util_pack_z(PIPE_FORMAT_Z16_UNORM, border[0]);
+        case PIPE_FORMAT_X8Z24_UNORM:
+        case PIPE_FORMAT_S8_USCALED_Z24_UNORM:
+            if (is_r500) {
+                return util_pack_z(PIPE_FORMAT_X8Z24_UNORM, border[0]);
+            } else {
+                return util_pack_z(PIPE_FORMAT_Z16_UNORM, border[0]) << 16;
+            }
+        default:
+            assert(0);
+            return 0;
+        }
+    }
+
     /* Apply inverse swizzle of the format. */
     for (i = 0; i < 4; i++) {
         switch (desc->swizzle[i]) {
@@ -619,6 +638,12 @@ static uint32_t r300_get_border_color(enum pipe_format format,
         }
     }
 
+    /* Compressed formats. */
+    if (util_format_is_compressed(format)) {
+        util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc);
+        return uc.ui;
+    }
+
     switch (desc->channel[0].size) {
         case 4:
             util_pack_color(border_swizzled, PIPE_FORMAT_B4G4R4A4_UNORM, &uc);
@@ -642,6 +667,15 @@ static uint32_t r300_get_border_color(enum pipe_format format,
         case 10:
             util_pack_color(border_swizzled, PIPE_FORMAT_B10G10R10A2_UNORM, &uc);
             break;
+
+        case 16:
+            if (desc->nr_channels <= 2) {
+                border_swizzled[0] = border_swizzled[2];
+                util_pack_color(border_swizzled, PIPE_FORMAT_R16G16_UNORM, &uc);
+            } else {
+                util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
+            }
+            break;
     }
 
     return uc.ui;
@@ -683,7 +717,8 @@ static void r300_merge_textures_and_samplers(struct r300_context* r300)
             /* Set the border color. */
             texstate->border_color =
                 r300_get_border_color(view->base.format,
-                                      sampler->state.border_color);
+                                      sampler->state.border_color,
+                                      r300->screen->caps.is_r500);
 
             /* determine min/max levels */
             max_level = MIN3(sampler->max_lod + view->base.first_level,