radeonsi: move format handling into si_state.c
authorChristian König <deathsimple@vodafone.de>
Fri, 20 Jul 2012 09:08:22 +0000 (11:08 +0200)
committerChristian König <deathsimple@vodafone.de>
Tue, 24 Jul 2012 10:29:30 +0000 (12:29 +0200)
Signed-off-by: Christian König <deathsimple@vodafone.de>
src/gallium/drivers/radeonsi/evergreen_state.c
src/gallium/drivers/radeonsi/radeonsi_pipe.h
src/gallium/drivers/radeonsi/si_state.c
src/gallium/drivers/radeonsi/si_state.h

index 441a09b97c3222c35cc43c0e3ca3ff3875490a9a..f3627538c5f73f10479c40445e2b08f2d34d140e 100644 (file)
@@ -76,540 +76,6 @@ static uint32_t r600_translate_stencil_op(int s_op)
 }
 #endif
 
-static uint32_t si_translate_dbformat(enum pipe_format format)
-{
-       switch (format) {
-       case PIPE_FORMAT_Z16_UNORM:
-               return V_028040_Z_16;
-       case PIPE_FORMAT_Z24X8_UNORM:
-       case PIPE_FORMAT_Z24_UNORM_S8_UINT:
-               return V_028040_Z_24; /* XXX no longer supported on SI */
-       case PIPE_FORMAT_Z32_FLOAT:
-       case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
-               return V_028040_Z_32_FLOAT;
-       default:
-               return ~0U;
-       }
-}
-
-static uint32_t si_translate_colorswap(enum pipe_format format)
-{
-       switch (format) {
-       /* 8-bit buffers. */
-       case PIPE_FORMAT_L4A4_UNORM:
-       case PIPE_FORMAT_A4R4_UNORM:
-               return V_028C70_SWAP_ALT;
-
-       case PIPE_FORMAT_A8_UNORM:
-       case PIPE_FORMAT_A8_UINT:
-       case PIPE_FORMAT_A8_SINT:
-       case PIPE_FORMAT_R4A4_UNORM:
-               return V_028C70_SWAP_ALT_REV;
-       case PIPE_FORMAT_I8_UNORM:
-       case PIPE_FORMAT_L8_UNORM:
-       case PIPE_FORMAT_I8_UINT:
-       case PIPE_FORMAT_I8_SINT:
-       case PIPE_FORMAT_L8_UINT:
-       case PIPE_FORMAT_L8_SINT:
-       case PIPE_FORMAT_L8_SRGB:
-       case PIPE_FORMAT_R8_UNORM:
-       case PIPE_FORMAT_R8_SNORM:
-       case PIPE_FORMAT_R8_UINT:
-       case PIPE_FORMAT_R8_SINT:
-               return V_028C70_SWAP_STD;
-
-       /* 16-bit buffers. */
-       case PIPE_FORMAT_B5G6R5_UNORM:
-               return V_028C70_SWAP_STD_REV;
-
-       case PIPE_FORMAT_B5G5R5A1_UNORM:
-       case PIPE_FORMAT_B5G5R5X1_UNORM:
-               return V_028C70_SWAP_ALT;
-
-       case PIPE_FORMAT_B4G4R4A4_UNORM:
-       case PIPE_FORMAT_B4G4R4X4_UNORM:
-               return V_028C70_SWAP_ALT;
-
-       case PIPE_FORMAT_Z16_UNORM:
-               return V_028C70_SWAP_STD;
-
-       case PIPE_FORMAT_L8A8_UNORM:
-       case PIPE_FORMAT_L8A8_UINT:
-       case PIPE_FORMAT_L8A8_SINT:
-       case PIPE_FORMAT_L8A8_SRGB:
-               return V_028C70_SWAP_ALT;
-       case PIPE_FORMAT_R8G8_UNORM:
-       case PIPE_FORMAT_R8G8_UINT:
-       case PIPE_FORMAT_R8G8_SINT:
-               return V_028C70_SWAP_STD;
-
-       case PIPE_FORMAT_R16_UNORM:
-       case PIPE_FORMAT_R16_UINT:
-       case PIPE_FORMAT_R16_SINT:
-       case PIPE_FORMAT_R16_FLOAT:
-               return V_028C70_SWAP_STD;
-
-       /* 32-bit buffers. */
-       case PIPE_FORMAT_A8B8G8R8_SRGB:
-               return V_028C70_SWAP_STD_REV;
-       case PIPE_FORMAT_B8G8R8A8_SRGB:
-               return V_028C70_SWAP_ALT;
-
-       case PIPE_FORMAT_B8G8R8A8_UNORM:
-       case PIPE_FORMAT_B8G8R8X8_UNORM:
-               return V_028C70_SWAP_ALT;
-
-       case PIPE_FORMAT_A8R8G8B8_UNORM:
-       case PIPE_FORMAT_X8R8G8B8_UNORM:
-               return V_028C70_SWAP_ALT_REV;
-       case PIPE_FORMAT_R8G8B8A8_SNORM:
-       case PIPE_FORMAT_R8G8B8A8_UNORM:
-       case PIPE_FORMAT_R8G8B8A8_SSCALED:
-       case PIPE_FORMAT_R8G8B8A8_USCALED:
-       case PIPE_FORMAT_R8G8B8A8_SINT:
-       case PIPE_FORMAT_R8G8B8A8_UINT:
-       case PIPE_FORMAT_R8G8B8X8_UNORM:
-               return V_028C70_SWAP_STD;
-
-       case PIPE_FORMAT_A8B8G8R8_UNORM:
-       case PIPE_FORMAT_X8B8G8R8_UNORM:
-       /* case PIPE_FORMAT_R8SG8SB8UX8U_NORM: */
-               return V_028C70_SWAP_STD_REV;
-
-       case PIPE_FORMAT_Z24X8_UNORM:
-       case PIPE_FORMAT_Z24_UNORM_S8_UINT:
-               return V_028C70_SWAP_STD;
-
-       case PIPE_FORMAT_X8Z24_UNORM:
-       case PIPE_FORMAT_S8_UINT_Z24_UNORM:
-               return V_028C70_SWAP_STD;
-
-       case PIPE_FORMAT_R10G10B10A2_UNORM:
-       case PIPE_FORMAT_R10G10B10X2_SNORM:
-       case PIPE_FORMAT_R10SG10SB10SA2U_NORM:
-               return V_028C70_SWAP_STD;
-
-       case PIPE_FORMAT_B10G10R10A2_UNORM:
-       case PIPE_FORMAT_B10G10R10A2_UINT:
-               return V_028C70_SWAP_ALT;
-
-       case PIPE_FORMAT_R11G11B10_FLOAT:
-       case PIPE_FORMAT_R32_FLOAT:
-       case PIPE_FORMAT_R32_UINT:
-       case PIPE_FORMAT_R32_SINT:
-       case PIPE_FORMAT_Z32_FLOAT:
-       case PIPE_FORMAT_R16G16_FLOAT:
-       case PIPE_FORMAT_R16G16_UNORM:
-       case PIPE_FORMAT_R16G16_UINT:
-       case PIPE_FORMAT_R16G16_SINT:
-               return V_028C70_SWAP_STD;
-
-       /* 64-bit buffers. */
-       case PIPE_FORMAT_R32G32_FLOAT:
-       case PIPE_FORMAT_R32G32_UINT:
-       case PIPE_FORMAT_R32G32_SINT:
-       case PIPE_FORMAT_R16G16B16A16_UNORM:
-       case PIPE_FORMAT_R16G16B16A16_SNORM:
-       case PIPE_FORMAT_R16G16B16A16_USCALED:
-       case PIPE_FORMAT_R16G16B16A16_SSCALED:
-       case PIPE_FORMAT_R16G16B16A16_UINT:
-       case PIPE_FORMAT_R16G16B16A16_SINT:
-       case PIPE_FORMAT_R16G16B16A16_FLOAT:
-       case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
-
-       /* 128-bit buffers. */
-       case PIPE_FORMAT_R32G32B32A32_FLOAT:
-       case PIPE_FORMAT_R32G32B32A32_SNORM:
-       case PIPE_FORMAT_R32G32B32A32_UNORM:
-       case PIPE_FORMAT_R32G32B32A32_SSCALED:
-       case PIPE_FORMAT_R32G32B32A32_USCALED:
-       case PIPE_FORMAT_R32G32B32A32_SINT:
-       case PIPE_FORMAT_R32G32B32A32_UINT:
-               return V_028C70_SWAP_STD;
-       default:
-               R600_ERR("unsupported colorswap format %d\n", format);
-               return ~0U;
-       }
-       return ~0U;
-}
-
-static uint32_t si_translate_colorformat(enum pipe_format format)
-{
-       switch (format) {
-       /* 8-bit buffers. */
-       case PIPE_FORMAT_A8_UNORM:
-       case PIPE_FORMAT_A8_UINT:
-       case PIPE_FORMAT_A8_SINT:
-       case PIPE_FORMAT_I8_UNORM:
-       case PIPE_FORMAT_I8_UINT:
-       case PIPE_FORMAT_I8_SINT:
-       case PIPE_FORMAT_L8_UNORM:
-       case PIPE_FORMAT_L8_UINT:
-       case PIPE_FORMAT_L8_SINT:
-       case PIPE_FORMAT_L8_SRGB:
-       case PIPE_FORMAT_R8_UNORM:
-       case PIPE_FORMAT_R8_SNORM:
-       case PIPE_FORMAT_R8_UINT:
-       case PIPE_FORMAT_R8_SINT:
-               return V_028C70_COLOR_8;
-
-       /* 16-bit buffers. */
-       case PIPE_FORMAT_B5G6R5_UNORM:
-               return V_028C70_COLOR_5_6_5;
-
-       case PIPE_FORMAT_B5G5R5A1_UNORM:
-       case PIPE_FORMAT_B5G5R5X1_UNORM:
-               return V_028C70_COLOR_1_5_5_5;
-
-       case PIPE_FORMAT_B4G4R4A4_UNORM:
-       case PIPE_FORMAT_B4G4R4X4_UNORM:
-               return V_028C70_COLOR_4_4_4_4;
-
-       case PIPE_FORMAT_L8A8_UNORM:
-       case PIPE_FORMAT_L8A8_UINT:
-       case PIPE_FORMAT_L8A8_SINT:
-       case PIPE_FORMAT_L8A8_SRGB:
-       case PIPE_FORMAT_R8G8_UNORM:
-       case PIPE_FORMAT_R8G8_UINT:
-       case PIPE_FORMAT_R8G8_SINT:
-               return V_028C70_COLOR_8_8;
-
-       case PIPE_FORMAT_Z16_UNORM:
-       case PIPE_FORMAT_R16_UNORM:
-       case PIPE_FORMAT_R16_UINT:
-       case PIPE_FORMAT_R16_SINT:
-       case PIPE_FORMAT_R16_FLOAT:
-       case PIPE_FORMAT_R16G16_FLOAT:
-               return V_028C70_COLOR_16;
-
-       /* 32-bit buffers. */
-       case PIPE_FORMAT_A8B8G8R8_SRGB:
-       case PIPE_FORMAT_A8B8G8R8_UNORM:
-       case PIPE_FORMAT_A8R8G8B8_UNORM:
-       case PIPE_FORMAT_B8G8R8A8_SRGB:
-       case PIPE_FORMAT_B8G8R8A8_UNORM:
-       case PIPE_FORMAT_B8G8R8X8_UNORM:
-       case PIPE_FORMAT_R8G8B8A8_SNORM:
-       case PIPE_FORMAT_R8G8B8A8_UNORM:
-       case PIPE_FORMAT_R8G8B8X8_UNORM:
-       case PIPE_FORMAT_R8SG8SB8UX8U_NORM:
-       case PIPE_FORMAT_X8B8G8R8_UNORM:
-       case PIPE_FORMAT_X8R8G8B8_UNORM:
-       case PIPE_FORMAT_R8G8B8_UNORM:
-       case PIPE_FORMAT_R8G8B8A8_SSCALED:
-       case PIPE_FORMAT_R8G8B8A8_USCALED:
-       case PIPE_FORMAT_R8G8B8A8_SINT:
-       case PIPE_FORMAT_R8G8B8A8_UINT:
-               return V_028C70_COLOR_8_8_8_8;
-
-       case PIPE_FORMAT_R10G10B10A2_UNORM:
-       case PIPE_FORMAT_R10G10B10X2_SNORM:
-       case PIPE_FORMAT_B10G10R10A2_UNORM:
-       case PIPE_FORMAT_B10G10R10A2_UINT:
-       case PIPE_FORMAT_R10SG10SB10SA2U_NORM:
-               return V_028C70_COLOR_2_10_10_10;
-
-       case PIPE_FORMAT_Z24X8_UNORM:
-       case PIPE_FORMAT_Z24_UNORM_S8_UINT:
-               return V_028C70_COLOR_8_24;
-
-       case PIPE_FORMAT_X8Z24_UNORM:
-       case PIPE_FORMAT_S8_UINT_Z24_UNORM:
-               return V_028C70_COLOR_24_8;
-
-       case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
-               return V_028C70_COLOR_X24_8_32_FLOAT;
-
-       case PIPE_FORMAT_R32_FLOAT:
-       case PIPE_FORMAT_Z32_FLOAT:
-               return V_028C70_COLOR_32;
-
-       case PIPE_FORMAT_R16G16_SSCALED:
-       case PIPE_FORMAT_R16G16_UNORM:
-       case PIPE_FORMAT_R16G16_UINT:
-       case PIPE_FORMAT_R16G16_SINT:
-               return V_028C70_COLOR_16_16;
-
-       case PIPE_FORMAT_R11G11B10_FLOAT:
-               return V_028C70_COLOR_10_11_11;
-
-       /* 64-bit buffers. */
-       case PIPE_FORMAT_R16G16B16_USCALED:
-       case PIPE_FORMAT_R16G16B16_SSCALED:
-       case PIPE_FORMAT_R16G16B16A16_UINT:
-       case PIPE_FORMAT_R16G16B16A16_SINT:
-       case PIPE_FORMAT_R16G16B16A16_USCALED:
-       case PIPE_FORMAT_R16G16B16A16_SSCALED:
-       case PIPE_FORMAT_R16G16B16A16_UNORM:
-       case PIPE_FORMAT_R16G16B16A16_SNORM:
-       case PIPE_FORMAT_R16G16B16_FLOAT:
-       case PIPE_FORMAT_R16G16B16A16_FLOAT:
-               return V_028C70_COLOR_16_16_16_16;
-
-       case PIPE_FORMAT_R32G32_FLOAT:
-       case PIPE_FORMAT_R32G32_USCALED:
-       case PIPE_FORMAT_R32G32_SSCALED:
-       case PIPE_FORMAT_R32G32_SINT:
-       case PIPE_FORMAT_R32G32_UINT:
-               return V_028C70_COLOR_32_32;
-
-       /* 128-bit buffers. */
-       case PIPE_FORMAT_R32G32B32A32_SNORM:
-       case PIPE_FORMAT_R32G32B32A32_UNORM:
-       case PIPE_FORMAT_R32G32B32A32_SSCALED:
-       case PIPE_FORMAT_R32G32B32A32_USCALED:
-       case PIPE_FORMAT_R32G32B32A32_SINT:
-       case PIPE_FORMAT_R32G32B32A32_UINT:
-       case PIPE_FORMAT_R32G32B32A32_FLOAT:
-               return V_028C70_COLOR_32_32_32_32;
-
-       /* YUV buffers. */
-       case PIPE_FORMAT_UYVY:
-       case PIPE_FORMAT_YUYV:
-       /* 96-bit buffers. */
-       case PIPE_FORMAT_R32G32B32_FLOAT:
-       /* 8-bit buffers. */
-       case PIPE_FORMAT_L4A4_UNORM:
-       case PIPE_FORMAT_R4A4_UNORM:
-       case PIPE_FORMAT_A4R4_UNORM:
-       default:
-               return ~0U; /* Unsupported. */
-       }
-}
-
-static uint32_t si_translate_texformat(struct pipe_screen *screen,
-                                      enum pipe_format format,
-                                      const struct util_format_description *desc,
-                                      int first_non_void)
-{
-       boolean uniform = TRUE;
-       int i;
-
-       /* Colorspace (return non-RGB formats directly). */
-       switch (desc->colorspace) {
-       /* Depth stencil formats */
-       case UTIL_FORMAT_COLORSPACE_ZS:
-               switch (format) {
-               case PIPE_FORMAT_Z16_UNORM:
-                       return V_008F14_IMG_DATA_FORMAT_16;
-               case PIPE_FORMAT_X24S8_UINT:
-               case PIPE_FORMAT_Z24X8_UNORM:
-               case PIPE_FORMAT_Z24_UNORM_S8_UINT:
-                       return V_008F14_IMG_DATA_FORMAT_24_8;
-               case PIPE_FORMAT_S8X24_UINT:
-               case PIPE_FORMAT_X8Z24_UNORM:
-               case PIPE_FORMAT_S8_UINT_Z24_UNORM:
-                       return V_008F14_IMG_DATA_FORMAT_8_24;
-               case PIPE_FORMAT_S8_UINT:
-                       return V_008F14_IMG_DATA_FORMAT_8;
-               case PIPE_FORMAT_Z32_FLOAT:
-                       return V_008F14_IMG_DATA_FORMAT_32;
-               case PIPE_FORMAT_Z32_FLOAT_S8X24_UINT:
-                       return V_008F14_IMG_DATA_FORMAT_X24_8_32;
-               default:
-                       goto out_unknown;
-               }
-
-       case UTIL_FORMAT_COLORSPACE_YUV:
-               goto out_unknown; /* TODO */
-
-       case UTIL_FORMAT_COLORSPACE_SRGB:
-               break;
-
-       default:
-               break;
-       }
-
-       /* TODO compressed formats */
-
-       if (format == PIPE_FORMAT_R9G9B9E5_FLOAT) {
-               return V_008F14_IMG_DATA_FORMAT_5_9_9_9;
-       } else if (format == PIPE_FORMAT_R11G11B10_FLOAT) {
-               return V_008F14_IMG_DATA_FORMAT_10_11_11;
-       }
-
-       /* R8G8Bx_SNORM - TODO CxV8U8 */
-
-       /* See whether the components are of the same size. */
-       for (i = 1; i < desc->nr_channels; i++) {
-               uniform = uniform && desc->channel[0].size == desc->channel[i].size;
-       }
-
-       /* Non-uniform formats. */
-       if (!uniform) {
-               switch(desc->nr_channels) {
-               case 3:
-                       if (desc->channel[0].size == 5 &&
-                           desc->channel[1].size == 6 &&
-                           desc->channel[2].size == 5) {
-                               return V_008F14_IMG_DATA_FORMAT_5_6_5;
-                       }
-                       goto out_unknown;
-               case 4:
-                       if (desc->channel[0].size == 5 &&
-                           desc->channel[1].size == 5 &&
-                           desc->channel[2].size == 5 &&
-                           desc->channel[3].size == 1) {
-                               return V_008F14_IMG_DATA_FORMAT_1_5_5_5;
-                       }
-                       if (desc->channel[0].size == 10 &&
-                           desc->channel[1].size == 10 &&
-                           desc->channel[2].size == 10 &&
-                           desc->channel[3].size == 2) {
-                               return V_008F14_IMG_DATA_FORMAT_2_10_10_10;
-                       }
-                       goto out_unknown;
-               }
-               goto out_unknown;
-       }
-
-       if (first_non_void < 0 || first_non_void > 3)
-               goto out_unknown;
-
-       /* uniform formats */
-       switch (desc->channel[first_non_void].size) {
-       case 4:
-               switch (desc->nr_channels) {
-               case 2:
-                       return V_008F14_IMG_DATA_FORMAT_4_4;
-               case 4:
-                       return V_008F14_IMG_DATA_FORMAT_4_4_4_4;
-               }
-               break;
-       case 8:
-               switch (desc->nr_channels) {
-               case 1:
-                       return V_008F14_IMG_DATA_FORMAT_8;
-               case 2:
-                       return V_008F14_IMG_DATA_FORMAT_8_8;
-               case 4:
-                       return V_008F14_IMG_DATA_FORMAT_8_8_8_8;
-               }
-               break;
-       case 16:
-               switch (desc->nr_channels) {
-               case 1:
-                       return V_008F14_IMG_DATA_FORMAT_16;
-               case 2:
-                       return V_008F14_IMG_DATA_FORMAT_16_16;
-               case 4:
-                       return V_008F14_IMG_DATA_FORMAT_16_16_16_16;
-               }
-               break;
-       case 32:
-               switch (desc->nr_channels) {
-               case 1:
-                       return V_008F14_IMG_DATA_FORMAT_32;
-               case 2:
-                       return V_008F14_IMG_DATA_FORMAT_32_32;
-               case 3:
-                       return V_008F14_IMG_DATA_FORMAT_32_32_32;
-               case 4:
-                       return V_008F14_IMG_DATA_FORMAT_32_32_32_32;
-               }
-       }
-
-out_unknown:
-       /* R600_ERR("Unable to handle texformat %d %s\n", format, util_format_name(format)); */
-       return ~0;
-}
-
-static bool si_is_sampler_format_supported(struct pipe_screen *screen, enum pipe_format format)
-{
-       return si_translate_texformat(screen, format, util_format_description(format),
-                                     util_format_get_first_non_void_channel(format)) != ~0U;
-}
-
-uint32_t si_translate_vertexformat(struct pipe_screen *screen,
-                                  enum pipe_format format,
-                                  const struct util_format_description *desc,
-                                  int first_non_void)
-{
-       uint32_t result;
-
-       if (desc->channel[first_non_void].type == UTIL_FORMAT_TYPE_FIXED)
-               return ~0;
-
-       result = si_translate_texformat(screen, format, desc, first_non_void);
-       if (result == V_008F0C_BUF_DATA_FORMAT_INVALID ||
-           result > V_008F0C_BUF_DATA_FORMAT_32_32_32_32)
-               result = ~0;
-
-       return result;
-}
-
-static bool si_is_vertex_format_supported(struct pipe_screen *screen, enum pipe_format format)
-{
-       return si_translate_vertexformat(screen, format, util_format_description(format),
-                                        util_format_get_first_non_void_channel(format)) != ~0U;
-}
-
-static bool r600_is_colorbuffer_format_supported(enum pipe_format format)
-{
-       return si_translate_colorformat(format) != ~0U &&
-               si_translate_colorswap(format) != ~0U;
-}
-
-static bool r600_is_zs_format_supported(enum pipe_format format)
-{
-       return si_translate_dbformat(format) != ~0U;
-}
-
-boolean si_is_format_supported(struct pipe_screen *screen,
-                              enum pipe_format format,
-                              enum pipe_texture_target target,
-                              unsigned sample_count,
-                              unsigned usage)
-{
-       unsigned retval = 0;
-
-       if (target >= PIPE_MAX_TEXTURE_TYPES) {
-               R600_ERR("r600: unsupported texture type %d\n", target);
-               return FALSE;
-       }
-
-       if (!util_format_is_supported(format, usage))
-               return FALSE;
-
-       /* Multisample */
-       if (sample_count > 1)
-               return FALSE;
-
-       if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
-           si_is_sampler_format_supported(screen, format)) {
-               retval |= PIPE_BIND_SAMPLER_VIEW;
-       }
-
-       if ((usage & (PIPE_BIND_RENDER_TARGET |
-                     PIPE_BIND_DISPLAY_TARGET |
-                     PIPE_BIND_SCANOUT |
-                     PIPE_BIND_SHARED)) &&
-           r600_is_colorbuffer_format_supported(format)) {
-               retval |= usage &
-                         (PIPE_BIND_RENDER_TARGET |
-                          PIPE_BIND_DISPLAY_TARGET |
-                          PIPE_BIND_SCANOUT |
-                          PIPE_BIND_SHARED);
-       }
-
-       if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
-           r600_is_zs_format_supported(format)) {
-               retval |= PIPE_BIND_DEPTH_STENCIL;
-       }
-
-       if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
-           si_is_vertex_format_supported(screen, format)) {
-               retval |= PIPE_BIND_VERTEX_BUFFER;
-       }
-
-       if (usage & PIPE_BIND_TRANSFER_READ)
-               retval |= PIPE_BIND_TRANSFER_READ;
-       if (usage & PIPE_BIND_TRANSFER_WRITE)
-               retval |= PIPE_BIND_TRANSFER_WRITE;
-
-       return retval == usage;
-}
-
 static void evergreen_set_polygon_stipple(struct pipe_context *ctx,
                                         const struct pipe_poly_stipple *state)
 {
index a0dcc41166453f7c15146b9495f58c3cda15977b..0521c9b31be069a1fc67d764cc5c7555f19b6bac 100644 (file)
@@ -252,15 +252,6 @@ static INLINE void r600_atom_dirty(struct r600_context *rctx, struct r600_atom *
 
 /* evergreen_state.c */
 void cayman_init_state_functions(struct r600_context *rctx);
-uint32_t si_translate_vertexformat(struct pipe_screen *screen,
-                                  enum pipe_format format,
-                                  const struct util_format_description *desc,
-                                  int first_non_void);
-boolean si_is_format_supported(struct pipe_screen *screen,
-                              enum pipe_format format,
-                              enum pipe_texture_target target,
-                              unsigned sample_count,
-                              unsigned usage);
 
 /* r600_blit.c */
 void r600_init_blit_functions(struct r600_context *rctx);
index 318d97ff800a1b770d3881c5151603cc45c9ca17..978c1948c182b819fdd4f1cbf7837114a3e493f3 100644 (file)
@@ -1216,6 +1216,106 @@ static unsigned si_tex_dim(unsigned dim)
        }
 }
 
+/*
+ * Format support testing
+ */
+
+static bool si_is_sampler_format_supported(struct pipe_screen *screen, enum pipe_format format)
+{
+       return si_translate_texformat(screen, format, util_format_description(format),
+                                     util_format_get_first_non_void_channel(format)) != ~0U;
+}
+
+uint32_t si_translate_vertexformat(struct pipe_screen *screen,
+                                  enum pipe_format format,
+                                  const struct util_format_description *desc,
+                                  int first_non_void)
+{
+       uint32_t result;
+
+       if (desc->channel[first_non_void].type == UTIL_FORMAT_TYPE_FIXED)
+               return ~0;
+
+       result = si_translate_texformat(screen, format, desc, first_non_void);
+       if (result == V_008F0C_BUF_DATA_FORMAT_INVALID ||
+           result > V_008F0C_BUF_DATA_FORMAT_32_32_32_32)
+               result = ~0;
+
+       return result;
+}
+
+static bool si_is_vertex_format_supported(struct pipe_screen *screen, enum pipe_format format)
+{
+       return si_translate_vertexformat(screen, format, util_format_description(format),
+                                        util_format_get_first_non_void_channel(format)) != ~0U;
+}
+
+static bool si_is_colorbuffer_format_supported(enum pipe_format format)
+{
+       return si_translate_colorformat(format) != ~0U &&
+               si_translate_colorswap(format) != ~0U;
+}
+
+static bool si_is_zs_format_supported(enum pipe_format format)
+{
+       return si_translate_dbformat(format) != ~0U;
+}
+
+bool si_is_format_supported(struct pipe_screen *screen,
+                           enum pipe_format format,
+                           enum pipe_texture_target target,
+                           unsigned sample_count,
+                           unsigned usage)
+{
+       unsigned retval = 0;
+
+       if (target >= PIPE_MAX_TEXTURE_TYPES) {
+               R600_ERR("r600: unsupported texture type %d\n", target);
+               return FALSE;
+       }
+
+       if (!util_format_is_supported(format, usage))
+               return FALSE;
+
+       /* Multisample */
+       if (sample_count > 1)
+               return FALSE;
+
+       if ((usage & PIPE_BIND_SAMPLER_VIEW) &&
+           si_is_sampler_format_supported(screen, format)) {
+               retval |= PIPE_BIND_SAMPLER_VIEW;
+       }
+
+       if ((usage & (PIPE_BIND_RENDER_TARGET |
+                     PIPE_BIND_DISPLAY_TARGET |
+                     PIPE_BIND_SCANOUT |
+                     PIPE_BIND_SHARED)) &&
+           si_is_colorbuffer_format_supported(format)) {
+               retval |= usage &
+                         (PIPE_BIND_RENDER_TARGET |
+                          PIPE_BIND_DISPLAY_TARGET |
+                          PIPE_BIND_SCANOUT |
+                          PIPE_BIND_SHARED);
+       }
+
+       if ((usage & PIPE_BIND_DEPTH_STENCIL) &&
+           si_is_zs_format_supported(format)) {
+               retval |= PIPE_BIND_DEPTH_STENCIL;
+       }
+
+       if ((usage & PIPE_BIND_VERTEX_BUFFER) &&
+           si_is_vertex_format_supported(screen, format)) {
+               retval |= PIPE_BIND_VERTEX_BUFFER;
+       }
+
+       if (usage & PIPE_BIND_TRANSFER_READ)
+               retval |= PIPE_BIND_TRANSFER_READ;
+       if (usage & PIPE_BIND_TRANSFER_WRITE)
+               retval |= PIPE_BIND_TRANSFER_WRITE;
+
+       return retval == usage;
+}
+
 /*
  * framebuffer handling
  */
index cb993774f4c2b69fdf8be144943367c6c7443fc0..e94797c63bc75fd531734346831143ce522f0d5d 100644 (file)
@@ -156,6 +156,15 @@ union si_state {
        } while(0);
 
 /* si_state.c */
+uint32_t si_translate_vertexformat(struct pipe_screen *screen,
+                                  enum pipe_format format,
+                                  const struct util_format_description *desc,
+                                  int first_non_void);
+bool si_is_format_supported(struct pipe_screen *screen,
+                           enum pipe_format format,
+                           enum pipe_texture_target target,
+                           unsigned sample_count,
+                           unsigned usage);
 void si_init_state_functions(struct r600_context *rctx);
 void si_init_config(struct r600_context *rctx);