diff options
author | Fredrik Höglund <fredrik@kde.org> | 2014-01-20 17:58:15 +0100 |
---|---|---|
committer | Fredrik Höglund <fredrik@kde.org> | 2015-10-07 01:26:38 +0200 |
commit | 95b9120110f8893b40250d8f8612a903707a904d (patch) | |
tree | b18d4943f87aa85c1c5d1e5e3e016fc7c52621b7 | |
parent | 42e459657a21bc52ed8db06bad56c77ef7696a74 (diff) |
arb_multi_bind: Add a glBindImageTextures testarb-multi-bind
This test verifies that glBindImageTextures works as expected.
-rw-r--r-- | tests/all.py | 1 | ||||
-rw-r--r-- | tests/spec/arb_multi_bind/CMakeLists.gl.txt | 1 | ||||
-rw-r--r-- | tests/spec/arb_multi_bind/image-textures.c | 296 |
3 files changed, 298 insertions, 0 deletions
diff --git a/tests/all.py b/tests/all.py index ef6fd4904..ca83ecb93 100644 --- a/tests/all.py +++ b/tests/all.py @@ -3591,6 +3591,7 @@ with profile.group_manager( 'bindbuffersrange uniform-buffers') g(['arb_multi_bind-bindbuffersrange', 'xfb-buffers'], 'bindbuffersrange xfb-buffers') + g(['arb_multi_bind-image-textures'], 'image-textures') g(['arb_multi_bind-samplers'], 'samplers') g(['arb_multi_bind-textures'], 'textures') g(['arb_multi_bind-vertexbuffers'], 'vertexbuffers') diff --git a/tests/spec/arb_multi_bind/CMakeLists.gl.txt b/tests/spec/arb_multi_bind/CMakeLists.gl.txt index 8c8b94c75..56627225c 100644 --- a/tests/spec/arb_multi_bind/CMakeLists.gl.txt +++ b/tests/spec/arb_multi_bind/CMakeLists.gl.txt @@ -11,6 +11,7 @@ link_libraries ( piglit_add_executable (arb_multi_bind-bindbuffersbase bindbuffersbase.c) piglit_add_executable (arb_multi_bind-bindbuffersrange bindbuffersrange.c) +piglit_add_executable (arb_multi_bind-image-textures image-textures.c) piglit_add_executable (arb_multi_bind-samplers samplers.c) piglit_add_executable (arb_multi_bind-textures textures.c) piglit_add_executable (arb_multi_bind-vertexbuffers vertexbuffers.c) diff --git a/tests/spec/arb_multi_bind/image-textures.c b/tests/spec/arb_multi_bind/image-textures.c new file mode 100644 index 000000000..f4fc5cb78 --- /dev/null +++ b/tests/spec/arb_multi_bind/image-textures.c @@ -0,0 +1,296 @@ +/* + * Copyright © 2014 Fredrik Höglund + * + * 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. + */ + +/** + * @file image-textures.c + * + * Tests that glBindImageTextures works as expected. + */ + +#include "piglit-util-gl.h" + + +PIGLIT_GL_TEST_CONFIG_BEGIN + + config.supports_gl_compat_version = 30; + config.supports_gl_core_version = 31; + + config.window_visual = PIGLIT_GL_VISUAL_RGB | PIGLIT_GL_VISUAL_DOUBLE; + +PIGLIT_GL_TEST_CONFIG_END + + +enum piglit_result +piglit_display(void) +{ + /* unreached */ + return PIGLIT_FAIL; +} + + +/** + * Compares an indexed parameter value against the expected value, + * and returns true if they match and false otherwise. + */ +static bool +check_binding_param(GLenum param, GLuint index, GLint expected) +{ + GLint value; + glGetIntegeri_v(param, index, &value); + + if (value != expected) { + fprintf(stderr, "%s[%u] = %d, expected %d\n", + piglit_get_gl_enum_name(param), + index, value, expected); + return false; + } + + return true; +} + + +/** + * Checks that the image texture binding given by index matches the expected + * values. + */ +bool +check_binding_(GLuint index, GLuint texture, GLboolean layered, + GLbitfield access, GLenum format, + const char *file, unsigned line) +{ + bool pass = true; + + pass = check_binding_param(GL_IMAGE_BINDING_NAME, + index, texture) && pass; + + pass = check_binding_param(GL_IMAGE_BINDING_LEVEL, + index, 0) && pass; + + pass = check_binding_param(GL_IMAGE_BINDING_LAYER, + index, 0) && pass; + + pass = check_binding_param(GL_IMAGE_BINDING_LAYERED, + index, layered) && pass; + + pass = check_binding_param(GL_IMAGE_BINDING_ACCESS, + index, access) && pass; + + pass = check_binding_param(GL_IMAGE_BINDING_FORMAT, + index, format) && pass; + + if (!pass) + fprintf(stderr, "(Error at %s:%u)\n", file, line); + + return pass; +} + + +/** + * Checks that the given texture ID is not a valid texture. + */ +static bool +check_is_not_texture_(GLuint id, const char *expr, const char *file, unsigned line) +{ + if (glIsTexture(id)) { + fprintf(stderr, "%s = %u is a valid texture\n", expr, id); + fprintf(stderr, "(Error at %s:%u)\n", file, line); + return false; + } + + return true; +} + + +#define check_binding(index, texture, layered, access, format) \ + check_binding_(index, texture, layered, access, format, \ + __FILE__, __LINE__) + +#define check_is_not_texture(id) \ + check_is_not_texture_(id, #id, __FILE__, __LINE__) + + +void +piglit_init(int argc, char **argv) +{ + GLint value; + GLuint textures[4]; + GLuint texture; + int i; + bool pass = true; + + piglit_require_extension("GL_ARB_multi_bind"); + piglit_require_extension("GL_ARB_shader_image_load_store"); + + /* The ARB_multi_bind spec says: + * + * "An INVALID_OPERATION error is generated if <first> + <count> is + * greater than the number of image units supported by the + * implementation." + */ + glGetIntegerv(GL_MAX_IMAGE_UNITS, &value); + glBindImageTextures(0, value + 1, NULL); + pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; + + /* The ARB_multi_bind spec says: + * + * "An INVALID_OPERATION error is generated if any value in + * <textures> is not zero or the name of an existing texture + * object (per binding)." + */ + + /* Create a single valid texture */ + glGenTextures(1, &texture); + glBindTexture(GL_TEXTURE_2D, texture); + glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_FLOAT, NULL); + + /* Verify that binding an non-generated texture fails */ + textures[0] = texture + 1; /* Invalid */ + textures[1] = texture; /* Valid */ + glBindImageTextures(0, 2, textures); + pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; + + /* Verify that unit 0 is unchanged and that + * texture[1] was bound to unit 1. + */ + pass = check_binding(0, 0, GL_FALSE, GL_READ_ONLY, GL_R8) && pass; + pass = check_binding(1, texture, GL_FALSE, + GL_READ_WRITE, GL_R8) && pass; + + /* Verify that the non-generated texture was not created */ + pass = check_is_not_texture(textures[0]) && pass; + + /* Verify that binding a texture that has not been created fails */ + glGenTextures(1, &textures[0]); + glBindImageTextures(2, 2, textures); + pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; + + /* Verify that the unit 2 is unchanged and that + * texture[1] was bound to unit 3. + */ + pass = check_binding(2, 0, GL_FALSE, GL_READ_ONLY, GL_R8) && pass; + pass = check_binding(3, texture, GL_FALSE, + GL_READ_WRITE, GL_R8) && pass; + + /* Verify that the generated texture was not created */ + pass = check_is_not_texture(textures[0]) && pass; + + /* The ARB_multi_bind spec says: + * + * "An INVALID_OPERATION error is generated if the width, height, + * or depth of the level zero texture image of any texture in + * <textures> is zero (per binding)." + */ + + /* Create texture[0] by binding it, and attach a 0x0 image to it. */ + glBindTexture(GL_TEXTURE_2D, textures[0]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 0, 0, 0, GL_RED, GL_FLOAT, NULL); + + /* Verify that binding it with glBindImageTextures fails */ + glBindImageTextures(4, 2, textures); + pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; + + /* Verify that the unit 4 is unchanged and that + * texture[1] was bound to unit 5. + */ + pass = check_binding(4, 0, GL_FALSE, GL_READ_ONLY, GL_R8) && pass; + pass = check_binding(5, texture, GL_FALSE, + GL_READ_WRITE, GL_R8) && pass; + + /* The ARB_multi_bind spec says: + * + * "An INVALID_OPERATION error is generated if the internal format + * of the level zero texture image of any texture in <textures> is + * not found in table 8.33 (per binding)." + */ + + /* Replace the base level image in texture[0] with one that + * has an invalid format, but valid dimensions. + */ + glBindTexture(GL_TEXTURE_2D, textures[0]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB8, 1, 1, 0, + GL_RGB, GL_FLOAT, NULL); + + /* Verify that binding it with glBindImageTextures fails */ + glBindImageTextures(6, 2, textures); + pass = piglit_check_gl_error(GL_INVALID_OPERATION) && pass; + + /* Verify that the unit 6 is unchanged and that + * texture[1] was bound to unit 7. + */ + pass = check_binding(6, 0, GL_FALSE, GL_READ_ONLY, GL_R8) && pass; + pass = check_binding(7, texture, GL_FALSE, + GL_READ_WRITE, GL_R8) && pass; + + glDeleteTextures(2, textures); + + /* Generate four textures */ + glGenTextures(4, textures); + + /* Bind each texture and add a 1x1 image */ + glBindTexture(GL_TEXTURE_2D, textures[0]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_R8, 1, 1, 0, GL_RED, GL_FLOAT, NULL); + + glBindTexture(GL_TEXTURE_2D, textures[1]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RG8, 1, 1, 0, GL_RG, GL_FLOAT, NULL); + + glBindTexture(GL_TEXTURE_2D, textures[2]); + glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, 1, 1, 0, + GL_RGBA, GL_FLOAT, NULL); + + glBindTexture(GL_TEXTURE_3D, textures[3]); + glTexImage3D(GL_TEXTURE_3D, 0, GL_RGBA8, 1, 1, 1, 0, GL_RGBA, + GL_FLOAT, NULL); + + /* Bind the textures to image units [0..4] */ + glBindImageTextures(0, 4, textures); + pass = piglit_check_gl_error(GL_NO_ERROR) && pass; + + /* Verify that the textures were successfully bound */ + pass = check_binding(0, textures[0], GL_FALSE, + GL_READ_WRITE, GL_R8) && pass; + pass = check_binding(1, textures[1], GL_FALSE, + GL_READ_WRITE, GL_RG8) && pass; + pass = check_binding(2, textures[2], GL_FALSE, + GL_READ_WRITE, GL_RGBA8) && pass; + pass = check_binding(3, textures[3], GL_TRUE, + GL_READ_WRITE, GL_RGBA8) && pass; + + /* Unbind a single texture */ + texture = 0; + glBindImageTextures(1, 1, &texture); + + /* Verify that the texture was unbound and that the image unit + * has been reset + */ + pass = check_binding(1, 0, GL_FALSE, GL_READ_ONLY, GL_R8) && pass; + + /* Unbind all textures */ + glBindImageTextures(0, 8, NULL); + + /* Verify that the textures were unbound */ + for (i = 0; i < 8; i++) + pass = check_binding(i, 0, GL_FALSE, + GL_READ_ONLY, GL_R8) && pass; + + piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL); +} |