| 1 |
/* |
| 2 |
* Copyright (C) 2021 Collabora, Ltd. |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#ifndef __PAN_DESC_H |
| 7 |
#define __PAN_DESC_H |
| 8 |
|
| 9 |
#include "genxml/gen_macros.h" |
| 10 |
|
| 11 |
#include "kmod/pan_kmod.h" |
| 12 |
#include "pan_image.h" |
| 13 |
#include "pan_pool.h" |
| 14 |
|
| 15 |
struct pan_buffer_view { |
| 16 |
enum pipe_format format; |
| 17 |
struct { |
| 18 |
unsigned narrow; |
| 19 |
unsigned hdr; |
| 20 |
} astc; |
| 21 |
unsigned width_el; |
| 22 |
uint64_t base; |
| 23 |
}; |
| 24 |
|
| 25 |
struct pan_compute_dim { |
| 26 |
uint32_t x, y, z; |
| 27 |
}; |
| 28 |
|
| 29 |
struct pan_fb_color_attachment { |
| 30 |
const struct pan_image_view *view; |
| 31 |
bool *crc_valid; |
| 32 |
bool clear; |
| 33 |
bool preload; |
| 34 |
bool discard; |
| 35 |
uint32_t clear_value[4]; |
| 36 |
}; |
| 37 |
|
| 38 |
struct pan_fb_zs_attachment { |
| 39 |
struct { |
| 40 |
const struct pan_image_view *zs, *s; |
| 41 |
} view; |
| 42 |
|
| 43 |
struct { |
| 44 |
bool z, s; |
| 45 |
} clear; |
| 46 |
|
| 47 |
struct { |
| 48 |
bool z, s; |
| 49 |
} discard; |
| 50 |
|
| 51 |
struct { |
| 52 |
bool z, s; |
| 53 |
} preload; |
| 54 |
|
| 55 |
struct { |
| 56 |
float depth; |
| 57 |
uint8_t stencil; |
| 58 |
} clear_value; |
| 59 |
}; |
| 60 |
|
| 61 |
struct pan_tiler_context { |
| 62 |
union { |
| 63 |
struct { |
| 64 |
uint64_t desc; |
| 65 |
/* A tiler descriptor can only handle a limited amount of layers. |
| 66 |
* If the number of layers is bigger than this, several tiler |
| 67 |
* descriptors will be issued, each with a different layer_offset. |
| 68 |
*/ |
| 69 |
uint8_t layer_offset; |
| 70 |
} valhall; |
| 71 |
struct { |
| 72 |
uint64_t desc; |
| 73 |
} bifrost; |
| 74 |
struct { |
| 75 |
/* Sum of vertex counts (for non-indexed draws), index counts, or ~0 if |
| 76 |
* any indirect draws are used. Helps tune hierarchy masks. |
| 77 |
*/ |
| 78 |
uint32_t vertex_count; |
| 79 |
bool disable; |
| 80 |
bool no_hierarchical_tiling; |
| 81 |
uint64_t polygon_list; |
| 82 |
struct { |
| 83 |
uint64_t start; |
| 84 |
unsigned size; |
| 85 |
} heap; |
| 86 |
} midgard; |
| 87 |
}; |
| 88 |
}; |
| 89 |
|
| 90 |
struct pan_tls_info { |
| 91 |
struct { |
| 92 |
uint64_t ptr; |
| 93 |
unsigned size; |
| 94 |
} tls; |
| 95 |
|
| 96 |
struct { |
| 97 |
unsigned instances; |
| 98 |
uint64_t ptr; |
| 99 |
unsigned size; |
| 100 |
} wls; |
| 101 |
}; |
| 102 |
|
| 103 |
struct pan_fb_bifrost_info { |
| 104 |
struct { |
| 105 |
struct pan_ptr dcds; |
| 106 |
unsigned modes[3]; |
| 107 |
} pre_post; |
| 108 |
}; |
| 109 |
|
| 110 |
struct pan_bbox { |
| 111 |
unsigned minx, miny, maxx, maxy; |
| 112 |
}; |
| 113 |
|
| 114 |
struct pan_fb_info { |
| 115 |
unsigned width, height; |
| 116 |
/* Draw-extent controlled by viewports/scissors. |
| 117 |
* Max values are exclusive */ |
| 118 |
struct pan_bbox draw_extent; |
| 119 |
/* frame_bounding_box controls the bounding box in the framebuffer |
| 120 |
* descriptor for the entire pass. This is being controlled by the |
| 121 |
* renderArea of a renderpass in Vulkan. On GL, this covers the |
| 122 |
* entire frame. Max values are exclusive. */ |
| 123 |
struct pan_bbox frame_bounding_box; |
| 124 |
unsigned nr_samples; |
| 125 |
unsigned force_samples; /* samples used for rasterization */ |
| 126 |
unsigned rt_count; |
| 127 |
struct pan_fb_color_attachment rts[8]; |
| 128 |
struct pan_fb_zs_attachment zs; |
| 129 |
|
| 130 |
struct { |
| 131 |
unsigned stride; |
| 132 |
uint64_t base; |
| 133 |
} tile_map; |
| 134 |
|
| 135 |
union { |
| 136 |
struct pan_fb_bifrost_info bifrost; |
| 137 |
}; |
| 138 |
|
| 139 |
/* Optimal tile buffer size. */ |
| 140 |
unsigned tile_buf_budget; |
| 141 |
unsigned z_tile_buf_budget; |
| 142 |
unsigned tile_size; |
| 143 |
unsigned cbuf_allocation; |
| 144 |
|
| 145 |
/* Sample position array. */ |
| 146 |
uint64_t sample_positions; |
| 147 |
|
| 148 |
/* Only used on Valhall */ |
| 149 |
bool sprite_coord_origin; |
| 150 |
bool first_provoking_vertex; |
| 151 |
bool allow_hsr_prepass; |
| 152 |
|
| 153 |
/* indicates whether pixel local storage is enabled */ |
| 154 |
bool pls_enabled; |
| 155 |
}; |
| 156 |
|
| 157 |
struct pan_clean_tile { |
| 158 |
/* clean_tile_write_enable mask on the 8 color attachments. */ |
| 159 |
uint8_t write_rt_mask; |
| 160 |
|
| 161 |
/* clean_tile_write_enable flag on the depth/stencil attachment. */ |
| 162 |
uint8_t write_zs : 1; |
| 163 |
}; |
| 164 |
|
| 165 |
static inline bool |
| 166 |
pan_clean_tile_write_rt_enabled(struct pan_clean_tile clean_tile, |
| 167 |
unsigned index) |
| 168 |
{ |
| 169 |
return (clean_tile.write_rt_mask >> index) & 1; |
| 170 |
} |
| 171 |
|
| 172 |
static inline bool |
| 173 |
pan_clean_tile_write_zs_enabled(struct pan_clean_tile clean_tile) |
| 174 |
{ |
| 175 |
return clean_tile.write_zs; |
| 176 |
} |
| 177 |
|
| 178 |
static inline bool |
| 179 |
pan_clean_tile_write_any_set(struct pan_clean_tile clean_tile) |
| 180 |
{ |
| 181 |
return clean_tile.write_rt_mask || clean_tile.write_zs; |
| 182 |
} |
| 183 |
|
| 184 |
static inline unsigned |
| 185 |
pan_wls_instances(const struct pan_compute_dim *dim) |
| 186 |
{ |
| 187 |
return util_next_power_of_two(dim->x) * util_next_power_of_two(dim->y) * |
| 188 |
util_next_power_of_two(dim->z); |
| 189 |
} |
| 190 |
|
| 191 |
static inline unsigned |
| 192 |
pan_wls_adjust_size(unsigned wls_size) |
| 193 |
{ |
| 194 |
return util_next_power_of_two(MAX2(wls_size, 128)); |
| 195 |
} |
| 196 |
|
| 197 |
static inline unsigned |
| 198 |
pan_calc_workgroups_per_task(const struct pan_compute_dim *shader_local_size, |
| 199 |
const struct pan_kmod_dev_props *props) |
| 200 |
{ |
| 201 |
/* Each shader core can run N tasks and a total of M threads at any single |
| 202 |
* time, thus each task should ideally have no more than M/N threads. */ |
| 203 |
unsigned max_threads_per_task = |
| 204 |
props->max_threads_per_core / props->max_tasks_per_core; |
| 205 |
|
| 206 |
/* To achieve the best utilization, we should aim for as many workgroups |
| 207 |
* per tasks as we can fit without exceeding the above thread limit */ |
| 208 |
unsigned threads_per_wg = |
| 209 |
shader_local_size->x * shader_local_size->y * shader_local_size->z; |
| 210 |
assert(threads_per_wg > 0 && threads_per_wg <= props->max_threads_per_wg); |
| 211 |
unsigned wg_per_task = DIV_ROUND_UP(max_threads_per_task, threads_per_wg); |
| 212 |
assert(wg_per_task > 0 && wg_per_task <= max_threads_per_task); |
| 213 |
|
| 214 |
return wg_per_task; |
| 215 |
} |
| 216 |
|
| 217 |
static inline unsigned |
| 218 |
pan_calc_wls_instances(const struct pan_compute_dim *shader_local_size, |
| 219 |
const struct pan_kmod_dev_props *props, |
| 220 |
const struct pan_compute_dim *dim) |
| 221 |
{ |
| 222 |
/* NOTE: If the instance count is lower than the number of workgroups |
| 223 |
* being dispatched, the HW will hold back workgroups until instances |
| 224 |
* can be reused. */ |
| 225 |
unsigned instances; |
| 226 |
unsigned wg_per_task = |
| 227 |
pan_calc_workgroups_per_task(shader_local_size, props); |
| 228 |
unsigned max_instances_per_core = |
| 229 |
util_next_power_of_two(wg_per_task * props->max_tasks_per_core); |
| 230 |
|
| 231 |
/* Not passing workgroup dimensions implies indirect compute. */ |
| 232 |
if (!dim) { |
| 233 |
/* Assume we utilize all shader cores to the max */ |
| 234 |
instances = max_instances_per_core; |
| 235 |
} else { |
| 236 |
/* NOTE: There is no benefit from allocating more instances than what |
| 237 |
* can concurrently be used by the HW */ |
| 238 |
instances = MIN2(pan_wls_instances(dim), max_instances_per_core); |
| 239 |
} |
| 240 |
return instances; |
| 241 |
} |
| 242 |
|
| 243 |
static inline unsigned |
| 244 |
pan_calc_total_wls_size(unsigned wls_size, unsigned wls_instances, |
| 245 |
unsigned max_core_id_plus_one) |
| 246 |
{ |
| 247 |
unsigned size = pan_wls_adjust_size(wls_size); |
| 248 |
|
| 249 |
return size * wls_instances * max_core_id_plus_one; |
| 250 |
} |
| 251 |
|
| 252 |
#ifdef PAN_ARCH |
| 253 |
|
| 254 |
static inline enum mali_sample_pattern |
| 255 |
pan_sample_pattern(unsigned samples) |
| 256 |
{ |
| 257 |
switch (samples) { |
| 258 |
case 1: |
| 259 |
return MALI_SAMPLE_PATTERN_SINGLE_SAMPLED; |
| 260 |
#if PAN_ARCH >= 12 |
| 261 |
case 2: |
| 262 |
return MALI_SAMPLE_PATTERN_ROTATED_2X_GRID; |
| 263 |
#endif |
| 264 |
case 4: |
| 265 |
return MALI_SAMPLE_PATTERN_ROTATED_4X_GRID; |
| 266 |
case 8: |
| 267 |
return MALI_SAMPLE_PATTERN_D3D_8X_GRID; |
| 268 |
#if PAN_ARCH >= 5 |
| 269 |
case 16: |
| 270 |
return MALI_SAMPLE_PATTERN_D3D_16X_GRID; |
| 271 |
#endif |
| 272 |
default: |
| 273 |
UNREACHABLE("Unsupported sample count"); |
| 274 |
} |
| 275 |
} |
| 276 |
|
| 277 |
static inline struct pan_image_block_size |
| 278 |
pan_effective_tile_block_size(unsigned tile_size) |
| 279 |
{ |
| 280 |
/* Tile is either a square or a rect whose width is twice the height. */ |
| 281 |
unsigned shift_h = util_logbase2(tile_size); |
| 282 |
unsigned shift_w = shift_h + 1; |
| 283 |
unsigned h = 1 << (shift_h >> 1); |
| 284 |
unsigned w = 1 << (shift_w >> 1); |
| 285 |
|
| 286 |
return (struct pan_image_block_size){w, h}; |
| 287 |
} |
| 288 |
|
| 289 |
void GENX(pan_select_tile_size)(struct pan_fb_info *fb); |
| 290 |
|
| 291 |
bool GENX(pan_force_clean_write_on)(const struct pan_image *image, |
| 292 |
unsigned fb_tile_size_px); |
| 293 |
|
| 294 |
void GENX(pan_emit_tls)(const struct pan_tls_info *info, |
| 295 |
struct mali_local_storage_packed *out); |
| 296 |
|
| 297 |
int GENX(pan_select_crc_rt)(const struct pan_fb_info *fb, unsigned tile_size); |
| 298 |
|
| 299 |
struct pan_attachment_info { |
| 300 |
const struct pan_image_view *iview; |
| 301 |
unsigned layer_or_z_slice; |
| 302 |
unsigned fb_tile_size_px; |
| 303 |
}; |
| 304 |
|
| 305 |
#if PAN_ARCH >= 5 |
| 306 |
void GENX(pan_emit_default_color_attachment)(enum pipe_format format, |
| 307 |
void *payload); |
| 308 |
void GENX(pan_emit_linear_color_attachment)(const struct pan_attachment_info *att, |
| 309 |
void *payload); |
| 310 |
void GENX(pan_emit_linear_s_attachment)(const struct pan_attachment_info *att, |
| 311 |
void *payload); |
| 312 |
void GENX(pan_emit_linear_zs_attachment)(const struct pan_attachment_info *att, |
| 313 |
void *payload); |
| 314 |
void GENX(pan_emit_u_tiled_color_attachment)(const struct pan_attachment_info *att, |
| 315 |
void *payload); |
| 316 |
void GENX(pan_emit_u_tiled_s_attachment)(const struct pan_attachment_info *att, |
| 317 |
void *payload); |
| 318 |
void GENX(pan_emit_u_tiled_zs_attachment)(const struct pan_attachment_info *att, |
| 319 |
void *payload); |
| 320 |
void GENX(pan_emit_afbc_color_attachment)(const struct pan_attachment_info *att, |
| 321 |
void *payload); |
| 322 |
void GENX(pan_emit_afbc_zs_attachment)(const struct pan_attachment_info *att, |
| 323 |
void *payload); |
| 324 |
void GENX(pan_emit_afbc_s_attachment)(const struct pan_attachment_info *att, |
| 325 |
void *payload); |
| 326 |
#endif |
| 327 |
|
| 328 |
#if PAN_ARCH >= 10 |
| 329 |
void |
| 330 |
GENX(pan_emit_interleaved_64k_color_attachment)(const struct pan_attachment_info *att, |
| 331 |
void *payload); |
| 332 |
void GENX(pan_emit_interleaved_64k_zs_attachment)(const struct pan_attachment_info *att, |
| 333 |
void *payload); |
| 334 |
void GENX(pan_emit_interleaved_64k_s_attachment)(const struct pan_attachment_info *att, |
| 335 |
void *payload); |
| 336 |
|
| 337 |
void GENX(pan_emit_afrc_color_attachment)(const struct pan_attachment_info *att, |
| 338 |
void *payload); |
| 339 |
#endif |
| 340 |
|
| 341 |
unsigned GENX(pan_emit_fbd)(const struct pan_fb_info *fb, unsigned layer_idx, |
| 342 |
const struct pan_tls_info *tls, |
| 343 |
const struct pan_tiler_context *tiler_ctx, |
| 344 |
void *out); |
| 345 |
|
| 346 |
#if PAN_ARCH >= 6 |
| 347 |
unsigned GENX(pan_select_tiler_hierarchy_mask)(uint32_t width, uint32_t height, |
| 348 |
uint32_t max_levels, |
| 349 |
uint32_t tile_size, |
| 350 |
uint32_t mem_budget); |
| 351 |
#endif |
| 352 |
|
| 353 |
#if PAN_ARCH <= 9 |
| 354 |
void GENX(pan_emit_fragment_job_payload)(const struct pan_fb_info *fb, |
| 355 |
uint64_t fbd, void *out); |
| 356 |
#endif |
| 357 |
|
| 358 |
#endif /* ifdef PAN_ARCH */ |
| 359 |
|
| 360 |
#endif |