Debian Codegraph @

src/imagination/vulkan/pvr_common.h

raw
1 /*
2 * Copyright © 2023 Imagination Technologies Ltd.
3 *
4 * based in part on anv driver which is:
5 * Copyright © 2015 Intel Corporation
6 *
7 * based in part on radv driver which is:
8 * Copyright © 2016 Red Hat.
9 * Copyright © 2016 Bas Nieuwenhuizen
10 *
11 * Permission is hereby granted, free of charge, to any person obtaining a copy
12 * of this software and associated documentation files (the "Software"), to deal
13 * in the Software without restriction, including without limitation the rights
14 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15 * copies of the Software, and to permit persons to whom the Software is
16 * furnished to do so, subject to the following conditions:
17 *
18 * The above copyright notice and this permission notice (including the next
19 * paragraph) shall be included in all copies or substantial portions of the
20 * Software.
21 *
22 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
23 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
25 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
26 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
27 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
28 * SOFTWARE.
29 */
30
31 #ifndef PVR_COMMON_H
32 #define PVR_COMMON_H
33
34 #include <stdbool.h>
35 #include <stdint.h>
36 #include <vulkan/vulkan.h>
37
38 /* FIXME: Rename this, and ensure it only contains what's
39 * relevant for the driver/compiler interface (no Vulkan types).
40 */
41
42 #include "hwdef/rogue_hw_defs.h"
43 #include "pco/pco_data.h"
44 #include "pvr_limits.h"
45 #include "pvr_types.h"
46 #include "util/list.h"
47 #include "util/macros.h"
48 #include "util/vma.h"
49 #include "vk_descriptor_set_layout.h"
50 #include "vk_object.h"
51 #include "vk_sync.h"
52
53 #define PVR_WORKGROUP_DIMENSIONS 3U
54
55 #define PVR_SAMPLER_DESCRIPTOR_SIZE 4U
56 #define PVR_IMAGE_DESCRIPTOR_SIZE 4U
57
58 #define PVR_STATE_PBE_DWORDS 2U
59
60 #define PVR_PIPELINE_LAYOUT_SUPPORTED_DESCRIPTOR_TYPE_COUNT \
61 (uint32_t)(VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT + 1U)
62
63 #define PVR_TRANSFER_MAX_LAYERS 1U
64 #define PVR_TRANSFER_MAX_LOADS 4U
65 #define PVR_TRANSFER_MAX_IMAGES \
66 (PVR_TRANSFER_MAX_LAYERS * PVR_TRANSFER_MAX_LOADS)
67
68 /* TODO: move into a common surface library? */
69 enum pvr_memlayout {
70 PVR_MEMLAYOUT_UNDEFINED = 0, /* explicitly treat 0 as undefined */
71 PVR_MEMLAYOUT_LINEAR,
72 PVR_MEMLAYOUT_TWIDDLED,
73 PVR_MEMLAYOUT_3DTWIDDLED,
74 };
75
76 enum pvr_texture_state {
77 PVR_TEXTURE_STATE_SAMPLE,
78 PVR_TEXTURE_STATE_STORAGE,
79 PVR_TEXTURE_STATE_ATTACHMENT,
80 PVR_TEXTURE_STATE_MAX_ENUM,
81 };
82
83 enum pvr_sub_cmd_type {
84 PVR_SUB_CMD_TYPE_INVALID = 0, /* explicitly treat 0 as invalid */
85 PVR_SUB_CMD_TYPE_GRAPHICS,
86 PVR_SUB_CMD_TYPE_COMPUTE,
87 PVR_SUB_CMD_TYPE_TRANSFER,
88 PVR_SUB_CMD_TYPE_QUERY,
89 PVR_SUB_CMD_TYPE_EVENT,
90 };
91
92 enum pvr_event_type {
93 PVR_EVENT_TYPE_SET,
94 PVR_EVENT_TYPE_RESET,
95 PVR_EVENT_TYPE_WAIT,
96 PVR_EVENT_TYPE_BARRIER,
97 };
98
99 enum pvr_depth_stencil_usage {
100 PVR_DEPTH_STENCIL_USAGE_UNDEFINED = 0, /* explicitly treat 0 as undefined */
101 PVR_DEPTH_STENCIL_USAGE_NEEDED,
102 PVR_DEPTH_STENCIL_USAGE_NEVER,
103 };
104
105 enum pvr_job_type {
106 PVR_JOB_TYPE_GEOM,
107 PVR_JOB_TYPE_FRAG,
108 PVR_JOB_TYPE_COMPUTE,
109 PVR_JOB_TYPE_TRANSFER,
110 PVR_JOB_TYPE_QUERY,
111 PVR_JOB_TYPE_MAX
112 };
113
114 enum pvr_pipeline_type {
115 PVR_PIPELINE_TYPE_INVALID = 0, /* explicitly treat 0 as undefined */
116 PVR_PIPELINE_TYPE_GRAPHICS,
117 PVR_PIPELINE_TYPE_COMPUTE,
118 };
119
120 enum pvr_pipeline_stage_bits {
121 PVR_PIPELINE_STAGE_GEOM_BIT = BITFIELD_BIT(PVR_JOB_TYPE_GEOM),
122 PVR_PIPELINE_STAGE_FRAG_BIT = BITFIELD_BIT(PVR_JOB_TYPE_FRAG),
123 PVR_PIPELINE_STAGE_COMPUTE_BIT = BITFIELD_BIT(PVR_JOB_TYPE_COMPUTE),
124 PVR_PIPELINE_STAGE_TRANSFER_BIT = BITFIELD_BIT(PVR_JOB_TYPE_TRANSFER),
125 /* Note that this doesn't map to VkPipelineStageFlagBits so be careful with
126 * this.
127 */
128 PVR_PIPELINE_STAGE_QUERY_BIT = BITFIELD_BIT(PVR_JOB_TYPE_QUERY),
129 };
130
131 #define PVR_PIPELINE_STAGE_ALL_GRAPHICS_BITS \
132 (PVR_PIPELINE_STAGE_GEOM_BIT | PVR_PIPELINE_STAGE_FRAG_BIT)
133
134 #define PVR_PIPELINE_STAGE_ALL_BITS \
135 (PVR_PIPELINE_STAGE_ALL_GRAPHICS_BITS | PVR_PIPELINE_STAGE_COMPUTE_BIT | \
136 PVR_PIPELINE_STAGE_TRANSFER_BIT)
137
138 #define PVR_NUM_SYNC_PIPELINE_STAGES 4U
139
140 /* Warning: Do not define an invalid stage as 0 since other code relies on 0
141 * being the first shader stage. This allows for stages to be split or added
142 * in the future. Defining 0 as invalid will very likely cause problems.
143 */
144 enum pvr_stage_allocation {
145 PVR_STAGE_ALLOCATION_VERTEX_GEOMETRY,
146 PVR_STAGE_ALLOCATION_FRAGMENT,
147 PVR_STAGE_ALLOCATION_COMPUTE,
148 PVR_STAGE_ALLOCATION_COUNT
149 };
150
151 enum pvr_filter {
152 PVR_FILTER_DONTCARE, /* Any filtering mode is acceptable. */
153 PVR_FILTER_POINT,
154 PVR_FILTER_LINEAR,
155 PVR_FILTER_BICUBIC,
156 };
157
158 enum pvr_resolve_op {
159 PVR_RESOLVE_BLEND,
160 PVR_RESOLVE_MIN,
161 PVR_RESOLVE_MAX,
162 PVR_RESOLVE_SAMPLE0,
163 PVR_RESOLVE_SAMPLE1,
164 PVR_RESOLVE_SAMPLE2,
165 PVR_RESOLVE_SAMPLE3,
166 PVR_RESOLVE_SAMPLE4,
167 PVR_RESOLVE_SAMPLE5,
168 PVR_RESOLVE_SAMPLE6,
169 PVR_RESOLVE_SAMPLE7,
170 };
171
172 enum pvr_event_state {
173 PVR_EVENT_STATE_SET_BY_HOST,
174 PVR_EVENT_STATE_RESET_BY_HOST,
175 PVR_EVENT_STATE_SET_BY_DEVICE,
176 PVR_EVENT_STATE_RESET_BY_DEVICE
177 };
178
179 enum pvr_deferred_cs_command_type {
180 PVR_DEFERRED_CS_COMMAND_TYPE_DBSC,
181 PVR_DEFERRED_CS_COMMAND_TYPE_DBSC2,
182 };
183
184 enum pvr_query_type {
185 PVR_QUERY_TYPE_AVAILABILITY_WRITE,
186 PVR_QUERY_TYPE_RESET_QUERY_POOL,
187 PVR_QUERY_TYPE_COPY_QUERY_RESULTS,
188 };
189
190 struct pvr_buffer_descriptor {
191 uint64_t addr;
192 uint32_t size;
193 uint32_t offset;
194 } PACKED;
195 static_assert(sizeof(struct pvr_buffer_descriptor) == 4 * sizeof(uint32_t),
196 "pvr_buffer_descriptor size is invalid.");
197
198 struct pvr_sampler_descriptor {
199 uint64_t words[ROGUE_NUM_TEXSTATE_SAMPLER_WORDS];
200 uint32_t meta[PCO_SAMPLER_META_COUNT];
201 uint64_t gather_words[ROGUE_NUM_TEXSTATE_SAMPLER_WORDS];
202 } PACKED;
203 static_assert(sizeof(struct pvr_sampler_descriptor) ==
204 ROGUE_NUM_TEXSTATE_SAMPLER_WORDS * sizeof(uint64_t) * 2 +
205 PCO_SAMPLER_META_COUNT * sizeof(uint32_t),
206 "pvr_sampler_descriptor size is invalid.");
207
208 struct pvr_image_descriptor {
209 uint64_t words[ROGUE_NUM_TEXSTATE_IMAGE_WORDS];
210 uint32_t meta[PCO_IMAGE_META_COUNT];
211 } PACKED;
212 static_assert(sizeof(struct pvr_image_descriptor) ==
213 ROGUE_NUM_TEXSTATE_IMAGE_WORDS * sizeof(uint64_t) +
214 PCO_IMAGE_META_COUNT * sizeof(uint32_t),
215 "pvr_image_descriptor size is invalid.");
216
217 struct pvr_combined_image_sampler_descriptor {
218 struct pvr_image_descriptor image;
219 struct pvr_sampler_descriptor sampler;
220 } PACKED;
221 static_assert(
222 sizeof(struct pvr_combined_image_sampler_descriptor) ==
223 (ROGUE_NUM_TEXSTATE_IMAGE_WORDS + ROGUE_NUM_TEXSTATE_SAMPLER_WORDS * 2) *
224 sizeof(uint64_t) +
225 (PCO_IMAGE_META_COUNT + PCO_SAMPLER_META_COUNT) * sizeof(uint32_t),
226 "pvr_combined_image_sampler_descriptor size is invalid.");
227
228 struct pvr_event {
229 struct vk_object_base base;
230
231 enum pvr_event_state state;
232 struct vk_sync *sync;
233 };
234
235 #define PVR_MAX_DYNAMIC_BUFFERS \
236 (PVR_MAX_DESCRIPTOR_SET_UNIFORM_DYNAMIC_BUFFERS + \
237 PVR_MAX_DESCRIPTOR_SET_STORAGE_DYNAMIC_BUFFERS)
238
239 struct pvr_descriptor_state {
240 struct pvr_descriptor_set *sets[PVR_MAX_DESCRIPTOR_SETS];
241 uint32_t dirty_sets;
242 };
243
244 #undef PVR_MAX_DYNAMIC_BUFFERS
245
246 struct pvr_pds_upload {
247 struct pvr_suballoc_bo *pvr_bo;
248 /* Offset from the pds heap base address. */
249 uint32_t data_offset;
250 /* Offset from the pds heap base address. */
251 uint32_t code_offset;
252
253 /* data_size + code_size = program_size. */
254 uint32_t data_size;
255 uint32_t code_size;
256 };
257
258 VK_DEFINE_NONDISP_HANDLE_CASTS(pvr_event, base, VkEvent, VK_OBJECT_TYPE_EVENT)
259
260 #endif /* PVR_COMMON_H */