[Piglit] [PATCH v2 4/4] GL_MESA_pack_invert: make it endian-safe

Oded Gabbay oded.gabbay at gmail.com
Thu Mar 31 11:51:59 UTC 2016


On Tue, Mar 29, 2016 at 10:37 AM, Ilia Mirkin <imirkin at alum.mit.edu> wrote:
> On Tue, Mar 29, 2016 at 5:06 AM, Oded Gabbay <oded.gabbay at gmail.com> wrote:
>> In this test we use GL_BGRA + GL_UNSIGNED_BYTE. However, the test
>> function constructs the expected colors array as 32-bit values, which is
>> a wrong way to build expected results values when testing array_of_bytes
>> (GL_UNSIGNED_BYTE) in an endian-safe way.
>>
>> This patch fixes this bug by building the expected colors using array of
>> array_of_bytes.
>>
>> This fixes the test in llvmpipe, softpipe and r600g in big-endian machine.
>>
>> Signed-off-by: Oded Gabbay <oded.gabbay at gmail.com>
>> ---
>>  tests/spec/mesa_pack_invert/readpixels.c | 12 ++++++------
>>  1 file changed, 6 insertions(+), 6 deletions(-)
>>
>> diff --git a/tests/spec/mesa_pack_invert/readpixels.c b/tests/spec/mesa_pack_invert/readpixels.c
>> index f8fbebe..af508a3 100644
>> --- a/tests/spec/mesa_pack_invert/readpixels.c
>> +++ b/tests/spec/mesa_pack_invert/readpixels.c
>> @@ -47,18 +47,18 @@ PIGLIT_GL_TEST_CONFIG_END
>>  static bool
>>  check_unorm(const uint32_t *data, const char *name)
>>  {
>> -       static const uint32_t colors[] = {
>> -               0x000000ff,
>> -               0xffffffff,
>> -               0x00ff0000,
>> -               0x0000ff00
>> +       static const uint8_t colors[4][4] = {
>> +               {0xff, 0x00, 0x00, 0x00},
>> +               {0xff, 0xff, 0xff, 0xff},
>> +               {0x00, 0x00, 0xff, 0x00},
>> +               {0x00, 0xff, 0x00, 0x00}
>>         };
>>         int x, y;
>>
>>         for (y = 0; y < H; y++) {
>>                 for (x = 0; x < W; x++) {
>>                         int i = (y >= H / 2) * 2 + (x >= W / 2);
>> -                       uint32_t expected = colors[i];
>> +                       uint32_t expected = *((uint32_t *) ((uint8_t *) &colors[i][0]));
>
> Is the double-cast really necessary here? You can't just do
>
> *(uint32_t *)&colors[i][0]
>
> ?

Yes, I'll change that.
Oded
>
>>
>>                         if (data[y * W + x] != expected) {
>>                                 fprintf(stderr,
>> --
>> 2.5.5
>>
>> _______________________________________________
>> Piglit mailing list
>> Piglit at lists.freedesktop.org
>> https://lists.freedesktop.org/mailman/listinfo/piglit


More information about the Piglit mailing list