xref: /aosp_15_r20/external/mesa3d/src/asahi/vulkan/hk_descriptor_set_layout.h (revision 6104692788411f58d303aa86923a9ff6ecaded22)
1 /*
2  * Copyright 2024 Valve Corporation
3  * Copyright 2024 Alyssa Rosenzweig
4  * Copyright 2022-2023 Collabora Ltd. and Red Hat Inc.
5  * SPDX-License-Identifier: MIT
6  */
7 
8 #pragma once
9 
10 #include "hk_private.h"
11 
12 #include "vk_descriptor_set_layout.h"
13 #include "vk_object.h"
14 
15 struct hk_device;
16 struct hk_physical_device;
17 struct hk_sampler;
18 struct vk_pipeline_layout;
19 
20 struct hk_descriptor_set_binding_layout {
21    /* The type of the descriptors in this binding */
22    VkDescriptorType type;
23 
24    /* Flags provided when this binding was created */
25    VkDescriptorBindingFlags flags;
26 
27    /* Number of array elements in this binding (or size in bytes for inline
28     * uniform data)
29     */
30    uint32_t array_size;
31 
32    /* Offset into the descriptor buffer where this descriptor lives */
33    uint32_t offset;
34 
35    /* Stride between array elements in the descriptor buffer */
36    uint8_t stride;
37 
38    /* Index into the dynamic buffer binding array */
39    uint8_t dynamic_buffer_index;
40 
41    /* Immutable samplers (or NULL if no immutable samplers) */
42    struct hk_sampler **immutable_samplers;
43 };
44 
45 struct hk_descriptor_set_layout {
46    struct vk_descriptor_set_layout vk;
47 
48    /* Size of the descriptor buffer for this descriptor set */
49    /* Does not contain the size needed for variable count descriptors */
50    uint32_t non_variable_descriptor_buffer_size;
51 
52    /* Number of dynamic UBO bindings in this set */
53    uint8_t dynamic_buffer_count;
54 
55    /* Number of bindings in this descriptor set */
56    uint32_t binding_count;
57 
58    /* Bindings in this descriptor set */
59    struct hk_descriptor_set_binding_layout binding[0];
60 };
61 
62 VK_DEFINE_NONDISP_HANDLE_CASTS(hk_descriptor_set_layout, vk.base,
63                                VkDescriptorSetLayout,
64                                VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
65 
66 void hk_descriptor_stride_align_for_type(
67    const struct hk_physical_device *pdev, VkDescriptorType type,
68    const VkMutableDescriptorTypeListEXT *type_list, uint32_t *stride,
69    uint32_t *alignment);
70 
71 static inline struct hk_descriptor_set_layout *
vk_to_hk_descriptor_set_layout(struct vk_descriptor_set_layout * layout)72 vk_to_hk_descriptor_set_layout(struct vk_descriptor_set_layout *layout)
73 {
74    return container_of(layout, struct hk_descriptor_set_layout, vk);
75 }
76