Path: blob/21.2-virgl/src/panfrost/lib/pan_util.c
4560 views
/*1* Copyright (C) 2019 Collabora, Ltd.2*3* Permission is hereby granted, free of charge, to any person obtaining a4* copy of this software and associated documentation files (the "Software"),5* to deal in the Software without restriction, including without limitation6* the rights to use, copy, modify, merge, publish, distribute, sublicense,7* and/or sell copies of the Software, and to permit persons to whom the8* Software is furnished to do so, subject to the following conditions:9*10* The above copyright notice and this permission notice (including the next11* paragraph) shall be included in all copies or substantial portions of the12* Software.13*14* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR15* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,16* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL17* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER18* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,19* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE20* SOFTWARE.21*/2223#include <stdio.h>24#include "pan_texture.h"25#include "panfrost-quirks.h"2627/* Translate a PIPE swizzle quad to a 12-bit Mali swizzle code. PIPE28* swizzles line up with Mali swizzles for the XYZW01, but PIPE swizzles have29* an additional "NONE" field that we have to mask out to zero. Additionally,30* PIPE swizzles are sparse but Mali swizzles are packed */3132unsigned33panfrost_translate_swizzle_4(const unsigned char swizzle[4])34{35unsigned out = 0;3637for (unsigned i = 0; i < 4; ++i) {38unsigned translated = (swizzle[i] > PIPE_SWIZZLE_1) ? PIPE_SWIZZLE_0 : swizzle[i];39out |= (translated << (3*i));40}4142return out;43}4445void46panfrost_invert_swizzle(const unsigned char *in, unsigned char *out)47{48/* First, default to all zeroes to prevent uninitialized junk */4950for (unsigned c = 0; c < 4; ++c)51out[c] = PIPE_SWIZZLE_0;5253/* Now "do" what the swizzle says */5455for (unsigned c = 0; c < 4; ++c) {56unsigned char i = in[c];5758/* Who cares? */59assert(PIPE_SWIZZLE_X == 0);60if (i > PIPE_SWIZZLE_W)61continue;6263/* Invert */64unsigned idx = i - PIPE_SWIZZLE_X;65out[idx] = PIPE_SWIZZLE_X + c;66}67}6869/* Formats requiring blend shaders are stored raw in the tilebuffer and will70* have 0 as their pixel format. Assumes dithering is set, I don't know of a71* case when it makes sense to turn off dithering. */7273unsigned74panfrost_format_to_bifrost_blend(const struct panfrost_device *dev,75enum pipe_format format)76{77mali_pixel_format pixfmt = (dev->arch >= 7) ?78panfrost_blendable_formats_v7[format].bifrost :79panfrost_blendable_formats_v6[format].bifrost;8081return pixfmt ?: dev->formats[format].hw;82}838485