[Piglit] [PATCH v2 4/4] Add API tests for KHR_texture_compression_astc_ldr

Nanley Chery nanleychery at gmail.com
Mon Sep 14 15:23:29 PDT 2015


On Tue, Sep 8, 2015 at 11:45 AM, Chad Versace <chad.versace at intel.com>
wrote:

> On Fri 28 Aug 2015, Nanley Chery wrote:
> > From: Nanley Chery <nanley.g.chery at intel.com>
> >
> > These tests check that the GL error returned by valid and invalid API
> calls
> > are as defined by the spec.
> >
> > Signed-off-by: Nanley Chery <nanley.g.chery at intel.com>
> > ---
> >  .../khr_texture_compression_astc/CMakeLists.gl.txt |   1 +
> >  .../CMakeLists.gles2.txt                           |   1 +
> >  .../khr_compressed_astc-basic.c                    | 366
> +++++++++++++++++++++
> >  3 files changed, 368 insertions(+)
> >  create mode 100644
> tests/spec/khr_texture_compression_astc/khr_compressed_astc-basic.c
> >
> > diff --git a/tests/spec/khr_texture_compression_astc/CMakeLists.gl.txt
> b/tests/spec/khr_texture_compression_astc/CMakeLists.gl.txt
> > index a47c7d3..79500f7 100644
> > --- a/tests/spec/khr_texture_compression_astc/CMakeLists.gl.txt
> > +++ b/tests/spec/khr_texture_compression_astc/CMakeLists.gl.txt
> > @@ -10,5 +10,6 @@ link_libraries (
> >  )
> >
> >  piglit_add_executable(khr_compressed_astc-miptree_${piglit_target_api}
> khr_compressed_astc-miptree.c)
> > +piglit_add_executable(khr_compressed_astc-basic_${piglit_target_api}
> khr_compressed_astc-basic.c)
> >
> >  # vim: ft=cmake:
> > diff --git
> a/tests/spec/khr_texture_compression_astc/CMakeLists.gles2.txt
> b/tests/spec/khr_texture_compression_astc/CMakeLists.gles2.txt
> > index 047b8ac..3fb6fa5 100644
> > --- a/tests/spec/khr_texture_compression_astc/CMakeLists.gles2.txt
> > +++ b/tests/spec/khr_texture_compression_astc/CMakeLists.gles2.txt
> > @@ -4,5 +4,6 @@ include_directories(
> >  )
> >  link_libraries(piglitutil_${piglit_target_api})
> >  piglit_add_executable(khr_compressed_astc-miptree_${piglit_target_api}
> khr_compressed_astc-miptree.c)
> > +piglit_add_executable(khr_compressed_astc-basic_${piglit_target_api}
> khr_compressed_astc-basic.c)
> >
> >  # vim: ft=cmake:
> > diff --git
> a/tests/spec/khr_texture_compression_astc/khr_compressed_astc-basic.c
> b/tests/spec/khr_texture_compression_astc/khr_compressed_astc-basic.c
> > new file mode 100644
> > index 0000000..d83ad5e
> > --- /dev/null
> > +++ b/tests/spec/khr_texture_compression_astc/khr_compressed_astc-basic.c
> > @@ -0,0 +1,366 @@
>
> > +#include "piglit-util-gl.h"
> > +
> > +static const GLenum cube_map_face_targets[] = {
> > +   GL_TEXTURE_CUBE_MAP_POSITIVE_X,
> > +   GL_TEXTURE_CUBE_MAP_NEGATIVE_X,
> > +   GL_TEXTURE_CUBE_MAP_POSITIVE_Y,
> > +   GL_TEXTURE_CUBE_MAP_NEGATIVE_Y,
> > +   GL_TEXTURE_CUBE_MAP_POSITIVE_Z,
> > +   GL_TEXTURE_CUBE_MAP_NEGATIVE_Z
> > +};
> > +
> > +static const GLenum good_targets[] = {
>
> There are additional good targets: 3D and and CUBE_MAP. Please rename
> this variable to indicate that these are "good targets" for
> glCompressedTex*3D().
>
> I'm not sure what you mean by additional good targets. I've renamed the
variable to good_compressed_tex_3d_targets.

> > +   GL_TEXTURE_2D_ARRAY,
> > +   GL_TEXTURE_CUBE_MAP_ARRAY_EXT,
> > +   GL_TEXTURE_3D,
> > +};
> > +
> > +typedef struct _astc_fmt {
> > +     GLenum fmt;
> > +     int bw;
> > +     int bh;
> > +     int bb;
> > +} astc_fmt;
>
> Since the underscored struct tag is nowhere used, you should remove it.
>
> Please add a one-line comment for each of the astc_fmt fields.
>
> Fixed these two.

> > +
> > +static const astc_fmt formats[] = {
> > +    {GL_COMPRESSED_RGBA_ASTC_4x4_KHR          ,  4,  4, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_5x4_KHR          ,  5,  4, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_5x5_KHR          ,  5,  5, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_6x5_KHR          ,  6,  5, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_6x6_KHR          ,  6,  6, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_8x5_KHR          ,  8,  5, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_8x6_KHR          ,  8,  6, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_8x8_KHR          ,  8,  8, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_10x5_KHR         , 10,  5, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_10x6_KHR         , 10,  6, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_10x8_KHR         , 10,  8, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_10x10_KHR        , 10, 10, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_12x10_KHR        , 12, 10, 16},
> > +    {GL_COMPRESSED_RGBA_ASTC_12x12_KHR        , 12, 12, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_4x4_KHR  ,  4,  4, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x4_KHR  ,  5,  4, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_5x5_KHR  ,  5,  5, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x5_KHR  ,  6,  5, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_6x6_KHR  ,  6,  6, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x5_KHR  ,  8,  5, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x6_KHR  ,  8,  6, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_8x8_KHR  ,  8,  8, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x5_KHR , 10,  5, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x6_KHR , 10,  6, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x8_KHR , 10,  8, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_10x10_KHR, 10, 10, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x10_KHR, 12, 10, 16},
> > +    {GL_COMPRESSED_SRGB8_ALPHA8_ASTC_12x12_KHR, 12, 12, 16}
> > +};
> > +
> > +
> > +#define REQUIRE_ERROR(expected_error) \
> > +do {\
> > +     if (!piglit_check_gl_error(expected_error))\
> > +             piglit_report_result(PIGLIT_FAIL);\
> > +} while (0)
>
> Add a space before the line-continuation slashes. That's the style found
> elsewhere in Piglit. Like this:
>
> #define REQUIRE_ERROR(expected_error) \
>         do { \
>                 blah; \
>         } while (0)
>
>
Fixed.

>
> > +/*
> > + * The KHR_texture_compression_astc_ldr spec says:
> > + *   * An INVALID_OPERATION error is generated by CompressedTexImage3D
> if
> > + *   <internalformat> is one of the the formats in table 8.19 and
> <target>
> > + *   is not TEXTURE_2D_ARRAY, TEXTURE_CUBE_MAP_ARRAY, or TEXTURE_3D.
> > + *
> > + *   * An INVALID_OPERATION error is generated by CompressedTexImage3D
> if
> > + *   <internalformat> is TEXTURE_CUBE_MAP_ARRAY and the "Cube Map Array"
> > + *   column of table 8.19 is *not* checked, or if <internalformat> is
> > + *   TEXTURE_3D and the "3D Tex." column of table 8.19 is *not* checked"
> > + *
> > + * Discussion:
> > + *   * Since this extension only increases the allowed targets, the
> > + *   existing errors are assumed to be already handled, and the allowed
> > + *   targets are tested to be free of errors.
> > + *
> > + *   * Since all ASTC formats have the "Cube Map Array" column checked,
> > + *   test that no error is generated from calling CompressedTexImage3D
> with
> > + *   the TEXTURE_CUBE_MAP_ARRAY target.
> > + *
> > + */
> > +void test_compressed_teximg_3d(int fi, bool have_cube_map_ext)
> > +{
> > +     int j;
> > +     GLuint tex3D;
> > +     char fake_tex_data[6*16];
> > +     bool have_hdr = piglit_is_extension_supported(
> > +                     "GL_KHR_texture_compression_astc_hdr");
> > +
> > +     for (j = 0; j < ARRAY_SIZE(good_targets); ++j) {
> > +
> > +             /* Skip the cube_map target if there's no support */
> > +             if (good_targets[j] == GL_TEXTURE_CUBE_MAP_ARRAY_EXT &&
> > +                     !have_cube_map_ext)
> > +                     continue;
> > +
> > +             /* Run the command */
> > +             glGenTextures(1, &tex3D);
> > +             glBindTexture(good_targets[j], tex3D);
> > +             glCompressedTexImage3D(good_targets[j], 0, formats[fi].fmt,
> > +                     4, 4, 6, 0, 6*formats[fi].bb, fake_tex_data);
> > +
> > +             /* Test expected GL errors */
> > +             if (good_targets[j] == GL_TEXTURE_3D && !have_hdr) {
> > +                     REQUIRE_ERROR(GL_INVALID_OPERATION);
> > +             } else {
> > +                     REQUIRE_ERROR(GL_NO_ERROR);
> > +             }
> > +
> > +             glDeleteTextures(1, &tex3D);
> > +     }
> > +}
> > +
> > +/*
> > + * The KHR_texture_compression_astc_ldr spec says:
> > + *  "An INVALID_VALUE error is generated by
> > + *
> > + *     * CompressedTexImage2D if <target> is
> > + *       one of the cube map face targets from table 8.21, and
> > + *     * CompressedTexImage3D if <target> is TEXTURE_CUBE_MAP_ARRAY,
> > + *
> > + *   and <width> and <height> are not equal."
> > + */
> > +void test_non_square_img(int fi)
> > +{
> > +     int j;
> > +     char fake_tex_data[6*16];
> > +     GLuint cube_tex;
> > +
> > +     glGenTextures(1, &cube_tex);
> > +     glBindTexture(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, cube_tex);
> > +
> > +     /* Test CompressedTexImage2D */
> > +     for (j = 0; j < ARRAY_SIZE(cube_map_face_targets); ++j) {
> > +             glCompressedTexImage2D(cube_map_face_targets[j], 0,
> > +                                     formats[fi].fmt, 4, 3, 0,
> > +                                     formats[fi].bb, fake_tex_data);
> > +             REQUIRE_ERROR(GL_INVALID_VALUE);
> > +     }
> > +
> > +     /* Test CompressedTexImage3D */
> > +     glCompressedTexImage3D(GL_TEXTURE_CUBE_MAP_ARRAY_EXT, 0,
> > +             formats[fi].fmt, 4, 3, 6, 0, 6*formats[fi].bb,
> fake_tex_data);
> > +     REQUIRE_ERROR(GL_INVALID_VALUE);
>
> If HDR is unsupported, I think glCompressedTexImage3D is allowed to
> emit GL_INVALID_OPERATION here. So, I think glCompressedTexImage3D()
> should be tested on non-square dimensions only if HDR is supported.
>
> Agreed. I just made a patch for mesa to support this behavior. I'm
thinking it'd be better to check that for GL_INVALID_OPERATION if HDR is
not supported, and GL_INVALID_VALUE otherwise.

> > +
> > +     glDeleteTextures(1, &cube_tex);
> > +
> > +}
> > +
> > +int get_expected_size(int width, int height, int bw, int bh, int bb)
> > +{
> > +     int nbw = (width + bw - 1) / bw;
> > +     int nbh = (height + bh - 1) / bh;
> > +     return nbw * nbh * bb;
> > +}
> > +
> > +
> > +/*
> > + * The KHR_texture_compression_astc_ldr spec says:
> > + *  * "An INVALID_OPERATION error is generated if format is one of the
> formats
> > + *    in table 8.19 and any of the following conditions occurs. The
> block
> > + *    width and height refer to the values in the corresponding column
> of the
> > + *    table.
> > + *
> > + *      * <width> is not a multiple of the format's block width, and
> <width> +
> > + *        <xoffset> is not equal to the value of TEXTURE_WIDTH.
> > + *      * height is not a multiple of the format's block height, and
> <height>
> > + *        + <yoffset> is not equal to the value of TEXTURE_HEIGHT.
> > + *      * <xoffset> or <yoffset> is not a multiple of the block width or
> > + *        height, respectively."
> > + *
> > + *   [...]
> > + *
> > + *   ASTC texture formats are supported by immutable-format textures
> only if
> > + *   such textures are supported by the underlying implementation (e.g.
> > + *   OpenGL 4.1 or later, OpenGL ES 3.0 or later, or earlier versions
> > + *   supporting the GL_EXT_texture_storage extension). Otherwise,
> remove all
> > + *   references to the Tex*Storage* commands from this specification.
> > + */
> > +void test_sub_img(int fi)
> > +{
> > +     GLuint tex;
> > +     char fake_tex_data[4*16];
> > +     int width = 7;
> > +     int height = 7;
>
> > +     int expectedSizeGood = get_expected_size(4, 4,
> > +                             formats[fi].bw,
> > +                             formats[fi].bh, formats[fi].bb);
> > +     int expectedSizeBad = get_expected_size(width, height,
> > +                             formats[fi].bw,
> > +                             formats[fi].bh, formats[fi].bb);
>
> Piglit doesn't use camelCase. These variables should be snake_case.
>
> Fixed.

> > +
> > +     /* Allocate enough to hold the larger case */
> > +     glGenTextures(1, &tex);
> > +     glBindTexture(GL_TEXTURE_2D, tex);
> > +     glTexStorage2D(GL_TEXTURE_2D, 1, formats[fi].fmt, 14, 14);
> > +     REQUIRE_ERROR(GL_NO_ERROR);
>
> To prevent unintended crashes, especially for the bad case, the test
> should:
>     assert(expectedSizeGood) <= sizeof(fake_tex_data);
>     assert(expectedSizeBad) <= sizeof(fake_tex_data);
>
> Fixed.

> > +
> > +     /* Check for No Error */
> > +     glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
> > +             formats[fi].bw, formats[fi].bh,
> > +             formats[fi].fmt, expectedSizeGood, fake_tex_data);
> > +     REQUIRE_ERROR(GL_NO_ERROR);
> > +
> > +     /* Check for expected Error */
> > +     glCompressedTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, width, height,
> > +                     formats[fi].fmt, expectedSizeBad, fake_tex_data);
> > +     REQUIRE_ERROR(GL_INVALID_OPERATION);
> > +
> > +     glDeleteTextures(1, &tex);
> > +
> > +     if (piglit_is_extension_supported("GL_EXT_texture_storage")) {
> If I interpreted the ASTC spec correctly, then this block should be
> taken even when the GL_EXT_texture_storage string is not advertised. It
> should be taken if have_tex_storage_support().
>
> I checked for this extension for the call to glTextureStorage3DEXT.

Spec quote:

    If extension "EXT_texture_storage" is supported, these tokens are also
    accepted by TexStorage2DEXT, TextureStorage2DEXT, TexStorage3DEXT and
    TextureStorage3DEXT.

Since Mesa actually doesn't support these functions, I'll call
glTexStorage3D instead and remove the condition.

> +             /* Check for expected Error */
> > +             glGenTextures(1, &tex);
> > +             glTextureStorage3DEXT(tex, GL_TEXTURE_3D, 1,
> formats[fi].fmt,
> > +                                     14, 14, 1);
> > +             glCompressedTexImage3D(GL_TEXTURE_3D, 0, formats[fi].fmt,
> > +                             7, 7, 1, 0, expectedSizeBad,
> fake_tex_data);
> > +             REQUIRE_ERROR(GL_INVALID_OPERATION);
> > +             glDeleteTextures(1, &tex);
> > +     }
> > +}
> > +
> > +/*
> > + * The KHR_texture_compression_astc_ldr spec says:
> > + *   [...] the ASTC format specifiers will not be added to
> > + *   Table 3.14, and thus will not be accepted by the TexImage*D
> > + *   functions, and will not be returned by the (already deprecated)
> > + *   COMPRESSED_TEXTURE_FORMATS query.
> > + *
> > + * Discussion:
> > + *   The deprecated query is handled by:
> > + *   tests/spec/arb_texture_compression/invalid-formats.c
> > + *   In TexImage*D, the format should be automatically
> > + *   converted to the base internal format of GL_RGBA.
> > + */
> > +void test_tex_img(int fi, bool have_mipmap)
> > +{
> > +     GLuint tex;
> > +     char fake_tex_data[16];
> > +     glGenTextures(1, &tex);
> > +     glBindTexture(GL_TEXTURE_2D, tex);
>
> When C code follows the C89 style (as all Pigit code does), an empty
> line should separate the block of variable declarations from the first
> function call.
>
> Fixed.

> > +
> > +     /* Allocate for an ASTC texture for following texsubimage calls
>         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Incomplete phrase.
>
> Fixed.

> > +      * Since TexImage*D must fail, then the corresponding TexSubImage
> > +      * calls must fail as well.
> > +      */
> > +     glCompressedTexImage2D(GL_TEXTURE_2D, 0,
> > +             formats[fi].fmt, 4, 4, 0, formats[fi].bb, fake_tex_data);
> > +     REQUIRE_ERROR(GL_NO_ERROR);
> > +
> > +     /* Check for expected error from Tex*Image*D family of functions */
> > +     glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0,
> > +             4, 4, GL_RGBA, GL_UNSIGNED_BYTE, fake_tex_data);
> > +     REQUIRE_ERROR(GL_INVALID_OPERATION);
> > +
> > +     glTexImage2D(GL_TEXTURE_2D, 0,
> > +             formats[fi].fmt, 4, 4, 0, GL_RGBA, GL_UNSIGNED_BYTE, NULL);
> > +     REQUIRE_ERROR(GL_INVALID_OPERATION);
> > +
> > +     glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, 4, 4);
> > +     REQUIRE_ERROR(GL_INVALID_OPERATION);
> > +
> > +     glCopyTexImage2D(GL_TEXTURE_2D, 0, formats[fi].fmt, 0, 0, 4, 4, 0);
> > +     REQUIRE_ERROR(GL_INVALID_OPERATION);
> > +
> > +     /* Check for expected error from the online compression resulting
> from
> > +      * calling GenerateMipmap.
> > +      */
> > +     if (have_mipmap) {
> > +             glGenerateMipmap(GL_TEXTURE_2D);
> > +             REQUIRE_ERROR(GL_INVALID_OPERATION);
> > +     }
> > +
> > +     glDeleteTextures(1, &tex);
> > +
> > +}
> > +
> > +bool static inline
> > +have_tex_storage_support()
> > +{
> > +#if defined (PIGLIT_USE_OPENGL)
> > +     return piglit_get_gl_version() >= 42 ||
> > +             piglit_is_extension_supported("GL_ARB_texture_storage");
> > +#else
> > +     return piglit_get_gl_version() >= 30 ||
> > +             piglit_is_extension_supported("GL_EXT_texture_storage");
> > +#endif
> > +}
> > +
> > +
> > +bool static inline
> > +have_cube_map_array_support()
> > +{
> > +#if defined (PIGLIT_USE_OPENGL_ES3)
>
> I don't believe this block is reachable because the config block
> declares
>     config.supports_gl_es_version = 10
> instead of 30.
>
> Rather than fidget with GLES version, though, it's best to just use the
> same preprocessor pattern that you used in have_tex_storage_support(),
> which should work regardless of the GLES version.
>
> Fixed.

> > +     return
> piglit_is_extension_supported("GL_EXT_texture_cube_map_array");
> > +#elif defined (PIGLIT_USE_OPENGL)
> > +     return piglit_get_gl_version() >= 40 ||
> > +
>  piglit_is_extension_supported("GL_ARB_texture_cube_map_array");
> > +#endif
> > +     return false;
> > +}
> > +
> > +
> > +enum piglit_result
> > +piglit_display(void)
> > +{
> > +     unsigned i;
> > +     bool have_cube_map_ext = have_cube_map_array_support();
> > +     bool have_tex_stor_ext = have_tex_storage_support();
>
> > +     bool have_mipmap =
> piglit_is_extension_supported("GL_ARB_framebuffer_object");
>
> Please rename have_mipmap to have_generate_mipmap, have_gen_mipmap, or
> something similar. Also, the check looks incorrect. Is glGenerateMipmap
> really associated with GL_ARB_framebuffer_object?
>
>
> It isn't associated. Fixed.

> > +     for (i = 0; i < ARRAY_SIZE(formats); i++) {
> > +             if (have_cube_map_ext)
> > +                     test_non_square_img(i);
> > +             if (have_tex_stor_ext)
> > +                     test_sub_img(i);
> > +             test_compressed_teximg_3d(i, have_cube_map_ext);
> > +             test_tex_img(i, have_mipmap);
> > +     }
> > +
> > +     piglit_report_result(PIGLIT_PASS);
> > +}
> > +
>
>
> > +PIGLIT_GL_TEST_CONFIG_BEGIN
> > +
> > +     config.supports_gl_compat_version = 11;
> > +     config.supports_gl_es_version = 10;
>
> Bumping the required ES version from 1.0 to 2.0 will improve test
> coverage. GLES 2.0 implementations are much more common that GLES 1.0
> implementations.
>
> Fixed.

> > +
> > +     config.window_visual = PIGLIT_GL_VISUAL_RGB |
> PIGLIT_GL_VISUAL_DOUBLE;
> > +
> > +PIGLIT_GL_TEST_CONFIG_END
>
> The config block should near the top of the file, preferably before any
> functions or static data.
>
Fixed.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/piglit/attachments/20150914/7ea5fac9/attachment-0001.html>


More information about the Piglit mailing list