[Mesa-dev] [PATCH 1/2] mesa: Add functions _mesa_[un]pack_is_default()

Neil Roberts neil at linux.intel.com
Fri Oct 12 04:31:01 PDT 2012

Chad Versace <chad.versace at linux.intel.com> writes:

> +bool
> +_mesa_pack_is_default(struct gl_context *ctx)
> +{
> +   return memcmp(&ctx->Pack, &ctx->DefaultPacking,
> +                 sizeof(struct gl_pixelstore_attrib)) == 0;
> +}

It seems like a shame that this wouldn't catch the cases where the row
length and alignment are set to values that are equivalent to the
default. For example, the API in Cogl just accepts a rowstride and we
use that to calculate values to pass for the alignment and row length.
That means the row length would never be zero and Cogl would never be
able to take advantage of the optimisation. We can't be the only ones
who do that! Maybe the function could also take the width and format and
check that the alignment is a multiple of the cpp of the format and that
the row length == the width.

The gl_pixelstore_attrib has a pointer at the bottom after 3 byte
fields. That means the struct will have some padding to make it aligned
and for the memcmp to pass it will also have have the same values for
the unused padding bytes. I'm not sure if that's a real concern or not
but it doesn't seem very robust.

- Neil

More information about the mesa-dev mailing list