On Wed, Feb 22, 2012 at 1:54 PM, Brian Paul <span dir="ltr">&lt;<a href="mailto:brian.e.paul@gmail.com">brian.e.paul@gmail.com</a>&gt;</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 &lt;<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>&gt; wrote:<br>
&gt; Driver throws assertion failure or segfaults with large textures.<br>
&gt;<br>
&gt; Reproduces the errors reported in:<br>
&gt; <a href="https://bugs.freedesktop.org/show_bug.cgi?id=44970" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=44970</a><br>
&gt; <a href="https://bugs.freedesktop.org/show_bug.cgi?id=46303" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=46303</a><br>
&gt;<br>
&gt; Signed-off-by: Anuj Phogat &lt;<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>&gt;<br>
&gt; ---<br>
&gt; Please ignore previous patch sent on this thread.<br>
&gt; V2: This version adds other texture targets and texture data types<br>
&gt;    Changed the name of test case<br>
&gt;<br>
&gt;  tests/all.tests              |    1 +<br>
&gt;  tests/bugs/CMakeLists.gl.txt |    1 +<br>
&gt;  tests/bugs/large-textures.c  |  224 ++++++++++++++++++++++++++++++++++++++++++<br>
&gt;  3 files changed, 226 insertions(+), 0 deletions(-)<br>
&gt;  create mode 100644 tests/bugs/large-textures.c<br>
&gt;<br>
&gt; diff --git a/tests/all.tests b/tests/all.tests<br>
&gt; index e4d56b8..d006e9a 100644<br>
&gt; --- a/tests/all.tests<br>
&gt; +++ b/tests/all.tests<br>
&gt; @@ -569,6 +569,7 @@ add_plain_test(bugs, &#39;fdo24066&#39;)<br>
&gt;  add_plain_test(bugs, &#39;fdo25614-genmipmap&#39;)<br>
&gt;  add_plain_test(bugs, &#39;fdo28551&#39;)<br>
&gt;  add_plain_test(bugs, &#39;fdo31934&#39;)<br>
&gt; +add_plain_test(bugs, &#39;large-textures&#39;)<br>
&gt;  add_plain_test(bugs, &#39;point-sprite&#39;)<br>
&gt;  add_plain_test(bugs, &#39;r300-readcache&#39;)<br>
&gt;  add_plain_test(bugs, &#39;tex1d-2dborder&#39;)<br>
&gt; diff --git a/tests/bugs/CMakeLists.gl.txt b/tests/bugs/CMakeLists.gl.txt<br>
&gt; index 5c1864e..8cdd4d0 100644<br>
&gt; --- a/tests/bugs/CMakeLists.gl.txt<br>
&gt; +++ b/tests/bugs/CMakeLists.gl.txt<br>
&gt; @@ -32,6 +32,7 @@ add_executable (fdo24066 fdo24066.c)<br>
&gt;  add_executable (fdo25614-genmipmap fdo25614-genmipmap.c)<br>
&gt;  add_executable (fdo28551 fdo28551.c)<br>
&gt;  add_executable (fdo31934 fdo31934.c)<br>
&gt; +add_executable (large-textures large-textures.c)<br>
&gt;  add_executable (tri-tex-crash tri-tex-crash.c)<br>
&gt;  add_executable (vbo-buffer-unmap vbo-buffer-unmap.c)<br>
&gt;<br>
&gt; diff --git a/tests/bugs/large-textures.c b/tests/bugs/large-textures.c<br>
&gt; new file mode 100644<br>
&gt; index 0000000..8d5751f<br>
&gt; --- /dev/null<br>
&gt; +++ b/tests/bugs/large-textures.c<br>
&gt; @@ -0,0 +1,224 @@<br>
&gt; +/* Copyright © 2012 Intel Corporation<br>
&gt; + *<br>
&gt; + * Permission is hereby granted, free of charge, to any person obtaining a<br>
&gt; + * copy of this software and associated documentation files (the &quot;Software&quot;),<br>
&gt; + * to deal in the Software without restriction, including without limitation<br>
&gt; + * the rights to use, copy, modify, merge, publish, distribute, sublicense,<br>
&gt; + * and/or sell copies of the Software, and to permit persons to whom the<br>
&gt; + * Software is furnished to do so, subject to the following conditions:<br>
&gt; + *<br>
&gt; + * The above copyright notice and this permission notice (including the next<br>
&gt; + * paragraph) shall be included in all copies or substantial portions of the<br>
&gt; + * Software.<br>
&gt; + *<br>
&gt; + * THE SOFTWARE IS PROVIDED &quot;AS IS&quot;, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR<br>
&gt; + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,<br>
&gt; + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL<br>
&gt; + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER<br>
&gt; + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING<br>
&gt; + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS<br>
&gt; + * IN THE SOFTWARE.<br>
&gt; + */<br>
&gt; +<br>
&gt; +/**<br>
&gt; + * \file large-textures.c<br>
&gt; + * Verify that large textures are handled correctly in mesa driver<br>
&gt; + *<br>
&gt; + * This test works by calling glTexImage2D/3D and glTexSubImage2D/3D functions<br>
&gt; + * with different texture targets. Each texture target is tested with texture<br>
&gt; + * sizes up to the maximum supported texture size. All the calls to<br>
&gt; + * glTexImage2D() and glTexSubImage2D() should ensure no segmentation faults/<br>
&gt; + * assertion failures in mesa driver.<br>
&gt; + *<br>
&gt; + * This test case reproduces the errors reported in:<br>
&gt; + * <a href="https://bugs.freedesktop.org/show_bug.cgi?id=44970" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=44970</a><br>
&gt; + * <a href="https://bugs.freedesktop.org/show_bug.cgi?id=46303" target="_blank">https://bugs.freedesktop.org/show_bug.cgi?id=46303</a><br>
&gt; + *<br>
&gt; + * \Author Anuj Phogat &lt;<a href="mailto:anuj.phogat@gmail.com">anuj.phogat@gmail.com</a>&gt;<br>
&gt; + */<br>
&gt; +<br>
&gt; +#include &quot;piglit-util.h&quot;<br>
&gt; +#define MAX_2D_TEXTURE 8192<br>
&gt; +#define COLOR_COMPONENTS 4<br>
&gt; +<br>
&gt; +int piglit_width = 100, piglit_height = 100;<br>
&gt; +int piglit_window_mode = GLUT_RGBA | GLUT_DOUBLE;<br>
&gt; +<br>
&gt; +char *target_string[] = {<br>
&gt; +       &quot;GL_TEXTURE_1D&quot;,<br>
&gt; +       &quot;GL_TEXTURE_2D&quot;,<br>
&gt; +       &quot;GL_TEXTURE_CUBE_MAP&quot;,<br>
&gt; +       &quot;GL_TEXTURE_3D&quot;,<br>
&gt; +       };<br>
&gt; +<br>
&gt; +char *format_string[] = {<br>
&gt; +       &quot;GL_RGBA8&quot;,<br>
&gt; +       &quot;GL_RGBA16&quot;,<br>
&gt; +       &quot;GL_RGBA32F&quot;,<br>
&gt; +       };<br>
<br>
</div></div>You shouldn&#39;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">


&gt; +GLenum target[] = {<br>
&gt; +       GL_TEXTURE_1D,<br>
&gt; +       GL_TEXTURE_2D,<br>
&gt; +       GL_TEXTURE_CUBE_MAP,<br>
&gt; +       GL_TEXTURE_3D,<br>
&gt; +       };<br>
&gt; +<br>
&gt; +GLenum internalformat[] = {<br>
&gt; +       //GL_RGBA8,<br>
&gt; +       //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>
&gt; +       GL_RGBA32F,<br>
<br>
If you&#39;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>
&gt; +       };<br>
&gt; +<br>
&gt; +<br>
&gt; +GLenum maxTargetEnum(GLenum target)<br>
&gt; +{<br>
&gt; +       switch(target) {<br>
&gt; +       case GL_TEXTURE_1D:<br>
&gt; +       case GL_TEXTURE_2D:<br>
&gt; +               return GL_MAX_TEXTURE_SIZE;<br>
&gt; +       case GL_TEXTURE_3D:<br>
&gt; +               return GL_MAX_3D_TEXTURE_SIZE;<br>
&gt; +       case GL_TEXTURE_CUBE_MAP_ARB:<br>
&gt; +               return GL_MAX_CUBE_MAP_TEXTURE_SIZE_ARB;<br>
&gt; +       case GL_TEXTURE_RECTANGLE:<br>
&gt; +               return GL_MAX_RECTANGLE_TEXTURE_SIZE;<br>
&gt; +       case GL_RENDERBUFFER_EXT:<br>
&gt; +               return GL_MAX_RENDERBUFFER_SIZE_EXT;<br>
&gt; +       default:<br>
&gt; +               printf (&quot;Invalid texture target used&quot;);<br>
&gt; +               return 0;<br>
&gt; +       }<br>
&gt; +}<br>
&gt; +<br>
&gt; +void piglit_init(int argc, char **argv)<br>
&gt; +{<br>
&gt; +       GLuint tex;<br>
&gt; +       GLint maxSide;<br>
&gt; +       int i, j, k, side;<br>
&gt; +       const uint64_t nPixels = (uint64_t)(MAX_2D_TEXTURE + 3) *<br>
&gt; +                                (uint64_t)(MAX_2D_TEXTURE + 3);<br>
&gt; +       /* Allocate the data array for maximum texture size used in this test<br>
&gt; +        * and initialize to zero<br>
&gt; +        */<br>
&gt; +       GLfloat *pixels = (GLfloat *) calloc(nPixels * COLOR_COMPONENTS,<br>
&gt; +                                            sizeof(float));<br>
<br>
</div></div>I think you should allocate &#39;pixels&#39; 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">
&gt; +       if ( pixels == NULL) {<br>
&gt; +               printf(&quot;\nUnable to allocate texture data array&quot;);<br>
&gt; +               piglit_report_result(PIGLIT_SKIP);<br>
&gt; +               return;<br>
&gt; +       }<br>
&gt; +<br>
&gt; +       glMatrixMode(GL_PROJECTION);<br>
&gt; +       glPushMatrix();<br>
&gt; +       glLoadIdentity();<br>
&gt; +       glOrtho(0, piglit_width, 0, piglit_height, -1, 1);<br>
&gt; +       glMatrixMode(GL_MODELVIEW);<br>
&gt; +       glPushMatrix();<br>
&gt; +       glLoadIdentity();<br>
&gt; +       glClearColor(0.2, 0.2, 0.2, 1.0);<br>
&gt; +       glClear(GL_COLOR_BUFFER_BIT);<br>
&gt; +<br>
&gt; +       for ( i = 0; i &lt; ARRAY_SIZE(target); i++) {<br>
&gt; +               /* Query the maximum supported texture size */<br>
&gt; +               glGetIntegerv(maxTargetEnum(target[i]), &amp;maxSide);<br>
&gt; +               printf(&quot;\n%s, Maximum allowable texture size = %d\n&quot;,<br>
&gt; +                      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&#39;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&#39;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">
&gt; +               glGenTextures(1, &amp;tex);<br>
&gt; +               glBindTexture(target[i], tex);<br>
&gt; +               glTexParameteri(target[i], GL_TEXTURE_MIN_FILTER, GL_NEAREST);<br>
&gt; +               glTexParameteri(target[i], GL_TEXTURE_MAG_FILTER, GL_NEAREST);<br>
&gt; +               glTexParameteri(target[i], GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);<br>
&gt; +               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>
&gt; +               for (j = 0; j &lt; ARRAY_SIZE(internalformat); j++) {<br>
&gt; +                       for ( side = maxSide/2; side &lt; maxSide + 2; side++) {<br>
&gt; +                               switch (target[i]) {<br>
&gt; +                               case GL_TEXTURE_1D:<br>
&gt; +                                       glTexImage1D(target[i], 0,<br>
&gt; +                                                    internalformat[j],<br>
&gt; +                                                    side, 0,<br>
&gt; +                                                    GL_RGBA, GL_FLOAT, NULL);<br>
&gt; +                                       glTexSubImage1D(target[i], 0, 0,<br>
&gt; +                                                       side/2, GL_RGBA,<br>
&gt; +                                                       GL_FLOAT, pixels);<br>
&gt; +                                       break;<br>
&gt; +<br>
&gt; +                               case GL_TEXTURE_2D:<br>
&gt; +                                       glTexImage2D(target[i], 0,<br>
&gt; +                                                    internalformat[j],<br>
&gt; +                                                    side, side, 0,<br>
&gt; +                                                    GL_RGBA, GL_FLOAT, NULL);<br>
&gt; +                                       glTexSubImage2D(target[i], 0, 0, 0,<br>
&gt; +                                                       side/2, side/2,<br>
&gt; +                                                       GL_RGBA, GL_FLOAT, pixels);<br>
&gt; +                               break;<br>
&gt; +<br>
&gt; +                               case GL_TEXTURE_3D:<br>
&gt; +<br>
&gt; +                                       glTexParameteri(target[i],<br>
&gt; +                                                       GL_TEXTURE_WRAP_R,<br>
&gt; +                                                       GL_CLAMP_TO_EDGE);<br>
&gt; +                                       glTexImage3D(target[i], 0,<br>
&gt; +                                                    internalformat[j],<br>
&gt; +                                                    side, side,<br>
&gt; +                                                    side, 0, GL_RGBA,<br>
&gt; +                                                    GL_FLOAT, NULL);<br>
&gt; +<br>
&gt; +                                       glTexSubImage3D(target[i], 0, 0, 0, 0,<br>
&gt; +                                                       side/2, side/2, side/2,<br>
&gt; +                                                       GL_RGBA, GL_FLOAT, pixels);<br>
&gt; +                                       break;<br>
&gt; +<br>
&gt; +                               case GL_TEXTURE_CUBE_MAP_ARB:<br>
&gt; +                                       for (k = 0; k &lt; 6; k++) {<br>
&gt; +                                               glTexImage2D(<br>
&gt; +                                               GL_TEXTURE_CUBE_MAP_POSITIVE_X + k,<br>
&gt; +                                               0, internalformat[j],<br>
&gt; +                                               side, side, 0,<br>
&gt; +                                               GL_RGBA, GL_FLOAT, NULL);<br>
&gt; +                                       }<br>
&gt; +                                       for (k = 0; k &lt; 6; k++) {<br>
&gt; +                                               glTexSubImage2D(<br>
&gt; +                                               GL_TEXTURE_CUBE_MAP_POSITIVE_X + k,<br>
&gt; +                                               0, 0, 0,<br>
&gt; +                                               side/2, side/2,<br>
&gt; +                                               GL_RGBA, GL_FLOAT, pixels);<br>
&gt; +                                               if (glGetError() != GL_NO_ERROR)<br>
&gt; +                                               {<br>
&gt; +                                                  printf(&quot;GL Error1: while&quot;<br>
&gt; +                                                         &quot; testing %s, texture&quot;<br>
&gt; +                                                         &quot; size = %d, internal&quot;<br>
&gt; +                                                         &quot; format = %s\n&quot;,<br>
&gt; +                                                         target_string[i], side,<br>
&gt; +                                                         format_string[j]);<br>
&gt; +                                                  piglit_reset_gl_error();<br>
&gt; +                                               }<br>
&gt; +                                       }<br>
&gt; +                                       break;<br>
&gt; +                               }<br>
&gt; +                               if (glGetError() != GL_NO_ERROR)<br>
&gt; +                               {<br>
&gt; +                                  printf(&quot;GL Error2: while testing %s, texture&quot;<br>
&gt; +                                         &quot; size = %d, internal format = %s\n&quot;,<br>
&gt; +                                         target_string[i], side,<br>
&gt; +                                         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">
&gt; +                                  piglit_reset_gl_error();<br>
&gt; +                                  /* skip larger texture sizes for this texture<br>
&gt; +                                   * target<br>
&gt; +                                   */<br>
&gt; +                                  //break;<br>
&gt; +                               }<br>
&gt; +                       }<br>
&gt; +               }<br>
&gt; +               glDeleteTextures(1, &amp;tex);<br>
&gt; +       }<br>
&gt; +       /* If execution reaches this point, return PIGLIT_PASS */<br>
&gt; +       piglit_report_result(PIGLIT_PASS);<br>
&gt; +}<br>
&gt; +<br>
&gt; +enum piglit_result<br>
&gt; +piglit_display(void)<br>
&gt; +{<br>
&gt; +       return PIGLIT_FAIL;<br>
&gt; +}<br>
&gt; --<br>
&gt; 1.7.7.6<br>
&gt;<br>
</div>&gt; _______________________________________________<br>
&gt; Piglit mailing list<br>
&gt; <a href="mailto:Piglit@lists.freedesktop.org">Piglit@lists.freedesktop.org</a><br>
&gt; <a href="http://lists.freedesktop.org/mailman/listinfo/piglit" target="_blank">http://lists.freedesktop.org/mailman/listinfo/piglit</a><br>
</blockquote></div><br>