On Wed, Feb 22, 2012 at 1:54 PM, Brian Paul <span dir="ltr"><<a href="mailto:brian.e.paul@gmail.com">brian.e.paul@gmail.com</a>></span> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="HOEnZb"><div class="h5">On Wed, Feb 22, 2012 at 3:45 PM, Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>> wrote:<br>
> Driver throws assertion failure or segfaults with large textures.<br>
><br>
> Reproduces the errors reported in:<br>
> <a href="https://bugs.freedesktop.org/show_bug.cgi?id=44970" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=44970</a><br>
> <a href="https://bugs.freedesktop.org/show_bug.cgi?id=46303" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=46303</a><br>
><br>
> Signed-off-by: Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>><br>
> ---<br>
> Please ignore previous patch sent on this thread.<br>
> V2: This version adds other texture targets and texture data types<br>
> Changed the name of test case<br>
><br>
> tests/all.tests | 1 +<br>
> tests/bugs/CMakeLists.gl.txt | 1 +<br>
> tests/bugs/large-textures.c | 224 ++++++++++++++++++++++++++++++++++++++++++<br>
> 3 files changed, 226 insertions(+), 0 deletions(-)<br>
> create mode 100644 tests/bugs/large-textures.c<br>
><br>
> diff --git a/tests/all.tests b/tests/all.tests<br>
> index e4d56b8..d006e9a 100644<br>
> --- a/tests/all.tests<br>
> +++ b/tests/all.tests<br>
> @@ -569,6 +569,7 @@ add_plain_test(bugs, 'fdo24066')<br>
> add_plain_test(bugs, 'fdo25614-genmipmap')<br>
> add_plain_test(bugs, 'fdo28551')<br>
> add_plain_test(bugs, 'fdo31934')<br>
> +add_plain_test(bugs, 'large-textures')<br>
> add_plain_test(bugs, 'point-sprite')<br>
> add_plain_test(bugs, 'r300-readcache')<br>
> add_plain_test(bugs, 'tex1d-2dborder')<br>
> diff --git a/tests/bugs/CMakeLists.gl.txt b/tests/bugs/CMakeLists.gl.txt<br>
> index 5c1864e..8cdd4d0 100644<br>
> --- a/tests/bugs/CMakeLists.gl.txt<br>
> +++ b/tests/bugs/CMakeLists.gl.txt<br>
> @@ -32,6 +32,7 @@ add_executable (fdo24066 fdo24066.c)<br>
> add_executable (fdo25614-genmipmap fdo25614-genmipmap.c)<br>
> add_executable (fdo28551 fdo28551.c)<br>
> add_executable (fdo31934 fdo31934.c)<br>
> +add_executable (large-textures large-textures.c)<br>
> add_executable (tri-tex-crash tri-tex-crash.c)<br>
> add_executable (vbo-buffer-unmap vbo-buffer-unmap.c)<br>
><br>
> diff --git a/tests/bugs/large-textures.c b/tests/bugs/large-textures.c<br>
> new file mode 100644<br>
> index 0000000..8d5751f<br>
> --- /dev/null<br>
> +++ b/tests/bugs/large-textures.c<br>
> @@ -0,0 +1,224 @@<br>
> +/* Copyright © 2012 Intel Corporation<br>
> + *<br>
> + * Permission is hereby granted, free of charge, to any person obtaining a<br>
> + * copy of this software and associated documentation files (the "Software"),<br>
> + * to deal in the Software without restriction, including without limitation<br>
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
> + * and/or sell copies of the Software, and to permit persons to whom the<br>
> + * Software is furnished to do so, subject to the following conditions:<br>
> + *<br>
> + * The above copyright notice and this permission notice (including the next<br>
> + * paragraph) shall be included in all copies or substantial portions of the<br>
> + * Software.<br>
> + *<br>
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL<br>
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
> + * IN THE SOFTWARE.<br>
> + */<br>
> +<br>
> +/**<br>
> + * \file large-textures.c<br>
> + * Verify that large textures are handled correctly in mesa driver<br>
> + *<br>
> + * This test works by calling glTexImage2D/3D and glTexSubImage2D/3D functions<br>
> + * with different texture targets. Each texture target is tested with texture<br>
> + * sizes up to the maximum supported texture size. All the calls to<br>
> + * glTexImage2D() and glTexSubImage2D() should ensure no segmentation faults/<br>
> + * assertion failures in mesa driver.<br>
> + *<br>
> + * This test case reproduces the errors reported in:<br>
> + * <a href="https://bugs.freedesktop.org/show_bug.cgi?id=44970" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=44970</a><br>
> + * <a href="https://bugs.freedesktop.org/show_bug.cgi?id=46303" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=46303</a><br>
> + *<br>
> + * \Author Anuj Phogat <<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>><br>
> + */<br>
> +<br>
> +#include "piglit-util.h"<br>
> +#define MAX_2D_TEXTURE 8192<br>
> +#define COLOR_COMPONENTS 4<br>
> +<br>
> +int piglit_width = 100, piglit_height = 100;<br>
> +int piglit_window_mode = GLUT_RGBA | GLUT_DOUBLE;<br>
> +<br>
> +char *target_string[] = {<br>
> + "GL_TEXTURE_1D",<br>
> + "GL_TEXTURE_2D",<br>
> + "GL_TEXTURE_CUBE_MAP",<br>
> + "GL_TEXTURE_3D",<br>
> + };<br>
> +<br>
> +char *format_string[] = {<br>
> + "GL_RGBA8",<br>
> + "GL_RGBA16",<br>
> + "GL_RGBA32F",<br>
> + };<br>
<br>
</div></div>You shouldn't need lists of strings like that since we have<br>
piglit_get_gl_enum_name().</blockquote><div>I will use this function to get the strings. </div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
> +GLenum target[] = {<br>
> + GL_TEXTURE_1D,<br>
> + GL_TEXTURE_2D,<br>
> + GL_TEXTURE_CUBE_MAP,<br>
> + GL_TEXTURE_3D,<br>
> + };<br>
> +<br>
> +GLenum internalformat[] = {<br>
> + //GL_RGBA8,<br>
> + //GL_RGBA16,<br>
<br>
</div>Are those formats commented out for a reason?<br></blockquote><div>Sorry, I forgot to remove the comments .</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
> + GL_RGBA32F,<br>
<br>
If you're going to test a floating point format, you should check if<br>
GL_ARB_texture_float is supported.<br>
<div><div class="h5"><br>
<br>
> + };<br>
> +<br>
> +<br>
> +GLenum maxTargetEnum(GLenum target)<br>
> +{<br>
> + switch(target) {<br>
> + case GL_TEXTURE_1D:<br>
> + case GL_TEXTURE_2D:<br>
> + return GL_MAX_TEXTURE_SIZE;<br>
> + case GL_TEXTURE_3D:<br>
> + return GL_MAX_3D_TEXTURE_SIZE;<br>
> + case GL_TEXTURE_CUBE_MAP_ARB:<br>
> + return GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB;<br>
> + case GL_TEXTURE_RECTANGLE:<br>
> + return GL_MAX_RECTANGLE_TEXTURE_SIZE;<br>
> + case GL_RENDERBUFFER_EXT:<br>
> + return GL_MAX_RENDERBUFFER_SIZE_EXT;<br>
> + default:<br>
> + printf ("Invalid texture target used");<br>
> + return 0;<br>
> + }<br>
> +}<br>
> +<br>
> +void piglit_init(int argc, char **argv)<br>
> +{<br>
> + GLuint tex;<br>
> + GLint maxSide;<br>
> + int i, j, k, side;<br>
> + const uint64_t nPixels = (uint64_t)(MAX_2D_TEXTURE + 3) *<br>
> + (uint64_t)(MAX_2D_TEXTURE + 3);<br>
> + /* Allocate the data array for maximum texture size used in this test<br>
> + * and initialize to zero<br>
> + */<br>
> + GLfloat *pixels = (GLfloat *) calloc(nPixels * COLOR_COMPONENTS,<br>
> + sizeof(float));<br>
<br>
</div></div>I think you should allocate 'pixels' according to the max texture size<br>
you get below. Suppose GL returns a max size of 16384 (which is<br>
greater than MAX_2D_TEXTURE). I think you might out of bounds below.</blockquote><div>I will fix this in my next patch. </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
> + if ( pixels == NULL) {<br>
> + printf("\nUnable to allocate texture data array");<br>
> + piglit_report_result(PIGLIT_SKIP);<br>
> + return;<br>
> + }<br>
> +<br>
> + glMatrixMode(GL_PROJECTION);<br>
> + glPushMatrix();<br>
> + glLoadIdentity();<br>
> + glOrtho(0, piglit_width, 0, piglit_height, -1, 1);<br>
> + glMatrixMode(GL_MODELVIEW);<br>
> + glPushMatrix();<br>
> + glLoadIdentity();<br>
> + glClearColor(0.2, 0.2, 0.2, 1.0);<br>
> + glClear(GL_COLOR_BUFFER_BIT);<br>
> +<br>
> + for ( i = 0; i < ARRAY_SIZE(target); i++) {<br>
> + /* Query the maximum supported texture size */<br>
> + glGetIntegerv(maxTargetEnum(target[i]), &maxSide);<br>
> + printf("\n%s, Maximum allowable texture size = %d\n",<br>
> + target_string[i], maxSide);<br>
<br>
</div>You should probably try using a proxy texture to find the max<br>
supported texture size for each internal format. Querying<br>
GL_MAX_TEXTURE_SIZE doesn't always give the whole story. For<br>
example, a texel may be 1 (A8) or 16 bytes (RGBA float). There may<br>
enough be memory for a 16Kx16K texture of the 1-byte format but not<br>
the 16-byte format.<br>
<br>
Maybe you should do two tests: one that just uses the MAX_TEXTURE_SIZE<br>
value as-is and another that uses a proxy texture to find the max size<br>
for a particular format. In both cases, we don't want crashes or<br>
failed assertions.</blockquote><div>I agree. I will add the code for testing with size returned by proxy textures as well.</div><div><br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div class="im">
> + glGenTextures(1, &tex);<br>
> + glBindTexture(target[i], tex);<br>
> + glTexParameteri(target[i], GL_TEXTURE_MIN_FILTER, GL_NEAREST);<br>
> + glTexParameteri(target[i], GL_TEXTURE_MAG_FILTER, GL_NEAREST);<br>
> + glTexParameteri(target[i], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);<br>
> + glTexParameteri(target[i], GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);<br>
<br>
</div>Is there a reason to set the texture wrap state?</blockquote><div>This is redundant. can be removed.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
</blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="h5">
<br>
> + for (j = 0; j < ARRAY_SIZE(internalformat); j++) {<br>
> + for ( side = maxSide/2; side < maxSide + 2; side++) {<br>
> + switch (target[i]) {<br>
> + case GL_TEXTURE_1D:<br>
> + glTexImage1D(target[i], 0,<br>
> + internalformat[j],<br>
> + side, 0,<br>
> + GL_RGBA, GL_FLOAT, NULL);<br>
> + glTexSubImage1D(target[i], 0, 0,<br>
> + side/2, GL_RGBA,<br>
> + GL_FLOAT, pixels);<br>
> + break;<br>
> +<br>
> + case GL_TEXTURE_2D:<br>
> + glTexImage2D(target[i], 0,<br>
> + internalformat[j],<br>
> + side, side, 0,<br>
> + GL_RGBA, GL_FLOAT, NULL);<br>
> + glTexSubImage2D(target[i], 0, 0, 0,<br>
> + side/2, side/2,<br>
> + GL_RGBA, GL_FLOAT, pixels);<br>
> + break;<br>
> +<br>
> + case GL_TEXTURE_3D:<br>
> +<br>
> + glTexParameteri(target[i],<br>
> + GL_TEXTURE_WRAP_R,<br>
> + GL_CLAMP_TO_EDGE);<br>
> + glTexImage3D(target[i], 0,<br>
> + internalformat[j],<br>
> + side, side,<br>
> + side, 0, GL_RGBA,<br>
> + GL_FLOAT, NULL);<br>
> +<br>
> + glTexSubImage3D(target[i], 0, 0, 0, 0,<br>
> + side/2, side/2, side/2,<br>
> + GL_RGBA, GL_FLOAT, pixels);<br>
> + break;<br>
> +<br>
> + case GL_TEXTURE_CUBE_MAP_ARB:<br>
> + for (k = 0; k < 6; k++) {<br>
> + glTexImage2D(<br>
> + GL_TEXTURE_CUBE_MAP_POSITIVE_X + k,<br>
> + 0, internalformat[j],<br>
> + side, side, 0,<br>
> + GL_RGBA, GL_FLOAT, NULL);<br>
> + }<br>
> + for (k = 0; k < 6; k++) {<br>
> + glTexSubImage2D(<br>
> + GL_TEXTURE_CUBE_MAP_POSITIVE_X + k,<br>
> + 0, 0, 0,<br>
> + side/2, side/2,<br>
> + GL_RGBA, GL_FLOAT, pixels);<br>
> + if (glGetError() != GL_NO_ERROR)<br>
> + {<br>
> + printf("GL Error1: while"<br>
> + " testing %s, texture"<br>
> + " size = %d, internal"<br>
> + " format = %s\n",<br>
> + target_string[i], side,<br>
> + format_string[j]);<br>
> + piglit_reset_gl_error();<br>
> + }<br>
> + }<br>
> + break;<br>
> + }<br>
> + if (glGetError() != GL_NO_ERROR)<br>
> + {<br>
> + printf("GL Error2: while testing %s, texture"<br>
> + " size = %d, internal format = %s\n",<br>
> + target_string[i], side,<br>
> + format_string[j]);<br>
<br>
</div></div>It would be good to query for an error both after glTexImage() and<br>
glTexSubImage() to know more precisely which function might be<br>
failing.</blockquote><div>I agree.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">
> + piglit_reset_gl_error();<br>
> + /* skip larger texture sizes for this texture<br>
> + * target<br>
> + */<br>
> + //break;<br>
> + }<br>
> + }<br>
> + }<br>
> + glDeleteTextures(1, &tex);<br>
> + }<br>
> + /* If execution reaches this point, return PIGLIT_PASS */<br>
> + piglit_report_result(PIGLIT_PASS);<br>
> +}<br>
> +<br>
> +enum piglit_result<br>
> +piglit_display(void)<br>
> +{<br>
> + return PIGLIT_FAIL;<br>
> +}<br>
> --<br>
> 1.7.7.6<br>
><br>
</div>> _______________________________________________<br>
> Piglit mailing list<br>
> <a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
> <a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</blockquote></div><br>