From: Brian Paul Date: Thu, 6 Mar 2014 18:45:42 +0000 (-0700) Subject: st/mesa: add test_format_conversion() debug function X-Git-Url: https://git.libre-soc.org/?a=commitdiff_plain;h=6d2dffe8b143b2f81179279d25d3ac247f4e278f;p=mesa.git st/mesa: add test_format_conversion() debug function To check that the st_mesa_format_to_pipe_format() and st_pipe_format_to_mesa_format() functions correctly convert all corresponding Mesa/Gallium formats. This found that MESA_FORMAT_YCBCR_REV was missing in st_mesa_format_to_pipe_format(). Fixed that too. Reviewed-by: Marek Olšák --- diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 0be900e7777..a55ee307979 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -121,6 +121,8 @@ st_mesa_format_to_pipe_format(mesa_format mesaFormat) return PIPE_FORMAT_Z32_FLOAT_S8X24_UINT; case MESA_FORMAT_YCBCR: return PIPE_FORMAT_UYVY; + case MESA_FORMAT_YCBCR_REV: + return PIPE_FORMAT_YUYV; case MESA_FORMAT_RGB_DXT1: return PIPE_FORMAT_DXT1_RGB; case MESA_FORMAT_RGBA_DXT1: @@ -759,12 +761,40 @@ st_pipe_format_to_mesa_format(enum pipe_format format) return MESA_FORMAT_R8G8B8A8_SRGB; default: - assert(0); return MESA_FORMAT_NONE; } } +/** + * Debug only: check that the two functions above correctly map + * Mesa formats to Gallium formats and back again. + */ +static void +test_format_conversion(void) +{ + GLuint i; + + /* test all Mesa formats */ + for (i = 1; i < MESA_FORMAT_COUNT; i++) { + enum pipe_format pf = st_mesa_format_to_pipe_format(i); + if (pf != PIPE_FORMAT_NONE) { + mesa_format mf = st_pipe_format_to_mesa_format(pf); + assert(mf == i); + } + } + + /* Test all Gallium formats */ + for (i = 1; i < PIPE_FORMAT_COUNT; i++) { + mesa_format mf = st_pipe_format_to_mesa_format(i); + if (mf != MESA_FORMAT_NONE) { + enum pipe_format pf = st_mesa_format_to_pipe_format(mf); + assert(pf == i); + } + } +} + + /** * Map GL texture formats to Gallium pipe formats. */ @@ -1641,6 +1671,18 @@ st_choose_format(struct st_context *st, GLenum internalFormat, int i, j; enum pipe_format pf; +#ifdef DEBUG + { + static boolean firstCall = TRUE; + if (firstCall) { + test_format_conversion(); + firstCall = FALSE; + } + } +#else + (void) test_format_conversion; +#endif + /* can't render to compressed formats at this time */ if (_mesa_is_compressed_format(st->ctx, internalFormat) && (bindings & ~PIPE_BIND_SAMPLER_VIEW)) {