r600: add support for more rendering formats
authorAlex Deucher <alexdeucher@gmail.com>
Mon, 26 Apr 2010 19:00:28 +0000 (15:00 -0400)
committerAlex Deucher <alexdeucher@gmail.com>
Mon, 26 Apr 2010 19:02:13 +0000 (15:02 -0400)
src/mesa/drivers/dri/r600/r600_context.c
src/mesa/drivers/dri/r600/r600_tex.c
src/mesa/drivers/dri/r600/r600_tex.h
src/mesa/drivers/dri/r600/r700_chip.c

index fddac2f9bdc8011c887c954acb254e8308ca0ab5..ab6b6172352513e4f47bd51c758ff7286bd6d84e 100644 (file)
@@ -239,7 +239,7 @@ static void r600_init_vtbl(radeonContextPtr radeon)
        radeon->vtbl.emit_query_finish = r600_emit_query_finish;
        radeon->vtbl.check_blit = r600_check_blit;
        radeon->vtbl.blit = r600_blit;
-       radeon->vtbl.is_format_renderable = radeonIsFormatRenderable;
+       radeon->vtbl.is_format_renderable = r600IsFormatRenderable;
 }
 
 static void r600InitConstValues(GLcontext *ctx, radeonScreenPtr screen)
index 36a6e6e0a113c43d50c65e6955a1d3dfa6ffb2eb..41419f846015b75c4d0ef56fc1248f88fef7cabf 100644 (file)
@@ -392,6 +392,54 @@ static struct gl_texture_object *r600NewTextureObject(GLcontext * ctx,
        return &t->base;
 }
 
+unsigned r600IsFormatRenderable(gl_format mesa_format)
+{
+       switch (mesa_format) {
+       case MESA_FORMAT_RGBA8888:
+       case MESA_FORMAT_SIGNED_RGBA8888:
+       case MESA_FORMAT_RGBA8888_REV:
+       case MESA_FORMAT_SIGNED_RGBA8888_REV:
+       case MESA_FORMAT_ARGB8888:
+       case MESA_FORMAT_XRGB8888:
+       case MESA_FORMAT_ARGB8888_REV:
+       case MESA_FORMAT_XRGB8888_REV:
+       case MESA_FORMAT_RGB565:
+       case MESA_FORMAT_RGB565_REV:
+       case MESA_FORMAT_ARGB4444:
+       case MESA_FORMAT_ARGB4444_REV:
+       case MESA_FORMAT_ARGB1555:
+       case MESA_FORMAT_ARGB1555_REV:
+       case MESA_FORMAT_AL88:
+       case MESA_FORMAT_AL88_REV:
+       case MESA_FORMAT_RGB332:
+       case MESA_FORMAT_A8:
+       case MESA_FORMAT_I8:
+       case MESA_FORMAT_CI8:
+       case MESA_FORMAT_L8:
+       case MESA_FORMAT_RGBA_FLOAT32:
+       case MESA_FORMAT_RGBA_FLOAT16:
+       case MESA_FORMAT_ALPHA_FLOAT32:
+       case MESA_FORMAT_ALPHA_FLOAT16:
+       case MESA_FORMAT_LUMINANCE_FLOAT32:
+       case MESA_FORMAT_LUMINANCE_FLOAT16:
+       case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
+       case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
+       case MESA_FORMAT_INTENSITY_FLOAT32: /* X, X, X, X */
+       case MESA_FORMAT_INTENSITY_FLOAT16: /* X, X, X, X */
+       case MESA_FORMAT_X8_Z24:
+       case MESA_FORMAT_S8_Z24:
+       case MESA_FORMAT_Z24_S8:
+       case MESA_FORMAT_Z16:
+       case MESA_FORMAT_Z32:
+       case MESA_FORMAT_SRGBA8:
+       case MESA_FORMAT_SLA8:
+       case MESA_FORMAT_SL8:
+               return 1;
+       default:
+               return 0;
+       }
+}
+
 void r600InitTextureFuncs(radeonContextPtr radeon, struct dd_function_table *functions)
 {
        /* Note: we only plug in the functions we implement in the driver
index 1d75a2ecd69cce309310bc2555785ceb3472565b..771affdfa609e95956445e1f41f291c8f96587f4 100644 (file)
@@ -60,4 +60,6 @@ extern GLboolean r600ValidateBuffers(GLcontext * ctx);
 
 extern void r600InitTextureFuncs(radeonContextPtr radeon, struct dd_function_table *functions);
 
+unsigned r600IsFormatRenderable(gl_format mesa_format);
+
 #endif                         /* __r600_TEX_H__ */
index 63614b160ccbaf3ff7e183691b16306162e348ad..cefda3ac4bae9431b214e797f8142d08feaa9e89 100644 (file)
@@ -290,7 +290,7 @@ static void r700SendVTXState(GLcontext *ctx, struct radeon_state_atom *atom)
 static void r700SetRenderTarget(context_t *context, int id)
 {
     R700_CHIP_CONTEXT *r700 = (R700_CHIP_CONTEXT*)(&context->hw);
-
+    uint32_t format = COLOR_8_8_8_8, comp_swap = SWAP_ALT, number_type = NUMBER_UNORM;
     struct radeon_renderbuffer *rrb;
     unsigned int nPitchInPixel;
 
@@ -312,22 +312,251 @@ static void r700SetRenderTarget(context_t *context, int id)
     SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, ENDIAN_NONE, ENDIAN_shift, ENDIAN_mask);
     SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, ARRAY_LINEAR_GENERAL,
              CB_COLOR0_INFO__ARRAY_MODE_shift, CB_COLOR0_INFO__ARRAY_MODE_mask);
-    if(4 == rrb->cpp)
-    {
-        SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, COLOR_8_8_8_8,
-                 CB_COLOR0_INFO__FORMAT_shift, CB_COLOR0_INFO__FORMAT_mask);
-        SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, SWAP_ALT, COMP_SWAP_shift, COMP_SWAP_mask);
-    }
-    else
-    {
-        SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, COLOR_5_6_5,
-                 CB_COLOR0_INFO__FORMAT_shift, CB_COLOR0_INFO__FORMAT_mask);
-        SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, SWAP_ALT_REV,
-                 COMP_SWAP_shift, COMP_SWAP_mask);
+
+    switch (rrb->base.Format) {
+    case MESA_FORMAT_RGBA8888:
+            format = COLOR_8_8_8_8;
+            comp_swap = SWAP_STD_REV;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_SIGNED_RGBA8888:
+            format = COLOR_8_8_8_8;
+            comp_swap = SWAP_STD_REV;
+           number_type = NUMBER_SNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_RGBA8888_REV:
+            format = COLOR_8_8_8_8;
+            comp_swap = SWAP_STD;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_SIGNED_RGBA8888_REV:
+            format = COLOR_8_8_8_8;
+            comp_swap = SWAP_STD;
+           number_type = NUMBER_SNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_ARGB8888:
+    case MESA_FORMAT_XRGB8888:
+            format = COLOR_8_8_8_8;
+            comp_swap = SWAP_ALT;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_ARGB8888_REV:
+    case MESA_FORMAT_XRGB8888_REV:
+            format = COLOR_8_8_8_8;
+            comp_swap = SWAP_ALT_REV;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_RGB565:
+            format = COLOR_5_6_5;
+            comp_swap = SWAP_STD_REV;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_RGB565_REV:
+            format = COLOR_5_6_5;
+            comp_swap = SWAP_STD;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_ARGB4444:
+            format = COLOR_4_4_4_4;
+            comp_swap = SWAP_ALT;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_ARGB4444_REV:
+            format = COLOR_4_4_4_4;
+            comp_swap = SWAP_ALT_REV;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_ARGB1555:
+            format = COLOR_1_5_5_5;
+            comp_swap = SWAP_ALT;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_ARGB1555_REV:
+            format = COLOR_1_5_5_5;
+            comp_swap = SWAP_ALT_REV;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_AL88:
+            format = COLOR_8_8;
+            comp_swap = SWAP_STD;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_AL88_REV:
+            format = COLOR_8_8;
+            comp_swap = SWAP_STD_REV;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_RGB332:
+            format = COLOR_3_3_2;
+            comp_swap = SWAP_STD_REV;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_A8:
+            format = COLOR_8;
+            comp_swap = SWAP_ALT_REV;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_I8:
+    case MESA_FORMAT_CI8:
+            format = COLOR_8;
+            comp_swap = SWAP_STD;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_L8:
+            format = COLOR_8;
+            comp_swap = SWAP_ALT;
+           number_type = NUMBER_UNORM;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_RGBA_FLOAT32:
+            format = COLOR_32_32_32_32_FLOAT;
+            comp_swap = SWAP_STD_REV;
+           number_type = NUMBER_FLOAT;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, BLEND_FLOAT32_bit);
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_RGBA_FLOAT16:
+            format = COLOR_16_16_16_16_FLOAT;
+            comp_swap = SWAP_STD_REV;
+           number_type = NUMBER_FLOAT;
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_ALPHA_FLOAT32:
+            format = COLOR_32_FLOAT;
+            comp_swap = SWAP_ALT_REV;
+           number_type = NUMBER_FLOAT;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, BLEND_FLOAT32_bit);
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_ALPHA_FLOAT16:
+            format = COLOR_16_FLOAT;
+            comp_swap = SWAP_ALT_REV;
+           number_type = NUMBER_FLOAT;
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_LUMINANCE_FLOAT32:
+            format = COLOR_32_FLOAT;
+            comp_swap = SWAP_ALT;
+           number_type = NUMBER_FLOAT;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, BLEND_FLOAT32_bit);
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_LUMINANCE_FLOAT16:
+            format = COLOR_16_FLOAT;
+            comp_swap = SWAP_ALT;
+           number_type = NUMBER_FLOAT;
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT32:
+            format = COLOR_32_32_FLOAT;
+            comp_swap = SWAP_ALT_REV;
+           number_type = NUMBER_FLOAT;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, BLEND_FLOAT32_bit);
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_LUMINANCE_ALPHA_FLOAT16:
+            format = COLOR_16_16_FLOAT;
+            comp_swap = SWAP_ALT_REV;
+           number_type = NUMBER_FLOAT;
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_INTENSITY_FLOAT32: /* X, X, X, X */
+            format = COLOR_32_FLOAT;
+            comp_swap = SWAP_STD;
+           number_type = NUMBER_FLOAT;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, BLEND_FLOAT32_bit);
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_INTENSITY_FLOAT16: /* X, X, X, X */
+            format = COLOR_16_FLOAT;
+            comp_swap = SWAP_STD;
+           number_type = NUMBER_UNORM;
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_X8_Z24:
+    case MESA_FORMAT_S8_Z24:
+            format = COLOR_8_24;
+            comp_swap = SWAP_STD;
+           number_type = NUMBER_UNORM;
+           SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, ARRAY_1D_TILED_THIN1,
+                    CB_COLOR0_INFO__ARRAY_MODE_shift, CB_COLOR0_INFO__ARRAY_MODE_mask);
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_Z24_S8:
+            format = COLOR_24_8;
+            comp_swap = SWAP_STD;
+           number_type = NUMBER_UNORM;
+           SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, ARRAY_1D_TILED_THIN1,
+                    CB_COLOR0_INFO__ARRAY_MODE_shift, CB_COLOR0_INFO__ARRAY_MODE_mask);
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_Z16:
+            format = COLOR_16;
+            comp_swap = SWAP_STD;
+           number_type = NUMBER_UNORM;
+           SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, ARRAY_1D_TILED_THIN1,
+                    CB_COLOR0_INFO__ARRAY_MODE_shift, CB_COLOR0_INFO__ARRAY_MODE_mask);
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_Z32:
+            format = COLOR_32;
+            comp_swap = SWAP_STD;
+           number_type = NUMBER_UNORM;
+           SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, ARRAY_1D_TILED_THIN1,
+                    CB_COLOR0_INFO__ARRAY_MODE_shift, CB_COLOR0_INFO__ARRAY_MODE_mask);
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_SRGBA8:
+            format = COLOR_8_8_8_8;
+            comp_swap = SWAP_STD_REV;
+           number_type = NUMBER_SRGB;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_SLA8:
+            format = COLOR_8_8;
+            comp_swap = SWAP_ALT_REV;
+           number_type = NUMBER_SRGB;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    case MESA_FORMAT_SL8:
+            format = COLOR_8;
+            comp_swap = SWAP_ALT_REV;
+           number_type = NUMBER_SRGB;
+           SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+            break;
+    default:
+           _mesa_problem(context->radeon.glCtx, "unexpected format in r700SetRenderTarget()");
+           break;
     }
-    SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, SOURCE_FORMAT_bit);
+
+    /* must be 0 on r7xx */
+    if (context->radeon.radeonScreen->chip_family >= CHIP_FAMILY_RV770)
+           CLEARbit(r700->render_target[id].CB_COLOR0_INFO.u32All, BLEND_FLOAT32_bit);
+
+    SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, format,
+            CB_COLOR0_INFO__FORMAT_shift, CB_COLOR0_INFO__FORMAT_mask);
+    SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, comp_swap,
+            COMP_SWAP_shift, COMP_SWAP_mask);
+    SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, number_type,
+            NUMBER_TYPE_shift, NUMBER_TYPE_mask);
     SETbit(r700->render_target[id].CB_COLOR0_INFO.u32All, BLEND_CLAMP_bit);
-    SETfield(r700->render_target[id].CB_COLOR0_INFO.u32All, NUMBER_UNORM, NUMBER_TYPE_shift, NUMBER_TYPE_mask);
 
     r700->render_target[id].enabled = GL_TRUE;
 }