[Mesa-dev] Should GL_UN/PACK_IMAGE_HEIGHT affect GL_TEXTURE_1D_ARRAY?

Ian Romanick idr at freedesktop.org
Thu Feb 26 14:44:21 PST 2015


On 02/26/2015 08:25 AM, Neil Roberts wrote:
> Hi,
> 
> While trying to make _mesa_meta_pbo_TexSubImage understand the image
> height packing property I got stuck trying to work out whether it should
> have any affect for 1D array textures. Intuitively to me it seems like
> it shouldn't have any effect because you have to use glTexImage2D to
> specify the image so it is like the depth is always 1 and there is only
> a single image. If you wanted to put some padding between the rows you
> could always use GL_UN/PACK_ROW_LENGTH so I don't think the image height
> provides any extra functionality. I couldn't find any clear indication
> in the GL spec about it but it does explicitly say that
> GL_UN/PACK_SKIP_IMAGES should be ignored. It seems weird to ignore skip
> images but not the image height.
> 
> I made a piglit test which I'm attaching below to check what currently
> happens. If I run it on current Mesa with software fallback the image
> height is ignored for glTexImage2D but *is* used for glGetTexImage. This
> doesn't seem like it could possibly be the right behaviour because it is
> inconsistent. I also tried it on NVidia's driver and they do take the
> image height into account for both glTexImage2D and glGetTexImage which
> seems surprising to me.

IMAGE_HEIGHT is definitely used for glGetTexImage because that and
IMAGE_WIDTH allow you to get a subimage (before ARB_get_texture_sub_image).

I guess on glTexImage2D those could let you initialize a subregion of a
larger texture... kind of like doing glTexImage2D(..., NULL) followed by
glTexSubImage2D.  It does seem pretty weird.

Let me dig around in the specs and see if I can come up with a more
solid suggestion.

> Does anybody have any further insight about what's the right thing to
> do? Or perhaps someone could test it on some other drivers as well?
> 
> Regards,
> - Neil
> 
> ------- >8 --------------- (use git am --scissors to automatically chop here)
> Subject: Add a test for whether GL_UN/PACK_IMAGE_HEIGHT affects 1D_ARRAY tex
> 
> Tests setting GL_PACK_IMAGE_HEIGHT and then calling glGetTexImage for
> with GL_TEXTURE_1D_ARRAY. It also tests GL_UNPACK_IMAGE_HEIGHT with
> glTexImage2D. The image height should cause the rows to have padding
> between them. However in Mesa if it hits the software fallback path
> then the image height doesn't currently seem to affect glTexImage2D so
> the test fails.
> ---
>  tests/all.py                                    |   2 +
>  tests/texturing/CMakeLists.gl.txt               |   1 +
>  tests/texturing/array-texture-1d-image-height.c | 208 ++++++++++++++++++++++++
>  3 files changed, 211 insertions(+)
>  create mode 100644 tests/texturing/array-texture-1d-image-height.c
> 
> diff --git a/tests/all.py b/tests/all.py
> index 2d321c5..78535fe 100644
> --- a/tests/all.py
> +++ b/tests/all.py
> @@ -2663,6 +2663,8 @@ for test in ('depth-clear', 'depth-layered-clear', 'depth-draw', 'fs-writes-dept
>               'stencil-clear', 'stencil-layered-clear', 'stencil-draw', 'fs-writes-stencil'):
>      add_concurrent_test(ext_texture_array, ['fbo-depth-array', test])
>  add_plain_test(ext_texture_array, ['array-texture'])
> +add_concurrent_test(ext_texture_array, ['array-texture-1d-image-height'])
> +add_concurrent_test(ext_texture_array, ['array-texture-1d-image-height', 'pbo'])
>  add_concurrent_test(ext_texture_array, ['ext_texture_array-errors'])
>  add_concurrent_test(ext_texture_array, ['getteximage-targets', '1D_ARRAY'])
>  add_concurrent_test(ext_texture_array, ['getteximage-targets', '2D_ARRAY'])
> diff --git a/tests/texturing/CMakeLists.gl.txt b/tests/texturing/CMakeLists.gl.txt
> index b77f71f..10cb789 100644
> --- a/tests/texturing/CMakeLists.gl.txt
> +++ b/tests/texturing/CMakeLists.gl.txt
> @@ -13,6 +13,7 @@ link_libraries (
>  piglit_add_executable (1-1-linear-texture 1-1-linear-texture.c)
>  piglit_add_executable (array-depth-roundtrip array-depth-roundtrip.c)
>  piglit_add_executable (array-texture array-texture.c)
> +piglit_add_executable (array-texture-1d-image-height array-texture-1d-image-height.c)
>  piglit_add_executable (bptc-modes bptc-modes.c)
>  piglit_add_executable (bptc-float-modes bptc-float-modes.c)
>  piglit_add_executable (compressedteximage compressedteximage.c)
> diff --git a/tests/texturing/array-texture-1d-image-height.c b/tests/texturing/array-texture-1d-image-height.c
> new file mode 100644
> index 0000000..8167bc4
> --- /dev/null
> +++ b/tests/texturing/array-texture-1d-image-height.c
> @@ -0,0 +1,208 @@
> +/*
> + * Copyright (c) 2015 Intel Corporation
> + *
> + * Permission is hereby , 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.
> + *
> + *
> + * Test that GL_PACK_IMAGE_HEIGHT and GL_UNPACK_IMAGE_HEIGHT affect
> + * retrieving a GL_TEXTURE_1D_ARRAY. Setting the image height should
> + * cause gaps to be introduced between the rows.
> + *
> + * Author: Neil Roberts
> + */
> +
> +#include "piglit-util-gl.h"
> +
> +PIGLIT_GL_TEST_CONFIG_BEGIN
> +
> +	config.supports_gl_compat_version = 11;
> +
> +PIGLIT_GL_TEST_CONFIG_END
> +
> +enum piglit_result
> +piglit_display(void)
> +{
> +	/* Not used */
> +	return PIGLIT_FAIL;
> +}
> +
> +static bool
> +test_tex_image(bool use_pbo)
> +{
> +	/* 1x2 RGBA image, but with an extra row that should be
> +	 * skipped if image height is working correctly */
> +	GLubyte src_tex_data[] = {
> +		0xff, 0x00, 0x00, 0xff,
> +		0x00, 0xff, 0x00, 0xff, /* padding row */
> +		0x00, 0x00, 0xff, 0xff,
> +		0x24, 0x24, 0x24, 0xff, /* padding row */
> +	};
> +	/* Space for a 1x2 RGBA image */
> +	GLubyte dst_tex_data[4 * 2];
> +	GLuint tex;
> +	bool pass = true;
> +	GLuint pbo = 0;
> +
> +	glGenTextures(1, &tex);
> +	glBindTexture(GL_TEXTURE_1D_ARRAY, tex);
> +
> +	if (use_pbo) {
> +		glGenBuffers(1, &pbo);
> +		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, pbo);
> +		glBufferData(GL_PIXEL_UNPACK_BUFFER,
> +			     sizeof(src_tex_data),
> +			     src_tex_data,
> +			     GL_STATIC_DRAW);
> +	}
> +
> +	/* Set the image height. This should cause the second row of
> +	 * the source data to be skipped */
> +	glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 2);
> +	glTexImage2D(GL_TEXTURE_1D_ARRAY,
> +		     0, /* level */
> +		     GL_RGBA, /* internal format */
> +		     1, 2, /* width/height */
> +		     0, /* border */
> +		     GL_RGBA, /* format */
> +		     GL_UNSIGNED_BYTE,
> +		     use_pbo ? NULL : src_tex_data);
> +	glPixelStorei(GL_UNPACK_IMAGE_HEIGHT, 0);
> +
> +	if (use_pbo) {
> +		glBindBuffer(GL_PIXEL_UNPACK_BUFFER, 0);
> +		glDeleteBuffers(1, &pbo);
> +	}
> +
> +	memset(dst_tex_data, 0x42, sizeof(dst_tex_data));
> +
> +	glGetTexImage(GL_TEXTURE_1D_ARRAY,
> +		      0, /* level */
> +		      GL_RGBA, GL_UNSIGNED_BYTE,
> +		      dst_tex_data);
> +
> +	if (memcmp(dst_tex_data + 4, src_tex_data + 4 * 2, 4) == 0) {
> +		printf("GL_UNPACK_IMAGE_HEIGHT *does* affect "
> +		       "glTexImage2D(GL_TEXTURE_1D_ARRAY)\n");
> +	} else if (memcmp(dst_tex_data + 4, src_tex_data + 4, 4) == 0) {
> +		printf("GL_UNPACK_IMAGE_HEIGHT *does not* affect "
> +		       "glTexImage2D(GL_TEXTURE_1D_ARRAY)\n");
> +		pass = false;
> +	} else {
> +		printf("Unexpected values read from glGetTexImage\n");
> +		pass = false;
> +	}
> +
> +	return pass;
> +}
> +
> +static bool
> +test_get_tex_image(bool use_pbo)
> +{
> +	/* 1x2 RGBA image */
> +	GLubyte src_tex_data[] = {
> +		0xff, 0x00, 0x00, 0xff,
> +		0x00, 0xff, 0x00, 0xff
> +	};
> +	/* Enough space for image padding in the destination texture */
> +	GLubyte dst_tex_data[4 * 4];
> +	GLuint tex;
> +	bool pass = true;
> +	GLuint pbo = 0;
> +
> +	glGenTextures(1, &tex);
> +	glBindTexture(GL_TEXTURE_1D_ARRAY, tex);
> +	glTexImage2D(GL_TEXTURE_1D_ARRAY,
> +		     0, /* level */
> +		     GL_RGBA, /* internal format */
> +		     1, 2, /* width/height */
> +		     0, /* border */
> +		     GL_RGBA, /* format */
> +		     GL_UNSIGNED_BYTE,
> +		     src_tex_data);
> +
> +	memset(dst_tex_data, 0x42, sizeof(dst_tex_data));
> +
> +	if (use_pbo) {
> +		glGenBuffers(1, &pbo);
> +		glBindBuffer(GL_PIXEL_PACK_BUFFER, pbo);
> +		glBufferData(GL_PIXEL_PACK_BUFFER,
> +			     sizeof(dst_tex_data),
> +			     NULL,
> +			     GL_STREAM_READ);
> +	}
> +
> +	/* Set the image height. This should make the rows be padded out */
> +	glPixelStorei(GL_PACK_IMAGE_HEIGHT, 2);
> +	glGetTexImage(GL_TEXTURE_1D_ARRAY,
> +		      0, /* level */
> +		      GL_RGBA, GL_UNSIGNED_BYTE,
> +		      use_pbo ? NULL : dst_tex_data);
> +	glPixelStorei(GL_PACK_IMAGE_HEIGHT, 0);
> +
> +	if (use_pbo) {
> +		glGetBufferSubData(GL_PIXEL_PACK_BUFFER,
> +				   0, /* offset */
> +				   sizeof(dst_tex_data),
> +				   dst_tex_data);
> +		glBindBuffer(GL_PIXEL_PACK_BUFFER, 0);
> +		glDeleteBuffers(1, &pbo);
> +	}
> +
> +	if (memcmp(dst_tex_data + 2 * 4, src_tex_data + 4, 4) == 0) {
> +		printf("GL_PACK_IMAGE_HEIGHT *does* affect "
> +		       "glGetTexImage(GL_TEXTURE_1D_ARRAY)\n");
> +	} else if (memcmp(dst_tex_data + 4, src_tex_data + 4, 4) == 0) {
> +		printf("GL_PACK_IMAGE_HEIGHT *does not* affect "
> +		       "glGetTexImage(GL_TEXTURE_1D_ARRAY)\n");
> +		pass = false;
> +	} else {
> +		printf("Unexpected values read from glGetTexImage\n");
> +		pass = false;
> +	}
> +
> +	return pass;
> +}
> +
> +void
> +piglit_init(int argc, char **argv)
> +{
> +	bool pass = true;
> +	bool use_pbo = false;
> +	int i;
> +
> +	for (i = 1; i < argc; i++) {
> +		if (!strcmp(argv[i], "pbo")) {
> +			use_pbo = true;
> +		} else {
> +			printf("Error: Unknown parameter %s\n", argv[i]);
> +			piglit_report_result(PIGLIT_SKIP);
> +		}
> +	}
> +
> +	piglit_require_extension("GL_EXT_texture_array");
> +
> +	if (use_pbo)
> +		piglit_require_extension("GL_ARB_pixel_buffer_object");
> +
> +	pass = test_tex_image(use_pbo) && pass;
> +	pass = test_get_tex_image(use_pbo) && pass;
> +
> +	piglit_report_result(pass ? PIGLIT_PASS : PIGLIT_FAIL);
> +}
> 



More information about the mesa-dev mailing list