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_DYNAMIC_BUFFERS \
27 (MAX_DYNAMIC_UNIFORM_BUFFERS + MAX_DYNAMIC_STORAGE_BUFFERS)
28
29 #if PAN_ARCH <= 7
30 #define MAX_SETS 4
31 #else
32 #define MAX_SETS 15
33 #endif
34
35 struct panvk_descriptor_set_binding_layout {
36 VkDescriptorType type;
37 VkDescriptorBindingFlags flags;
38 unsigned desc_count;
39 unsigned desc_idx;
40 struct mali_sampler_packed *immutable_samplers;
41 };
42
43 struct panvk_descriptor_set_layout {
44 struct vk_descriptor_set_layout vk;
45 VkDescriptorSetLayoutCreateFlagBits flags;
46 unsigned desc_count;
47 unsigned dyn_buf_count;
48
49 /* Number of bindings in this descriptor set */
50 uint32_t binding_count;
51
52 /* Bindings in this descriptor set */
53 struct panvk_descriptor_set_binding_layout *bindings;
54 };
55
56 VK_DEFINE_NONDISP_HANDLE_CASTS(panvk_descriptor_set_layout, vk.base,
57 VkDescriptorSetLayout,
58 VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
59
60 static inline const struct panvk_descriptor_set_layout *
to_panvk_descriptor_set_layout(const struct vk_descriptor_set_layout * layout)61 to_panvk_descriptor_set_layout(const struct vk_descriptor_set_layout *layout)
62 {
63 return container_of(layout, const struct panvk_descriptor_set_layout, vk);
64 }
65
66 static inline const uint32_t
panvk_get_desc_stride(VkDescriptorType type)67 panvk_get_desc_stride(VkDescriptorType type)
68 {
69 /* One descriptor for the sampler, and one for the texture. */
70 return type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ? 2 : 1;
71 }
72
73 static inline uint32_t
panvk_get_desc_index(const struct panvk_descriptor_set_binding_layout * layout,uint32_t elem,VkDescriptorType type)74 panvk_get_desc_index(const struct panvk_descriptor_set_binding_layout *layout,
75 uint32_t elem, VkDescriptorType type)
76 {
77 assert(layout->type == type ||
78 (layout->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER &&
79 (type == VK_DESCRIPTOR_TYPE_SAMPLER ||
80 type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE)));
81
82 assert(!vk_descriptor_type_is_dynamic(layout->type));
83
84 uint32_t desc_idx =
85 layout->desc_idx + elem * panvk_get_desc_stride(layout->type);
86
87 /* In case of combined image-sampler, we put the texture first. */
88 if (layout->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER &&
89 type == VK_DESCRIPTOR_TYPE_SAMPLER)
90 desc_idx++;
91
92 return desc_idx;
93 }
94
95 #endif /* PANVK_VX_DESCRIPTOR_SET_LAYOUT_H */
96