• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2019 Collabora, Ltd.
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21  * SOFTWARE.
22  */
23 
24 #include <stdio.h>
25 #include "pan_texture.h"
26 
27 /* Translate a PIPE swizzle quad to a 12-bit Mali swizzle code. PIPE
28  * swizzles line up with Mali swizzles for the XYZW01, but PIPE swizzles have
29  * an additional "NONE" field that we have to mask out to zero. Additionally,
30  * PIPE swizzles are sparse but Mali swizzles are packed */
31 
32 unsigned
panfrost_translate_swizzle_4(const unsigned char swizzle[4])33 panfrost_translate_swizzle_4(const unsigned char swizzle[4])
34 {
35    unsigned out = 0;
36 
37    for (unsigned i = 0; i < 4; ++i) {
38       assert(swizzle[i] <= PIPE_SWIZZLE_1);
39       out |= (swizzle[i] << (3 * i));
40    }
41 
42    return out;
43 }
44 
45 void
panfrost_invert_swizzle(const unsigned char * in,unsigned char * out)46 panfrost_invert_swizzle(const unsigned char *in, unsigned char *out)
47 {
48    /* First, default to all zeroes to prevent uninitialized junk */
49 
50    for (unsigned c = 0; c < 4; ++c)
51       out[c] = PIPE_SWIZZLE_0;
52 
53    /* Now "do" what the swizzle says */
54 
55    for (unsigned c = 0; c < 4; ++c) {
56       unsigned char i = in[c];
57 
58       /* Who cares? */
59       assert(PIPE_SWIZZLE_X == 0);
60       if (i > PIPE_SWIZZLE_W)
61          continue;
62 
63       /* Invert */
64       unsigned idx = i - PIPE_SWIZZLE_X;
65       out[idx] = PIPE_SWIZZLE_X + c;
66    }
67 }
68