| 1 |
/* |
| 2 |
* Copyright 2022 Alyssa Rosenzweig |
| 3 |
* SPDX-License-Identifier: MIT |
| 4 |
*/ |
| 5 |
|
| 6 |
#pragma once |
| 7 |
|
| 8 |
#include <assert.h> |
| 9 |
#include <stdbool.h> |
| 10 |
#include <stdint.h> |
| 11 |
#include "drm-uapi/asahi_drm.h" |
| 12 |
#include "util/format/u_formats.h" |
| 13 |
#include "agx_pack.h" |
| 14 |
|
| 15 |
#ifdef __cplusplus |
| 16 |
extern "C" { |
| 17 |
#endif |
| 18 |
|
| 19 |
/* Maximum render targets per framebuffer. This is NOT architectural, but it |
| 20 |
* is the ~universal API limit so there's no point in allowing more. |
| 21 |
*/ |
| 22 |
#define AGX_MAX_RENDER_TARGETS (8) |
| 23 |
|
| 24 |
/* Forward declarations to keep the header lean */ |
| 25 |
struct nir_shader; |
| 26 |
struct nir_def; |
| 27 |
struct nir_builder; |
| 28 |
|
| 29 |
struct agx_tilebuffer_layout { |
| 30 |
/* Logical format of each render target. Use agx_tilebuffer_physical_format |
| 31 |
* to get the physical format. |
| 32 |
*/ |
| 33 |
enum pipe_format logical_format[AGX_MAX_RENDER_TARGETS]; |
| 34 |
|
| 35 |
/* Which render targets are spilled. */ |
| 36 |
bool spilled[AGX_MAX_RENDER_TARGETS]; |
| 37 |
|
| 38 |
/* Offset into the sample of each render target. If a render target is |
| 39 |
* spilled, its offset is UNDEFINED. Use agx_tilebuffer_offset_B to access. |
| 40 |
*/ |
| 41 |
uint8_t _offset_B[AGX_MAX_RENDER_TARGETS]; |
| 42 |
|
| 43 |
/* Total bytes per sample, rounded up as needed. Spilled render targets do |
| 44 |
* not count against this. |
| 45 |
*/ |
| 46 |
uint8_t sample_size_B; |
| 47 |
|
| 48 |
/* Number of samples per pixel */ |
| 49 |
uint8_t nr_samples; |
| 50 |
|
| 51 |
/* If layered rendering is used */ |
| 52 |
bool layered; |
| 53 |
|
| 54 |
/* Selected tile size in pixels. Either 32*32, 32*16, or 16*16. */ |
| 55 |
uint16_t tile_size; |
| 56 |
|
| 57 |
/* USC word corresponding to this configuration of the tilebuffer */ |
| 58 |
struct agx_usc_shared_packed usc; |
| 59 |
}; |
| 60 |
|
| 61 |
static inline void |
| 62 |
agx_tilebuffer_set_drm_cmd(struct drm_asahi_cmd_render *c, |
| 63 |
const struct agx_tilebuffer_layout *layout) |
| 64 |
{ |
| 65 |
c->utile_width_px = layout->tile_size >= 32 * 16 ? 32 : 16; |
| 66 |
c->utile_height_px = layout->tile_size <= 32 * 16 ? 16 : 32; |
| 67 |
} |
| 68 |
|
| 69 |
/* |
| 70 |
* _offset_B is undefined for non-spilled render targets. This safe accessor |
| 71 |
* asserts that render targets are not spilled rather than returning garbage. |
| 72 |
*/ |
| 73 |
static inline uint8_t |
| 74 |
agx_tilebuffer_offset_B(struct agx_tilebuffer_layout *layout, unsigned rt) |
| 75 |
{ |
| 76 |
assert(rt < AGX_MAX_RENDER_TARGETS); |
| 77 |
assert(!layout->spilled[rt] && "precondition"); |
| 78 |
|
| 79 |
return layout->_offset_B[rt]; |
| 80 |
} |
| 81 |
|
| 82 |
static inline bool |
| 83 |
agx_tilebuffer_spills(struct agx_tilebuffer_layout *layout) |
| 84 |
{ |
| 85 |
for (unsigned rt = 0; rt < AGX_MAX_RENDER_TARGETS; ++rt) { |
| 86 |
if (layout->spilled[rt]) |
| 87 |
return true; |
| 88 |
} |
| 89 |
|
| 90 |
return false; |
| 91 |
} |
| 92 |
|
| 93 |
struct agx_tilebuffer_layout |
| 94 |
agx_build_tilebuffer_layout(const enum pipe_format *formats, uint8_t nr_cbufs, |
| 95 |
uint8_t nr_samples, bool layered); |
| 96 |
|
| 97 |
void agx_tilebuffer_set_samples(struct agx_tilebuffer_layout *tib, |
| 98 |
unsigned nr_samples); |
| 99 |
|
| 100 |
bool agx_nir_lower_tilebuffer(struct nir_shader *shader, |
| 101 |
struct agx_tilebuffer_layout *tib, |
| 102 |
uint8_t *colormasks, unsigned *bindless_base, |
| 103 |
struct nir_def *write_samples, bool *translucent); |
| 104 |
|
| 105 |
bool agx_nir_lower_to_per_sample(struct nir_shader *shader); |
| 106 |
|
| 107 |
bool agx_nir_lower_monolithic_msaa(struct nir_shader *shader, |
| 108 |
uint8_t nr_samples); |
| 109 |
|
| 110 |
bool agx_nir_lower_sample_intrinsics(struct nir_shader *shader, |
| 111 |
bool ignore_sample_mask_without_msaa); |
| 112 |
|
| 113 |
uint32_t agx_tilebuffer_total_size(struct agx_tilebuffer_layout *tib); |
| 114 |
|
| 115 |
enum pipe_format |
| 116 |
agx_tilebuffer_physical_format(struct agx_tilebuffer_layout *tib, unsigned rt); |
| 117 |
|
| 118 |
bool agx_tilebuffer_supports_mask(struct agx_tilebuffer_layout *tib, |
| 119 |
unsigned rt); |
| 120 |
|
| 121 |
void agx_tilebuffer_pack_usc(struct agx_tilebuffer_layout *tib); |
| 122 |
|
| 123 |
#ifdef __cplusplus |
| 124 |
} /* extern C */ |
| 125 |
#endif |