r600g: handle 16/32 u/s norm formats properly
authorDave Airlie <airlied@redhat.com>
Thu, 10 Feb 2011 04:07:06 +0000 (14:07 +1000)
committerDave Airlie <airlied@redhat.com>
Fri, 11 Feb 2011 03:47:34 +0000 (13:47 +1000)
add support for the 32-bit types, also fixup the
export setting to handle types with channels > 11 bits properly

Signed-off-by: Dave Airlie <airlied@redhat.com>
src/gallium/drivers/r600/eg_state_inlines.h
src/gallium/drivers/r600/evergreen_state.c
src/gallium/drivers/r600/evergreend.h
src/gallium/drivers/r600/r600_state.c
src/gallium/drivers/r600/r600_state_inlines.h
src/gallium/drivers/r600/r600_texture.c
src/gallium/drivers/r600/r600d.h

index ca00e61f52b6ccf81d835eda3b895c3a6f8f4e49..46369cc1e26adbd006f834efb603cde52db23b7f 100644 (file)
@@ -362,14 +362,13 @@ static inline uint32_t r600_translate_colorswap(enum pipe_format format)
                /* 64-bit buffers. */
        case PIPE_FORMAT_R16G16B16A16_UNORM:
        case PIPE_FORMAT_R16G16B16A16_SNORM:
-               //              return V_028C70_COLOR_16_16_16_16;
        case PIPE_FORMAT_R16G16B16A16_FLOAT:
-               //              return V_028C70_COLOR_16_16_16_16_FLOAT;
 
                /* 128-bit buffers. */
        case PIPE_FORMAT_R32G32B32A32_FLOAT:
-               //              return V_028C70_COLOR_32_32_32_32_FLOAT;
-               return 0;
+       case PIPE_FORMAT_R32G32B32A32_SNORM:
+       case PIPE_FORMAT_R32G32B32A32_UNORM:
+               return V_028C70_SWAP_STD;
        default:
                R600_ERR("unsupported colorswap format %d\n", format);
                return ~0;
@@ -471,6 +470,9 @@ static INLINE uint32_t r600_translate_colorformat(enum pipe_format format)
                return V_028C70_COLOR_32_32;
 
                /* 128-bit buffers. */
+       case PIPE_FORMAT_R32G32B32A32_SNORM:
+       case PIPE_FORMAT_R32G32B32A32_UNORM:
+               return V_028C70_COLOR_32_32_32_32;
        case PIPE_FORMAT_R32G32B32_FLOAT:
                return V_028C70_COLOR_32_32_32_FLOAT;
        case PIPE_FORMAT_R32G32B32A32_FLOAT:
index 83ab0df9c1669965f3656f12a43a1b47a2d15a06..4821259e4e538e29cfb1bfd3ecbf71dc1e93a0b9 100644 (file)
@@ -648,6 +648,7 @@ static void evergreen_cb(struct r600_pipe_context *rctx, struct r600_pipe_state
        unsigned tile_type;
        const struct util_format_description *desc;
        struct r600_bo *bo[3];
+       int i;
 
        surf = (struct r600_surface *)state->cbufs[cb];
        rtex = (struct r600_resource_texture*)state->cbufs[cb]->texture;
@@ -679,8 +680,19 @@ static void evergreen_cb(struct r600_pipe_context *rctx, struct r600_pipe_state
                S_028C70_ARRAY_MODE(rtex->array_mode[level]) |
                S_028C70_BLEND_CLAMP(1) |
                S_028C70_NUMBER_TYPE(ntype);
-       if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
-               color_info |= S_028C70_SOURCE_FORMAT(1);
+
+       for (i = 0; i < 4; i++) {
+               if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
+                       break;
+               }
+       }
+
+       /* we can only set the export size if any thing is snorm/unorm component is > 11 bits,
+          if we aren't a float, sint or uint */
+       if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS &&
+           desc->channel[i].size < 12 && desc->channel[i].type != UTIL_FORMAT_TYPE_FLOAT &&
+           ntype != 4 && ntype != 5)
+               color_info |= S_028C70_SOURCE_FORMAT(V_028C70_EXPORT_4C_16BPC);
 
        if (rtex->tiled) {
                tile_type = rtex->tile_type;
index dec32b504ee7212f970bc4991bc5bc6ee274d39f..f0a1ee0cd02e0abb27d264d2412ad7170ac99429 100644 (file)
 #define   S_028C70_SOURCE_FORMAT(x)                    (((x) & 0x3) << 24)
 #define   G_028C70_SOURCE_FORMAT(x)                    (((x) >> 24) & 0x3)
 #define   C_028C70_SOURCE_FORMAT                       0xFCFFFFFF
+#define     V_028C70_EXPORT_4C_32BPC                   0x0
+#define     V_028C70_EXPORT_4C_16BPC                   0x1
+#define     V_028C70_EXPORT_2C_32BPC                   0x2 /* Do not use */
 #define   S_028C70_RAT(x)                              (((x) & 0x1) << 26)
 #define   G_028C70_RAT(x)                              (((x) >> 26) & 0x1)
 #define   C_028C70_RAT                                 0xFBFFFFFF
index 74dad450729f25e6d8c3953bb878059cbba4c5ea..0834bf404a01ab2e56a7f3304a88995f4bba0bb9 100644 (file)
@@ -692,6 +692,7 @@ static void r600_cb(struct r600_pipe_context *rctx, struct r600_pipe_state *rsta
        unsigned offset;
        const struct util_format_description *desc;
        struct r600_bo *bo[3];
+       int i;
 
        surf = (struct r600_surface *)state->cbufs[cb];
        rtex = (struct r600_resource_texture*)state->cbufs[cb]->texture;
@@ -716,6 +717,12 @@ static void r600_cb(struct r600_pipe_context *rctx, struct r600_pipe_state *rsta
        if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB)
                ntype = V_0280A0_NUMBER_SRGB;
 
+       for (i = 0; i < 4; i++) {
+               if (desc->channel[i].type != UTIL_FORMAT_TYPE_VOID) {
+                       break;
+               }
+       }
+
        format = r600_translate_colorformat(surf->base.format);
        swap = r600_translate_colorswap(surf->base.format);
        color_info = S_0280A0_FORMAT(format) |
@@ -723,8 +730,12 @@ static void r600_cb(struct r600_pipe_context *rctx, struct r600_pipe_state *rsta
                S_0280A0_ARRAY_MODE(rtex->array_mode[level]) |
                S_0280A0_BLEND_CLAMP(1) |
                S_0280A0_NUMBER_TYPE(ntype);
-       if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS)
-               color_info |= S_0280A0_SOURCE_FORMAT(1);
+
+       /* on R600 this can't be set if BLEND_CLAMP isn't set,
+          if BLEND_FLOAT32 is set of > 11 bits in a UNORM or SNORM */
+       if (desc->colorspace != UTIL_FORMAT_COLORSPACE_ZS &&
+           desc->channel[i].size < 12)
+               color_info |= S_0280A0_SOURCE_FORMAT(V_0280A0_EXPORT_NORM);
 
        r600_pipe_state_add_reg(rstate,
                                R_028040_CB_COLOR0_BASE + cb * 4,
index f68bc849e2e72a548d8a40cef8bf42b587f2e360..81805158966dd480f0ff3d937febc5fada1a0763 100644 (file)
@@ -355,14 +355,13 @@ static inline uint32_t r600_translate_colorswap(enum pipe_format format)
                /* 64-bit buffers. */
        case PIPE_FORMAT_R16G16B16A16_UNORM:
        case PIPE_FORMAT_R16G16B16A16_SNORM:
-               //              return FMT_16_16_16_16;
        case PIPE_FORMAT_R16G16B16A16_FLOAT:
-               //              return FMT_16_16_16_16_FLOAT;
 
                /* 128-bit buffers. */
        case PIPE_FORMAT_R32G32B32A32_FLOAT:
-               //              return FMT_32_32_32_32_FLOAT;
-               return 0;
+       case PIPE_FORMAT_R32G32B32A32_SNORM:
+       case PIPE_FORMAT_R32G32B32A32_UNORM:
+               return V_0280A0_SWAP_STD;
        default:
                R600_ERR("unsupported colorswap format %d\n", format);
                return ~0;
@@ -469,6 +468,9 @@ static INLINE uint32_t r600_translate_colorformat(enum pipe_format format)
                return V_0280A0_COLOR_32_32_32_FLOAT;
        case PIPE_FORMAT_R32G32B32A32_FLOAT:
                return V_0280A0_COLOR_32_32_32_32_FLOAT;
+       case PIPE_FORMAT_R32G32B32A32_SNORM:
+       case PIPE_FORMAT_R32G32B32A32_UNORM:
+               return V_0280A0_COLOR_32_32_32_32;
 
                /* YUV buffers. */
        case PIPE_FORMAT_UYVY:
index b7bfdd8c166281f90da57a8a673dbf1deca0ece9..df8072fc13c320103862cd31a17171513b877224 100644 (file)
@@ -990,6 +990,19 @@ uint32_t r600_translate_texformat(enum pipe_format format,
                                result = FMT_16_16_16_16;
                                goto out_word4;
                        }
+                       goto out_unknown;
+               case 32:
+                       switch (desc->nr_channels) {
+                       case 1:
+                               result = FMT_32;
+                               goto out_word4;
+                       case 2:
+                               result = FMT_32_32;
+                               goto out_word4;
+                       case 4:
+                               result = FMT_32_32_32_32;
+                               goto out_word4;
+                       }
                }
                goto out_unknown;
 
index 1814f504ed965bebb25fc8818028c7cf2f406093..e8558c49a7cab03827b6773f2b3a3d4d05727f87 100644 (file)
 #define   S_0280A0_SOURCE_FORMAT(x)                    (((x) & 0x1) << 27)
 #define   G_0280A0_SOURCE_FORMAT(x)                    (((x) >> 27) & 0x1)
 #define   C_0280A0_SOURCE_FORMAT                       0xF7FFFFFF
+#define     V_0280A0_EXPORT_FULL                       0
+#define     V_0280A0_EXPORT_NORM                       1
 #define R_028060_CB_COLOR0_SIZE                      0x028060
 #define   S_028060_PITCH_TILE_MAX(x)                   (((x) & 0x3FF) << 0)
 #define   G_028060_PITCH_TILE_MAX(x)                   (((x) >> 0) & 0x3FF)