On 14 September 2012 09:03, José Fonseca <span dir="ltr"><<a href="mailto:jose.r.fonseca@gmail.com" target="_blank">jose.r.fonseca@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">
Hi Carl,<br>
<div><div class="h5"><br>
On Mon, Sep 10, 2012 at 11:11 PM, Carl Worth <<a href="mailto:cworth@cworth.org">cworth@cworth.org</a>> wrote:<br>
> I've attached a trace that demonstrates a bug in capturing texture data<br>
> blobs while tracing. The code being traced does the following:<br>
><br>
>         /* A 2x2 RGB texture requires 16 bytes with the default<br>
>          * GL_UNPACK_ALIGNMENT value of 4. */<br>
>         uint8_t data[16];<br>
><br>
>         /* ... Initialize data, gen and bind texture here ... */<br>
><br>
>         glTexImage2D (GL_TEXTURE_2D,<br>
>                       0, GL_RGB8,<br>
>                       2, 2, 0,<br>
>                       GL_RGB, GL_UNSIGNED_BYTE, data);<br>
><br>
> As you can see, the resulting trace has:<br>
><br>
>         850 glTexImage2D(target = GL_TEXTURE_2D, level = 0,<br>
>         internalformat = GL_RGB8, width = 2, height = 2, border = 0,<br>
>         format = GL_RGB, type = GL_UNSIGNED_BYTE, pixels = blob(12))<br>
><br>
> That is, the trace has captured only 12 bytes of data. But there is<br>
> required data in 14 bytes, (and for full alignment 16 bytes are<br>
> required).<br>
><br>
> It appears that _gl_image_size in glsize.hpp is doing lots of work to<br>
> compute the correct image size (and checking GL_UNPACK_ALIGNMENT). I<br>
> believe that the code that should be performing the alignment is the<br>
> following:<br>
><br>
>     if ((GLint)bits_per_pixel < alignment*8 &&<br>
>         (bits_per_pixel & 7) == 0 &&<br>
>         _is_pot(bits_per_pixel)) {<br>
>         row_stride = _align(row_stride, alignment);<br>
>     }<br>
><br>
> The second and third sub-conditions of that condition appear to be<br>
> causing the problem here. In this case bits_per_pixel is 12, so<br>
> (bits_per_pixel & 7) != 0. Also, bits_per_pixel is not a power of 2.<br>
<br>
</div></div>Actually bits_per_pixel here should be 3*8 == 24. But indeed that's not a POT.<br>
<div class="im"><br>
> I'm not sure why either of these sub-conditions are present. Why would<br>
> we not want to always satisfy the alignment requirements?<br>
><br>
> I'll follow up with a patch that just removes these<br>
> sub-conditions. Please let me know if there's some more appropriate<br>
> solution here.<br>
<br>
</div>glspec21.20061201.pdf , pg 131, says<br>
<br>
  "If the number of bits per element is not 1, 2, 4, or 8 times<br>
the number of bits in a GL ubyte, then k = nl for all values of a."<br>
<br>
where a is alignment. That is, when the number of bits per element is<br>
not 8bits, 16bits, 32bits, or 64bits, then alignment should be ignore<br>
for row_stride. </blockquote><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
The "(bits_per_pixel & 7) == 0 &&  _is_pot(bits_per_pixel)" is not<br>
fully correct either. it should be<br>
<br>
diff --git a/helpers/glsize.hpp b/helpers/glsize.hpp<br>
index a589199..cc31414 100644<br>
--- a/helpers/glsize.hpp<br>
+++ b/helpers/glsize.hpp<br>
@@ -683,9 +683,11 @@ _gl_image_size(GLenum format, GLenum type,<br>
GLsizei width, GLsizei height, GLsize<br>
<br>
     size_t row_stride = (row_length*bits_per_pixel + 7)/8;<br>
<br>
-    if ((GLint)bits_per_pixel < alignment*8 &&<br>
-        (bits_per_pixel & 7) == 0 &&<br>
-        _is_pot(bits_per_pixel)) {<br>
+    if ((bits_per_pixel == 1*8 ||<br>
+         bits_per_pixel == 2*8 ||<br>
+         bits_per_pixel == 4*8 ||<br>
+         bits_per_pixel == 8*8) &&<br>
+        (GLint)bits_per_pixel < alignment*8) {<br>
         row_stride = _align(row_stride, alignment);<br>
     }<br>
<br>
<br>
But still, AFAICT, unless I'm misinterpreting the meaning of "bits per<br>
element", apitrace is correct, and the driver/application is wrong.<br></blockquote><div><br>I think you're right, Jose.  And unless I'm much mistaken, Mesa has never followed this rule correctly.  Carl, would you mind sending me the test program you were using to investigate this?  I'd like to try it on my nVidia machine.  Assuming that the nVidia driver follows the spec, I'll file a Mesa bug report.<br>
 </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Jose<br>
</blockquote></div><br>