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 <marek.olsak@amd.com>
This commit is contained in:
Brian Paul 2014-03-06 11:45:42 -07:00
parent d8f7e3d79e
commit 6d2dffe8b1

View file

@ -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)) {