Path: blob/21.2-virgl/src/panfrost/lib/pan_texture.h
4560 views
/*1* Copyright (C) 2008 VMware, Inc.2* Copyright (C) 2014 Broadcom3* Copyright (C) 2018-2019 Alyssa Rosenzweig4* Copyright (C) 2019-2020 Collabora, Ltd.5*6* Permission is hereby granted, free of charge, to any person obtaining a7* copy of this software and associated documentation files (the "Software"),8* to deal in the Software without restriction, including without limitation9* the rights to use, copy, modify, merge, publish, distribute, sublicense,10* and/or sell copies of the Software, and to permit persons to whom the11* Software is furnished to do so, subject to the following conditions:12*13* The above copyright notice and this permission notice (including the next14* paragraph) shall be included in all copies or substantial portions of the15* Software.16*17* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR18* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,19* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL20* THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER21* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,22* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE23* SOFTWARE.24*25*/2627#ifndef __PAN_TEXTURE_H28#define __PAN_TEXTURE_H2930#include <stdbool.h>31#include "drm-uapi/drm_fourcc.h"32#include "util/format/u_format.h"33#include "compiler/shader_enums.h"34#include "midgard_pack.h"35#include "pan_bo.h"36#include "pan_device.h"37#include "pan_util.h"38#include "pan_format.h"3940#define PAN_MODIFIER_COUNT 441extern uint64_t pan_best_modifiers[PAN_MODIFIER_COUNT];4243struct pan_image_slice_layout {44unsigned offset;45unsigned line_stride;46unsigned row_stride;47unsigned surface_stride;4849struct {50/* Size of the AFBC header preceding each slice */51unsigned header_size;5253/* Size of the AFBC body */54unsigned body_size;5556/* Stride between two rows of AFBC headers */57unsigned row_stride;5859/* Stride between AFBC headers of two consecutive surfaces.60* For 3D textures, this must be set to header size since61* AFBC headers are allocated together, for 2D arrays this62* should be set to size0, since AFBC headers are placed at63* the beginning of each layer64*/65unsigned surface_stride;66} afbc;6768/* If checksumming is enabled following the slice, what69* is its offset/stride? */70struct {71unsigned offset;72unsigned stride;73unsigned size;74} crc;7576unsigned size;77};7879enum pan_image_crc_mode {80PAN_IMAGE_CRC_NONE,81PAN_IMAGE_CRC_INBAND,82PAN_IMAGE_CRC_OOB,83};8485#ifndef PAN_PACK_H86/* Avoid the GenXML dependence */8788enum mali_texture_dimension {89MALI_TEXTURE_DIMENSION_CUBE = 0,90MALI_TEXTURE_DIMENSION_1D = 1,91MALI_TEXTURE_DIMENSION_2D = 2,92MALI_TEXTURE_DIMENSION_3D = 3,93};94#endif9596struct pan_image_layout {97uint64_t modifier;98enum pipe_format format;99unsigned width, height, depth;100unsigned nr_samples;101enum mali_texture_dimension dim;102unsigned nr_slices;103struct pan_image_slice_layout slices[MAX_MIP_LEVELS];104unsigned array_size;105unsigned array_stride;106unsigned data_size;107108enum pan_image_crc_mode crc_mode;109/* crc_size != 0 only if crc_mode == OOB otherwise CRC words are110* counted in data_size */111unsigned crc_size;112};113114struct pan_image_mem {115struct panfrost_bo *bo;116unsigned offset;117};118119struct pan_image {120struct pan_image_mem data;121struct pan_image_mem crc;122struct pan_image_layout layout;123};124125struct pan_image_view {126/* Format, dimension and sample count of the view might differ from127* those of the image (2D view of a 3D image surface for instance).128*/129enum pipe_format format;130enum mali_texture_dimension dim;131unsigned first_level, last_level;132unsigned first_layer, last_layer;133unsigned char swizzle[4];134const struct pan_image *image;135136/* If EXT_multisampled_render_to_texture is used, this may be137* greater than image->layout.nr_samples. */138unsigned nr_samples;139140/* Only valid if dim == 1D, needed to implement buffer views */141struct {142unsigned offset;143unsigned size;144} buf;145};146147unsigned148panfrost_compute_checksum_size(149struct pan_image_slice_layout *slice,150unsigned width,151unsigned height);152153/* AFBC */154155bool156panfrost_format_supports_afbc(const struct panfrost_device *dev,157enum pipe_format format);158159#define AFBC_HEADER_BYTES_PER_TILE 16160161unsigned162panfrost_afbc_header_size(unsigned width, unsigned height);163164bool165panfrost_afbc_can_ytr(enum pipe_format format);166167unsigned168panfrost_block_dim(uint64_t modifier, bool width, unsigned plane);169170unsigned171panfrost_estimate_texture_payload_size(const struct panfrost_device *dev,172const struct pan_image_view *iview);173174void175panfrost_new_texture(const struct panfrost_device *dev,176const struct pan_image_view *iview,177void *out,178const struct panfrost_ptr *payload);179180unsigned181panfrost_get_layer_stride(const struct pan_image_layout *layout,182unsigned level);183184unsigned185panfrost_texture_offset(const struct pan_image_layout *layout,186unsigned level, unsigned array_idx,187unsigned surface_idx);188189struct pan_pool;190struct pan_scoreboard;191192/* DRM modifier helper */193194#define drm_is_afbc(mod) \195((mod >> 52) == (DRM_FORMAT_MOD_ARM_TYPE_AFBC | \196(DRM_FORMAT_MOD_VENDOR_ARM << 4)))197198/* Map modifiers to mali_texture_layout for packing in a texture descriptor */199200static inline enum mali_texture_layout201panfrost_modifier_to_layout(uint64_t modifier)202{203if (drm_is_afbc(modifier))204return MALI_TEXTURE_LAYOUT_AFBC;205else if (modifier == DRM_FORMAT_MOD_ARM_16X16_BLOCK_U_INTERLEAVED)206return MALI_TEXTURE_LAYOUT_TILED;207else if (modifier == DRM_FORMAT_MOD_LINEAR)208return MALI_TEXTURE_LAYOUT_LINEAR;209else210unreachable("Invalid modifer");211}212213struct pan_image_explicit_layout {214unsigned offset;215unsigned line_stride;216};217218bool219pan_image_layout_init(const struct panfrost_device *dev,220struct pan_image_layout *layout,221uint64_t modifier,222enum pipe_format format,223enum mali_texture_dimension dim,224unsigned width, unsigned height, unsigned depth,225unsigned array_size, unsigned nr_samples,226unsigned nr_slices,227enum pan_image_crc_mode crc_mode,228const struct pan_image_explicit_layout *explicit_layout);229230struct pan_surface {231union {232mali_ptr data;233struct {234mali_ptr header;235mali_ptr body;236} afbc;237};238};239240void241pan_iview_get_surface(const struct pan_image_view *iview,242unsigned level, unsigned layer, unsigned sample,243struct pan_surface *surf);244245#endif246247248