From 92d27236723bf42343c5d40e9e54ded6575ff485 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Wed, 7 Jul 2021 20:08:40 -0400 Subject: [PATCH] panfrost: Move arch-independent pan_format code Now pan_format.c is just tables. Signed-off-by: Alyssa Rosenzweig Part-of: --- src/panfrost/lib/meson.build | 1 + src/panfrost/lib/pan_format.c | 60 ----------------------------- src/panfrost/lib/pan_texture.h | 10 ----- src/panfrost/lib/pan_util.c | 86 ++++++++++++++++++++++++++++++++++++++++++ src/panfrost/lib/pan_util.h | 10 +++++ 5 files changed, 97 insertions(+), 70 deletions(-) create mode 100644 src/panfrost/lib/pan_util.c diff --git a/src/panfrost/lib/meson.build b/src/panfrost/lib/meson.build index f938510..745652c 100644 --- a/src/panfrost/lib/meson.build +++ b/src/panfrost/lib/meson.build @@ -38,6 +38,7 @@ libpanfrost_lib_files = files( 'pan_scoreboard.c', 'pan_scratch.c', 'pan_props.c', + 'pan_util.c', ) libpanfrost_decode_files = files( diff --git a/src/panfrost/lib/pan_format.c b/src/panfrost/lib/pan_format.c index 27f7696..24eefc3 100644 --- a/src/panfrost/lib/pan_format.c +++ b/src/panfrost/lib/pan_format.c @@ -654,63 +654,3 @@ const struct panfrost_format panfrost_pipe_format_v7[PIPE_FORMAT_COUNT] = { PAN_V7(R32G32B32X32_UINT, RGBA32UI, RGB1, L, VTR_), PAN_V7(R32G32B32X32_SINT, RGBA32I, RGB1, L, VTR_), }; - -/* 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) { - unsigned translated = (swizzle[i] > PIPE_SWIZZLE_1) ? PIPE_SWIZZLE_0 : swizzle[i]; - out |= (translated << (3*i)); - } - - return out; -} - -void -panfrost_invert_swizzle(const unsigned char *in, unsigned char *out) -{ - /* First, default to all zeroes to prevent uninitialized junk */ - - 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 */ - unsigned idx = i - PIPE_SWIZZLE_X; - out[idx] = PIPE_SWIZZLE_X + c; - } -} - -/* Formats requiring blend shaders are stored raw in the tilebuffer and will - * have 0 as their pixel format. Assumes dithering is set, I don't know of a - * case when it makes sense to turn off dithering. */ - -unsigned -panfrost_format_to_bifrost_blend(const struct panfrost_device *dev, - enum pipe_format format) -{ - mali_pixel_format pixfmt = panfrost_blendable_formats[format].bifrost; - - if (pixfmt) { - return pixfmt | ((dev->quirks & HAS_SWIZZLES) ? - panfrost_get_default_swizzle(4) : 0); - } else { - return dev->formats[format].hw; - } -} diff --git a/src/panfrost/lib/pan_texture.h b/src/panfrost/lib/pan_texture.h index a1de0da..a73fe4f 100644 --- a/src/panfrost/lib/pan_texture.h +++ b/src/panfrost/lib/pan_texture.h @@ -187,12 +187,6 @@ extern const struct pan_blendable_format panfrost_blendable_formats[PIPE_FORMAT_ extern const struct panfrost_format panfrost_pipe_format_v6[PIPE_FORMAT_COUNT]; extern const struct panfrost_format panfrost_pipe_format_v7[PIPE_FORMAT_COUNT]; -unsigned -panfrost_translate_swizzle_4(const unsigned char swizzle[4]); - -void -panfrost_invert_swizzle(const unsigned char *in, unsigned char *out); - /* Helpers to construct swizzles */ #define PAN_V6_SWIZZLE(R, G, B, A) ( \ @@ -225,10 +219,6 @@ panfrost_bifrost_swizzle(unsigned components) return components < 4 ? 0x10 : 0x00; } -unsigned -panfrost_format_to_bifrost_blend(const struct panfrost_device *dev, - enum pipe_format format); - struct pan_pool; struct pan_scoreboard; diff --git a/src/panfrost/lib/pan_util.c b/src/panfrost/lib/pan_util.c new file mode 100644 index 0000000..4bf70cd --- /dev/null +++ b/src/panfrost/lib/pan_util.c @@ -0,0 +1,86 @@ +/* + * 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 +#include "pan_texture.h" +#include "panfrost-quirks.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) { + unsigned translated = (swizzle[i] > PIPE_SWIZZLE_1) ? PIPE_SWIZZLE_0 : swizzle[i]; + out |= (translated << (3*i)); + } + + return out; +} + +void +panfrost_invert_swizzle(const unsigned char *in, unsigned char *out) +{ + /* First, default to all zeroes to prevent uninitialized junk */ + + 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 */ + unsigned idx = i - PIPE_SWIZZLE_X; + out[idx] = PIPE_SWIZZLE_X + c; + } +} + +/* Formats requiring blend shaders are stored raw in the tilebuffer and will + * have 0 as their pixel format. Assumes dithering is set, I don't know of a + * case when it makes sense to turn off dithering. */ + +unsigned +panfrost_format_to_bifrost_blend(const struct panfrost_device *dev, + enum pipe_format format) +{ + mali_pixel_format pixfmt = panfrost_blendable_formats[format].bifrost; + + if (pixfmt) { + return pixfmt | ((dev->quirks & HAS_SWIZZLES) ? + panfrost_get_default_swizzle(4) : 0); + } else { + return dev->formats[format].hw; + } +} diff --git a/src/panfrost/lib/pan_util.h b/src/panfrost/lib/pan_util.h index 37d44d8..390caba 100644 --- a/src/panfrost/lib/pan_util.h +++ b/src/panfrost/lib/pan_util.h @@ -42,4 +42,14 @@ #define PAN_DBG_PANBLIT 0x0800 #define PAN_DBG_NOINDIRECT 0x1000 +unsigned +panfrost_translate_swizzle_4(const unsigned char swizzle[4]); + +void +panfrost_invert_swizzle(const unsigned char *in, unsigned char *out); + +unsigned +panfrost_format_to_bifrost_blend(const struct panfrost_device *dev, + enum pipe_format format); + #endif /* PAN_UTIL_H */ -- 2.7.4