mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-05-28 14:18:13 +02:00
panfrost_invert_swizzle produces a (one-sided) inverse, that is a function g such that g(f(x)) = x. However, it is actually used in some cases where we want a two-sided inverse, where we also have f(g(x)) = x. An example is its use to pre-swizzle border color values so that a later pass will un-swizzle them. If the swizzle is not one-to-one this two sided inverse does not exist. However, we can do better than the original code, e.g. for an RRR1 swizzle inverse produced was originally B000, which when applied on the wrong side results in BBB1 as output, whereas R000 would produce the desired RRR1 output. Using the first valid component we see, rather than the last one, is thus usually better. The "correct" solution is to re-write all the code that uses an inverse to handle non-unique inverses. But frankly these uses only crop up in fairly niche cases like tests, and it's probably not worth spending a lot of effort to deal with these edge cases when this patch fixes most of them. Fixes some failing piglit ext_framebuffer_multisample tests. Reviewed-by: Erik Faye-Lund <erik.faye-lund@collabora.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/31060>
71 lines
2.4 KiB
C
71 lines
2.4 KiB
C
/*
|
|
* Copyright (C) 2019 Collabora, Ltd.
|
|
*
|
|
* Permission is hereby granted, free of charge, to any person obtaining a
|
|
* copy of this software and associated documentation files (the "Software"),
|
|
* to deal in the Software without restriction, including without limitation
|
|
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
|
|
* and/or sell copies of the Software, and to permit persons to whom the
|
|
* Software is furnished to do so, subject to the following conditions:
|
|
*
|
|
* The above copyright notice and this permission notice (including the next
|
|
* paragraph) shall be included in all copies or substantial portions of the
|
|
* Software.
|
|
*
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
|
|
* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
* SOFTWARE.
|
|
*/
|
|
|
|
#include <stdio.h>
|
|
#include "pan_texture.h"
|
|
|
|
/* Translate a PIPE swizzle quad to a 12-bit Mali swizzle code. PIPE
|
|
* swizzles line up with Mali swizzles for the XYZW01, but PIPE swizzles have
|
|
* an additional "NONE" field that we have to mask out to zero. Additionally,
|
|
* PIPE swizzles are sparse but Mali swizzles are packed */
|
|
|
|
unsigned
|
|
panfrost_translate_swizzle_4(const unsigned char swizzle[4])
|
|
{
|
|
unsigned out = 0;
|
|
|
|
for (unsigned i = 0; i < 4; ++i) {
|
|
assert(swizzle[i] <= PIPE_SWIZZLE_1);
|
|
out |= (swizzle[i] << (3 * i));
|
|
}
|
|
|
|
return out;
|
|
}
|
|
|
|
void
|
|
panfrost_invert_swizzle(const unsigned char *in, unsigned char *out)
|
|
{
|
|
/* First, default to all zeroes, both to prevent uninitialized junk
|
|
and to provide a known baseline so we can tell when components
|
|
have been modified
|
|
*/
|
|
|
|
for (unsigned c = 0; c < 4; ++c)
|
|
out[c] = PIPE_SWIZZLE_0;
|
|
|
|
/* Now "do" what the swizzle says */
|
|
|
|
for (unsigned c = 0; c < 4; ++c) {
|
|
unsigned char i = in[c];
|
|
|
|
/* Who cares? */
|
|
assert(PIPE_SWIZZLE_X == 0);
|
|
if (i > PIPE_SWIZZLE_W)
|
|
continue;
|
|
|
|
/* Invert (only if we haven't already applied) */
|
|
unsigned idx = i - PIPE_SWIZZLE_X;
|
|
if (out[idx] == PIPE_SWIZZLE_0)
|
|
out[idx] = PIPE_SWIZZLE_X + c;
|
|
}
|
|
}
|