diff options
author | Alyssa Rosenzweig <[email protected]> | 2020-02-18 12:17:59 -0500 |
---|---|---|
committer | Alyssa Rosenzweig <[email protected]> | 2020-02-21 07:27:01 -0500 |
commit | 58f14018b4f0e47d72f718f322f8aa0a5b8d0f0a (patch) | |
tree | 73e4bdc479dcfc718c84c9a3acac5491fab2f7a4 /src/panfrost | |
parent | 5ddf7ad9d2098d21e1346b8ceb2756901ae1b0c1 (diff) |
panfrost: Move pan_afbc.c to root
Now that PIPE formats are shared across Mesa, this well-documented piece
of code is a good fit for root panfrost, let's move it and get a little
closer to taming the mess of resources.
Signed-off-by: Alyssa Rosenzweig <[email protected]>
Reviewed-by: Boris Brezillon <[email protected]>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/merge_requests/3858>
Diffstat (limited to 'src/panfrost')
-rw-r--r-- | src/panfrost/encoder/meson.build | 1 | ||||
-rw-r--r-- | src/panfrost/encoder/pan_afbc.c | 126 | ||||
-rw-r--r-- | src/panfrost/encoder/pan_texture.h | 9 |
3 files changed, 136 insertions, 0 deletions
diff --git a/src/panfrost/encoder/meson.build b/src/panfrost/encoder/meson.build index d1335ab8f02..650289586fa 100644 --- a/src/panfrost/encoder/meson.build +++ b/src/panfrost/encoder/meson.build @@ -22,6 +22,7 @@ libpanfrost_encoder_files = files( 'pan_encoder.h', + 'pan_afbc.c', 'pan_attributes.c', 'pan_invocation.c', 'pan_sampler.c', diff --git a/src/panfrost/encoder/pan_afbc.c b/src/panfrost/encoder/pan_afbc.c new file mode 100644 index 00000000000..f29020e15b8 --- /dev/null +++ b/src/panfrost/encoder/pan_afbc.c @@ -0,0 +1,126 @@ +/* + * 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. + * + * Authors: + * Alyssa Rosenzweig <[email protected]> + */ + +#include "pan_texture.h" + +/* Arm FrameBuffer Compression (AFBC) is a lossless compression scheme natively + * implemented in Mali GPUs (as well as many display controllers paired with + * Mali GPUs, etc). Where possible, Panfrost prefers to use AFBC for both + * rendering and texturing. In most cases, this is a performance-win due to a + * dramatic reduction in memory bandwidth and cache locality compared to a + * linear resources. + * + * AFBC divides the framebuffer into 16x16 tiles (other sizes possible, TODO: + * do we need to support this?). So, the width and height each must be aligned + * up to 16 pixels. This is inherently good for performance; note that for a 4 + * byte-per-pixel format like RGBA8888, that means that rows are 16*4=64 byte + * aligned, which is the cache-line size. + * + * For each AFBC-compressed resource, there is a single contiguous + * (CPU/GPU-shared) buffer. This buffer itself is divided into two parts: + * header and body, placed immediately after each other. + * + * The AFBC header contains 16 bytes of metadata per tile. + * + * The AFBC body is the same size as the original linear resource (padded to + * the nearest tile). Although the body comes immediately after the header, it + * must also be cache-line aligned, so there can sometimes be a bit of padding + * between the header and body. + * + * As an example, a 64x64 RGBA framebuffer contains 64/16 = 4 tiles horizontally and + * 4 tiles vertically. There are 4*4=16 tiles in total, each containing 16 + * bytes of metadata, so there is a 16*16=256 byte header. 64x64 is already + * tile aligned, so the body is 64*64 * 4 bytes per pixel = 16384 bytes of + * body. + * + * From userspace, Panfrost needs to be able to calculate these sizes. It + * explicitly does not and can not know the format of the data contained within + * this header and body. The GPU has native support for AFBC encode/decode. For + * an internal FBO or a framebuffer used for scanout with an AFBC-compatible + * winsys/display-controller, the buffer is maintained AFBC throughout flight, + * and the driver never needs to know the internal data. For edge cases where + * the driver really does need to read/write from the AFBC resource, we + * generate a linear staging buffer and use the GPU to blit AFBC<--->linear. + * TODO: Implement me. */ + +#define AFBC_TILE_WIDTH 16 +#define AFBC_TILE_HEIGHT 16 +#define AFBC_HEADER_BYTES_PER_TILE 16 +#define AFBC_CACHE_ALIGN 64 + +/* Is it possible to AFBC compress a particular format? Common formats (and + * YUV) are compressible. Some obscure formats are not and fallback on linear, + * at a performance hit. Also, if you need to disable AFBC entirely in the + * driver for debug/profiling, just always return false here. */ + +bool +panfrost_format_supports_afbc(enum pipe_format format) +{ + const struct util_format_description *desc = + util_format_description(format); + + /* sRGB cannot be AFBC, but it can be tiled. TODO: Verify. The blob + * does not do AFBC for SRGB8_ALPHA8, but it's not clear why it + * shouldn't be able to. */ + + if (desc->colorspace == UTIL_FORMAT_COLORSPACE_SRGB) + return false; + + if (util_format_is_rgba8_variant(desc)) + return true; + + /* Z32/Z16/S8 are all compressible as well, but they are implemented as + * Z24S8 with wasted bits. So Z24S8 is the only format we actually need + * to handle compressed, and we can make the state tracker deal with + * the rest. */ + + if (format == PIPE_FORMAT_Z24_UNORM_S8_UINT) + return true; + + /* TODO: AFBC of other formats */ + + return false; +} + +unsigned +panfrost_afbc_header_size(unsigned width, unsigned height) +{ + /* Align to tile */ + unsigned aligned_width = ALIGN_POT(width, AFBC_TILE_WIDTH); + unsigned aligned_height = ALIGN_POT(height, AFBC_TILE_HEIGHT); + + /* Compute size in tiles, rather than pixels */ + unsigned tile_count_x = aligned_width / AFBC_TILE_WIDTH; + unsigned tile_count_y = aligned_height / AFBC_TILE_HEIGHT; + unsigned tile_count = tile_count_x * tile_count_y; + + /* Multiply to find the header size */ + unsigned header_bytes = tile_count * AFBC_HEADER_BYTES_PER_TILE; + + /* Align and go */ + return ALIGN_POT(header_bytes, AFBC_CACHE_ALIGN); + +} diff --git a/src/panfrost/encoder/pan_texture.h b/src/panfrost/encoder/pan_texture.h index 54b2e39122e..043fcc3af10 100644 --- a/src/panfrost/encoder/pan_texture.h +++ b/src/panfrost/encoder/pan_texture.h @@ -29,6 +29,7 @@ #define __PAN_TEXTURE_H #include <stdbool.h> +#include "util/format/u_format.h" struct panfrost_slice { unsigned offset; @@ -54,4 +55,12 @@ panfrost_compute_checksum_size( unsigned width, unsigned height); +/* AFBC */ + +bool +panfrost_format_supports_afbc(enum pipe_format format); + +unsigned +panfrost_afbc_header_size(unsigned width, unsigned height); + #endif |