<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Aug 21, 2015 at 2:12 PM, Chad Versace <span dir="ltr"><<a href="mailto:chad.versace@intel.com" target="_blank">chad.versace@intel.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Wed 19 Aug 2015, Nanley Chery wrote:<br>
> From: Nanley Chery <<a href="mailto:nanley.g.chery@intel.com">nanley.g.chery@intel.com</a>><br>
><br>
> We currently check that our format info table is sane during context<br>
> initialization in debug builds. Perform this check during<br>
> `make check` instead. This enables format testing in release builds<br>
> and removes the requirement of an exhuastive switch for<br>
> _mesa_uncompressed_format_to_type_and_comps().<br>
><br>
> Signed-off-by: Nanley Chery <<a href="mailto:nanley.g.chery@intel.com">nanley.g.chery@intel.com</a>><br>
> ---<br>
> src/mesa/main/context.c | 4 -<br>
> src/mesa/main/formats.c | 157 ++---------------------------------<br>
> src/mesa/main/tests/Makefile.am | 1 +<br>
> src/mesa/main/tests/mesa_formats.cpp | 130 +++++++++++++++++++++++++++++<br>
> 4 files changed, 137 insertions(+), 155 deletions(-)<br>
> create mode 100644 src/mesa/main/tests/mesa_formats.cpp<br>
<br>
</span>Overall the patch looks good. I found a few small problems, though. See<br>
below.<br>
<div><div class="h5"><br>
><br>
> diff --git a/src/mesa/main/context.c b/src/mesa/main/context.c<br>
> index 7451e5a..6a40c0a 100644<br>
> --- a/src/mesa/main/context.c<br>
> +++ b/src/mesa/main/context.c<br>
> @@ -402,10 +402,6 @@ one_time_init( struct gl_context *ctx )<br>
> PACKAGE_VERSION, __DATE__, __TIME__);<br>
> }<br>
> #endif<br>
> -<br>
> -#ifdef DEBUG<br>
> - _mesa_test_formats();<br>
> -#endif<br>
> }<br>
><br>
> /* per-API one-time init */<br>
> diff --git a/src/mesa/main/formats.c b/src/mesa/main/formats.c<br>
> index 24c16ee..e58b917 100644<br>
> --- a/src/mesa/main/formats.c<br>
> +++ b/src/mesa/main/formats.c<br>
> @@ -81,6 +81,7 @@ static const struct gl_format_info *<br>
> _mesa_get_format_info(mesa_format format)<br>
> {<br>
> const struct gl_format_info *info = &format_info[format];<br>
> + STATIC_ASSERT(ARRAY_SIZE(format_info) == MESA_FORMAT_COUNT);<br>
> assert(info->Name == format);<br>
> return info;<br>
> }<br>
> @@ -869,118 +870,6 @@ _mesa_format_row_stride(mesa_format format, GLsizei width)<br>
> }<br>
><br>
><br>
> -/**<br>
> - * Debug/test: check that all uncompressed formats are handled in the<br>
> - * _mesa_uncompressed_format_to_type_and_comps() function. When new pixel<br>
> - * formats are added to Mesa, that function needs to be updated.<br>
> - * This is a no-op after the first call.<br>
> - */<br>
> -static void<br>
> -check_format_to_type_and_comps(void)<br>
> -{<br>
> - mesa_format f;<br>
> -<br>
> - for (f = MESA_FORMAT_NONE + 1; f < MESA_FORMAT_COUNT; f++) {<br>
> - GLenum datatype = 0;<br>
> - GLuint comps = 0;<br>
> - /* This function will emit a problem/warning if the format is<br>
> - * not handled.<br>
> - */<br>
> - if (!_mesa_is_format_compressed(f))<br>
> - _mesa_uncompressed_format_to_type_and_comps(f, &datatype, &comps);<br>
> - }<br>
> -}<br>
> -<br>
> -/**<br>
> - * Do sanity checking of the format info table.<br>
> - */<br>
> -void<br>
> -_mesa_test_formats(void)<br>
> -{<br>
> - GLuint i;<br>
> -<br>
> - STATIC_ASSERT(ARRAY_SIZE(format_info) == MESA_FORMAT_COUNT);<br>
> -<br>
> - for (i = 0; i < MESA_FORMAT_COUNT; i++) {<br>
> - const struct gl_format_info *info = _mesa_get_format_info(i);<br>
> - assert(info);<br>
> -<br>
> - assert(info->Name == i);<br>
> -<br>
> - if (info->Name == MESA_FORMAT_NONE)<br>
> - continue;<br>
> -<br>
> - if (info->BlockWidth == 1 && info->BlockHeight == 1) {<br>
> - if (info->RedBits > 0) {<br>
> - GLuint t = info->RedBits + info->GreenBits<br>
> - + info->BlueBits + info->AlphaBits;<br>
> - assert(t / 8 <= info->BytesPerBlock);<br>
> - (void) t;<br>
> - }<br>
> - }<br>
> -<br>
> - assert(info->DataType == GL_UNSIGNED_NORMALIZED ||<br>
> - info->DataType == GL_SIGNED_NORMALIZED ||<br>
> - info->DataType == GL_UNSIGNED_INT ||<br>
> - info->DataType == GL_INT ||<br>
> - info->DataType == GL_FLOAT ||<br>
> - /* Z32_FLOAT_X24S8 has DataType of GL_NONE */<br>
> - info->DataType == GL_NONE);<br>
> -<br>
> - if (info->BaseFormat == GL_RGB) {<br>
> - assert(info->RedBits > 0);<br>
> - assert(info->GreenBits > 0);<br>
> - assert(info->BlueBits > 0);<br>
> - assert(info->AlphaBits == 0);<br>
> - assert(info->LuminanceBits == 0);<br>
> - assert(info->IntensityBits == 0);<br>
> - }<br>
> - else if (info->BaseFormat == GL_RGBA) {<br>
> - assert(info->RedBits > 0);<br>
> - assert(info->GreenBits > 0);<br>
> - assert(info->BlueBits > 0);<br>
> - assert(info->AlphaBits > 0);<br>
> - assert(info->LuminanceBits == 0);<br>
> - assert(info->IntensityBits == 0);<br>
> - }<br>
> - else if (info->BaseFormat == GL_RG) {<br>
> - assert(info->RedBits > 0);<br>
> - assert(info->GreenBits > 0);<br>
> - assert(info->BlueBits == 0);<br>
> - assert(info->AlphaBits == 0);<br>
> - assert(info->LuminanceBits == 0);<br>
> - assert(info->IntensityBits == 0);<br>
> - }<br>
> - else if (info->BaseFormat == GL_RED) {<br>
> - assert(info->RedBits > 0);<br>
> - assert(info->GreenBits == 0);<br>
> - assert(info->BlueBits == 0);<br>
> - assert(info->AlphaBits == 0);<br>
> - assert(info->LuminanceBits == 0);<br>
> - assert(info->IntensityBits == 0);<br>
> - }<br>
> - else if (info->BaseFormat == GL_LUMINANCE) {<br>
> - assert(info->RedBits == 0);<br>
> - assert(info->GreenBits == 0);<br>
> - assert(info->BlueBits == 0);<br>
> - assert(info->AlphaBits == 0);<br>
> - assert(info->LuminanceBits > 0);<br>
> - assert(info->IntensityBits == 0);<br>
> - }<br>
> - else if (info->BaseFormat == GL_INTENSITY) {<br>
> - assert(info->RedBits == 0);<br>
> - assert(info->GreenBits == 0);<br>
> - assert(info->BlueBits == 0);<br>
> - assert(info->AlphaBits == 0);<br>
> - assert(info->LuminanceBits == 0);<br>
> - assert(info->IntensityBits > 0);<br>
> - }<br>
> - }<br>
> -<br>
> - check_format_to_type_and_comps();<br>
> -}<br>
> -<br>
> -<br>
><br>
> /**<br>
> * Return datatype and number of components per texel for the given<br>
> @@ -1518,48 +1407,14 @@ _mesa_uncompressed_format_to_type_and_comps(mesa_format format,<br>
> case MESA_FORMAT_COUNT:<br>
> assert(0);<br>
> return;<br>
> -<br>
> - case MESA_FORMAT_RGB_FXT1:<br>
> - case MESA_FORMAT_RGBA_FXT1:<br>
> - case MESA_FORMAT_RGB_DXT1:<br>
> - case MESA_FORMAT_RGBA_DXT1:<br>
> - case MESA_FORMAT_RGBA_DXT3:<br>
> - case MESA_FORMAT_RGBA_DXT5:<br>
> - case MESA_FORMAT_SRGB_DXT1:<br>
> - case MESA_FORMAT_SRGBA_DXT1:<br>
> - case MESA_FORMAT_SRGBA_DXT3:<br>
> - case MESA_FORMAT_SRGBA_DXT5:<br>
> - case MESA_FORMAT_R_RGTC1_UNORM:<br>
> - case MESA_FORMAT_R_RGTC1_SNORM:<br>
> - case MESA_FORMAT_RG_RGTC2_UNORM:<br>
> - case MESA_FORMAT_RG_RGTC2_SNORM:<br>
> - case MESA_FORMAT_L_LATC1_UNORM:<br>
> - case MESA_FORMAT_L_LATC1_SNORM:<br>
> - case MESA_FORMAT_LA_LATC2_UNORM:<br>
> - case MESA_FORMAT_LA_LATC2_SNORM:<br>
> - case MESA_FORMAT_ETC1_RGB8:<br>
> - case MESA_FORMAT_ETC2_RGB8:<br>
> - case MESA_FORMAT_ETC2_SRGB8:<br>
> - case MESA_FORMAT_ETC2_RGBA8_EAC:<br>
> - case MESA_FORMAT_ETC2_SRGB8_ALPHA8_EAC:<br>
> - case MESA_FORMAT_ETC2_R11_EAC:<br>
> - case MESA_FORMAT_ETC2_RG11_EAC:<br>
> - case MESA_FORMAT_ETC2_SIGNED_R11_EAC:<br>
> - case MESA_FORMAT_ETC2_SIGNED_RG11_EAC:<br>
> - case MESA_FORMAT_ETC2_RGB8_PUNCHTHROUGH_ALPHA1:<br>
> - case MESA_FORMAT_ETC2_SRGB8_PUNCHTHROUGH_ALPHA1:<br>
> - case MESA_FORMAT_BPTC_RGBA_UNORM:<br>
> - case MESA_FORMAT_BPTC_SRGB_ALPHA_UNORM:<br>
> - case MESA_FORMAT_BPTC_RGB_SIGNED_FLOAT:<br>
> - case MESA_FORMAT_BPTC_RGB_UNSIGNED_FLOAT:<br>
> - assert(_mesa_is_format_compressed(format));<br>
> - case MESA_FORMAT_NONE:<br>
> - /* For debug builds, warn if any formats are not handled */<br>
> -#ifdef DEBUG<br>
> default:<br>
> -#endif<br>
> +/* For debug builds, warn if any formats are not handled */<br>
> +#ifdef DEBUG<br>
> _mesa_problem(NULL, "bad format %s in _mesa_uncompressed_format_to_type_and_comps",<br>
> _mesa_get_format_name(format));<br>
> +#endif<br>
<br>
</div></div>_mesa_problem() should be called unconditionally here. I looked at a few<br>
dozen calls to _mesa_problem(), and I could find no precedent for<br>
guarding it with #ifdef DEBUG.<br>
<div><div class="h5"><br>
> + assert(format == MESA_FORMAT_NONE ||<br>
> + _mesa_is_format_compressed(format));<br>
> *datatype = 0;<br>
> *comps = 1;<br>
> }<br>
> diff --git a/src/mesa/main/tests/Makefile.am b/src/mesa/main/tests/Makefile.am<br>
> index 251474d..9467f3b 100644<br>
> --- a/src/mesa/main/tests/Makefile.am<br>
> +++ b/src/mesa/main/tests/Makefile.am<br>
> @@ -27,6 +27,7 @@ AM_CPPFLAGS += -DHAVE_SHARED_GLAPI<br>
><br>
> main_test_SOURCES += \<br>
> dispatch_sanity.cpp \<br>
> + mesa_formats.cpp \<br>
> program_state_string.cpp<br>
><br>
> main_test_LDADD += \<br>
> diff --git a/src/mesa/main/tests/mesa_formats.cpp b/src/mesa/main/tests/mesa_formats.cpp<br>
> new file mode 100644<br>
> index 0000000..7bf9147<br>
> --- /dev/null<br>
> +++ b/src/mesa/main/tests/mesa_formats.cpp<br>
> @@ -0,0 +1,130 @@<br>
> +/*<br>
> + * Copyright © 2015 Intel Corporation<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the next<br>
> + * paragraph) shall be included in all copies or substantial portions of the<br>
> + * Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER<br>
> + * DEALINGS IN THE SOFTWARE.<br>
> + */<br>
> +<br>
> +/**<br>
> + * \name mesa_formats.cpp<br>
> + *<br>
> + * Verify that all mesa formats are handled in certain functions and that<br>
> + * the format info table is sane.<br>
> + *<br>
> + */<br>
> +<br>
> +#include <gtest/gtest.h><br>
> +<br>
> +#include "main/formats.h"<br>
> +#include "main/glformats.h"<br>
> +<br>
> +/**<br>
> + * Debug/test: check that all uncompressed formats are handled in the<br>
> + * _mesa_uncompressed_format_to_type_and_comps() function. When new pixel<br>
> + * formats are added to Mesa, that function needs to be updated.<br>
> + */<br>
> +TEST(MesaFormatsTest, FormatTypeAndComps)<br>
> +{<br>
> + for (int fi = MESA_FORMAT_NONE + 1; fi < MESA_FORMAT_COUNT; ++fi) {<br>
> + mesa_format f = (mesa_format) fi;<br>
> +<br>
> + /* This function will emit a problem/warning if the format is<br>
> + * not handled.<br>
> + */<br>
> + if (!_mesa_is_format_compressed(f)) {<br>
> + GLenum datatype = 0;<br>
> + GLuint comps = 0;<br>
> + _mesa_uncompressed_format_to_type_and_comps(f, &datatype, &comps);<br>
> +<br>
> + /* If the datatype is zero, the format was not handled */<br>
> + ASSERT_NE(datatype, (GLenum)0);<br>
<br>
</div></div>I think the test should also assert that comps >= 1.<br>
<div><div class="h5"><br></div></div></blockquote><div>In the failure scenario for this function, comps will be set equal to 1. It can also be set equal to 1 for certain valid formats as well.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
> + }<br>
> +<br>
> + }<br>
> +}<br>
> +<br>
> +/**<br>
> + * Do sanity checking of the format info table.<br>
> + */<br>
> +TEST(MesaFormatsTest, FormatSanity)<br>
> +{<br>
> + for (int fi = 0; fi < MESA_FORMAT_COUNT; ++fi) {<br>
> + mesa_format f = (mesa_format) fi;<br>
> + GLenum datatype = _mesa_get_format_datatype(f);<br>
> + GLint r = _mesa_get_format_bits(f, GL_RED_BITS);<br>
> + GLint g = _mesa_get_format_bits(f, GL_GREEN_BITS);<br>
> + GLint b = _mesa_get_format_bits(f, GL_BLUE_BITS);<br>
> + GLint a = _mesa_get_format_bits(f, GL_ALPHA_BITS);<br>
> + GLint l = _mesa_get_format_bits(f, GL_TEXTURE_LUMINANCE_SIZE);<br>
> + GLint i = _mesa_get_format_bits(f, GL_TEXTURE_INTENSITY_SIZE);<br>
> +<br>
> + /* Note: Z32_FLOAT_X24S8 has datatype of GL_NONE */<br>
> + ASSERT_TRUE(datatype == GL_NONE ||<br>
> + datatype == GL_UNSIGNED_NORMALIZED ||<br>
> + datatype == GL_SIGNED_NORMALIZED ||<br>
> + datatype == GL_UNSIGNED_INT ||<br>
> + datatype == GL_INT ||<br>
> + datatype == GL_FLOAT);<br>
> +<br>
> + if (r > 0 && !_mesa_is_format_compressed(f)) {<br>
> + GLint bytes = _mesa_get_format_bytes(f);<br>
> + ASSERT_LE((r+g+b+a) / 8, bytes);<br>
> + }<br>
> +<br>
> +/* Determines if the base format has a channel [rgba] or property [li].<br>
> + * > indicates existance<br>
> + * == indicates non-existance<br>
> + */<br>
> +#define HAS_PROP(rop,gop,bop,aop,lop,iop) \<br>
> +do { \<br>
> + ASSERT_TRUE(r rop 0); \<br>
> + ASSERT_TRUE(g gop 0); \<br>
> + ASSERT_TRUE(b bop 0); \<br>
> + ASSERT_TRUE(a aop 0); \<br>
> + ASSERT_TRUE(l lop 0); \<br>
> + ASSERT_TRUE(i iop 0); \<br>
> +} while(0)<br>
<br>
</div></div>Please indent the macro as if it were part of the function body. Like<br>
this:<br>
<br>
---#define HAS_PROP(rop,gop,bop,aop,lop,iop) \<br>
------do { \<br>
---------ASSERT_TRUE(r rop 0); \<br>
---------ASSERT_TRUE(g gop 0); \<br>
---------ASSERT_TRUE(b bop 0); \<br>
---------ASSERT_TRUE(a aop 0); \<br>
---------ASSERT_TRUE(l lop 0); \<br>
---------ASSERT_TRUE(i iop 0); \<br>
------} while(0)<br>
<div class="HOEnZb"><div class="h5"><br>
> +<br>
> + switch (_mesa_get_format_base_format(f)) {<br>
> + case GL_RGBA:<br>
> + HAS_PROP(>,>,>,>,==,==);<br>
> + break;<br>
> + case GL_RGB:<br>
> + HAS_PROP(>,>,>,==,==,==);<br>
> + break;<br>
> + case GL_RG:<br>
> + HAS_PROP(>,>,==,==,==,==);<br>
> + break;<br>
> + case GL_RED:<br>
> + HAS_PROP(>,==,==,==,==,==);<br>
> + break;<br>
> + case GL_LUMINANCE:<br>
> + HAS_PROP(==,==,==,==,>,==);<br>
> + break;<br>
> + case GL_INTENSITY:<br>
> + HAS_PROP(==,==,==,==,==,>);<br>
> + break;<br>
> + default:<br>
> + break;<br>
> + }<br>
> +<br>
> +#undef HAS_PROP<br>
> +<br>
> + }<br>
> +}<br>
> --<br>
> 2.5.0<br>
><br>
</div></div></blockquote></div><br></div></div>