| 1 |
|
| 2 |
. |
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
#ifndef FREEDRENO_LRZ_LAYOUT_H_ |
| 7 |
#define FREEDRENO_LRZ_LAYOUT_H_ |
| 8 |
|
| 9 |
#include <stdint.h> |
| 10 |
|
| 11 |
#include "freedreno_layout.h" |
| 12 |
|
| 13 |
BEGINC; |
| 14 |
|
| 15 |
struct fdl_lrz_layout { |
| 16 |
uint32_t lrz_offset; |
| 17 |
uint32_t lrz_pitch; |
| 18 |
uint32_t lrz_slice_pitch; |
| 19 |
uint32_t lrz_height; |
| 20 |
uint32_t lrz_layer_size; |
| 21 |
uint32_t lrz_buffer_size; |
| 22 |
uint32_t lrz_fc_offset; |
| 23 |
uint32_t lrz_fc_size; |
| 24 |
uint32_t lrz_total_size; |
| 25 |
}; |
| 26 |
|
| 27 |
void |
| 28 |
fdl5_lrz_layout_init(struct fdl_lrz_layout *lrz_layout, uint32_t width, |
| 29 |
uint32_t height, uint32_t nr_samples); |
| 30 |
ENDC; |
| 31 |
|
| 32 |
#ifdef __cplusplus |
| 33 |
#include "common/freedreno_lrz.h" |
| 34 |
|
| 35 |
static inline void |
| 36 |
fdl6_lrz_get_super_sampled_size(uint32_t *width, uint32_t *height, |
| 37 |
uint32_t nr_samples) |
| 38 |
{ |
| 39 |
switch (nr_samples) { |
| 40 |
case 8: |
| 41 |
*height *= 2; |
| 42 |
FALLTHROUGH; |
| 43 |
case 4: |
| 44 |
*width *= 2; |
| 45 |
FALLTHROUGH; |
| 46 |
case 2: |
| 47 |
*height *= 2; |
| 48 |
break; |
| 49 |
default: |
| 50 |
break; |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
template <chip CHIP> |
| 55 |
static uint32_t |
| 56 |
fdl6_lrz_get_fc_size(uint32_t width, uint32_t height, uint32_t nr_samples, |
| 57 |
uint32_t array_layers) |
| 58 |
{ |
| 59 |
fdl6_lrz_get_super_sampled_size(&width, &height, nr_samples); |
| 60 |
|
| 61 |
unsigned nblocksx = DIV_ROUND_UP(DIV_ROUND_UP(width, 8), 16); |
| 62 |
unsigned nblocksy = DIV_ROUND_UP(DIV_ROUND_UP(height, 8), 4); |
| 63 |
|
| 64 |
uint32_t lrz_fc_size = |
| 65 |
DIV_ROUND_UP(nblocksx * nblocksy, 8) * array_layers; |
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
|
| 70 |
if (lrz_fc_size > fd_lrzfc_layout<CHIP>::FC_SIZE) { |
| 71 |
lrz_fc_size = 0; |
| 72 |
} |
| 73 |
|
| 74 |
return lrz_fc_size; |
| 75 |
} |
| 76 |
|
| 77 |
struct fdl_lrz_fdm_extra_size { |
| 78 |
uint32_t extra_width; |
| 79 |
uint32_t extra_height; |
| 80 |
}; |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
template <chip CHIP> |
| 86 |
static struct fdl_lrz_fdm_extra_size |
| 87 |
fdl6_lrz_get_max_fdm_extra_size(const struct fd_dev_info *dev_info, |
| 88 |
uint32_t width, uint32_t height, |
| 89 |
uint32_t nr_samples, uint32_t array_layers) |
| 90 |
{ |
| 91 |
constexpr uint32_t MIN_TILE_SIZE_FOR_FDM_OFFSET = 192; |
| 92 |
|
| 93 |
if (fdl6_lrz_get_fc_size<CHIP>(width, height, nr_samples, array_layers) == 0) { |
| 94 |
return {dev_info->tile_max_w, dev_info->tile_max_h}; |
| 95 |
} |
| 96 |
|
| 97 |
uint32_t max_extra_size = MIN2(dev_info->tile_max_w, dev_info->tile_max_h); |
| 98 |
uint32_t step = MIN2(dev_info->gmem_align_w, dev_info->gmem_align_h); |
| 99 |
uint32_t min_extra_size = MAX2(step, MIN_TILE_SIZE_FOR_FDM_OFFSET); |
| 100 |
|
| 101 |
while (max_extra_size > min_extra_size) { |
| 102 |
if (fdl6_lrz_get_fc_size<CHIP>(width + max_extra_size, |
| 103 |
height + max_extra_size, nr_samples, |
| 104 |
array_layers) != 0) { |
| 105 |
|
| 106 |
return {util_round_down_npot(max_extra_size, dev_info->gmem_align_w), |
| 107 |
util_round_down_npot(max_extra_size, dev_info->gmem_align_h)}; |
| 108 |
} |
| 109 |
|
| 110 |
max_extra_size -= step; |
| 111 |
} |
| 112 |
|
| 113 |
return {dev_info->tile_max_w, dev_info->tile_max_h}; |
| 114 |
} |
| 115 |
|
| 116 |
template <chip CHIP> |
| 117 |
static void |
| 118 |
fdl6_lrz_layout_init(struct fdl_lrz_layout *lrz_layout, |
| 119 |
struct fdl_layout *layout, uint32_t extra_width, |
| 120 |
uint32_t extra_height, |
| 121 |
const struct fd_dev_info *dev_info, uint32_t lrz_offset, |
| 122 |
uint32_t array_layers) |
| 123 |
{ |
| 124 |
if (CHIP >= A8XX) { |
| 125 |
static const struct lrz_block { |
| 126 |
uint16_t width; |
| 127 |
uint16_t height; |
| 128 |
} lrz_block_sizes[4][4] = { |
| 129 |
[0] = { |
| 130 |
[MSAA_ONE] = { 64, 128 }, |
| 131 |
[MSAA_TWO] = { 64, 64 }, |
| 132 |
[MSAA_FOUR] = { 32, 64 }, |
| 133 |
[MSAA_EIGHT] = { 32, 32 }, |
| 134 |
}, |
| 135 |
[1] = { |
| 136 |
[MSAA_ONE] = { 128, 128 }, |
| 137 |
[MSAA_TWO] = { 128, 64 }, |
| 138 |
[MSAA_FOUR] = { 64, 64 }, |
| 139 |
[MSAA_EIGHT] = { 64, 32 }, |
| 140 |
}, |
| 141 |
[2] = { |
| 142 |
[MSAA_ONE] = { 192, 128 }, |
| 143 |
[MSAA_TWO] = { 192, 64 }, |
| 144 |
[MSAA_FOUR] = { 96, 64 }, |
| 145 |
[MSAA_EIGHT] = { 96, 32 }, |
| 146 |
}, |
| 147 |
[3] = { |
| 148 |
[MSAA_ONE] = { 128, 256 }, |
| 149 |
[MSAA_TWO] = { 128, 128 }, |
| 150 |
[MSAA_FOUR] = { 64, 128 }, |
| 151 |
[MSAA_EIGHT] = { 64, 64 }, |
| 152 |
}, |
| 153 |
}; |
| 154 |
const struct lrz_block *lrz_block = &lrz_block_sizes[dev_info->num_slices - 1][ffs(layout->nr_samples) - 1]; |
| 155 |
|
| 156 |
const unsigned per_slice_block_width_in_tiles = 8; |
| 157 |
const unsigned per_slice_block_height_in_tiles = 16; |
| 158 |
|
| 159 |
const unsigned surface_width_in_blocks = |
| 160 |
DIV_ROUND_UP(layout->width0 + extra_width, lrz_block->width); |
| 161 |
const unsigned surface_height_in_blocks = |
| 162 |
DIV_ROUND_UP(layout->height0 + extra_height, lrz_block->height); |
| 163 |
|
| 164 |
lrz_layout->lrz_pitch = |
| 165 |
align(surface_width_in_blocks * per_slice_block_width_in_tiles, 64); |
| 166 |
|
| 167 |
|
| 168 |
|
| 169 |
|
| 170 |
|
| 171 |
lrz_layout->lrz_height = dev_info->num_slices * |
| 172 |
surface_height_in_blocks * per_slice_block_height_in_tiles; |
| 173 |
|
| 174 |
lrz_layout->lrz_slice_pitch = surface_height_in_blocks * |
| 175 |
per_slice_block_height_in_tiles * lrz_layout->lrz_pitch * 2; |
| 176 |
|
| 177 |
lrz_layout->lrz_layer_size = lrz_layout->lrz_slice_pitch * dev_info->num_slices; |
| 178 |
} else { |
| 179 |
unsigned width = layout->width0 + extra_width; |
| 180 |
unsigned height = layout->height0 + extra_height; |
| 181 |
fdl6_lrz_get_super_sampled_size(&width, &height, layout->nr_samples); |
| 182 |
|
| 183 |
lrz_layout->lrz_pitch = align(DIV_ROUND_UP(width, 8), 32); |
| 184 |
lrz_layout->lrz_height = align(DIV_ROUND_UP(height, 8), 32); |
| 185 |
|
| 186 |
lrz_layout->lrz_layer_size = |
| 187 |
lrz_layout->lrz_pitch * lrz_layout->lrz_height * sizeof(uint16_t); |
| 188 |
} |
| 189 |
|
| 190 |
lrz_layout->lrz_offset = lrz_offset; |
| 191 |
lrz_layout->lrz_buffer_size = lrz_layout->lrz_layer_size * array_layers; |
| 192 |
|
| 193 |
|
| 194 |
lrz_layout->lrz_fc_size = fdl6_lrz_get_fc_size<CHIP>( |
| 195 |
layout->width0 + extra_width, layout->height0 + extra_height, |
| 196 |
layout->nr_samples, array_layers); |
| 197 |
|
| 198 |
if (!dev_info->props.enable_lrz_fast_clear) { |
| 199 |
lrz_layout->lrz_fc_size = 0; |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
uint32_t lrz_size = lrz_layout->lrz_buffer_size * |
| 204 |
(CHIP >= A7XX ? 2 : 1); |
| 205 |
|
| 206 |
if (dev_info->props.enable_lrz_fast_clear || |
| 207 |
dev_info->props.has_lrz_dir_tracking) { |
| 208 |
lrz_layout->lrz_fc_offset = |
| 209 |
lrz_layout->lrz_offset + lrz_size; |
| 210 |
lrz_size += sizeof(fd_lrzfc_layout<CHIP>); |
| 211 |
} |
| 212 |
|
| 213 |
lrz_layout->lrz_total_size = lrz_size; |
| 214 |
|
| 215 |
uint32_t lrz_clear_height = lrz_layout->lrz_height * array_layers; |
| 216 |
if (((lrz_clear_height - 1) >> 14) > 0) { |
| 217 |
|
| 218 |
lrz_layout->lrz_height = 0; |
| 219 |
lrz_layout->lrz_total_size = 0; |
| 220 |
} |
| 221 |
} |
| 222 |
#endif |
| 223 |
|
| 224 |
#endif |