| 1 |
/* |
| 2 |
* Copyright © 2024 Imagination Technologies Ltd. |
| 3 |
* |
| 4 |
* SPDX-License-Identifier: MIT |
| 5 |
*/ |
| 6 |
|
| 7 |
#ifndef PCO_DATA_H |
| 8 |
#define PCO_DATA_H |
| 9 |
|
| 10 |
/** |
| 11 |
* \file pco_data.h |
| 12 |
* |
| 13 |
* \brief PCO shader-specific data/compiler-driver interface. |
| 14 |
*/ |
| 15 |
|
| 16 |
#include "common/pvr_limits.h" |
| 17 |
#include "compiler/shader_enums.h" |
| 18 |
#include "nir/nir_lower_blend.h" |
| 19 |
#include "util/format/u_format.h" |
| 20 |
|
| 21 |
#include <stdbool.h> |
| 22 |
|
| 23 |
#define PCO_POINT_SAMPLER 0xffff |
| 24 |
#define PCO_IA_SAMPLER 0xfffe |
| 25 |
|
| 26 |
/* Compiler-specific forward-declarations. */ |
| 27 |
typedef struct _pco_shader pco_shader; |
| 28 |
|
| 29 |
/** Generic range struct. */ |
| 30 |
typedef struct _pco_range { |
| 31 |
unsigned start; |
| 32 |
unsigned count; |
| 33 |
union { |
| 34 |
unsigned stride; |
| 35 |
unsigned offset; |
| 36 |
}; |
| 37 |
} pco_range; |
| 38 |
|
| 39 |
/** PCO vertex shader-specific data. */ |
| 40 |
typedef struct _pco_vs_data { |
| 41 |
/** Attributes/input mappings. */ |
| 42 |
pco_range attribs[VERT_ATTRIB_MAX]; |
| 43 |
|
| 44 |
enum pipe_format attrib_formats[VERT_ATTRIB_MAX]; |
| 45 |
|
| 46 |
/** Varyings/output mappings. */ |
| 47 |
pco_range varyings[VARYING_SLOT_MAX]; |
| 48 |
|
| 49 |
unsigned clip_count; |
| 50 |
unsigned cull_count; |
| 51 |
|
| 52 |
unsigned f32_smooth; /** Number of F32 linear varyings. */ |
| 53 |
unsigned f32_flat; /** Number of F32 flat varyings. */ |
| 54 |
unsigned f32_npc; /** Number of F32 NPC varyings. */ |
| 55 |
|
| 56 |
unsigned f16_smooth; /** Number of F16 linear varyings. */ |
| 57 |
unsigned f16_flat; /** Number of F16 flat varyings. */ |
| 58 |
unsigned f16_npc; /** Number of F16 NPC varyings. */ |
| 59 |
|
| 60 |
unsigned vtxouts; /** How many vertex outputs are written to. */ |
| 61 |
} pco_vs_data; |
| 62 |
|
| 63 |
enum pco_front_face_op { |
| 64 |
PCO_FRONT_FACE_OP_NOP, |
| 65 |
PCO_FRONT_FACE_OP_SWAP, |
| 66 |
PCO_FRONT_FACE_OP_TRUE, |
| 67 |
}; |
| 68 |
|
| 69 |
/** PCO fragment shader-specific data. */ |
| 70 |
typedef struct _pco_fs_data { |
| 71 |
/** Varyings/input mappings. */ |
| 72 |
pco_range varyings[VARYING_SLOT_MAX]; |
| 73 |
|
| 74 |
/** Results/output mappings. */ |
| 75 |
pco_range outputs[FRAG_RESULT_MAX]; |
| 76 |
|
| 77 |
/** If outputs are to be placed in tile buffers. */ |
| 78 |
uint8_t output_tile_buffers; |
| 79 |
|
| 80 |
/** Fragment output formats. */ |
| 81 |
enum pipe_format output_formats[FRAG_RESULT_MAX]; |
| 82 |
|
| 83 |
/** On-chip input attachment mappings. */ |
| 84 |
pco_range ias_onchip[8]; |
| 85 |
|
| 86 |
/** On-chip input attachment formats. */ |
| 87 |
enum pipe_format ia_formats[8]; |
| 88 |
|
| 89 |
uint8_t ia_tile_buffers; |
| 90 |
uint8_t ia_has_stencil; |
| 91 |
|
| 92 |
unsigned num_tile_buffers; |
| 93 |
|
| 94 |
pco_range meta; |
| 95 |
|
| 96 |
gl_frag_result z_replicate; |
| 97 |
|
| 98 |
/* Blend options. */ |
| 99 |
nir_lower_blend_options blend_opts; |
| 100 |
pco_range blend_consts; |
| 101 |
uint8_t blend_consts_needed; |
| 102 |
|
| 103 |
uint16_t rasterization_samples; |
| 104 |
|
| 105 |
pco_range tile_buffers; |
| 106 |
|
| 107 |
pco_range sample_locations; |
| 108 |
|
| 109 |
gl_varying_slot view_index_slot; |
| 110 |
|
| 111 |
struct { |
| 112 |
bool w; /** Whether the shader uses pos.w. */ |
| 113 |
bool z; /** Whether the shader uses pos.z */ |
| 114 |
bool pntc; /** Whether the shader uses point coord. */ |
| 115 |
bool phase_change; /** Whether the shader does a phase change. */ |
| 116 |
bool fbfetch; /** Whether the shader fetches from the framebuffer. */ |
| 117 |
bool depth_feedback; |
| 118 |
bool discard; |
| 119 |
bool early_frag; |
| 120 |
bool sample_shading; |
| 121 |
bool sample_locations; |
| 122 |
bool alpha_to_coverage; |
| 123 |
bool olchk_skip; |
| 124 |
} uses; |
| 125 |
|
| 126 |
struct { |
| 127 |
bool color_write_enable; |
| 128 |
} meta_present; |
| 129 |
} pco_fs_data; |
| 130 |
|
| 131 |
/** PCO compute shader-specific data. */ |
| 132 |
typedef struct _pco_cs_data { |
| 133 |
unsigned workgroup_size[3]; /** Workgroup size. */ |
| 134 |
|
| 135 |
pco_range shmem; |
| 136 |
bool zero_shmem; |
| 137 |
} pco_cs_data; |
| 138 |
|
| 139 |
/** PCO image descriptor metadata. */ |
| 140 |
enum pco_image_meta { |
| 141 |
PCO_IMAGE_META_LAYER_SIZE, |
| 142 |
PCO_IMAGE_META_BUFFER_ELEMS, |
| 143 |
PCO_IMAGE_META_Z_SLICE, |
| 144 |
PCO_IMAGE_META_PCK_INFO, |
| 145 |
|
| 146 |
PCO_IMAGE_META_COUNT, |
| 147 |
}; |
| 148 |
|
| 149 |
/** PCO sampler descriptor metadata. */ |
| 150 |
enum pco_sampler_meta { |
| 151 |
PCO_SAMPLER_META_COMPARE_OP, |
| 152 |
PCO_SAMPLER_META_RSVD0, |
| 153 |
PCO_SAMPLER_META_RSVD1, |
| 154 |
PCO_SAMPLER_META_RSVD2, |
| 155 |
|
| 156 |
PCO_SAMPLER_META_COUNT, |
| 157 |
}; |
| 158 |
|
| 159 |
/** PCO descriptor binding data. */ |
| 160 |
typedef struct _pco_binding_data { |
| 161 |
pco_range range; /** Descriptor location range. */ |
| 162 |
bool used; /** Whether the descriptor binding is used by the shader. */ |
| 163 |
|
| 164 |
/** Whether the descriptor binding is a combined image sampler. */ |
| 165 |
bool is_img_smp; |
| 166 |
} pco_binding_data; |
| 167 |
|
| 168 |
/** PCO descriptor set data. */ |
| 169 |
typedef struct _pco_descriptor_set_data { |
| 170 |
pco_range range; /** Descriptor location range. */ |
| 171 |
pco_range dynamic_range; /** Dynamic descriptor location range. */ |
| 172 |
|
| 173 |
unsigned binding_count; /** Number of bindings. */ |
| 174 |
pco_binding_data *bindings; /** Descriptor set bindings. */ |
| 175 |
|
| 176 |
bool used; /** Whether the descriptor set is used by the shader. */ |
| 177 |
} pco_descriptor_set_data; |
| 178 |
|
| 179 |
/** PCO push constant data. */ |
| 180 |
typedef struct _pco_push_const_data { |
| 181 |
pco_range range; /** Push constant range. */ |
| 182 |
|
| 183 |
unsigned used; |
| 184 |
} pco_push_const_data; |
| 185 |
|
| 186 |
/** PCO common data. */ |
| 187 |
typedef struct _pco_common_data { |
| 188 |
/** System value mappings. */ |
| 189 |
pco_range sys_vals[SYSTEM_VALUE_MAX]; |
| 190 |
|
| 191 |
/** Descriptor set data. */ |
| 192 |
pco_descriptor_set_data desc_sets[PVR_MAX_DESCRIPTOR_SETS]; |
| 193 |
|
| 194 |
/** Push constant data. */ |
| 195 |
pco_push_const_data push_consts; |
| 196 |
|
| 197 |
pco_range point_sampler; |
| 198 |
pco_range ia_sampler; |
| 199 |
|
| 200 |
unsigned temps; /** Number of allocated temp registers. */ |
| 201 |
unsigned vtxins; /** Number of allocated vertex input registers. */ |
| 202 |
unsigned interns; /** Number of allocated internal registers. */ |
| 203 |
|
| 204 |
unsigned spilled_temps; |
| 205 |
pco_range spill_info; /* addr_lo, addr_hi, block_size */ |
| 206 |
|
| 207 |
unsigned scratch; |
| 208 |
pco_range scratch_info; /* addr_lo, addr_hi, block_size */ |
| 209 |
|
| 210 |
unsigned coeffs; /** Number of allocated coefficient registers. */ |
| 211 |
unsigned shareds; /** Number of allocated shared registers. */ |
| 212 |
|
| 213 |
unsigned entry_offset; /** Offset of the shader entrypoint. */ |
| 214 |
|
| 215 |
struct { |
| 216 |
bool atomics; /** Whether the shader uses atomics. */ |
| 217 |
bool barriers; /** Whether the shader uses barriers. */ |
| 218 |
bool side_effects; /** Whether the shader has side effects. */ |
| 219 |
bool empty; /** Whether the shader is empty. */ |
| 220 |
bool point_sampler; /** Whether the shader uses a point sampler. */ |
| 221 |
bool ia_sampler; /** Does the shader use an input attachment sampler? */ |
| 222 |
bool usclib; /** Does the shader use usclib functions? */ |
| 223 |
} uses; |
| 224 |
|
| 225 |
bool robust_buffer_access; |
| 226 |
bool null_descriptor; |
| 227 |
bool image_2d_view_of_3d; |
| 228 |
bool multiview; |
| 229 |
} pco_common_data; |
| 230 |
|
| 231 |
/** PCO shader data. */ |
| 232 |
typedef struct _pco_data { |
| 233 |
union { |
| 234 |
pco_vs_data vs; |
| 235 |
pco_fs_data fs; |
| 236 |
pco_cs_data cs; |
| 237 |
}; |
| 238 |
|
| 239 |
pco_common_data common; |
| 240 |
} pco_data; |
| 241 |
|
| 242 |
/** PCO precompiled shader data. */ |
| 243 |
typedef struct PACKED _pco_precomp_data { |
| 244 |
uint8_t temps; |
| 245 |
uint8_t vtxins; |
| 246 |
|
| 247 |
uint16_t coeffs : 12; |
| 248 |
uint16_t shareds : 12; |
| 249 |
|
| 250 |
uint16_t size_dwords; |
| 251 |
|
| 252 |
uint8_t pad[1]; |
| 253 |
|
| 254 |
uint32_t binary[]; |
| 255 |
} pco_precomp_data; |
| 256 |
static_assert(sizeof(pco_precomp_data) == 8, "sizeof(pco_precomp_data) != 8"); |
| 257 |
|
| 258 |
pco_precomp_data pco_get_precomp_data(pco_shader *shader); |
| 259 |
|
| 260 |
struct pvr_stats pco_get_pvr_stats(pco_shader *shader); |
| 261 |
#endif /* PCO_DATA_H */ |