[Mesa-dev] [V3 PATCH 2/8] mesa: Change 4 color component ubyte formats
Marek Olšák
maraeo at gmail.com
Fri Jan 17 13:24:00 PST 2014
Incorrect. You have to manually check if the pack and unpack functions
access the components using bitwise operations or arrays.
Consider char pix[]. The array formats use arrays for accessing, for example:
char *p = &pix[(y*width+x)*4];
p[0] = r;
p[1] = g;
p[2] = b;
p[3] = a;
Packed formats use bitwise operators for accessing, for example:
uint32_t *p = &pix[(y*width+x)*4];
*p = r | (g << 8) | (b << 16) | (a << 24);
It's okay to have both RGBA8 array and packed formats. For example,
Gallium has these array formats:
PIPE_FORMAT_R8G8B8A8_UNORM
PIPE_FORMAT_B8G8R8A8_UNORM
PIPE_FORMAT_A8R8G8B8_UNORM
PIPE_FORMAT_A8B8G8R8_UNORM
And it defines these packed formats by using the array formats
according to the CPU architecture:
#if defined(PIPE_ARCH_LITTLE_ENDIAN)
#define PIPE_FORMAT_RGBA8888_UNORM PIPE_FORMAT_R8G8B8A8_UNORM
#define PIPE_FORMAT_BGRA8888_UNORM PIPE_FORMAT_B8G8R8A8_UNORM
#define PIPE_FORMAT_ARGB8888_UNORM PIPE_FORMAT_A8R8G8B8_UNORM
#define PIPE_FORMAT_ABGR8888_UNORM PIPE_FORMAT_A8B8G8R8_UNORM
#elif defined(PIPE_ARCH_BIG_ENDIAN)
#define PIPE_FORMAT_ABGR8888_UNORM PIPE_FORMAT_R8G8B8A8_UNORM
#define PIPE_FORMAT_ARGB8888_UNORM PIPE_FORMAT_B8G8R8A8_UNORM
#define PIPE_FORMAT_BGRA8888_UNORM PIPE_FORMAT_A8R8G8B8_UNORM
#define PIPE_FORMAT_RGBA8888_UNORM PIPE_FORMAT_A8B8G8R8_UNORM
#endif
This way, Gallium has all the possible RGBA8 array formats and also
the possible RGBA8 packed formats, so we can use whatever we want.
Marek
On Fri, Jan 17, 2014 at 9:41 PM, Mark Mueller <markkmueller at gmail.com> wrote:
>
>
>
> On Fri, Jan 17, 2014 at 8:58 AM, Brian Paul <brianp at vmware.com> wrote:
>>
>> On 01/17/2014 03:45 AM, Mark Mueller wrote:
>>>
>>> Change all 4 color component unsigned byte formats to meet spec:
>>> s/MESA_FORMAT_RGBA8888\b/MESA_FORMAT_ABGR_UNORM8/g
>>> s/MESA_FORMAT_RGBA8888_REV\b/MESA_FORMAT_RGBA_UNORM8/g
>>> s/MESA_FORMAT_ARGB8888\b/MESA_FORMAT_BGRA_UNORM8/g
>>> s/MESA_FORMAT_ARGB8888_REV\b/MESA_FORMAT_ARGB_UNORM8/g
>>> s/MESA_FORMAT_RGBX8888\b/MESA_FORMAT_XBGR_UNORM8/g
>>> s/MESA_FORMAT_RGBX8888_REV\b/MESA_FORMAT_RGBX_UNORM8/g
>>> s/MESA_FORMAT_XRGB8888\b/MESA_FORMAT_BGRX_UNORM8/g
>>> s/MESA_FORMAT_XRGB8888_REV\b/MESA_FORMAT_XRGB_UNORM8/g
>>>
>>
>>
>> I'm not sure this is right. If you look at the existing code such as
>> src/mesa/main/format_{un}pack.c you'll see that these formats are treated as
>> packed formats, not arrays.
>>
>
> Ah. Array formats are really rare with OGL, that was unexpected but now
> really ancient issues with memory throughput optimization are surfacing.
> Those were the days.
>
> Thus Array Types would only include the much smaller group of all 32
> bit-per-component formats, and formats with an odd number of 8 or 16 bit
> components. Right?
>
> So the naming convention would be a derivation of MESA_FORMAT_R8G8B8A8_UNORM
> for these.
>
> Mark
>
>
> _______________________________________________
> mesa-dev mailing list
> mesa-dev at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/mesa-dev
>
More information about the mesa-dev
mailing list