[Mesa-dev] [PATCH] st/mesa: add test_format_conversion() debug function
Marek Olšák
maraeo at gmail.com
Thu Mar 6 17:54:41 PST 2014
Reviewed-by: Marek Olšák <marek.olsak at amd.com>
Marek
On Thu, Mar 6, 2014 at 7:53 PM, Brian Paul <brianp at vmware.com> wrote:
> 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.
> ---
> src/mesa/state_tracker/st_format.c | 44 +++++++++++++++++++++++++++++++++++-
> 1 file changed, 43 insertions(+), 1 deletion(-)
>
> diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c
> index 0be900e7..a55ee30 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,13 +761,41 @@ 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.
> */
> struct format_mapping
> @@ -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)) {
> --
> 1.7.10.4
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
More information about the mesa-dev
mailing list