A texture-data alignment bug when tracing

Carl Worth cworth at cworth.org
Mon Sep 10 15:11:13 PDT 2012


I've attached a trace that demonstrates a bug in capturing texture data
blobs while tracing. The code being traced does the following:

	/* A 2x2 RGB texture requires 16 bytes with the default
	 * GL_UNPACK_ALIGNMENT value of 4. */
	uint8_t data[16];

	/* ... Initialize data, gen and bind texture here ... */

	glTexImage2D (GL_TEXTURE_2D,
		      0, GL_RGB8,
		      2, 2, 0,
		      GL_RGB, GL_UNSIGNED_BYTE, data);

As you can see, the resulting trace has:

	850 glTexImage2D(target = GL_TEXTURE_2D, level = 0,
	internalformat = GL_RGB8, width = 2, height = 2, border = 0,
	format = GL_RGB, type = GL_UNSIGNED_BYTE, pixels = blob(12))

That is, the trace has captured only 12 bytes of data. But there is
required data in 14 bytes, (and for full alignment 16 bytes are
required).

It appears that _gl_image_size in glsize.hpp is doing lots of work to
compute the correct image size (and checking GL_UNPACK_ALIGNMENT). I
believe that the code that should be performing the alignment is the
following:

    if ((GLint)bits_per_pixel < alignment*8 &&
        (bits_per_pixel & 7) == 0 &&
        _is_pot(bits_per_pixel)) {
        row_stride = _align(row_stride, alignment);
    }

The second and third sub-conditions of that condition appear to be
causing the problem here. In this case bits_per_pixel is 12, so
(bits_per_pixel & 7) != 0. Also, bits_per_pixel is not a power of 2.

I'm not sure why either of these sub-conditions are present. Why would
we not want to always satisfy the alignment requirements?

I'll follow up with a patch that just removes these
sub-conditions. Please let me know if there's some more appropriate
solution here.

-Carl

-- 
carl.d.worth at intel.com

-------------- next part --------------
A non-text attachment was scrubbed...
Name: texture-alignment-bug.trace
Type: application/octet-stream
Size: 57717 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/apitrace/attachments/20120910/4f3c84dc/attachment-0001.obj>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: not available
URL: <http://lists.freedesktop.org/archives/apitrace/attachments/20120910/4f3c84dc/attachment-0001.pgp>


More information about the apitrace mailing list