[Piglit] [PATCH 1/2] gl-3.0/required-sized-formats: New test for GL3.0.
Ian Romanick
idr at freedesktop.org
Mon Nov 7 09:37:52 PST 2011
On 11/06/2011 08:32 PM, Eric Anholt wrote:
Does this test pass on any of the closed-source drivers? Since it uses
floating-point depth textures, I assume it doesn't pass on Mesa yet.
> ---
> tests/all.tests | 1 +
> tests/spec/gl-3.0/CMakeLists.gl.txt | 17 ++
> tests/spec/gl-3.0/required-sized-formats.c | 414 ++++++++++++++++++++++++++++
I have some tests outstanding that put things in tests/spec/gl-3.0/api.
I think this test should go in tests/spec/gl-3.0/fbo or
tests/spec/gl-3.0/texture. I assume we'll have a similar test that
tries to create FBOs in all of the required format combinations.
> 3 files changed, 432 insertions(+), 0 deletions(-)
> create mode 100644 tests/spec/gl-3.0/CMakeLists.gl.txt
> create mode 100644 tests/spec/gl-3.0/required-sized-formats.c
>
> diff --git a/tests/all.tests b/tests/all.tests
> index 5c9d133..6345040 100644
> --- a/tests/all.tests
> +++ b/tests/all.tests
> @@ -790,6 +790,7 @@ gl30 = Group()
> spec['!OpenGL 3.0'] = gl30
> add_concurrent_test(gl30, 'clearbuffer-invalid-drawbuffer')
> add_concurrent_test(gl30, 'clearbuffer-invalid-buffer')
> +add_concurrent_test(gl30, 'gl-3.0-required-sized-formats')
>
> # Group spec/glsl-1.00
> spec['glsl-1.00'] = Group()
> diff --git a/tests/spec/gl-3.0/CMakeLists.gl.txt b/tests/spec/gl-3.0/CMakeLists.gl.txt
> new file mode 100644
> index 0000000..8efa283
> --- /dev/null
> +++ b/tests/spec/gl-3.0/CMakeLists.gl.txt
> @@ -0,0 +1,17 @@
> +include_directories(
> + ${GLEXT_INCLUDE_DIR}
> + ${OPENGL_INCLUDE_PATH}
> + ${GLUT_INCLUDE_DIR}
> + ${piglit_SOURCE_DIR}/tests/util
> +)
> +
> +link_libraries (
> + piglitutil
> + ${OPENGL_gl_LIBRARY}
> + ${OPENGL_glu_LIBRARY}
> + ${GLUT_glut_LIBRARY}
> +)
> +
> +add_executable (gl-3.0-required-sized-formats required-sized-formats.c)
> +
> +# vim: ft=cmake:
> diff --git a/tests/spec/gl-3.0/required-sized-formats.c b/tests/spec/gl-3.0/required-sized-formats.c
> new file mode 100644
> index 0000000..f77ad6e
> --- /dev/null
> +++ b/tests/spec/gl-3.0/required-sized-formats.c
> @@ -0,0 +1,414 @@
> +/* Copyright © 2011 Intel Corporation
> + *
> + * 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, sublicense,
> + * 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 NONINFRINGEMENT. IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS 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 "piglit-util.h"
> +
> +/**
> + * @file required-sized-formats.c
> + *
> + * Tests that the required sized internal formats for GL 3.0 are
> + * exposed. See page 180 of the GL 3.0 pdf (20080923), "Required
> + * Texture Formats". Notably:
> + *
> + * "In addition, implementations are required to support the
> + * following sized internal formats. Requesting one of these
> + * internal formats for any texture type will allocate exactly
> + * the internal component sizes and types shown for that format
> + * in tables 3.16- 3.17:"
> + */
> +
> +int piglit_width = 32;
> +int piglit_height = 32;
> +int piglit_window_mode = GLUT_DOUBLE | GLUT_RGB | GLUT_ALPHA;
> +
> +/* F=float, UN=unsigned normalized, SN=signed normalized, I=int,
> + * U=uint.
> + */
> +enum bits_types {
> + NONE,
> +
> + UN32,
> + F32,
> + I32,
> + U32,
> +
> + UN16,
> + F16,
> + I16,
> + U16,
> +
> + UN8,
> + SN8,
> + I8,
> + U8,
> +
> + UN10,
> + UN2,
> +
> + F11,
> + F10,
> + F9,
> +
> + UN24,
> +
> + /* Compressed internalformats get treated specially. */
> + UCMP,
> + SCMP,
> +
> + BITS_MAX,
> +};
> +
> +static const struct {
> + int size;
> + GLenum type;
> +} bits[BITS_MAX] = {
> + { 0, GL_NONE },
> +
> + { 32, GL_UNSIGNED_NORMALIZED },
> + { 32, GL_FLOAT },
> + { 32, GL_INT },
> + { 32, GL_UNSIGNED_INT },
> +
> + { 16, GL_UNSIGNED_NORMALIZED },
> + { 16, GL_FLOAT },
> + { 16, GL_INT },
> + { 16, GL_UNSIGNED_INT },
> +
> + { 8, GL_UNSIGNED_NORMALIZED },
> + { 8, GL_SIGNED_NORMALIZED },
> + { 8, GL_INT },
> + { 8, GL_UNSIGNED_INT },
> +
> + { 10, GL_UNSIGNED_NORMALIZED },
> + { 2, GL_UNSIGNED_NORMALIZED },
> +
> + { 11, GL_FLOAT },
> + { 10, GL_FLOAT },
> + { 9, GL_FLOAT },
> +
> + { 24, GL_UNSIGNED_NORMALIZED },
> +
> + { ~0, GL_UNSIGNED_NORMALIZED },
> + { ~0, GL_SIGNED_NORMALIZED },
> +};
> +
> +enum {
> + R,
> + G,
> + B,
> + A,
> + L,
> + I,
> + D,
> + S,
> + CHANNELS,
> +};
> +
> +#define FORMAT(token, r, g, b, a, l, i, d, s) \
> + { #token, token, { r, g, b, a, l, i, d, s } }
> +
> +static const struct {
> + const char *name;
> + GLenum token;
> + enum bits_types bits[CHANNELS];
> +} formats[] = {
> + /* Required color formats */
> + FORMAT(GL_RGBA32F, F32, F32, F32, F32, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGBA32I, I32, I32, I32, I32, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGBA32UI, U32, U32, U32, U32, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGBA16, UN16, UN16, UN16, UN16, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGBA16F, F16, F16, F16, F16, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGBA16I, I16, I16, I16, I16, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGBA16UI, U16, U16, U16, U16, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGBA8, UN8, UN8, UN8, UN8, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGBA8I, I8, I8, I8, I8, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGBA8UI, U8, U8, U8, U8, NONE, NONE, NONE, NONE),
> + FORMAT(GL_SRGB8_ALPHA8, UN8, UN8, UN8, UN8, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGB10_A2, UN10, UN10, UN10, UN2, NONE, NONE, NONE, NONE),
> +
> + FORMAT(GL_R11F_G11F_B10F, F11, F11, F10, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RG32F, F32, F32, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RG32I, I32, I32, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RG32UI, U32, U32, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RG16, UN16, UN16, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RG16F, F16, F16, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RG16I, I16, I16, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RG16UI, U16, U16, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RG8, UN8, UN8, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RG8I, I8, I8, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RG8UI, U8, U8, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_R32F, F32, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_R32I, I32, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_R32UI, U32, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_R16F, F16, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_R16I, I16, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_R16UI, U16, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_R16, UN16, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_R8, UN8, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_R8I, I8, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_R8UI, U8, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_ALPHA8, NONE, NONE, NONE, UN8, NONE, NONE, NONE, NONE),
> +
> + /* Required color formats (texture-only): */
> + FORMAT(GL_RGB32F, F32, F32, F32, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGB32I, I32, I32, I32, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGB32UI, U32, U32, U32, NONE, NONE, NONE, NONE, NONE),
> +
> + FORMAT(GL_RGB16F, F16, F16, F16, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGB16I, I16, I16, I16, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGB16UI, U16, U16, U16, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGB16, UN16, UN16, UN16, NONE, NONE, NONE, NONE, NONE),
> +
> + FORMAT(GL_RGB8, UN8, UN8, UN8, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGB8I, I8, I8, I8, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_RGB8UI, U8, U8, U8, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_SRGB8, UN8, UN8, UN8, NONE, NONE, NONE, NONE, NONE),
> +
> + FORMAT(GL_RGB9_E5, F9, F9, F9, NONE, NONE, NONE, NONE, NONE),
> +
> + FORMAT(GL_COMPRESSED_RG_RGTC2, UCMP, UCMP, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_COMPRESSED_SIGNED_RG_RGTC2, SCMP, SCMP, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_COMPRESSED_RED_RGTC1, UCMP, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> + FORMAT(GL_COMPRESSED_SIGNED_RED_RGTC1, SCMP, NONE, NONE, NONE, NONE, NONE, NONE, NONE),
> +
> + FORMAT(GL_DEPTH_COMPONENT32F, NONE, NONE, NONE, NONE, NONE, NONE,
> + F32, NONE),
> + FORMAT(GL_DEPTH_COMPONENT24, NONE, NONE, NONE, NONE, NONE, NONE,
> + UN24, NONE),
> + FORMAT(GL_DEPTH_COMPONENT16, NONE, NONE, NONE, NONE, NONE, NONE,
> + UN16, NONE),
> +
> + FORMAT(GL_DEPTH32F_STENCIL8, NONE, NONE, NONE, NONE, NONE, NONE,
> + F32, UN8),
> + FORMAT(GL_DEPTH24_STENCIL8, NONE, NONE, NONE, NONE, NONE, NONE,
> + UN24, UN8),
> +};
> +
> +GLenum type_queries[CHANNELS] = {
> + GL_TEXTURE_RED_TYPE,
> + GL_TEXTURE_GREEN_TYPE,
> + GL_TEXTURE_BLUE_TYPE,
> + GL_TEXTURE_ALPHA_TYPE,
> + GL_TEXTURE_LUMINANCE_TYPE,
> + GL_TEXTURE_INTENSITY_TYPE,
> + GL_TEXTURE_DEPTH_TYPE,
> + GL_NONE,
> +};
> +
> +GLenum size_queries[CHANNELS] = {
> + GL_TEXTURE_RED_SIZE,
> + GL_TEXTURE_GREEN_SIZE,
> + GL_TEXTURE_BLUE_SIZE,
> + GL_TEXTURE_ALPHA_SIZE,
> + GL_TEXTURE_LUMINANCE_SIZE,
> + GL_TEXTURE_INTENSITY_SIZE,
> + GL_TEXTURE_DEPTH_SIZE,
> + GL_TEXTURE_STENCIL_SIZE,
> +};
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> + bool pass = true;
> + float green[4] = {0.0, 1.0, 0.0, 0.0};
> + float red[4] = {1.0, 0.0, 0.0, 0.0};
> +
> + glDisable(GL_RASTERIZER_DISCARD);
> + glClearBufferfv(GL_COLOR, 0, green);
> +
> + glEnable(GL_RASTERIZER_DISCARD);
> + glClearBufferfv(GL_COLOR, 0, red);
> +
> + pass = piglit_probe_rect_rgba(0, 0, piglit_width, piglit_height, green);
> +
> + glutSwapBuffers();
> +
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;
Is this copy-and-pasted from another test? Since the real test happesn
in piglit_init, it seems like this should be the usual 'return
PIGLIT_FAIL;' version of piglit_display.
> +}
> +
> +static void
> +print_bits(int size, GLenum type)
> +{
> + /* For compressed formats, there is no particular value for
> + * the channel size specified.
> + */
> + if (size == ~0)
> + printf("??");
> + else
> + printf("%2d", size);
> +
> + if (type == GL_FLOAT)
> + printf("f ");
> + else if (type == GL_INT)
> + printf("i ");
> + else if (type == GL_UNSIGNED_INT)
> + printf("ui");
> + else if (type == GL_SIGNED_NORMALIZED)
> + printf("s ");
> + else if (type == GL_UNSIGNED_NORMALIZED ||
> + (size == 0&& type == GL_NONE))
> + printf(" ");
> + else
> + printf("??");
printf("profit");
Sorry, I couldn't resist.
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + bool pass = true;
> + GLuint tex;
> + int i, c;
> +
> + if (!GLEW_VERSION_3_0) {
> + printf("Requires GL 3.0\n");
> + piglit_report_result(PIGLIT_SKIP);
> + }
> +
> + glGenTextures(1,&tex);
> + glBindTexture(GL_TEXTURE_2D, tex);
> +
> + for (i = 0; i< ARRAY_SIZE(formats); i++) {
> + GLint sizes[CHANNELS];
> + GLint types[CHANNELS];
> + bool format_pass = true;
> + GLenum format, type;
> +
> + if (formats[i].token == GL_DEPTH24_STENCIL8 ||
> + formats[i].token == GL_DEPTH32F_STENCIL8) {
> + format = GL_DEPTH_STENCIL;
> + type = GL_UNSIGNED_INT_24_8;
> + } else if (bits[formats[i].bits[D]].size) {
> + format = GL_DEPTH_COMPONENT;
> + type = GL_FLOAT;
> + } else {
> + format = GL_RGBA;
> + type = GL_FLOAT;
> +
> + /* Have to specify integer data for integer textures. */
> + for (c = R; c<= I; c++) {
> + if (bits[formats[i].bits[c]].type == GL_UNSIGNED_INT ||
> + bits[formats[i].bits[c]].type == GL_INT) {
> + format = GL_RGBA_INTEGER;
> + type = GL_UNSIGNED_INT;
> + break;
> + }
> + }
> + }
> +
> + glTexImage2D(GL_TEXTURE_2D, 0, formats[i].token,
> + 1, 1, 0,
> + format, type, NULL);
> +
> + if (glGetError() != 0) {
> + printf("Unexpected error creating %s texture\n",
> + formats[i].name);
> + pass = false;
> + continue;
> + }
> +
> + for (c = 0; c< CHANNELS; c++) {
> + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
> + size_queries[c],&sizes[c]);
> + if (c != S) {
> + glGetTexLevelParameteriv(GL_TEXTURE_2D, 0,
> + type_queries[c],
> + &types[c]);
> + } else {
> + /* For stencil, there's no query for
> + * the type, so our table above
> + * records a type/size of unorm 8, and
> + * we'll just set the query result
> + * here to unorm so that we only look
> + * at the size.
> + */
> + if (sizes[c] != 0)
> + types[c] = GL_UNSIGNED_NORMALIZED;
> + else
> + types[c] = GL_NONE;
> + }
> +
> + /* We use ~0 as the signal for the compressed
> + * texture formats. While the colors being
> + * interpolated across the 4x4 blocks have 8
> + * bits in them, the spec suggests reporting
> + * some approximate value less than that.
> + * From page 319 of the GL 3.0 spec:
> + *
> + * "Queries of value of TEXTURE RED SIZE,
> + * TEXTURE GREEN SIZE, [...] return the
> + * actual resolutions of the stored image
> + * array components, not the resolutions
> + * specified when the image array was
> + * defined. For texture images with a
> + * compressed internal format, the
> + * resolutions returned specify the
> + * component resolution of an
> + * uncompressed internal format that
> + * produces an image of roughly the same
> + * quality as the compressed image in
> + * question. Since the quality of the
> + * implementation’s compression algorithm
> + * is likely data-dependent, the returned
> + * component sizes should be treated only
> + * as rough approximations.
> + */
> + if (formats[i].bits[c] == SCMP ||
> + formats[i].bits[c] == UCMP) {
> + if (sizes[c]<= 0 || sizes[c]> 8)
> + format_pass = false;
> + } else {
> + if (sizes[c] != bits[formats[i].bits[c]].size) {
> + format_pass = false;
> + }
> + }
> +
> + if (types[c] != bits[formats[i].bits[c]].type)
> + format_pass = false;
> + }
> +
> + if (!format_pass) {
> + printf("format %s:\n",
> + formats[i].name);
> +
> + printf(" expected: ");
> + for (c = 0; c< CHANNELS; c++) {
> + print_bits(bits[formats[i].bits[c]].size,
> + bits[formats[i].bits[c]].type);
> + printf(" ");
> + }
> + printf("\n");
> +
> + printf(" observed: ");
> + for (c = 0; c< CHANNELS; c++) {
> + print_bits(sizes[c], types[c]);
> + printf(" ");
> + }
> + printf("\n");
> +
> + pass = false;
> + }
> + }
> +
> + glDeleteTextures(1,&tex);
> +
> + piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
> +}
More information about the Piglit
mailing list