r600g: add SRGB support.
authorDave Airlie <airlied@redhat.com>
Fri, 6 Aug 2010 05:21:44 +0000 (15:21 +1000)
committerDave Airlie <airlied@redhat.com>
Fri, 6 Aug 2010 05:21:44 +0000 (15:21 +1000)
This enables GL2.1 and passes glean's texture_srgb test.

src/gallium/drivers/r600/r600_state.c
src/gallium/drivers/r600/r600_state_inlines.h
src/gallium/drivers/r600/r600d.h

index 82145617ca1fb1aa63ef798224c7cd7cd82c4836..1a8ec48936142be3b5f5c42bf39180eafb134160 100644 (file)
@@ -669,8 +669,9 @@ static int r600_cb0(struct r600_context *rctx, struct radeon_state *rstate)
        unsigned level = state->cbufs[0]->level;
        unsigned pitch, slice;
        unsigned color_info;
-       unsigned format, swap;
+       unsigned format, swap, ntype;
        int r;
+       const struct util_format_description *desc;
 
        r = radeon_state_init(rstate, rscreen->rw, R600_CB0_TYPE, R600_CB0);
        if (r)
@@ -688,12 +689,19 @@ static int r600_cb0(struct r600_context *rctx, struct radeon_state *rstate)
        pitch = (rtex->pitch[level] / rtex->bpt) / 8 - 1;
        slice = (rtex->pitch[level] / rtex->bpt) * state->cbufs[0]->height / 64 - 1;
 
+       ntype = 0;
+       desc = util_format_description(rtex->resource.base.b.format);
+       if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB)
+               ntype = NUM_FORMAT_SRGB;
+
        format = r600_translate_colorformat(rtex->resource.base.b.format);
        swap = r600_translate_colorswap(rtex->resource.base.b.format);
+
        color_info = S_0280A0_FORMAT(format) |
-         S_0280A0_COMP_SWAP(swap) |
-         S_0280A0_BLEND_CLAMP(1) |
-         S_0280A0_SOURCE_FORMAT(1);
+               S_0280A0_COMP_SWAP(swap) |
+               S_0280A0_BLEND_CLAMP(1) |
+               S_0280A0_SOURCE_FORMAT(1) |
+               S_0280A0_NUMBER_TYPE(ntype);
 
        rstate->states[R600_CB0__CB_COLOR0_BASE] = 0x00000000;
        rstate->states[R600_CB0__CB_COLOR0_INFO] = color_info;
@@ -1136,6 +1144,7 @@ static int r600_resource(struct r600_context *rctx, struct radeon_state *rstate,
                        S_038010_DST_SEL_Y(r600_tex_swizzle(view->swizzle_g)) |
                        S_038010_DST_SEL_Z(r600_tex_swizzle(view->swizzle_r)) |
                        S_038010_DST_SEL_W(r600_tex_swizzle(view->swizzle_a)) |
+                       S_038010_FORCE_DEGAMMA(desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB ? 1 : 0) |
                        S_038010_BASE_LEVEL(view->first_level);
        rstate->states[R600_PS_RESOURCE__RESOURCE0_WORD5] =
                        S_038014_LAST_LEVEL(view->last_level) |
index 4a955da1c02d7c9ca3d813f4d415067d96cb2763..fdc29386aea6438056a779065a7e671cba46a97f 100644 (file)
@@ -166,6 +166,12 @@ static uint32_t r600_translate_colorswap(enum pipe_format format)
         case PIPE_FORMAT_B4G4R4X4_UNORM:
                return SWAP_ALT;
                /* 32-bit buffers. */
+
+        case PIPE_FORMAT_A8B8G8R8_SRGB:
+               return SWAP_STD_REV;
+        case PIPE_FORMAT_B8G8R8A8_SRGB:
+               return SWAP_ALT;
+
         case PIPE_FORMAT_B8G8R8A8_UNORM:
         case PIPE_FORMAT_B8G8R8X8_UNORM:
                return SWAP_ALT;
@@ -244,6 +250,8 @@ static INLINE uint32_t r600_translate_colorformat(enum pipe_format format)
         case PIPE_FORMAT_X8B8G8R8_UNORM:
         case PIPE_FORMAT_R8G8B8X8_UNORM:
         case PIPE_FORMAT_R8SG8SB8UX8U_NORM:
+        case PIPE_FORMAT_A8B8G8R8_SRGB:
+        case PIPE_FORMAT_B8G8R8A8_SRGB:
                return V_0280A0_COLOR_8_8_8_8;
 
         case PIPE_FORMAT_R10G10B10A2_UNORM:
index 2d0ede20fa1f402354b42f1f609934bfcd238811..f9cad931859ca74a361d81a27e5037a2d827cb91 100644 (file)
 #define SWAP_ALT 1
 #define SWAP_STD_REV 2
 #define SWAP_ALT_REV 3
+
+#define NUM_FORMAT_SRGB 6
 #endif