| 1 |
/* |
| 2 |
* Copyright (C) 2008 VMware, Inc. |
| 3 |
* Copyright (C) 2014 Broadcom |
| 4 |
* Copyright (C) 2018-2019 Alyssa Rosenzweig |
| 5 |
* Copyright (C) 2019-2020 Collabora, Ltd. |
| 6 |
* SPDX-License-Identifier: MIT |
| 7 |
*/ |
| 8 |
|
| 9 |
#ifndef __PAN_LAYOUT_H |
| 10 |
#define __PAN_LAYOUT_H |
| 11 |
|
| 12 |
#ifdef __cplusplus |
| 13 |
extern "C" { |
| 14 |
#endif |
| 15 |
|
| 16 |
#include <stdbool.h> |
| 17 |
|
| 18 |
#include "genxml/gen_macros.h" |
| 19 |
|
| 20 |
#include "util/format/u_format.h" |
| 21 |
|
| 22 |
#define MAX_MIP_LEVELS 17 |
| 23 |
#define MAX_IMAGE_PLANES 3 |
| 24 |
|
| 25 |
struct pan_mod_handler; |
| 26 |
|
| 27 |
struct pan_afbc_image_slice_layout { |
| 28 |
struct { |
| 29 |
/* Number of bytes between two rows of AFBC headers. */ |
| 30 |
uint32_t row_stride_B; |
| 31 |
|
| 32 |
/* For 3D textures, this is the size in bytes of AFBC headers covering |
| 33 |
* a single Z slice. For 2D this is the total header size. This size is |
| 34 |
* the utile header size, it doesn't count the padding needed to meet the |
| 35 |
* body alignment constraints. Pass this to pan_afbc_body_offset() to get |
| 36 |
* the body offset. |
| 37 |
*/ |
| 38 |
uint32_t surface_size_B; |
| 39 |
} header; |
| 40 |
|
| 41 |
/* For 3D textures, this is the stride in bytes between AFBC headers of two |
| 42 |
* consecutive Z slices. For 2D, this is the total size of the 2D level. |
| 43 |
*/ |
| 44 |
uint64_t surface_stride_B; |
| 45 |
}; |
| 46 |
|
| 47 |
struct pan_tiled_or_linear_image_slice_layout { |
| 48 |
/* Number of bytes between two rows of tiles/lines. */ |
| 49 |
uint32_t row_stride_B; |
| 50 |
|
| 51 |
/* For 3D textures, this is the stride in bytes between two |
| 52 |
* consecutive Z slices. For 2DMS textures, this is the stride in bytes |
| 53 |
* between two sample planes. |
| 54 |
*/ |
| 55 |
uint64_t surface_stride_B; |
| 56 |
}; |
| 57 |
|
| 58 |
struct pan_image_slice_layout { |
| 59 |
/* Offset in bytes relative to the base bo bound. |
| 60 |
* |
| 61 |
* Unlike gallium, vulkan has to report explicit image subres layout which |
| 62 |
* disallows to hide the planar plane offset into the bo mapping. So we let |
| 63 |
* the slice offsets to include the plane offset of the native multi-planar |
| 64 |
* images to be consistent with the imported ones via explicit layout info. |
| 65 |
* Doing so allows us to use a single code path to correctly: |
| 66 |
* - report image subres layout and memory requirement |
| 67 |
* - bind image memory |
| 68 |
*/ |
| 69 |
uint64_t offset_B; |
| 70 |
|
| 71 |
/* Size of the MIP level in bytes. */ |
| 72 |
uint64_t size_B; |
| 73 |
|
| 74 |
/* Some properties have a different meaning depending on the modifier. |
| 75 |
* Those are placed in different structs under a union. */ |
| 76 |
union { |
| 77 |
/* Used only for AFBC images. */ |
| 78 |
struct pan_afbc_image_slice_layout afbc; |
| 79 |
/* Used for linear, u-tiled and AFRC images. */ |
| 80 |
struct pan_tiled_or_linear_image_slice_layout tiled_or_linear; |
| 81 |
}; |
| 82 |
|
| 83 |
/* If checksumming is enabled following the slice, what |
| 84 |
* is its offset/stride? */ |
| 85 |
struct { |
| 86 |
uint64_t offset_B; |
| 87 |
uint32_t stride_B; |
| 88 |
uint32_t size_B; |
| 89 |
} crc; |
| 90 |
}; |
| 91 |
|
| 92 |
struct pan_image_extent { |
| 93 |
unsigned width; |
| 94 |
unsigned height; |
| 95 |
unsigned depth; |
| 96 |
}; |
| 97 |
|
| 98 |
struct pan_image_props { |
| 99 |
uint64_t modifier; |
| 100 |
enum pipe_format format; |
| 101 |
struct pan_image_extent extent_px; |
| 102 |
unsigned nr_samples; |
| 103 |
enum mali_texture_dimension dim; |
| 104 |
unsigned nr_slices; |
| 105 |
unsigned array_size; |
| 106 |
bool crc; |
| 107 |
}; |
| 108 |
|
| 109 |
struct pan_image_layout { |
| 110 |
struct pan_image_slice_layout slices[MAX_MIP_LEVELS]; |
| 111 |
|
| 112 |
union { |
| 113 |
struct { |
| 114 |
int mode; |
| 115 |
} afbc; |
| 116 |
}; |
| 117 |
|
| 118 |
/* Image plane data size in bytes */ |
| 119 |
uint64_t data_size_B; |
| 120 |
uint64_t array_stride_B; |
| 121 |
}; |
| 122 |
|
| 123 |
struct pan_image_layout_constraints { |
| 124 |
/* |
| 125 |
* Plane offset in bytes |
| 126 |
* - For native images, it's the planar plane offset. |
| 127 |
* - For imported images, it's the user specified explicit offset. |
| 128 |
* |
| 129 |
* To be noted, this offset might be adjusted to choose an optimal alignment, |
| 130 |
* unless the layout constraints are explicit (wsi_row_patch_B != 0). |
| 131 |
*/ |
| 132 |
uint64_t offset_B; |
| 133 |
|
| 134 |
/* Row pitch in bytes. Non-zero if layout is explicit. */ |
| 135 |
uint32_t wsi_row_pitch_B; |
| 136 |
|
| 137 |
/* When true, AFBC/AFRC imports are stricter than they were when those |
| 138 |
* modifiers where introduced. */ |
| 139 |
bool strict; |
| 140 |
}; |
| 141 |
|
| 142 |
/* |
| 143 |
* Represents the block size of a single plane. For AFBC, this represents the |
| 144 |
* superblock size. For u-interleaving, this represents the tile size. |
| 145 |
*/ |
| 146 |
struct pan_image_block_size { |
| 147 |
/** Width of block */ |
| 148 |
unsigned width; |
| 149 |
|
| 150 |
/** Height of blocks */ |
| 151 |
unsigned height; |
| 152 |
}; |
| 153 |
|
| 154 |
/* |
| 155 |
* Determine the required alignment for the slice offset of an image. For |
| 156 |
* now, this is always aligned on 64-byte boundaries. */ |
| 157 |
static inline uint32_t |
| 158 |
pan_image_slice_align(uint64_t modifier) |
| 159 |
{ |
| 160 |
return 64; |
| 161 |
} |
| 162 |
|
| 163 |
static inline uint32_t |
| 164 |
pan_linear_or_tiled_row_align_req(unsigned arch, enum pipe_format format, |
| 165 |
unsigned plane_idx) |
| 166 |
{ |
| 167 |
if (arch < 7) { |
| 168 |
unsigned nplanes = util_format_get_num_planes(format); |
| 169 |
|
| 170 |
/* If this is a planar format, align on the plane blocksize. */ |
| 171 |
if (nplanes > 1) { |
| 172 |
enum pipe_format plane_format = |
| 173 |
util_format_get_plane_format(format, plane_idx); |
| 174 |
|
| 175 |
return util_next_power_of_two(util_format_get_blocksize(plane_format)); |
| 176 |
} |
| 177 |
|
| 178 |
/* Align on blocksize if the format is compressed. */ |
| 179 |
if (util_format_is_compressed(format)) |
| 180 |
return util_next_power_of_two(util_format_get_blocksize(format)); |
| 181 |
|
| 182 |
const struct util_format_description *fdesc = |
| 183 |
util_format_description(format); |
| 184 |
unsigned comp_sz_bits = 0; |
| 185 |
for (unsigned i = 0; i < ARRAY_SIZE(fdesc->channel); i++) { |
| 186 |
if (!fdesc->channel[0].size) |
| 187 |
continue; |
| 188 |
|
| 189 |
/* Align on a pixel if any component is not 8-bit aligned or not a |
| 190 |
* power of two. */ |
| 191 |
if (fdesc->channel[0].size % 8 != 0 || |
| 192 |
!util_is_power_of_two_nonzero(fdesc->channel[0].size)) |
| 193 |
return util_next_power_of_two(util_format_get_blocksize(format)); |
| 194 |
|
| 195 |
/* Align on a pixel if not all components have the same size. */ |
| 196 |
if (comp_sz_bits != 0 && comp_sz_bits != fdesc->channel[0].size) |
| 197 |
return util_next_power_of_two(util_format_get_blocksize(format)); |
| 198 |
|
| 199 |
comp_sz_bits = fdesc->channel[0].size; |
| 200 |
} |
| 201 |
|
| 202 |
/* If all components are the same size, 8-bit aligned and a power of two, |
| 203 |
* align on a component. */ |
| 204 |
return comp_sz_bits / 8; |
| 205 |
} |
| 206 |
|
| 207 |
switch (format) { |
| 208 |
/* For v7+, NV12/NV21/I420 have a looser alignment requirement of 16 bytes */ |
| 209 |
case PIPE_FORMAT_R8G8B8_420_UNORM_PACKED: |
| 210 |
case PIPE_FORMAT_R8_G8B8_420_UNORM: |
| 211 |
case PIPE_FORMAT_G8_B8R8_420_UNORM: |
| 212 |
case PIPE_FORMAT_R8_G8_B8_420_UNORM: |
| 213 |
case PIPE_FORMAT_R8_B8_G8_420_UNORM: |
| 214 |
case PIPE_FORMAT_R8_G8B8_422_UNORM: |
| 215 |
case PIPE_FORMAT_R8_B8G8_422_UNORM: |
| 216 |
return 16; |
| 217 |
/* the 10 bit formats have even looser alignment */ |
| 218 |
case PIPE_FORMAT_R10G10B10_420_UNORM_PACKED: |
| 219 |
case PIPE_FORMAT_R10_G10B10_420_UNORM: |
| 220 |
case PIPE_FORMAT_R10_G10B10_422_UNORM: |
| 221 |
return 1; |
| 222 |
default: |
| 223 |
return 64; |
| 224 |
} |
| 225 |
} |
| 226 |
|
| 227 |
/* |
| 228 |
* Given a format, determine the tile size used for u-interleaving. For formats |
| 229 |
* that are already block compressed, this is 4x4. For all other formats, this |
| 230 |
* is 16x16, hence the modifier name. |
| 231 |
*/ |
| 232 |
static inline struct pan_image_block_size |
| 233 |
pan_u_interleaved_tile_size_el(enum pipe_format format) |
| 234 |
{ |
| 235 |
if (util_format_is_compressed(format)) { |
| 236 |
return (struct pan_image_block_size){4, 4}; |
| 237 |
} else { |
| 238 |
assert(16 % util_format_get_blockwidth(format) == 0); |
| 239 |
assert(16 % util_format_get_blockheight(format) == 0); |
| 240 |
return (struct pan_image_block_size){ |
| 241 |
.width = 16 / util_format_get_blockwidth(format), |
| 242 |
.height = 16 / util_format_get_blockheight(format), |
| 243 |
}; |
| 244 |
} |
| 245 |
} |
| 246 |
|
| 247 |
/* Given a format, determine the tile size used for interleaved 64k. */ |
| 248 |
static inline struct pan_image_block_size |
| 249 |
pan_interleaved_64k_tile_size_el(enum pipe_format format) |
| 250 |
{ |
| 251 |
switch (util_format_get_blocksize(format)) { |
| 252 |
case 1: return (struct pan_image_block_size){256, 256}; |
| 253 |
case 2: return (struct pan_image_block_size){256, 128}; |
| 254 |
case 4: return (struct pan_image_block_size){128, 128}; |
| 255 |
case 8: return (struct pan_image_block_size){128, 64}; |
| 256 |
case 16: return (struct pan_image_block_size){64, 64}; |
| 257 |
default: |
| 258 |
UNREACHABLE("unsupported format"); |
| 259 |
return (struct pan_image_block_size){0, 0}; |
| 260 |
} |
| 261 |
} |
| 262 |
|
| 263 |
#ifdef __cplusplus |
| 264 |
} /* extern C */ |
| 265 |
#endif |
| 266 |
|
| 267 |
#endif |