Debian Codegraph @

src/imagination/vulkan/pvr_mrt.h

raw
1 /*
2 * Copyright © 2025 Imagination Technologies Ltd.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
7 #ifndef PVR_MRT_H
8 #define PVR_MRT_H
9
10 #include <stdbool.h>
11 #include <stdint.h>
12
13 #include <vulkan/vulkan.h>
14
15 #include "pvr_common.h"
16 #include "pvr_macros.h"
17
18 struct pvr_device;
19 struct pvr_dynamic_render_info;
20 struct pvr_cmd_buffer;
21
22 /* Specifies the location of render target writes. */
23 enum usc_mrt_resource_type {
24 USC_MRT_RESOURCE_TYPE_INVALID = 0, /* explicitly treat 0 as invalid. */
25 USC_MRT_RESOURCE_TYPE_OUTPUT_REG,
26 USC_MRT_RESOURCE_TYPE_MEMORY,
27 };
28
29 #define PVR_USC_RENDER_TARGET_MAXIMUM_SIZE_IN_DWORDS (4)
30
31 struct usc_mrt_desc {
32 /* Size (in bytes) of the intermediate storage required for each pixel in the
33 * render target.
34 */
35 uint32_t intermediate_size;
36
37 /* Mask of the bits from each dword which are read by the PBE. */
38 uint32_t valid_mask[PVR_USC_RENDER_TARGET_MAXIMUM_SIZE_IN_DWORDS];
39
40 /* Higher number = higher priority. Used to decide which render targets get
41 * allocated dedicated output registers.
42 */
43 uint32_t priority;
44 };
45
46 struct usc_mrt_resource {
47 /* Input description of render target. */
48 struct usc_mrt_desc mrt_desc;
49
50 /* Resource type allocated for render target. */
51 enum usc_mrt_resource_type type;
52
53 /* Intermediate pixel size (in bytes). */
54 uint32_t intermediate_size;
55
56 union {
57 /* If type == USC_MRT_RESOURCE_TYPE_OUTPUT_REG. */
58 struct {
59 /* The output register to use. */
60 uint32_t output_reg;
61
62 /* The offset in bytes into the output register. */
63 uint32_t offset;
64 } reg;
65
66 /* If type == USC_MRT_RESOURCE_TYPE_MEMORY. */
67 struct {
68 /* The index of the tile buffer to use. */
69 uint32_t tile_buffer;
70
71 /* The offset in dwords within the tile buffer. */
72 uint32_t offset_dw;
73 } mem;
74 };
75 };
76
77 struct usc_mrt_setup {
78 /* Number of render targets present. */
79 uint32_t num_render_targets;
80
81 /* Number of output registers used per-pixel (1, 2 or 4). */
82 uint32_t num_output_regs;
83
84 /* Number of tile buffers used. */
85 uint32_t num_tile_buffers;
86
87 /* Array of MRT resources allocated for each render target. The number of
88 * elements is determined by usc_mrt_setup::num_render_targets.
89 */
90 struct usc_mrt_resource *mrt_resources;
91
92 /* Don't set up source pos in emit. */
93 bool disable_source_pos_override;
94
95 /* Hash unique to this particular setup. */
96 uint32_t hash;
97 };
98
99 /* Max render targets for the clears loads state in load op.
100 * To account for resolve attachments, double the color attachments.
101 */
102 #define PVR_LOAD_OP_CLEARS_LOADS_MAX_RTS (PVR_MAX_COLOR_ATTACHMENTS * 2)
103
104 struct pvr_load_op {
105 bool is_hw_object;
106
107 struct pvr_suballoc_bo *usc_frag_prog_bo;
108 uint32_t const_shareds_count;
109 uint32_t shareds_count;
110 uint32_t num_tile_buffers;
111
112 struct pvr_pds_upload pds_frag_prog;
113
114 struct pvr_pds_upload pds_tex_state_prog;
115 uint32_t temps_count;
116
117 union {
118 const struct pvr_renderpass_hwsetup_render *hw_render;
119 const struct pvr_render_subpass *subpass;
120 };
121
122 /* TODO: We might not need to keep all of this around. Some stuff might just
123 * be for the compiler to ingest which we can then discard.
124 */
125 struct {
126 uint16_t rt_clear_mask;
127 uint16_t rt_load_mask;
128
129 uint16_t unresolved_msaa_mask;
130
131 /* The format to write to the output regs. */
132 VkFormat dest_vk_format[PVR_LOAD_OP_CLEARS_LOADS_MAX_RTS];
133
134 #define PVR_NO_DEPTH_CLEAR_TO_REG (-1)
135 /* If >= 0, write a depth clear value to the specified pixel output. */
136 int32_t depth_clear_to_reg;
137
138 const struct usc_mrt_setup *mrt_setup;
139 } clears_loads_state;
140
141 uint32_t view_indices[PVR_MAX_MULTIVIEW];
142
143 uint32_t view_count;
144 };
145
146 struct pvr_load_op_state {
147 uint32_t load_op_count;
148
149 /* Load op array indexed by HW render view (not by the index in the view
150 * mask).
151 */
152 struct pvr_load_op *load_ops;
153 };
154
155 #define CHECK_MASK_SIZE(_struct_type, _field_name, _nr_bits) \
156 static_assert(sizeof(((struct _struct_type *)NULL)->_field_name) * 8 >= \
157 _nr_bits, \
158 #_field_name " mask of struct " #_struct_type " too small")
159
160 CHECK_MASK_SIZE(pvr_load_op,
161 clears_loads_state.rt_clear_mask,
162 PVR_LOAD_OP_CLEARS_LOADS_MAX_RTS);
163 CHECK_MASK_SIZE(pvr_load_op,
164 clears_loads_state.rt_load_mask,
165 PVR_LOAD_OP_CLEARS_LOADS_MAX_RTS);
166 CHECK_MASK_SIZE(pvr_load_op,
167 clears_loads_state.unresolved_msaa_mask,
168 PVR_LOAD_OP_CLEARS_LOADS_MAX_RTS);
169
170 #undef CHECK_MASK_SIZE
171
172 #ifdef PVR_PER_ARCH
173 VkResult PVR_PER_ARCH(mrt_setup_partial_init)(
174 struct pvr_device *const device,
175 struct usc_mrt_setup *mrt_setup,
176 uint32_t num_renger_targets,
177 uint32_t num_output_regs,
178 uint32_t num_tile_buffers);
179
180 # define pvr_arch_mrt_setup_partial_init PVR_PER_ARCH(mrt_setup_partial_init)
181
182 VkResult PVR_PER_ARCH(init_usc_mrt_setup)(
183 struct pvr_device *device,
184 uint32_t attachment_count,
185 const VkFormat attachment_formats[attachment_count],
186 struct usc_mrt_setup *setup);
187
188 # define pvr_arch_init_usc_mrt_setup PVR_PER_ARCH(init_usc_mrt_setup)
189
190 void PVR_PER_ARCH(destroy_mrt_setup)(const struct pvr_device *device,
191 struct usc_mrt_setup *setup);
192
193 # define pvr_arch_destroy_mrt_setup PVR_PER_ARCH(destroy_mrt_setup)
194
195 void PVR_PER_ARCH(init_mrt_desc)(VkFormat format, struct usc_mrt_desc *desc);
196
197 # define pvr_arch_init_mrt_desc PVR_PER_ARCH(init_mrt_desc)
198
199 VkResult PVR_PER_ARCH(pds_unitex_state_program_create_and_upload)(
200 struct pvr_device *device,
201 const VkAllocationCallbacks *allocator,
202 uint32_t texture_kicks,
203 uint32_t uniform_kicks,
204 struct pvr_pds_upload *const pds_upload_out);
205
206 # define pvr_arch_pds_unitex_state_program_create_and_upload \
207 PVR_PER_ARCH(pds_unitex_state_program_create_and_upload)
208
209 VkResult
210 PVR_PER_ARCH(load_op_shader_generate)(struct pvr_device *device,
211 const VkAllocationCallbacks *allocator,
212 struct pvr_load_op *load_op);
213
214 # define pvr_arch_load_op_shader_generate \
215 PVR_PER_ARCH(load_op_shader_generate)
216
217 VkResult PVR_PER_ARCH(mrt_load_ops_setup)(struct pvr_cmd_buffer *cmd_buffer,
218 const VkAllocationCallbacks *alloc,
219 struct pvr_load_op_state **state);
220
221 # define pvr_arch_mrt_load_ops_setup PVR_PER_ARCH(mrt_load_ops_setup)
222
223 void PVR_PER_ARCH(mrt_load_op_state_cleanup)(const struct pvr_device *device,
224 const VkAllocationCallbacks *alloc,
225 struct pvr_load_op_state *state);
226
227 # define pvr_arch_mrt_load_op_state_cleanup \
228 PVR_PER_ARCH(mrt_load_op_state_cleanup)
229
230 #endif /* PVR_PER_ARCH */
231
232 #endif /* PVR_MRT_H */