From c2e46d34ea2c1ee44f19c0133e505f63c596a216 Mon Sep 17 00:00:00 2001 From: Andrew Wesie Date: Sat, 6 Oct 2018 19:22:34 -0500 Subject: [PATCH] pbo-getteximage: test PBO texture downloads --- tests/general/CMakeLists.gl.txt | 1 + tests/general/pbo-getteximage.c | 292 ++++++++++++++++++++++++++++++++ tests/opengl.py | 1 + 3 files changed, 294 insertions(+) create mode 100644 tests/general/pbo-getteximage.c diff --git a/tests/general/CMakeLists.gl.txt b/tests/general/CMakeLists.gl.txt index 83189fc42..e68897ea1 100644 --- a/tests/general/CMakeLists.gl.txt +++ b/tests/general/CMakeLists.gl.txt @@ -80,6 +80,7 @@ piglit_add_executable (masked-clear masked-clear.c) piglit_add_executable (object-namespace-pollution object-namespace-pollution.c) piglit_add_executable (pos-array pos-array.c) piglit_add_executable (pbo-drawpixels pbo-drawpixels.c) +piglit_add_executable (pbo-getteximage pbo-getteximage.c) piglit_add_executable (pbo-read-argb8888 pbo-read-argb8888.c) piglit_add_executable (pbo-readpixels-small pbo-readpixels-small.c) piglit_add_executable (pbo-teximage pbo-teximage.c) diff --git a/tests/general/pbo-getteximage.c b/tests/general/pbo-getteximage.c new file mode 100644 index 000000000..9661a0d4a --- /dev/null +++ b/tests/general/pbo-getteximage.c @@ -0,0 +1,292 @@ +/* + * Copyright © 2009 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. + * + * Authors: + * Eric Anholt + * + */ + +/** @file pbo-teximage.c + * + * Tests that using a PBO as the unpack buffer for glTexImage works correctly. + */ + +#include "piglit-util-gl.h" + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 10; + + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE; + +PIGLIT_GL_TEST_CONFIG_END + +#define BUFFER_OFFSET(i) ((char *)NULL + (i)) + +static GLboolean +probe(int x, int y, int z, float *expected, float *observed) +{ + if (expected[0] != observed[0] || + expected[1] != observed[1] || + expected[2] != observed[2]) { + printf("Probe color at (%i,%i,%i)\n", x, y, z); + printf(" Expected: b = %f g = %f r = %f a = %f\n", + expected[0], expected[1], expected[2], expected[3]); + printf(" Observed: b = %f g = %f r = %f a = %f\n", + observed[0], observed[1], observed[2], observed[3]); + + return GL_FALSE; + } else { + return GL_TRUE; + } +} + +static GLboolean +probe_all(int xoffset, int yoffset, int zoffset, + int width, int height, int depth, float *expected, float *observed) +{ + int x, y, z; + GLboolean pass = GL_TRUE; + + for (x = xoffset; x < width; ++x) + for (y = yoffset; y < height; ++y) + for (z = zoffset; z < depth; ++z) + { + pass &= probe(x, y, z, + expected + 4 * (x + width * y + width * height * z), + observed + 4 * (x + width * y + width * height * z)); + } + + return pass; +} + +static GLboolean +test_getteximage(GLenum target, int width, int height, int depth, float *pixels) +{ + float *addr; + GLboolean pass; + GLuint pbo, tex; + + glGenTextures(1, &tex); + glBindTexture(target, tex); + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + if (target == GL_TEXTURE_CUBE_MAP) + { + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels + 4 * 2 * 2 * 1); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels + 4 * 2 * 2 * 2); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels + 4 * 2 * 2 * 3); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels + 4 * 2 * 2 * 4); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels + 4 * 2 * 2 * 5); + depth = 6; + } + else if (depth) + { + glTexImage3D(target, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_FLOAT, pixels); + } + else if (height) + { + glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, pixels); + depth = 1; + } + else + { + glTexImage1D(target, 0, GL_RGBA, width, 0, GL_RGBA, GL_FLOAT, pixels); + height = 1; + depth = 1; + } + + glGenBuffersARB(1, &pbo); + glBindBufferARB(GL_PIXEL_PACK_BUFFER, pbo); + glBufferDataARB(GL_PIXEL_PACK_BUFFER, 4 * width * height * depth * sizeof(float), + NULL, GL_STREAM_DRAW_ARB); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + if (target == GL_TEXTURE_CUBE_MAP) + { + glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, GL_FLOAT, + BUFFER_OFFSET(0)); + glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, GL_FLOAT, + BUFFER_OFFSET(sizeof(float) * 4 * 2 * 2 * 1)); + glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, GL_FLOAT, + BUFFER_OFFSET(sizeof(float) * 4 * 2 * 2 * 2)); + glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, GL_FLOAT, + BUFFER_OFFSET(sizeof(float) * 4 * 2 * 2 * 3)); + glGetTexImage(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, GL_FLOAT, + BUFFER_OFFSET(sizeof(float) * 4 * 2 * 2 * 4)); + glGetTexImage(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, GL_FLOAT, + BUFFER_OFFSET(sizeof(float) * 4 * 2 * 2 * 5)); + + addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB); + pass = probe_all(0, 0, 0, width, height, depth, pixels, addr); + glUnmapBufferARB(GL_PIXEL_PACK_BUFFER); + } + else + { + glGetTexImage(target, 0, GL_RGBA, GL_FLOAT, 0); + + addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB); + pass = probe_all(0, 0, 0, width, height, depth, pixels, addr); + glUnmapBufferARB(GL_PIXEL_PACK_BUFFER); + } + + glBindBufferARB(GL_PIXEL_PACK_BUFFER, 0); + + glDeleteBuffersARB(1, &pbo); + glDeleteTextures(1, &tex); + return pass; +} + +static GLboolean +test_gettexturesubimage(GLenum target, int width, int height, int depth, float *pixels) +{ + int xoffset, yoffset, zoffset; + float *addr; + GLboolean pass; + GLuint pbo, tex; + + glGenTextures(1, &tex); + glBindTexture(target, tex); + glTexParameteri(target, GL_TEXTURE_MIN_FILTER, GL_NEAREST); + glTexParameteri(target, GL_TEXTURE_MAG_FILTER, GL_NEAREST); + + if (target == GL_TEXTURE_CUBE_MAP) + { + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_X, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels + 4 * 2 * 2 * 1); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Y, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels + 4 * 2 * 2 * 2); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Y, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels + 4 * 2 * 2 * 3); + glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_Z, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels + 4 * 2 * 2 * 4); + glTexImage2D(GL_TEXTURE_CUBE_MAP_NEGATIVE_Z, 0, GL_RGBA, width, height, + 0, GL_RGBA, GL_FLOAT, pixels + 4 * 2 * 2 * 5); + depth = 6; + } + else if (depth) + { + glTexImage3D(target, 0, GL_RGBA, width, height, depth, 0, GL_RGBA, GL_FLOAT, pixels); + } + else if (height) + { + glTexImage2D(target, 0, GL_RGBA, width, height, 0, GL_RGBA, GL_FLOAT, pixels); + depth = 1; + } + else + { + glTexImage1D(target, 0, GL_RGBA, width, 0, GL_RGBA, GL_FLOAT, pixels); + height = 1; + depth = 1; + } + + xoffset = 1 % width; + yoffset = 1 % height; + zoffset = 1 % depth; + + glGenBuffersARB(1, &pbo); + glBindBufferARB(GL_PIXEL_PACK_BUFFER, pbo); + glBufferDataARB(GL_PIXEL_PACK_BUFFER, 4 * width * height * depth * sizeof(float), + NULL, GL_STREAM_DRAW_ARB); + glPixelStorei(GL_PACK_ALIGNMENT, 1); + + glGetTextureSubImage(tex, 0, xoffset, yoffset, zoffset, + width - xoffset, height - yoffset, depth - zoffset, + GL_RGBA, GL_FLOAT, 4 * width * height * depth * sizeof(float), 0); + + addr = glMapBufferARB(GL_PIXEL_PACK_BUFFER, GL_READ_ONLY_ARB); + pass = probe_all(xoffset, yoffset, zoffset, width, height, depth, pixels, addr); + glUnmapBufferARB(GL_PIXEL_PACK_BUFFER); + + glBindBufferARB(GL_PIXEL_PACK_BUFFER, 0); + + glDeleteBuffersARB(1, &pbo); + glDeleteTextures(1, &tex); + return pass; +} + + +enum piglit_result +piglit_display(void) +{ + GLboolean pass = GL_TRUE; + float pixels[4 * (2 * 2 * 12)]; + unsigned int x, y, z; + + glClearColor(0.5, 0.5, 0.5, 0.0); + glClear(GL_COLOR_BUFFER_BIT); + + for (x = 0; x < 2; ++x) + for (y = 0; y < 2; ++y) + for (z = 0; z < 12; ++z) + { + pixels[4 * (x + 2 * y + 2 * 2 * z)] = x % 2; + pixels[4 * (x + 2 * y + 2 * 2 * z) + 1] = (x * 3) % 2; + pixels[4 * (x + 2 * y + 2 * 2 * z) + 2] = (x * 5) % 2; + pixels[4 * (x + 2 * y + 2 * 2 * z) + 3] = 0.0f; + } + + pass &= test_getteximage(GL_TEXTURE_1D, 2, 0, 0, pixels); + pass &= test_getteximage(GL_TEXTURE_1D_ARRAY, 2, 2, 0, pixels); + pass &= test_getteximage(GL_TEXTURE_2D, 2, 2, 0, pixels); + pass &= test_getteximage(GL_TEXTURE_2D_ARRAY, 2, 2, 2, pixels); + pass &= test_getteximage(GL_TEXTURE_3D, 2, 2, 2, pixels); + pass &= test_getteximage(GL_TEXTURE_CUBE_MAP, 2, 2, 0, pixels); + pass &= test_getteximage(GL_TEXTURE_CUBE_MAP_ARRAY, 2, 2, 12, pixels); + + pass &= test_gettexturesubimage(GL_TEXTURE_1D, 2, 0, 0, pixels); + pass &= test_gettexturesubimage(GL_TEXTURE_1D_ARRAY, 2, 2, 0, pixels); + pass &= test_gettexturesubimage(GL_TEXTURE_2D, 2, 2, 0, pixels); + pass &= test_gettexturesubimage(GL_TEXTURE_2D_ARRAY, 2, 2, 2, pixels); + pass &= test_gettexturesubimage(GL_TEXTURE_3D, 2, 2, 2, pixels); + pass &= test_gettexturesubimage(GL_TEXTURE_CUBE_MAP, 2, 2, 0, pixels); + + piglit_present_results(); + + return pass ? PIGLIT_PASS : PIGLIT_FAIL; +} + + +static void reshape(int width, int height) +{ + piglit_width = width; + piglit_height = height; + + piglit_ortho_projection(width, height, GL_FALSE); +} + +void +piglit_init(int argc, char **argv) +{ + reshape(piglit_width, piglit_height); + piglit_require_extension("GL_ARB_pixel_buffer_object"); +} diff --git a/tests/opengl.py b/tests/opengl.py index c6512b467..34e2762ae 100644 --- a/tests/opengl.py +++ b/tests/opengl.py @@ -2212,6 +2212,7 @@ with profile.test_list.group_manager( g(['cubemap', 'npot', 'pbo']) g(['fbo-pbo-readpixels-small'], run_concurrent=False) g(['pbo-drawpixels'], run_concurrent=False) + g(['pbo-getteximage'], run_concurrent=False) g(['pbo-read-argb8888'], run_concurrent=False) g(['pbo-readpixels-small'], run_concurrent=False) g(['pbo-teximage'], run_concurrent=False) -- 2.17.1