Debian Codegraph @

src/panfrost/vulkan/panvk_descriptor_set_layout.h

raw
1 /*
2 * Copyright © 2024 Collabora Ltd.
3 * SPDX-License-Identifier: MIT
4 */
5
6 #ifndef PANVK_DESCRIPTOR_SET_LAYOUT_H
7 #define PANVK_DESCRIPTOR_SET_LAYOUT_H
8
9 #ifndef PAN_ARCH
10 #error "PAN_ARCH must be defined"
11 #endif
12
13 #include <stdint.h>
14
15 #include "vk_descriptor_set_layout.h"
16 #include "vk_util.h"
17
18 #include "util/mesa-blake3.h"
19
20 #include "genxml/gen_macros.h"
21
22 #define PANVK_DESCRIPTOR_SIZE 32
23 #define MAX_DYNAMIC_UNIFORM_BUFFERS 16
24 #define MAX_DYNAMIC_STORAGE_BUFFERS 8
25 #define MAX_PUSH_DESCS 32
26 #define MAX_INLINE_UNIFORM_BLOCK_SIZE (1 << 16)
27 #define MAX_DYNAMIC_BUFFERS \
28 (MAX_DYNAMIC_UNIFORM_BUFFERS + MAX_DYNAMIC_STORAGE_BUFFERS)
29
30 #if PAN_ARCH < 9
31
32 /* On Bifrost, this is a software limit. We pick the minimum required by
33 * Vulkan, because Bifrost GPUs don't have unified descriptor tables,
34 * which forces us to aggregate all descriptors from all sets and dispatch
35 * them to per-type descriptor tables emitted at draw/dispatch time. The
36 * more sets we support the more copies we are likely to have to do at
37 * draw time. */
38 #define MAX_SETS 4
39
40 /* MALI_RENDERER_STATE::sampler_count is 16-bit. */
41 #define MAX_PER_SET_SAMPLERS UINT16_MAX
42 /* MALI_RENDERER_STATE::sampler_count is 16-bit. */
43 #define MAX_PER_SET_SAMPLED_IMAGES UINT16_MAX
44 /* MALI_RENDERER_STATE::uniform_buffer_count is 8-bit. We reserve 32 slots for
45 * our internal UBOs. */
46 #define MAX_PER_SET_UNIFORM_BUFFERS (UINT8_MAX - 32)
47 /* SSBOs are limited by the size of a uniform buffer which contains our
48 * panvk_ssbo_addr objects. panvk_ssbo_addr is 16-byte, and each uniform entry
49 * in the Mali UBO is 16-byte too. The number of entries is encoded in a
50 * 12-bit field, with a minus(1) modifier, which gives a maximum of 2^12 SSBO
51 * descriptors. */
52 #define MAX_PER_SET_STORAGE_BUFFERS (1 << 12)
53 /* MALI_ATTRIBUTE::buffer_index is 9-bit, and each image takes two
54 * MALI_ATTRIBUTE_BUFFER slots, which gives a maximum of (1 << 8) images. */
55 #define MAX_PER_SET_STORAGE_IMAGES (1 << 8)
56
57 #else
58
59 /* Valhall has native support for descriptor sets, and allows a maximum
60 * of 16 sets, but we reserve 9 for our internal use, so we have 7 left. */
61 #define MAX_SETS 7
62
63 /* Hardware limit is 2^24 each of buffer, texture, and sampler descriptors. We
64 * use the same hardware descriptors for multiple kinds of vulkan descriptors,
65 * and may want to reorganize these in the future, so advertise a lower limit
66 * of 2^20. */
67 #define MAX_DESCRIPTORS (1 << 20)
68 #define MAX_PER_SET_SAMPLERS MAX_DESCRIPTORS
69 #define MAX_PER_SET_SAMPLED_IMAGES MAX_DESCRIPTORS
70 #define MAX_PER_SET_UNIFORM_BUFFERS MAX_DESCRIPTORS
71 #define MAX_PER_SET_STORAGE_BUFFERS MAX_DESCRIPTORS
72 #define MAX_PER_SET_STORAGE_IMAGES MAX_DESCRIPTORS
73
74 #endif
75
76 /* A maximum of 8 color render targets, and one depth-stencil render target. */
77 #define MAX_PER_SET_INPUT_ATTACHMENTS (MAX_RTS + 1)
78
79 struct panvk_descriptor_set_binding_layout {
80 VkDescriptorType type;
81 VkDescriptorBindingFlags flags;
82 unsigned desc_count;
83 unsigned desc_idx;
84
85 /* if textures are present, maximum number of planes required per texture;
86 * 0 otherwise
87 */
88 unsigned textures_per_desc;
89
90 /* if samplers are present, maximum number of planes required per sampler;
91 * 0 otherwise
92 */
93 unsigned samplers_per_desc;
94
95 struct panvk_sampler **immutable_samplers;
96 };
97
98 struct panvk_descriptor_set_layout {
99 struct vk_descriptor_set_layout vk;
100 VkDescriptorSetLayoutCreateFlagBits flags;
101 unsigned desc_count;
102 unsigned dyn_buf_count;
103
104 /* Bitmask of which dynamic buffers are SSBOs */
105 uint32_t dyn_ssbos;
106
107 /* Number of bindings in this descriptor set */
108 uint32_t binding_count;
109
110 /* Bindings in this descriptor set */
111 struct panvk_descriptor_set_binding_layout *bindings;
112 };
113
114 VK_DEFINE_NONDISP_HANDLE_CASTS(panvk_descriptor_set_layout, vk.base,
115 VkDescriptorSetLayout,
116 VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
117
118 static inline const struct panvk_descriptor_set_layout *
119 to_panvk_descriptor_set_layout(const struct vk_descriptor_set_layout *layout)
120 {
121 return container_of(layout, const struct panvk_descriptor_set_layout, vk);
122 }
123
124 static inline const uint32_t
125 panvk_get_desc_stride(const struct panvk_descriptor_set_binding_layout *layout)
126 {
127 /* One descriptor for each sampler plane, and one for each texture. */
128 return layout->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER
129 ? layout->textures_per_desc + layout->samplers_per_desc : 1;
130 }
131
132 static inline const uint32_t
133 panvk_get_iub_desc_count(uint32_t size)
134 {
135 /* Each inline uniform block contains an internal buffer descriptor, in
136 * addition to as many descriptors as needed to contain the requested size
137 * in bytes. */
138 return DIV_ROUND_UP(size, PANVK_DESCRIPTOR_SIZE) + 1;
139 }
140
141 static inline const uint32_t
142 panvk_get_iub_size(uint32_t desc_count)
143 {
144 assert(desc_count >= 1);
145 return (desc_count - 1) * PANVK_DESCRIPTOR_SIZE;
146 }
147
148 struct panvk_subdesc_info {
149 VkDescriptorType type;
150 uint8_t plane;
151 };
152
153 #define IMPLICIT_SUBDESC_TYPE (VkDescriptorType)-1
154 #define NO_SUBDESC (struct panvk_subdesc_info){ \
155 .type = IMPLICIT_SUBDESC_TYPE, \
156 }
157 #define TEX_SUBDESC(__plane) (struct panvk_subdesc_info){ \
158 .type = VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE, \
159 .plane = __plane, \
160 }
161 #define SAMPLER_SUBDESC(__plane) (struct panvk_subdesc_info){ \
162 .type = VK_DESCRIPTOR_TYPE_SAMPLER, \
163 .plane = __plane, \
164 }
165
166 static inline struct panvk_subdesc_info
167 get_tex_subdesc_info(VkDescriptorType type, uint8_t plane)
168 {
169 return (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
170 ? TEX_SUBDESC(plane) : NO_SUBDESC;
171 }
172
173 static inline struct panvk_subdesc_info
174 get_sampler_subdesc_info(VkDescriptorType type, uint8_t plane)
175 {
176 return (type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER)
177 ? SAMPLER_SUBDESC(plane) : NO_SUBDESC;
178 }
179
180 static inline uint32_t
181 get_subdesc_idx(const struct panvk_descriptor_set_binding_layout *layout,
182 struct panvk_subdesc_info subdesc)
183 {
184 assert((subdesc.type == IMPLICIT_SUBDESC_TYPE) ||
185 (layout->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER &&
186 (subdesc.type == VK_DESCRIPTOR_TYPE_SAMPLER ||
187 subdesc.type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE)));
188
189 uint32_t subdesc_idx = 0;
190
191 /* In case of combined image-sampler, we put the texture first. */
192 if (subdesc.type == VK_DESCRIPTOR_TYPE_SAMPLER)
193 subdesc_idx += layout->textures_per_desc +
194 MIN2(subdesc.plane, layout->samplers_per_desc - 1);
195 else if (subdesc.type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE)
196 subdesc_idx += MIN2(subdesc.plane, layout->textures_per_desc - 1);
197
198 return subdesc_idx;
199 }
200
201 static inline uint32_t
202 panvk_get_desc_index(const struct panvk_descriptor_set_binding_layout *layout,
203 uint32_t elem, struct panvk_subdesc_info subdesc)
204 {
205 assert(!vk_descriptor_type_is_dynamic(layout->type));
206
207 return layout->desc_idx + elem * panvk_get_desc_stride(layout) +
208 get_subdesc_idx(layout, subdesc);
209 }
210
211 #endif /* PANVK_VX_DESCRIPTOR_SET_LAYOUT_H */