1 /*
2 * Copyright © 2022 Collabora Ltd. and Red Hat Inc.
3 * SPDX-License-Identifier: MIT
4 */
5 #ifndef NVK_DESCRIPTOR_SET_LAYOUT
6 #define NVK_DESCRIPTOR_SET_LAYOUT 1
7
8 #include "nvk_private.h"
9
10 #include "vk_descriptor_set_layout.h"
11 #include "vk_object.h"
12
13 #include "util/bitset.h"
14
15 struct nvk_device;
16 struct nvk_physical_device;
17 struct nvk_sampler;
18 struct vk_pipeline_layout;
19
20 struct nvk_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 nvk_sampler **immutable_samplers;
43 };
44
45 struct nvk_descriptor_set_layout {
46 struct vk_descriptor_set_layout vk;
47
48 VkDescriptorSetLayoutCreateFlagBits flags;
49
50 /* Size of the descriptor buffer for this descriptor set */
51 /* Does not contain the size needed for variable count descriptors */
52 uint32_t non_variable_descriptor_buffer_size;
53
54 /* Maximum possible buffer size for this descriptor set */
55 uint32_t max_buffer_size;
56
57 /* Number of dynamic UBO bindings in this set */
58 uint8_t dynamic_buffer_count;
59
60 /* Which dynamic buffers are UBOs */
61 BITSET_DECLARE(dynamic_ubos, NVK_MAX_DYNAMIC_BUFFERS);
62
63 /* Number of bindings in this descriptor set */
64 uint32_t binding_count;
65
66 /* Address to the embedded sampler descriptor buffer.
67 *
68 * This is allocated from nvk_device::heap and has the size
69 * non_variable_descriptor_buffer_size.
70 */
71 uint64_t embedded_samplers_addr;
72
73 /* Bindings in this descriptor set */
74 struct nvk_descriptor_set_binding_layout binding[0];
75 };
76
77 VK_DEFINE_NONDISP_HANDLE_CASTS(nvk_descriptor_set_layout, vk.base,
78 VkDescriptorSetLayout,
79 VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
80
81 void
82 nvk_descriptor_stride_align_for_type(const struct nvk_physical_device *pdev,
83 VkPipelineLayoutCreateFlags layout_flags,
84 VkDescriptorType type,
85 const VkMutableDescriptorTypeListEXT *type_list,
86 uint32_t *stride, uint32_t *alignment);
87
88 static inline struct nvk_descriptor_set_layout *
vk_to_nvk_descriptor_set_layout(struct vk_descriptor_set_layout * layout)89 vk_to_nvk_descriptor_set_layout(struct vk_descriptor_set_layout *layout)
90 {
91 return container_of(layout, struct nvk_descriptor_set_layout, vk);
92 }
93
94 #endif
95