| 1 |
/* |
| 2 |
* Copyright (C) 2019 Collabora, Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#include "pan_util.h" |
| 7 |
#include <stdio.h> |
| 8 |
|
| 9 |
/* Translate a PIPE swizzle quad to a 12-bit Mali swizzle code. PIPE |
| 10 |
* swizzles line up with Mali swizzles for the XYZW01, but PIPE swizzles have |
| 11 |
* an additional "NONE" field that we have to mask out to zero. Additionally, |
| 12 |
* PIPE swizzles are sparse but Mali swizzles are packed */ |
| 13 |
|
| 14 |
unsigned |
| 15 |
pan_translate_swizzle_4(const unsigned char swizzle[4]) |
| 16 |
{ |
| 17 |
unsigned out = 0; |
| 18 |
|
| 19 |
for (unsigned i = 0; i < 4; ++i) { |
| 20 |
assert(swizzle[i] <= PIPE_SWIZZLE_1); |
| 21 |
out |= (swizzle[i] << (3 * i)); |
| 22 |
} |
| 23 |
|
| 24 |
return out; |
| 25 |
} |
| 26 |
|
| 27 |
void |
| 28 |
pan_invert_swizzle(const unsigned char *in, unsigned char *out) |
| 29 |
{ |
| 30 |
/* First, default to all zeroes, both to prevent uninitialized junk |
| 31 |
and to provide a known baseline so we can tell when components |
| 32 |
have been modified |
| 33 |
*/ |
| 34 |
|
| 35 |
for (unsigned c = 0; c < 4; ++c) |
| 36 |
out[c] = PIPE_SWIZZLE_0; |
| 37 |
|
| 38 |
/* Now "do" what the swizzle says */ |
| 39 |
|
| 40 |
for (unsigned c = 0; c < 4; ++c) { |
| 41 |
unsigned char i = in[c]; |
| 42 |
|
| 43 |
/* Who cares? */ |
| 44 |
assert(PIPE_SWIZZLE_X == 0); |
| 45 |
if (i > PIPE_SWIZZLE_W) |
| 46 |
continue; |
| 47 |
|
| 48 |
/* Invert (only if we haven't already applied) */ |
| 49 |
unsigned idx = i - PIPE_SWIZZLE_X; |
| 50 |
if (out[idx] == PIPE_SWIZZLE_0) |
| 51 |
out[idx] = PIPE_SWIZZLE_X + c; |
| 52 |
} |
| 53 |
} |