r300g: finish up signed normalized textures and render targets
authorMarek Olšák <maraeo@gmail.com>
Mon, 14 Mar 2011 15:37:15 +0000 (16:37 +0100)
committerMarek Olšák <maraeo@gmail.com>
Tue, 29 Mar 2011 10:50:28 +0000 (12:50 +0200)
src/gallium/drivers/r300/r300_state_derived.c
src/gallium/drivers/r300/r300_texture.c

index ec00e2552ca6a7a2cc24b780ccf5871d093fb85c..50cde5528ef2f3ef41c0ff43fdb3dad6eca5a550 100644 (file)
@@ -592,6 +592,13 @@ static void r300_update_rs_block(struct r300_context *r300)
     }
 }
 
+static void rgba_to_bgra(float color[4])
+{
+    float x = color[0];
+    color[0] = color[2];
+    color[2] = x;
+}
+
 static uint32_t r300_get_border_color(enum pipe_format format,
                                       const float border[4],
                                       boolean is_r500)
@@ -625,13 +632,13 @@ static uint32_t r300_get_border_color(enum pipe_format format,
     for (i = 0; i < 4; i++) {
         switch (desc->swizzle[i]) {
         case UTIL_FORMAT_SWIZZLE_X:
-            border_swizzled[2] = border[i];
+            border_swizzled[0] = border[i];
             break;
         case UTIL_FORMAT_SWIZZLE_Y:
             border_swizzled[1] = border[i];
             break;
         case UTIL_FORMAT_SWIZZLE_Z:
-            border_swizzled[0] = border[i];
+            border_swizzled[2] = border[i];
             break;
         case UTIL_FORMAT_SWIZZLE_W:
             border_swizzled[3] = border[i];
@@ -648,34 +655,36 @@ static uint32_t r300_get_border_color(enum pipe_format format,
         case PIPE_FORMAT_LATC1_UNORM:
             /* Add 1/32 to round the border color instead of truncating. */
             /* The Y component is used for the border color. */
-            border_swizzled[1] = border_swizzled[2] + 1.0f/32;
+            border_swizzled[1] = border_swizzled[0] + 1.0f/32;
             util_pack_color(border_swizzled, PIPE_FORMAT_B4G4R4A4_UNORM, &uc);
             return uc.ui;
         case PIPE_FORMAT_RGTC2_SNORM:
         case PIPE_FORMAT_LATC2_SNORM:
-            border_swizzled[0] = border_swizzled[2];
             util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_SNORM, &uc);
             return uc.ui;
         case PIPE_FORMAT_RGTC2_UNORM:
         case PIPE_FORMAT_LATC2_UNORM:
-            util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
+            util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc);
             return uc.ui;
         default:
-            util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc);
+            util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
             return uc.ui;
         }
     }
 
     switch (desc->channel[0].size) {
         case 2:
+            rgba_to_bgra(border_swizzled);
             util_pack_color(border_swizzled, PIPE_FORMAT_B2G3R3_UNORM, &uc);
             break;
 
         case 4:
+            rgba_to_bgra(border_swizzled);
             util_pack_color(border_swizzled, PIPE_FORMAT_B4G4R4A4_UNORM, &uc);
             break;
 
         case 5:
+            rgba_to_bgra(border_swizzled);
             if (desc->channel[1].size == 5) {
                 util_pack_color(border_swizzled, PIPE_FORMAT_B5G5R5A1_UNORM, &uc);
             } else if (desc->channel[1].size == 6) {
@@ -687,32 +696,39 @@ static uint32_t r300_get_border_color(enum pipe_format format,
 
         default:
         case 8:
-            util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
+            if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED)
+               util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_SNORM, &uc);
+            else
+               util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc);
             break;
 
         case 10:
-            util_pack_color(border_swizzled, PIPE_FORMAT_B10G10R10A2_UNORM, &uc);
+            util_pack_color(border_swizzled, PIPE_FORMAT_R10G10B10A2_UNORM, &uc);
             break;
 
         case 16:
             if (desc->nr_channels <= 2) {
-                border_swizzled[0] = border_swizzled[2];
                 if (desc->channel[0].type == UTIL_FORMAT_TYPE_FLOAT) {
                     util_pack_color(border_swizzled, PIPE_FORMAT_R16G16_FLOAT, &uc);
+                } else if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
+                    util_pack_color(border_swizzled, PIPE_FORMAT_R16G16_SNORM, &uc);
                 } else {
                     util_pack_color(border_swizzled, PIPE_FORMAT_R16G16_UNORM, &uc);
                 }
             } else {
-                util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
+                if (desc->channel[0].type == UTIL_FORMAT_TYPE_SIGNED) {
+                    util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_SNORM, &uc);
+                } else {
+                    util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc);
+                }
             }
             break;
 
         case 32:
             if (desc->nr_channels == 1) {
-                border_swizzled[0] = border_swizzled[2];
                 util_pack_color(border_swizzled, PIPE_FORMAT_R32_FLOAT, &uc);
             } else {
-                util_pack_color(border_swizzled, PIPE_FORMAT_B8G8R8A8_UNORM, &uc);
+                util_pack_color(border_swizzled, PIPE_FORMAT_R8G8B8A8_UNORM, &uc);
             }
             break;
     }
index c650fb7ed3773709fd0c819475e7d8e527842d09..57e0c6183ff84c4b1538debecce2736815ea81d2 100644 (file)
@@ -116,10 +116,10 @@ uint32_t r300_translate_texformat(enum pipe_format format,
     unsigned i;
     boolean uniform = TRUE;
     const uint32_t sign_bit[4] = {
-        R300_TX_FORMAT_SIGNED_X,
-        R300_TX_FORMAT_SIGNED_Y,
-        R300_TX_FORMAT_SIGNED_Z,
         R300_TX_FORMAT_SIGNED_W,
+        R300_TX_FORMAT_SIGNED_Z,
+        R300_TX_FORMAT_SIGNED_Y,
+        R300_TX_FORMAT_SIGNED_X,
     };
 
     desc = util_format_description(format);
@@ -212,14 +212,14 @@ uint32_t r300_translate_texformat(enum pipe_format format,
         switch (format) {
             case PIPE_FORMAT_RGTC1_SNORM:
             case PIPE_FORMAT_LATC1_SNORM:
-                result |= sign_bit[1];
+                result |= sign_bit[2];
             case PIPE_FORMAT_LATC1_UNORM:
             case PIPE_FORMAT_RGTC1_UNORM:
                 return R500_TX_FORMAT_ATI1N | result;
 
             case PIPE_FORMAT_RGTC2_SNORM:
             case PIPE_FORMAT_LATC2_SNORM:
-                result |= sign_bit[2] | sign_bit[3];
+                result |= sign_bit[1] | sign_bit[0];
             case PIPE_FORMAT_RGTC2_UNORM:
             case PIPE_FORMAT_LATC2_UNORM:
                 return R400_TX_FORMAT_ATI2N | result;
@@ -390,18 +390,18 @@ static uint32_t r300_translate_colorformat(enum pipe_format format)
     switch (format) {
         /* 8-bit buffers. */
         case PIPE_FORMAT_A8_UNORM:
-        /*case PIPE_FORMAT_A8_SNORM:*/
+        case PIPE_FORMAT_A8_SNORM:
         case PIPE_FORMAT_I8_UNORM:
-        /*case PIPE_FORMAT_I8_SNORM:*/
+        case PIPE_FORMAT_I8_SNORM:
         case PIPE_FORMAT_L8_UNORM:
-        /*case PIPE_FORMAT_L8_SNORM:*/
+        case PIPE_FORMAT_L8_SNORM:
         case PIPE_FORMAT_R8_UNORM:
         case PIPE_FORMAT_R8_SNORM:
             return R300_COLOR_FORMAT_I8;
 
         /* 16-bit buffers. */
         case PIPE_FORMAT_L8A8_UNORM:
-        /*case PIPE_FORMAT_L8A8_SNORM:*/
+        case PIPE_FORMAT_L8A8_SNORM:
         case PIPE_FORMAT_R8G8_UNORM:
         case PIPE_FORMAT_R8G8_SNORM:
             return R300_COLOR_FORMAT_UV88;
@@ -490,9 +490,9 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format)
     unsigned i;
     const struct util_format_description *desc;
     static const uint32_t sign_bit[4] = {
-        R300_OUT_SIGN(0x1),
-        R300_OUT_SIGN(0x2),
         R300_OUT_SIGN(0x4),
+        R300_OUT_SIGN(0x2),
+        R300_OUT_SIGN(0x1),
         R300_OUT_SIGN(0x8),
     };
 
@@ -538,23 +538,25 @@ static uint32_t r300_translate_out_fmt(enum pipe_format format)
         /* 8-bit outputs, one channel.
          * COLORFORMAT_I8 stores the C2 component. */
         case PIPE_FORMAT_A8_UNORM:
-        /*case PIPE_FORMAT_A8_SNORM:*/
+        case PIPE_FORMAT_A8_SNORM:
             return modifier | R300_C2_SEL_A;
         case PIPE_FORMAT_I8_UNORM:
-        /*case PIPE_FORMAT_I8_SNORM:*/
+        case PIPE_FORMAT_I8_SNORM:
         case PIPE_FORMAT_L8_UNORM:
-        /*case PIPE_FORMAT_L8_SNORM:*/
+        case PIPE_FORMAT_L8_SNORM:
         case PIPE_FORMAT_R8_UNORM:
         case PIPE_FORMAT_R8_SNORM:
             return modifier | R300_C2_SEL_R;
 
         /* 16-bit outputs, two channels.
          * COLORFORMAT_UV88 stores C2 and C0. */
+        case PIPE_FORMAT_L8A8_SNORM:
+            modifier |= sign_bit[2];
         case PIPE_FORMAT_L8A8_UNORM:
-        /*case PIPE_FORMAT_L8A8_SNORM:*/
             return modifier | R300_C0_SEL_A | R300_C2_SEL_R;
-        case PIPE_FORMAT_R8G8_UNORM:
         case PIPE_FORMAT_R8G8_SNORM:
+            modifier |= sign_bit[2];
+        case PIPE_FORMAT_R8G8_UNORM:
             return modifier | R300_C0_SEL_G | R300_C2_SEL_R;
 
         /* BGRA outputs. */