From f8c27c277585141f2d2732732a8c64c7d40f0961 Mon Sep 17 00:00:00 2001 From: Eric Anholt Date: Mon, 1 Jul 2019 13:06:09 -0700 Subject: [PATCH] state_tracker: Move the format test out to be an actual unit test. We want errors in the table to show up as unit test failures in MRs. Also keeps unit test code out of the built drivers. Reviewed-by: Thomas Helland Reviewed-by: Kristian H. Kristensen --- src/mesa/state_tracker/st_format.c | 51 ----------- src/mesa/state_tracker/tests/meson.build | 14 +++ src/mesa/state_tracker/tests/st_format.c | 103 +++++++++++++++++++++++ 3 files changed, 117 insertions(+), 51 deletions(-) create mode 100644 src/mesa/state_tracker/tests/st_format.c diff --git a/src/mesa/state_tracker/st_format.c b/src/mesa/state_tracker/st_format.c index 7f2f1984e65..9e6f76739f7 100644 --- a/src/mesa/state_tracker/st_format.c +++ b/src/mesa/state_tracker/st_format.c @@ -1107,45 +1107,6 @@ st_pipe_format_to_mesa_format(enum pipe_format format) } } - -/** - * Debug only: check that the two functions above correctly map - * Mesa formats to Gallium formats and back again. - */ -static void -test_format_conversion(struct st_context *st) -{ - GLuint i; - - /* test all Mesa formats */ - for (i = 1; i < MESA_FORMAT_COUNT; i++) { - enum pipe_format pf; - - if (st_compressed_format_fallback(st, i)) - continue; - - pf = st_mesa_format_to_pipe_format(st, i); - if (pf != PIPE_FORMAT_NONE) { - mesa_format MAYBE_UNUSED 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 (st_compressed_format_fallback(st, mf)) - continue; - - if (mf != MESA_FORMAT_NONE) { - enum pipe_format MAYBE_UNUSED pf = - st_mesa_format_to_pipe_format(st, mf); - assert(pf == i); - } - } -} - - /** * Map GL texture formats to Gallium pipe formats. */ @@ -2196,18 +2157,6 @@ st_choose_format(struct st_context *st, GLenum internalFormat, int j; enum pipe_format pf; -#ifndef NDEBUG - { - static boolean firstCall = TRUE; - if (firstCall) { - test_format_conversion(st); - 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)) { diff --git a/src/mesa/state_tracker/tests/meson.build b/src/mesa/state_tracker/tests/meson.build index 892362b22ff..c01ad850e47 100644 --- a/src/mesa/state_tracker/tests/meson.build +++ b/src/mesa/state_tracker/tests/meson.build @@ -25,6 +25,20 @@ libmesa_st_test_common = static_library( dependencies : [dep_thread, idep_gtest], ) +test( + 'st_format_test', + executable( + 'st_format_test', + ['st_format.c'], + include_directories : inc_common, + link_with : [ + libmesa_st_test_common, libmesa_gallium, libglapi, libgallium, + libmesa_util, + ], + ), + suite : ['st_mesa'], +) + test( 'st_renumerate_test', executable( diff --git a/src/mesa/state_tracker/tests/st_format.c b/src/mesa/state_tracker/tests/st_format.c new file mode 100644 index 00000000000..47a5fd0a7f0 --- /dev/null +++ b/src/mesa/state_tracker/tests/st_format.c @@ -0,0 +1,103 @@ +/************************************************************************** + * + * Copyright 2007 VMware, Inc. + * Copyright (c) 2008-2010 VMware, Inc. + * Copyright (c) 2019 Google, LLC + * All Rights Reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the + * "Software"), to deal in the Software without restriction, including + * without limitation the rights to use, copy, modify, merge, publish, + * distribute, sub license, and/or sell copies of the Software, and to + * permit persons to whom the Software is furnished to do so, subject to + * the following conditions: + * + * The above copyright notice and this permission notice (including the + * next paragraph) shall be included in all copies or substantial portions + * of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. + * IN NO EVENT SHALL VMWARE AND/OR ITS SUPPLIERS BE LIABLE FOR + * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, + * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE + * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + * + **************************************************************************/ + +#include "pipe/p_context.h" +#include "pipe/p_screen.h" +#include "state_tracker/st_context.h" +#include "state_tracker/st_format.h" +#include "state_tracker/st_texture.h" +#include "util/u_format.h" +#include + +static boolean +is_format_supported(struct pipe_screen *pscreen, + enum pipe_format format, + enum pipe_texture_target target, + unsigned sample_count, + unsigned storage_sample_count, + unsigned usage) +{ + return true; +} + +int main(int argc, char **argv) +{ + struct pipe_screen screen = { + .is_format_supported = is_format_supported, + }; + struct pipe_context pctx = { + .screen = &screen, + }; + struct st_context local_st = { + .pipe = &pctx, + }; + struct st_context *st = &local_st; + + GLuint i; + + /* test all Mesa formats */ + for (i = 1; i < MESA_FORMAT_COUNT; i++) { + enum pipe_format pf; + + if (st_compressed_format_fallback(st, i)) + continue; + + pf = st_mesa_format_to_pipe_format(st, i); + if (pf != PIPE_FORMAT_NONE) { + mesa_format MAYBE_UNUSED mf = st_pipe_format_to_mesa_format(pf); + if (mf != i) { + fprintf(stderr, "Round-tripping %s -> %s -> %s failed\n", + _mesa_get_format_name(i), util_format_short_name(pf), + _mesa_get_format_name(mf)); + return 1; + } + } + } + + /* Test all Gallium formats */ + for (i = 1; i < PIPE_FORMAT_COUNT; i++) { + mesa_format mf = st_pipe_format_to_mesa_format(i); + if (st_compressed_format_fallback(st, mf)) + continue; + + if (mf != MESA_FORMAT_NONE) { + enum pipe_format MAYBE_UNUSED pf = + st_mesa_format_to_pipe_format(st, mf); + if (pf != i) { + fprintf(stderr, "Round-tripping %s -> %s -> %s failed\n", + util_format_short_name(i), + _mesa_get_format_name(pf), + util_format_short_name(pf)); + return 1; + } + } + } + + return 0; +} -- 2.30.2