[Piglit] [PATCH 1/6] arb_texture_view-max-level: new test for an NVIDIA texelFetch() bug
Ian Romanick
idr at freedesktop.org
Thu Nov 6 15:08:06 PST 2014
On 10/28/2014 08:00 AM, Brian Paul wrote:
> From: Shibdas Bandyopadhyay <sbandyopadhyay at vmware.com>
>
> ---
> tests/all.py | 1 +
> tests/spec/arb_texture_view/CMakeLists.gl.txt | 1 +
> tests/spec/arb_texture_view/max-level.c | 252 +++++++++++++++++++++++++
> 3 files changed, 254 insertions(+)
> create mode 100644 tests/spec/arb_texture_view/max-level.c
>
> diff --git a/tests/all.py b/tests/all.py
> index ea83695..e6a24c5 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -2251,6 +2251,7 @@ arb_texture_storage_multisample['tex-param'] = PiglitGLTest('arb_texture_storage
> arb_texture_view = {}
> spec['ARB_texture_view'] = arb_texture_view
> arb_texture_view['immutable_levels'] = PiglitGLTest('arb_texture_view-texture-immutable-levels', run_concurrent=True)
> +arb_texture_view['max-level'] = PiglitGLTest('arb_texture_view-max-level', run_concurrent=True)
> arb_texture_view['params'] = PiglitGLTest('arb_texture_view-params', run_concurrent=True)
> arb_texture_view['formats'] = PiglitGLTest('arb_texture_view-formats', run_concurrent=True)
> arb_texture_view['targets'] = PiglitGLTest('arb_texture_view-targets', run_concurrent=True)
> diff --git a/tests/spec/arb_texture_view/CMakeLists.gl.txt b/tests/spec/arb_texture_view/CMakeLists.gl.txt
> index d471999..2426ed2 100644
> --- a/tests/spec/arb_texture_view/CMakeLists.gl.txt
> +++ b/tests/spec/arb_texture_view/CMakeLists.gl.txt
> @@ -11,6 +11,7 @@ link_libraries(
>
> piglit_add_executable(arb_texture_view-getteximage-srgb getteximage-srgb.c)
> piglit_add_executable(arb_texture_view-texture-immutable-levels texture-immutable-levels.c)
> +piglit_add_executable(arb_texture_view-max-level max-level.c)
> piglit_add_executable(arb_texture_view-params params.c)
> piglit_add_executable(arb_texture_view-formats formats.c common.c)
> piglit_add_executable(arb_texture_view-targets targets.c common.c)
> diff --git a/tests/spec/arb_texture_view/max-level.c b/tests/spec/arb_texture_view/max-level.c
> new file mode 100644
> index 0000000..ee25adf
> --- /dev/null
> +++ b/tests/spec/arb_texture_view/max-level.c
> @@ -0,0 +1,252 @@
> +/*
> + * Copyright © 2014 VMware, Inc.
> + *
> + * 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.
> + */
> +
> +/**
> + * With Nvidia OpenGL drivers, the texelFetch() GLSL shader function
> + * cannot return the correct data in the TextureView if we set the texture
> + * parameter GL_TEXTURE_MAX_LEVEL for the TextureView.bug.
^^^^
Delete this.
> + *
> + * Known to be
> + * -- Present in : Nvidia GTX 650, driver - 319.32
> + * -- Fixed in : driver 319.59
> + */
> +
> +
> +#include "piglit-util-gl.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> + config.supports_gl_core_version = 32;
> + config.supports_gl_compat_version = 32;
> +
> + config.window_visual = PIGLIT_GL_VISUAL_RGBA | PIGLIT_GL_VISUAL_DOUBLE;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +#define WIDTH 32
> +#define HEIGHT 32
> +#define LEVELS 6
> +#define COLOR_RED 0xFF0000FF
> +#define COLOR_GREEN 0x00FF00FF
> +#define COLOR_BLUE 0x0000FFFF
> +#define COLOR_CYAN 0x00FFFFFF
> +#define COLOR_MAGENTA 0xFF00FFFF
> +#define COLOR_YELLOW 0xFFFF00FF
> +#define COLOR_GRAY 0x7F7F7FFF
> +#define CLEAR_COLOR 0x000033FF
I think this will not work if anyone runs the test on a big-endian machine.
> +#define NUM_VERTICES 4
> +#define ATTR_SIZE 4
> +#define VIEW_LEVEL 3
> +
> +static GLuint prog;
> +
> +static bool
> +test_max_level(void)
> +{
> + static const float vertArray[] = {
> + 1.0f, -1.0f, 0.0f, 1.0f,
> + 1.0f, 1.0f, 0.0f, 1.0f,
> + -1.0f, -1.0f, 0.0f, 1.0f,
> + -1.0f, 1.0f, 0.0f, 1.0f,
> + };
> + GLint attrLoc = -1, samplerLoc = -1;
> + const GLuint white = 0xffffffff;
> + const unsigned int colors[LEVELS] = {COLOR_RED, COLOR_GREEN,
> + COLOR_BLUE, COLOR_CYAN,
> + COLOR_CYAN, COLOR_MAGENTA};
static?
> + const unsigned int numPixels = WIDTH * HEIGHT;
> + GLuint texData[WIDTH * HEIGHT];
> + GLuint i, texFbo, tex, view, fbo, vertexArray, vertexBuf, l;
unsigned i, l;
GLint texFbo, tex, view, fbo, vertexArray, vertexBuf;
> +
> + for (i = 0; i < numPixels; ++i) {
Here and elsewhere, s/numPixels/ARRAY_SIZE(texData)/. Probably the same
with LEVELS and ARRAY_SIZE(colors).
> + texData[i] = white;
> + }
> +
> + /* Create 2D textures */
> + glGenTextures(1, &texFbo);
> + glActiveTexture(GL_TEXTURE0);
> + glBindTexture(GL_TEXTURE_2D, texFbo);
> + glTexStorage2D(GL_TEXTURE_2D, 1, GL_RGBA8, WIDTH, HEIGHT);
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
> + glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, WIDTH, HEIGHT,
> + GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, texData);
I don't think the glTexSubImage2D (or the loop to initialize texData)
are necessary.
> +
> + glGenTextures(1, &tex);
> + glBindTexture(GL_TEXTURE_2D, tex);
> + glTexStorage2D(GL_TEXTURE_2D, LEVELS, GL_RGBA8, WIDTH, HEIGHT);
> +
> + for (l = 0; l < LEVELS; ++l) {
> + for (i = 0; i < numPixels >> (l * 2); ++i) {
> + texData[i] = colors[l];
> + }
> +
> + glPixelStorei(GL_UNPACK_ROW_LENGTH, WIDTH >> l);
> + glPixelStorei(GL_UNPACK_ALIGNMENT, 1);
> + glTexSubImage2D(GL_TEXTURE_2D, l, 0, 0,
> + WIDTH >> l, HEIGHT >> l,
> + GL_RGBA, GL_UNSIGNED_INT_8_8_8_8,
> + texData);
> + }
> +
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, LEVELS - 1);
> +
> + /*
> + * Create a texture view that is the (VIEW_LEVEL) mipmap level
> + * of the original texture.
> + */
> + glGenTextures(1, &view);
> + glTextureView(view, GL_TEXTURE_2D, tex, GL_RGBA8,
> + VIEW_LEVEL, 1, 0, 1);
> + glBindTexture(GL_TEXTURE_2D, view);
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_BASE_LEVEL, 0);
> + glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAX_LEVEL, 0);
> +
> + if (!piglit_check_gl_error(GL_NO_ERROR))
> + return false;
> +
> + /* Setup the sampler */
> + samplerLoc = glGetUniformLocation(prog, "s");
> + glUniform1i(samplerLoc, 0); // GL_TEXTURE0
> +
> + /* Setup vertex attributes. */
> + attrLoc = glGetAttribLocation(prog, "Attr0");
> + glGenVertexArrays(1, &vertexArray);
> + glBindVertexArray(vertexArray);
> + glGenBuffers(1, &vertexBuf);
> + glBindBuffer(GL_ARRAY_BUFFER, vertexBuf);
> + glBufferData(GL_ARRAY_BUFFER, sizeof(vertArray), vertArray,
> + GL_STATIC_DRAW);
> + glEnableVertexAttribArray(attrLoc);
> + glVertexAttribPointer(attrLoc, ATTR_SIZE, GL_FLOAT, GL_FALSE,
> + ATTR_SIZE * sizeof(float), 0);
I think all of the preceding setup for the sampler and attributes could
happen in piglit_init.
> +
> + if (!piglit_check_gl_error(GL_NO_ERROR))
> + return false;
> +
> + /* Setup the FBO. */
> + glGenFramebuffers(1, &fbo);
> + glBindFramebuffer(GL_FRAMEBUFFER, fbo);
> + glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0,
> + GL_TEXTURE_2D, texFbo, 0);
> + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
> + GL_FRAMEBUFFER_COMPLETE) {
> + printf("incomplete framebuffer at line %d\n", __LINE__);
> + return false;
> + }
> +
> + glDrawBuffer(GL_COLOR_ATTACHMENT0);
> + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
> + GL_FRAMEBUFFER_COMPLETE) {
> + printf("incomplete framebuffer at line %d\n", __LINE__);
> + return false;
> + }
> +
> + /* Clear and draw */
> + glViewport(0, 0, WIDTH, HEIGHT);
> + glClearColor(((CLEAR_COLOR >> 24) & 0xFF) / 255.0f,
> + ((CLEAR_COLOR >> 16) & 0xFF) / 255.0f,
> + ((CLEAR_COLOR >> 8) & 0xFF) / 255.0f,
> + ((CLEAR_COLOR) & 0xFF) / 255.0f);
> + glClear(GL_COLOR_BUFFER_BIT);
> + glDrawArrays(GL_TRIANGLE_STRIP, 0, NUM_VERTICES);
> +
> + /* Read back */
> + glReadBuffer(GL_COLOR_ATTACHMENT0);
> + if (glCheckFramebufferStatus(GL_FRAMEBUFFER) !=
> + GL_FRAMEBUFFER_COMPLETE) {
> + printf("incomplete framebuffer at line %d\n", __LINE__);
> + return false;
> + }
Is this check actually necessary? It seems redundant with the one just
a few lines before.
> +
> + /* read color buffer */
> + glPixelStorei(GL_PACK_ROW_LENGTH, WIDTH);
> + glPixelStorei(GL_PACK_ALIGNMENT, 1);
> + memset(texData, 0, sizeof(texData));
> + glReadPixels(0, 0, WIDTH, HEIGHT,
> + GL_RGBA, GL_UNSIGNED_INT_8_8_8_8, texData);
> +
> + if (texData[0] != colors[VIEW_LEVEL]) {
> + printf("At pixel (0,0) expected 0x%x but found 0x%x\n",
> + colors[VIEW_LEVEL], texData[0]);
> + /* clean up */
> + glDeleteTextures(1, &tex);
> + glDeleteTextures(1, &texFbo);
> + glDeleteTextures(1, &view);
> + glDeleteFramebuffers(1, &fbo);
This is the only error path that cleans up. The typical way is to have
one place that does clean up and use goto.
> + return false;
> + }
> +
> + if (!piglit_check_gl_error(GL_NO_ERROR))
> + return false;
> +
> + glDeleteTextures(1, &tex);
> + glDeleteTextures(1, &texFbo);
> + glDeleteTextures(1, &view);
> + glDeleteFramebuffers(1, &fbo);
> + return true;
> +}
> +
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> + bool pass = test_max_level();
Just put the body of test_max_level in piglit_display.
> +
> + return pass ? PIGLIT_PASS : PIGLIT_FAIL;
> +}
> +
> +
> +static void
> +setup_shaders(void)
> +{
> + static const char *vsSrc =
> + "#version 150\n"
> + "in vec4 Attr0;"
If you call this piglit_vertex, the piglit utility code will set it up
for you.
> + "void main(void) {"
> + " gl_Position = Attr0;"
> + "}";
> + static const char *fsSrc =
> + "#version 150\n"
> + "uniform sampler2D s;"
> + "out vec4 fragColor0;"
> + "void main(void) {"
> + " fragColor0 = texelFetch(s, ivec2(0, 0), 0);"
> + "}";
> +
> + /* Create shaders and the program */
> + prog = piglit_build_simple_program(vsSrc, fsSrc);
> + glBindFragDataLocation(prog, 0, "fragColor0");
> + glLinkProgram(prog);
> + glUseProgram(prog);
> +}
> +
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> + piglit_require_extension("GL_ARB_texture_storage");
> + piglit_require_extension("GL_ARB_texture_view");
> +
> + setup_shaders();
Just put the body of setup_shaders in piglit_init.
> +}
>
More information about the Piglit
mailing list