[Piglit] [PATCH 05/21] arb_internalformat_query2: test for INTERNALFORMAT_{X}_SIZE pnames
Alejandro Piñeiro
apinheiro at igalia.com
Fri Jan 22 08:05:52 PST 2016
>From spec:
" INTERNALFORMAT_RED_SIZE
INTERNALFORMAT_GREEN_SIZE
INTERNALFORMAT_BLUE_SIZE
INTERNALFORMAT_ALPHA_SIZE
INTERNALFORMAT_DEPTH_SIZE
INTERNALFORMAT_STENCIL_SIZE
INTERNALFORMAT_SHARED_SIZE
For textures this query will return the same information as
querying GetTexLevelParameter{if}v for TEXTURE_*_SIZE would return.
If the internal format is unsupported, or if a particular component
is not present in the format, 0 is written to <params>."
So this test calls GetInternalformat with INTERNALFORMAT_SUPPORTED:
* If it is false, it checks that the returned value is 0.
* If it is true, for texture targets, checks that the returned value
is the same that calling GetTexLevelParameter{if}v.
In order to call GetTexLevelParameter, it requires to create a texture
for the given internalformat/target combination. If that fails it is
assumed that the current implementation doesn't support that
combination, and it is tested against 0 too. Note that this means
that the test would output some error messages even if the test
passes.
Tested on NVIDIA GeForce GTX 950 - NVIDIA 352.55: fails on the next
cases:
* Fails when trying to create a texture with some per-spec valid
internalformat, like 1D/3D textures with
GL_COMPRESSED_SIGNED_RED_RGTC1. Returns INVALID_ENUM, as if
TexCompressedImage1D were called.
* GL_TEXTURE_BUFFER has a limited ranged of internalformat supported
(table 3.15 from spec 4.2). So for example, creating a texture with
target GL_TEXTURE_BUFFER and internalformat GL_DEPTH_STENCIL would
fail. On those cases the query should return 0, but it is not
always the case.
---
tests/all.py | 1 +
.../arb_internalformat_query2/CMakeLists.gl.txt | 1 +
tests/spec/arb_internalformat_query2/common.c | 217 +++++++++++++++++++++
tests/spec/arb_internalformat_query2/common.h | 23 +++
.../internalformat-size-checks.c | 196 +++++++++++++++++++
5 files changed, 438 insertions(+)
create mode 100644 tests/spec/arb_internalformat_query2/internalformat-size-checks.c
diff --git a/tests/all.py b/tests/all.py
index 28e9fd1..8c56d34 100644
--- a/tests/all.py
+++ b/tests/all.py
@@ -3639,6 +3639,7 @@ with profile.group_manager(
g(['arb_internalformat_query2-api-errors'], 'API error checks')
g(['arb_internalformat_query2-generic-pname-checks'], 'Individual most generic pname checks')
g(['arb_internalformat_query2-samples-pnames'], 'SAMPLES and NUM_SAMPLE_COUNTS pname checks')
+ g(['arb_internalformat_query2-internalformat-size-checks'], 'All INTERNALFORMAT_<X>_SIZE pname checks')
with profile.group_manager(
PiglitGLTest, grouptools.join('spec', 'arb_map_buffer_range')) as g:
diff --git a/tests/spec/arb_internalformat_query2/CMakeLists.gl.txt b/tests/spec/arb_internalformat_query2/CMakeLists.gl.txt
index a204fb5..465501b 100644
--- a/tests/spec/arb_internalformat_query2/CMakeLists.gl.txt
+++ b/tests/spec/arb_internalformat_query2/CMakeLists.gl.txt
@@ -11,5 +11,6 @@ link_libraries (
piglit_add_executable (arb_internalformat_query2-api-errors api-errors.c)
piglit_add_executable (arb_internalformat_query2-generic-pname-checks generic-pname-checks.c common.c)
piglit_add_executable (arb_internalformat_query2-samples-pnames samples-pnames.c common.c)
+piglit_add_executable (arb_internalformat_query2-internalformat-size-checks internalformat-size-checks.c common.c)
# vim: ft=cmake:
diff --git a/tests/spec/arb_internalformat_query2/common.c b/tests/spec/arb_internalformat_query2/common.c
index 0678857..b22ea09 100644
--- a/tests/spec/arb_internalformat_query2/common.c
+++ b/tests/spec/arb_internalformat_query2/common.c
@@ -323,6 +323,223 @@ try_basic(const GLenum *targets, unsigned num_targets,
return pass;
}
+/* Returns a valid format for @internalformat, so it would be possible
+ * to create a texture using glTexImageXD with that
+ * format/internalformat combination */
+static GLenum
+format_for_internalformat(const GLenum internalformat)
+{
+ switch(internalformat) {
+ case GL_DEPTH_COMPONENT:
+ case GL_DEPTH_COMPONENT16:
+ case GL_DEPTH_COMPONENT24:
+ case GL_DEPTH_COMPONENT32:
+ case GL_DEPTH_COMPONENT32F:
+ return GL_DEPTH_COMPONENT;
+ case GL_DEPTH_STENCIL:
+ case GL_DEPTH24_STENCIL8:
+ case GL_DEPTH32F_STENCIL8:
+ return GL_DEPTH_STENCIL;
+ case GL_RGB10_A2UI:
+ case GL_R8I:
+ case GL_R8UI:
+ case GL_R16I:
+ case GL_R16UI:
+ case GL_R32I:
+ case GL_R32UI:
+ case GL_RG8I:
+ case GL_RG16I:
+ case GL_RG16UI:
+ case GL_RG32I:
+ case GL_RG32UI:
+ case GL_RGB8I:
+ case GL_RGB8UI:
+ case GL_RGB16I:
+ case GL_RGB16UI:
+ case GL_RGB32I:
+ case GL_RGB32UI:
+ case GL_RGBA8I:
+ case GL_RGBA8UI:
+ case GL_RGBA16I:
+ case GL_RGBA16UI:
+ case GL_RGBA32I:
+ case GL_RGBA32UI:
+ return GL_RGBA_INTEGER;
+ default:
+ return GL_RGBA;
+ }
+}
+
+static GLenum
+type_for_internalformat(const GLenum internalformat)
+{
+ switch(internalformat) {
+ case GL_DEPTH_STENCIL:
+ case GL_DEPTH24_STENCIL8:
+ case GL_DEPTH32F_STENCIL8:
+ return GL_UNSIGNED_INT_24_8;
+ default:
+ return GL_UNSIGNED_BYTE;
+ }
+}
+
+/*
+ * Some GetInternalformati*v pnames returns the same that
+ * GetTexParameter and GetTexLevelParameter. In order to use those, a
+ * texture is needed to be bound. This method creates and bind one
+ * texture based on @target and @internalformat. It returns the
+ * texture name on @tex_out. If target is GL_TEXTURE_BUFFER, a buffer
+ * is also needed, and returned on @buffer_out. Caller is responsible
+ * to free both if the call is successful.
+ *
+ * The type and format to be used to create the texture is any one
+ * valid for the given @internalformat.
+ *
+ * For texture targets, we also use this function to check if the /resource/
+ * (defined in the ARB_internalformat_query2 spec as an object of the
+ * appropriate type that has been created with <internalformat> and <target>)
+ * is supported by the implementation. If the texture creation fails, then the
+ * resource is unsupported.
+ *
+ * Returns true if it was possible to create the texture. False
+ * otherwise (unsupported /resource/).
+ *
+ */
+bool
+create_texture(const GLenum target,
+ const GLenum internalformat,
+ GLuint *tex_out,
+ GLuint *buffer_out)
+{
+ GLuint tex = 0;
+ GLuint buffer = 0;
+ GLenum type = type_for_internalformat(internalformat);
+ GLenum format = format_for_internalformat(internalformat);
+ bool result = true;
+ int height = 16;
+ int width = 16;
+ int depth = 16;
+ unsigned i;
+
+ glGenTextures(1, &tex);
+ glBindTexture(target, tex);
+
+ switch(target) {
+ case GL_TEXTURE_1D:
+ glTexImage1D(target, 0, internalformat, width, 0,
+ format, type, NULL);
+ break;
+ case GL_TEXTURE_1D_ARRAY:
+ case GL_TEXTURE_2D:
+ case GL_TEXTURE_RECTANGLE:
+ glTexImage2D(target, 0, internalformat, width, height, 0,
+ format, type, NULL);
+ break;
+ case GL_TEXTURE_CUBE_MAP:
+ for (i = 0; i < 6; i++) {
+ glTexImage2D(GL_TEXTURE_CUBE_MAP_POSITIVE_X + i, 0,
+ internalformat, width, height, 0, format, type,
+ NULL);
+ }
+ break;
+
+ case GL_TEXTURE_CUBE_MAP_ARRAY:
+ /* cube map arrays also use TexImage3D buth depth
+ * needs to be a multiple of six */
+ depth = 6;
+ case GL_TEXTURE_2D_ARRAY:
+ case GL_TEXTURE_3D:
+ glTexImage3D(target, 0, internalformat, width, height, depth, 0,
+ format, type, NULL);
+ break;
+ case GL_TEXTURE_2D_MULTISAMPLE:
+ glTexImage2DMultisample(target, 1, internalformat, width, height,
+ GL_FALSE);
+ break;
+ case GL_TEXTURE_2D_MULTISAMPLE_ARRAY:
+ glTexImage3DMultisample(target, 1, internalformat, width, height,
+ depth, GL_FALSE);
+ break;
+ case GL_TEXTURE_BUFFER:
+ glGenBuffers(1, &buffer);
+ glBindBuffer(GL_TEXTURE_BUFFER, buffer);
+ glTexBuffer(GL_TEXTURE_BUFFER, internalformat, buffer);
+ break;
+ default:
+ result = false;
+ fprintf(stderr, "\tError: %s is not a texture target\n",
+ piglit_get_gl_enum_name(target));
+ }
+
+ if (!piglit_check_gl_error(GL_NO_ERROR))
+ result = false;
+
+ if (!result) {
+ glDeleteTextures(1, &tex);
+ glDeleteBuffers(1, &buffer);
+ } else {
+ *tex_out = tex;
+ *buffer_out = buffer;
+ }
+ return result;
+}
+/*
+ * Builds a a texture using @target and @internalformat, and compares
+ * the result of calling GetTexLevelParameter using @pname with the
+ * result included at @data.params.
+ *
+ * At this point it is assumed that @target/@internalformat is a valid
+ * combination to create a texture unless it is not supported by the
+ * implementation. If the call to create_texture with those parameters
+ * fails, it is assumed that the resource is unsupported, so the check
+ * only compares against zero (the unsupported value).
+ *
+ * Returns true if the value is the same, false otherwise
+ */
+bool
+test_data_check_against_get_tex_level_parameter(test_data *data,
+ const GLenum target,
+ const GLenum pname,
+ const GLenum internalformat)
+{
+ GLint param;
+ bool result = true;
+ GLuint tex;
+ GLuint buffer;
+ GLenum real_target = target;
+
+ result = create_texture(target, internalformat, &tex, &buffer);
+ if (!result)
+ return test_data_is_unsupported_response(data, pname);
+
+ /* For cube maps GetTexLevelParameter receives one of the face
+ * targets, or proxy */
+ if (target == GL_TEXTURE_CUBE_MAP) {
+ real_target = GL_TEXTURE_CUBE_MAP_POSITIVE_X;
+ }
+ glGetTexLevelParameteriv(real_target, 0, pname, ¶m);
+ if (!piglit_check_gl_error(GL_NO_ERROR)) {
+ result = false;
+ fprintf(stderr, "\tError calling glGetTexLevelParameter\n");
+ goto cleanup;
+ }
+
+ result = test_data_value_at_index(data, 0) == param;
+
+ if (!result) {
+ fprintf(stderr, "\tError comparing glGetInternalformat "
+ "and glGetTexLevelParameter, params value=%" PRIu64 ", "
+ "expected value=%i\n",
+ test_data_value_at_index(data, 0), param);
+ }
+
+cleanup:
+ glDeleteTextures(1, &tex);
+ glDeleteBuffers(1, &buffer);
+
+ return result;
+}
+
/*
* Returns if @pname query2 dependencies are fulfilled. So for
* example, FRAMEBUFFER_RENDERABLE needs
diff --git a/tests/spec/arb_internalformat_query2/common.h b/tests/spec/arb_internalformat_query2/common.h
index 19c3e38..6ded749 100644
--- a/tests/spec/arb_internalformat_query2/common.h
+++ b/tests/spec/arb_internalformat_query2/common.h
@@ -62,6 +62,20 @@ static const GLenum invalid_targets[] = {
GL_TEXTURE_RENDERBUFFER_NV,
};
+static const GLenum texture_targets[] = {
+ GL_TEXTURE_1D,
+ GL_TEXTURE_1D_ARRAY,
+ GL_TEXTURE_2D,
+ GL_TEXTURE_2D_ARRAY,
+ GL_TEXTURE_3D,
+ GL_TEXTURE_CUBE_MAP,
+ GL_TEXTURE_CUBE_MAP_ARRAY,
+ GL_TEXTURE_RECTANGLE,
+ GL_TEXTURE_BUFFER,
+ GL_TEXTURE_2D_MULTISAMPLE,
+ GL_TEXTURE_2D_MULTISAMPLE_ARRAY,
+};
+
static const GLenum valid_pnames[] = {
GL_SAMPLES,
GL_NUM_SAMPLE_COUNTS,
@@ -332,3 +346,12 @@ bool check_query2_dependencies(const GLenum pname,
bool test_data_is_unsupported_response(test_data *data,
GLenum pname);
+
+bool test_data_check_against_get_tex_level_parameter(test_data *data,
+ const GLenum target,
+ const GLenum pname,
+ const GLenum internalformat);
+bool create_texture(const GLenum target,
+ const GLenum internalformat,
+ GLuint *tex_out,
+ GLuint *buffer_out);
diff --git a/tests/spec/arb_internalformat_query2/internalformat-size-checks.c b/tests/spec/arb_internalformat_query2/internalformat-size-checks.c
new file mode 100644
index 0000000..38cd440
--- /dev/null
+++ b/tests/spec/arb_internalformat_query2/internalformat-size-checks.c
@@ -0,0 +1,196 @@
+/*
+ * Copyright © 2015 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.
+ */
+
+/**
+ * \file internalformat-size-checks.c
+ * Verify a handful of conditions required by the following pnames:
+ * - INTERNALFORMAT_RED_SIZE
+ * - INTERNALFORMAT_GREEN_SIZE
+ * - INTERNALFORMAT_BLUE_SIZE
+ * - INTERNALFORMAT_ALPHA_SIZE
+ * - INTERNALFORMAT_DEPTH_SIZE
+ * - INTERNALFORMAT_STENCIL_SIZE
+ * - INTERNALFORMAT_SHARED_SIZE
+ */
+
+#include "common.h"
+
+PIGLIT_GL_TEST_CONFIG_BEGIN
+
+ config.supports_gl_compat_version = 10;
+ config.window_visual = PIGLIT_GL_VISUAL_RGB;
+
+PIGLIT_GL_TEST_CONFIG_END
+
+static const GLenum pnames[] = {
+ GL_INTERNALFORMAT_RED_SIZE,
+ GL_INTERNALFORMAT_GREEN_SIZE,
+ GL_INTERNALFORMAT_BLUE_SIZE,
+ GL_INTERNALFORMAT_ALPHA_SIZE,
+ GL_INTERNALFORMAT_DEPTH_SIZE,
+ GL_INTERNALFORMAT_STENCIL_SIZE,
+ GL_INTERNALFORMAT_SHARED_SIZE,
+};
+
+/* From spec:
+ *
+ * "For textures this query will return the same information
+ * as querying GetTexLevelParameter{if}v for TEXTURE_*_SIZE
+ * would return."
+ *
+ * The following are the pnames we would need to use when
+ * calling GetTexLevelParameter (so equivalent to pnames)
+ */
+static const GLenum equivalent_pnames[] = {
+ GL_TEXTURE_RED_SIZE,
+ GL_TEXTURE_GREEN_SIZE,
+ GL_TEXTURE_BLUE_SIZE,
+ GL_TEXTURE_ALPHA_SIZE,
+ GL_TEXTURE_DEPTH_SIZE,
+ GL_TEXTURE_STENCIL_SIZE,
+ GL_TEXTURE_SHARED_SIZE,
+};
+
+enum piglit_result
+piglit_display(void)
+{
+ return PIGLIT_FAIL;
+}
+
+/*
+ * From spec:
+ *
+ * "- INTERNALFORMAT_<X>_SIZE
+ *
+ * For uncompressed internal formats, queries of these values return
+ * the actual resolutions that would be used for storing image array
+ * components for the resource. For compressed internal formats, the
+ * resolutions returned specify the component resolution of an
+ * uncompressed internal format that produces an image of roughly the
+ * same quality as the compressed algorithm. For textures this query
+ * will return the same information as querying
+ * GetTexLevelParameter{if}v for TEXTURE_*_SIZE would return. If the
+ * internal format is unsupported, or if a particular component is not
+ * present in the format, 0 is written to <params>."
+ *
+ * So try_textures_size check if it is 0 when not supported, and that
+ * the returned value is the same that the one returned by
+ * GetTextLevelParameter when supported.
+ */
+static bool
+try_textures_size(const GLenum *targets, unsigned num_targets,
+ const GLenum *internalformats, unsigned num_internalformats,
+ const GLenum pname,
+ const GLenum equivalent_pname,
+ test_data *data)
+{
+ bool pass = true;
+ unsigned i;
+ unsigned j;
+
+ for (i = 0; i < num_targets; i++) {
+ for (j = 0; j < num_internalformats; j++) {
+ bool error_test;
+ bool value_test;
+ bool supported;
+
+ supported = check_query2_dependencies(pname, targets[i])
+ && test_data_check_supported(data, targets[i],
+ internalformats[j]);
+
+ test_data_execute(data, targets[i], internalformats[j],
+ pname);
+
+ error_test =
+ piglit_check_gl_error(GL_NO_ERROR);
+
+ value_test = supported ?
+ test_data_check_against_get_tex_level_parameter(data,
+ targets[i],
+ equivalent_pname,
+ internalformats[j]) :
+ test_data_is_unsupported_response(data, pname);
+
+ if (error_test && value_test)
+ continue;
+
+ print_failing_case(targets[i], internalformats[j],
+ pname, data);
+
+ pass = false;
+ }
+ }
+
+ return pass;
+}
+
+static bool
+check_textures_size(void)
+{
+ bool check_pass = true;
+ test_data *data = test_data_new(0, 1);
+ unsigned i;
+ int testing64;
+
+ for (i = 0; i < ARRAY_SIZE(pnames); i++) {
+ bool pass = true;
+
+ if (!piglit_is_gles()) {
+ if (pnames[i] == GL_INTERNALFORMAT_SHARED_SIZE ||
+ pnames[i] == GL_INTERNALFORMAT_STENCIL_SIZE) {
+ continue;
+ }
+ }
+
+ for (testing64 = 0; testing64 <= 1; testing64++) {
+ test_data_set_testing64(data, testing64);
+
+ pass = try_textures_size(texture_targets, ARRAY_SIZE(texture_targets),
+ valid_internalformats, ARRAY_SIZE(valid_internalformats),
+ pnames[i], equivalent_pnames[i],
+ data)
+ && pass;
+ }
+ piglit_report_subtest_result(pass ? PIGLIT_PASS : PIGLIT_FAIL,
+ "%s", piglit_get_gl_enum_name(pnames[i]));
+
+ check_pass = check_pass && pass;
+ }
+
+ test_data_clear(&data);
+
+ return check_pass;
+}
+
+void
+piglit_init(int argc, char **argv)
+{
+ bool pass = true;
+
+ piglit_require_extension("GL_ARB_internalformat_query2");
+
+ pass = check_textures_size()
+ && pass;
+
+ piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
+}
--
2.1.4
More information about the Piglit
mailing list