xref: /aosp_15_r20/external/mesa3d/src/panfrost/vulkan/panvk_descriptor_set_layout.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
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 
17 #include "util/mesa-blake3.h"
18 
19 #include "genxml/gen_macros.h"
20 
21 #define PANVK_DESCRIPTOR_SIZE       32
22 #define MAX_SETS                    (PAN_ARCH <= 7 ? 4 : 15)
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 struct panvk_descriptor_set_binding_layout {
30    VkDescriptorType type;
31    VkDescriptorBindingFlags flags;
32    unsigned desc_count;
33    unsigned desc_idx;
34    struct mali_sampler_packed *immutable_samplers;
35 };
36 
37 struct panvk_descriptor_set_layout {
38    struct vk_descriptor_set_layout vk;
39    VkDescriptorSetLayoutCreateFlagBits flags;
40    blake3_hash hash;
41    unsigned desc_count;
42    unsigned dyn_buf_count;
43 
44    /* Number of bindings in this descriptor set */
45    uint32_t binding_count;
46 
47    /* Bindings in this descriptor set */
48    struct panvk_descriptor_set_binding_layout *bindings;
49 };
50 
51 VK_DEFINE_NONDISP_HANDLE_CASTS(panvk_descriptor_set_layout, vk.base,
52                                VkDescriptorSetLayout,
53                                VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
54 
55 static inline const struct panvk_descriptor_set_layout *
to_panvk_descriptor_set_layout(const struct vk_descriptor_set_layout * layout)56 to_panvk_descriptor_set_layout(const struct vk_descriptor_set_layout *layout)
57 {
58    return container_of(layout, const struct panvk_descriptor_set_layout, vk);
59 }
60 
61 static inline const uint32_t
panvk_get_desc_stride(VkDescriptorType type)62 panvk_get_desc_stride(VkDescriptorType type)
63 {
64    /* One descriptor for the sampler, and one for the texture. */
65    return type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER ? 2 : 1;
66 }
67 
68 static inline uint32_t
panvk_get_desc_index(const struct panvk_descriptor_set_binding_layout * layout,uint32_t elem,VkDescriptorType type)69 panvk_get_desc_index(const struct panvk_descriptor_set_binding_layout *layout,
70                      uint32_t elem, VkDescriptorType type)
71 {
72    assert(layout->type == type ||
73           (layout->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER &&
74            (type == VK_DESCRIPTOR_TYPE_SAMPLER ||
75             type == VK_DESCRIPTOR_TYPE_SAMPLED_IMAGE)));
76 
77    assert(layout->type != VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC &&
78           layout->type != VK_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC);
79 
80    uint32_t desc_idx =
81       layout->desc_idx + elem * panvk_get_desc_stride(layout->type);
82 
83    /* In case of combined image-sampler, we put the texture first. */
84    if (layout->type == VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER &&
85        type == VK_DESCRIPTOR_TYPE_SAMPLER)
86       desc_idx++;
87 
88    return desc_idx;
89 }
90 
91 #endif /* PANVK_VX_DESCRIPTOR_SET_LAYOUT_H */
92