From ad44f587a8e3adbfa76aaea88f59e1f0724805b7 Mon Sep 17 00:00:00 2001 From: Alyssa Rosenzweig Date: Tue, 18 Feb 2020 18:11:42 -0500 Subject: [PATCH] panfrost: Move format translation to root Since PIPE formats are now shared across Mesa we can do this, and the routines themselves are good enough code that I'm happy to move them here. We'll use them momentarily. Signed-off-by: Alyssa Rosenzweig Reviewed-by: Boris Brezillon Part-of: --- src/gallium/drivers/panfrost/Makefile.sources | 2 - src/gallium/drivers/panfrost/meson.build | 1 - src/gallium/drivers/panfrost/pan_assemble.c | 1 - src/gallium/drivers/panfrost/pan_context.c | 1 - src/gallium/drivers/panfrost/pan_context.h | 1 + src/gallium/drivers/panfrost/pan_format.h | 66 ----------- src/gallium/drivers/panfrost/pan_fragment.c | 1 - src/gallium/drivers/panfrost/pan_mfbd.c | 3 - src/gallium/drivers/panfrost/pan_sfbd.c | 1 - src/gallium/drivers/panfrost/pan_varyings.c | 1 - src/panfrost/encoder/meson.build | 1 + .../encoder}/pan_format.c | 106 ++++++++---------- src/panfrost/encoder/pan_texture.h | 35 ++++++ 13 files changed, 85 insertions(+), 135 deletions(-) delete mode 100644 src/gallium/drivers/panfrost/pan_format.h rename src/{gallium/drivers/panfrost => panfrost/encoder}/pan_format.c (87%) diff --git a/src/gallium/drivers/panfrost/Makefile.sources b/src/gallium/drivers/panfrost/Makefile.sources index 2fd578877ef..835f2255fb6 100644 --- a/src/gallium/drivers/panfrost/Makefile.sources +++ b/src/gallium/drivers/panfrost/Makefile.sources @@ -19,8 +19,6 @@ C_SOURCES := \ pan_compute.c \ pan_context.c \ pan_context.h \ - pan_format.c \ - pan_format.h \ pan_fragment.c \ pan_attributes.c \ pan_job.c \ diff --git a/src/gallium/drivers/panfrost/meson.build b/src/gallium/drivers/panfrost/meson.build index 7b01ee47635..b79c4c0b8d0 100644 --- a/src/gallium/drivers/panfrost/meson.build +++ b/src/gallium/drivers/panfrost/meson.build @@ -35,7 +35,6 @@ files_panfrost = files( 'pan_job.c', 'pan_allocate.c', 'pan_assemble.c', - 'pan_format.c', 'pan_blending.c', 'pan_blend_shaders.c', 'pan_blend_cso.c', diff --git a/src/gallium/drivers/panfrost/pan_assemble.c b/src/gallium/drivers/panfrost/pan_assemble.c index d6b63219c3a..1ef81c5e20f 100644 --- a/src/gallium/drivers/panfrost/pan_assemble.c +++ b/src/gallium/drivers/panfrost/pan_assemble.c @@ -27,7 +27,6 @@ #include #include "pan_bo.h" #include "pan_context.h" -#include "pan_format.h" #include "pan_util.h" #include "compiler/nir/nir.h" diff --git a/src/gallium/drivers/panfrost/pan_context.c b/src/gallium/drivers/panfrost/pan_context.c index f234d9435c3..0d69036b9a2 100644 --- a/src/gallium/drivers/panfrost/pan_context.c +++ b/src/gallium/drivers/panfrost/pan_context.c @@ -29,7 +29,6 @@ #include "pan_bo.h" #include "pan_context.h" -#include "pan_format.h" #include "panfrost-quirks.h" #include "util/macros.h" diff --git a/src/gallium/drivers/panfrost/pan_context.h b/src/gallium/drivers/panfrost/pan_context.h index 1387c910b90..1a570261363 100644 --- a/src/gallium/drivers/panfrost/pan_context.h +++ b/src/gallium/drivers/panfrost/pan_context.h @@ -33,6 +33,7 @@ #include "pan_job.h" #include "pan_blend.h" #include "pan_encoder.h" +#include "pan_texture.h" #include "pipe/p_compiler.h" #include "pipe/p_config.h" diff --git a/src/gallium/drivers/panfrost/pan_format.h b/src/gallium/drivers/panfrost/pan_format.h deleted file mode 100644 index b82493df425..00000000000 --- a/src/gallium/drivers/panfrost/pan_format.h +++ /dev/null @@ -1,66 +0,0 @@ -/* - * © Copyright 2018 Alyssa Rosenzweig - * - * 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. - * - */ - -#ifndef __PAN_FORMAT_H__ -#define __PAN_FORMAT_H__ - -#include "pan_context.h" -#include "util/format/u_format.h" - -unsigned -panfrost_translate_swizzle_4(const unsigned char swizzle[4]); - -enum mali_format -panfrost_find_format(const struct util_format_description *desc); - -void -panfrost_invert_swizzle(const unsigned char *in, unsigned char *out); - -bool -panfrost_is_z24s8_variant(enum pipe_format fmt); - -static inline unsigned -panfrost_get_default_swizzle(unsigned components) -{ - switch (components) { - case 1: - return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_ZERO << 3) | - (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9); - case 2: - return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) | - (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9); - case 3: - return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) | - (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ONE << 9); - case 4: - return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) | - (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ALPHA << 9); - default: - unreachable("Invalid number of components"); - } -} - -#endif - - diff --git a/src/gallium/drivers/panfrost/pan_fragment.c b/src/gallium/drivers/panfrost/pan_fragment.c index e2d71c57a10..80b25a3893c 100644 --- a/src/gallium/drivers/panfrost/pan_fragment.c +++ b/src/gallium/drivers/panfrost/pan_fragment.c @@ -24,7 +24,6 @@ #include "pan_context.h" #include "pan_util.h" -#include "pan_format.h" #include "panfrost-quirks.h" #include "util/format/u_format.h" diff --git a/src/gallium/drivers/panfrost/pan_mfbd.c b/src/gallium/drivers/panfrost/pan_mfbd.c index c2cc11d1119..799fac14084 100644 --- a/src/gallium/drivers/panfrost/pan_mfbd.c +++ b/src/gallium/drivers/panfrost/pan_mfbd.c @@ -25,9 +25,6 @@ #include "pan_bo.h" #include "pan_context.h" #include "pan_util.h" -#include "pan_format.h" - -#include "util/format/u_format.h" static struct mali_rt_format panfrost_mfbd_format(struct pipe_surface *surf) diff --git a/src/gallium/drivers/panfrost/pan_sfbd.c b/src/gallium/drivers/panfrost/pan_sfbd.c index 6e80649abf6..fa62916a104 100644 --- a/src/gallium/drivers/panfrost/pan_sfbd.c +++ b/src/gallium/drivers/panfrost/pan_sfbd.c @@ -25,7 +25,6 @@ #include "pan_bo.h" #include "pan_context.h" #include "pan_util.h" -#include "pan_format.h" #include "util/format/u_format.h" diff --git a/src/gallium/drivers/panfrost/pan_varyings.c b/src/gallium/drivers/panfrost/pan_varyings.c index 52496aa26d7..0ec4d5633d2 100644 --- a/src/gallium/drivers/panfrost/pan_varyings.c +++ b/src/gallium/drivers/panfrost/pan_varyings.c @@ -25,7 +25,6 @@ #include "pan_bo.h" #include "pan_context.h" -#include "pan_format.h" #include "util/u_prim.h" static mali_ptr diff --git a/src/panfrost/encoder/meson.build b/src/panfrost/encoder/meson.build index 650289586fa..6a82fb30b96 100644 --- a/src/panfrost/encoder/meson.build +++ b/src/panfrost/encoder/meson.build @@ -24,6 +24,7 @@ libpanfrost_encoder_files = files( 'pan_afbc.c', 'pan_attributes.c', + 'pan_format.c', 'pan_invocation.c', 'pan_sampler.c', 'pan_tiler.c', diff --git a/src/gallium/drivers/panfrost/pan_format.c b/src/panfrost/encoder/pan_format.c similarity index 87% rename from src/gallium/drivers/panfrost/pan_format.c rename to src/panfrost/encoder/pan_format.c index b7f5e4449cf..80253072e89 100644 --- a/src/gallium/drivers/panfrost/pan_format.c +++ b/src/panfrost/encoder/pan_format.c @@ -1,5 +1,5 @@ /* - * © Copyright 2018 Alyssa Rosenzweig + * 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"), @@ -20,30 +20,13 @@ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * + * Authors: + * Alyssa Rosenzweig */ -#include "pan_format.h" - -/* From panwrap/panwrap-decoder, but we don't want to bring in all those headers */ -char *panwrap_format_name(enum mali_format format); - -/* Translate a Gallium swizzle quad to a 12-bit Mali swizzle code. Gallium - * swizzles line up with Mali swizzles for the XYZW01, but Gallium has an - * additional "NONE" field that we have to mask out to zero. Additionally, - * Gallium 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; -} +#include +#include "panfrost-job.h" +#include "pan_texture.h" static unsigned panfrost_translate_channel_width(unsigned size) @@ -57,11 +40,8 @@ panfrost_translate_channel_width(unsigned size) return MALI_CHANNEL_16; case 32: return MALI_CHANNEL_32; - default: { - fprintf(stderr, "Invalid width: %d\n", size); - assert(0); - return 0; - } + default: + unreachable("Invalid format width\n"); } } @@ -76,16 +56,14 @@ panfrost_translate_channel_type(unsigned type, unsigned size, bool norm) return norm ? MALI_FORMAT_SNORM : MALI_FORMAT_SINT; case UTIL_FORMAT_TYPE_FLOAT: - if (size == 16) { - /* With FLOAT, fp16 */ + /* fp16 -- SINT, fp32 -- UNORM ... gotta use those bits */ + + if (size == 16) return MALI_FORMAT_SINT; - } else if (size == 32) { - /* With FLOAT< fp32 */ + else if (size == 32) return MALI_FORMAT_UNORM; - } else { - assert(0); - return 0; - } + else + unreachable("Invalid float size"); default: unreachable("Invalid type"); @@ -96,7 +74,8 @@ panfrost_translate_channel_type(unsigned type, unsigned size, bool norm) * description */ enum mali_format -panfrost_find_format(const struct util_format_description *desc) { +panfrost_find_format(const struct util_format_description *desc) +{ /* Find first non-VOID channel */ struct util_format_channel_description chan = desc->channel[0]; @@ -112,14 +91,6 @@ panfrost_find_format(const struct util_format_description *desc) { /* Check for special formats */ switch (desc->format) { - case PIPE_FORMAT_YV12: - case PIPE_FORMAT_YV16: - case PIPE_FORMAT_IYUV: - case PIPE_FORMAT_NV21: - fprintf(stderr, "YUV format type %s (%d) is not yet supported, but it's probably close to NV12!\n", desc->name, desc->format); - assert(0); - break; - case PIPE_FORMAT_NV12: return MALI_NV12; @@ -254,6 +225,38 @@ panfrost_find_format(const struct util_format_description *desc) { return (enum mali_format) format; } +/* Is a format encoded like Z24S8 and therefore compatible for render? */ + +bool +panfrost_is_z24s8_variant(enum pipe_format fmt) +{ + switch (fmt) { + case PIPE_FORMAT_Z24_UNORM_S8_UINT: + case PIPE_FORMAT_Z24X8_UNORM: + return true; + default: + return false; + } +} + +/* 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) { @@ -277,16 +280,3 @@ panfrost_invert_swizzle(const unsigned char *in, unsigned char *out) out[idx] = PIPE_SWIZZLE_X + c; } } - -/* Is a format encoded like Z24S8 and therefore compatible for render? */ -bool -panfrost_is_z24s8_variant(enum pipe_format fmt) -{ - switch (fmt) { - case PIPE_FORMAT_Z24_UNORM_S8_UINT: - case PIPE_FORMAT_Z24X8_UNORM: - return true; - default: - return false; - } -} diff --git a/src/panfrost/encoder/pan_texture.h b/src/panfrost/encoder/pan_texture.h index 043fcc3af10..29be91cca83 100644 --- a/src/panfrost/encoder/pan_texture.h +++ b/src/panfrost/encoder/pan_texture.h @@ -63,4 +63,39 @@ panfrost_format_supports_afbc(enum pipe_format format); unsigned panfrost_afbc_header_size(unsigned width, unsigned height); +/* Formats */ + +enum mali_format +panfrost_find_format(const struct util_format_description *desc); + +bool +panfrost_is_z24s8_variant(enum pipe_format fmt); + +unsigned +panfrost_translate_swizzle_4(const unsigned char swizzle[4]); + +void +panfrost_invert_swizzle(const unsigned char *in, unsigned char *out); + +static inline unsigned +panfrost_get_default_swizzle(unsigned components) +{ + switch (components) { + case 1: + return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_ZERO << 3) | + (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9); + case 2: + return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) | + (MALI_CHANNEL_ZERO << 6) | (MALI_CHANNEL_ONE << 9); + case 3: + return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) | + (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ONE << 9); + case 4: + return (MALI_CHANNEL_RED << 0) | (MALI_CHANNEL_GREEN << 3) | + (MALI_CHANNEL_BLUE << 6) | (MALI_CHANNEL_ALPHA << 9); + default: + unreachable("Invalid number of components"); + } +} + #endif -- 2.30.2