1 /*
2 * Copyright 2019 Google LLC
3 * SPDX-License-Identifier: MIT
4 *
5 * based in part on anv and radv which are:
6 * Copyright © 2015 Intel Corporation
7 * Copyright © 2016 Red Hat.
8 * Copyright © 2016 Bas Nieuwenhuizen
9 */
10
11 #ifndef VN_DESCRIPTOR_SET_H
12 #define VN_DESCRIPTOR_SET_H
13
14 #include "vn_common.h"
15
16 enum vn_descriptor_type {
17 VN_DESCRIPTOR_TYPE_SAMPLER,
18 VN_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER,
19 VN_DESCRIPTOR_TYPE_SAMPLED_IMAGE,
20 VN_DESCRIPTOR_TYPE_STORAGE_IMAGE,
21 VN_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER,
22 VN_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER,
23 VN_DESCRIPTOR_TYPE_UNIFORM_BUFFER,
24 VN_DESCRIPTOR_TYPE_STORAGE_BUFFER,
25 VN_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC,
26 VN_DESCRIPTOR_TYPE_STORAGE_BUFFER_DYNAMIC,
27 VN_DESCRIPTOR_TYPE_INPUT_ATTACHMENT,
28 VN_DESCRIPTOR_TYPE_INLINE_UNIFORM_BLOCK,
29 VN_DESCRIPTOR_TYPE_MUTABLE_EXT,
30
31 /* add new enum types before this line */
32 VN_NUM_DESCRIPTOR_TYPES,
33 };
34
35 struct vn_descriptor_set_layout_binding {
36 enum vn_descriptor_type type;
37 uint32_t count;
38 bool has_immutable_samplers;
39 BITSET_DECLARE(mutable_descriptor_types, VN_NUM_DESCRIPTOR_TYPES);
40 };
41
42 struct vn_descriptor_set_layout {
43 struct vn_object_base base;
44
45 struct vn_refcount refcount;
46
47 uint32_t last_binding;
48 bool has_variable_descriptor_count;
49 bool is_push_descriptor;
50
51 /* bindings must be the last field in the layout */
52 struct vn_descriptor_set_layout_binding bindings[];
53 };
54 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_set_layout,
55 base.base,
56 VkDescriptorSetLayout,
57 VK_OBJECT_TYPE_DESCRIPTOR_SET_LAYOUT)
58
59 struct vn_descriptor_pool_state {
60 uint32_t set_count;
61 uint32_t iub_binding_count;
62 uint32_t descriptor_counts[VN_NUM_DESCRIPTOR_TYPES];
63 };
64
65 struct vn_descriptor_pool_state_mutable {
66 uint32_t max;
67 uint32_t used;
68 BITSET_DECLARE(types, VN_NUM_DESCRIPTOR_TYPES);
69 };
70
71 struct vn_descriptor_pool {
72 struct vn_object_base base;
73
74 VkAllocationCallbacks allocator;
75 bool async_set_allocation;
76 struct vn_descriptor_pool_state max;
77 struct vn_descriptor_pool_state used;
78
79 struct list_head descriptor_sets;
80
81 uint32_t mutable_states_count;
82 struct vn_descriptor_pool_state_mutable *mutable_states;
83 };
84 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_pool,
85 base.base,
86 VkDescriptorPool,
87 VK_OBJECT_TYPE_DESCRIPTOR_POOL)
88
89 struct vn_descriptor_set {
90 struct vn_object_base base;
91
92 struct vn_descriptor_set_layout *layout;
93 uint32_t last_binding_descriptor_count;
94
95 struct list_head head;
96 };
97 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_set,
98 base.base,
99 VkDescriptorSet,
100 VK_OBJECT_TYPE_DESCRIPTOR_SET)
101
102 struct vn_descriptor_update_template {
103 struct vn_object_base base;
104
105 struct {
106 VkPipelineBindPoint pipeline_bind_point;
107 struct vn_descriptor_set_layout *set_layout;
108 } push;
109
110 uint32_t entry_count;
111 uint32_t img_info_count;
112 uint32_t buf_info_count;
113 uint32_t bview_count;
114 uint32_t iub_count;
115 VkDescriptorUpdateTemplateEntry entries[];
116 };
117 VK_DEFINE_NONDISP_HANDLE_CASTS(vn_descriptor_update_template,
118 base.base,
119 VkDescriptorUpdateTemplate,
120 VK_OBJECT_TYPE_DESCRIPTOR_UPDATE_TEMPLATE)
121
122 struct vn_descriptor_set_writes {
123 VkWriteDescriptorSet *writes;
124 VkDescriptorImageInfo *img_infos;
125 };
126
127 struct vn_descriptor_set_update {
128 uint32_t write_count;
129 VkWriteDescriptorSet *writes;
130 VkDescriptorImageInfo *img_infos;
131 VkDescriptorBufferInfo *buf_infos;
132 VkBufferView *bview_handles;
133 VkWriteDescriptorSetInlineUniformBlock *iubs;
134 };
135
136 uint32_t
137 vn_descriptor_set_count_write_images(uint32_t write_count,
138 const VkWriteDescriptorSet *writes);
139
140 const VkWriteDescriptorSet *
141 vn_descriptor_set_get_writes(uint32_t write_count,
142 const VkWriteDescriptorSet *writes,
143 VkPipelineLayout pipeline_layout_handle,
144 struct vn_descriptor_set_writes *local);
145
146 void
147 vn_descriptor_set_fill_update_with_template(
148 struct vn_descriptor_update_template *templ,
149 VkDescriptorSet set_handle,
150 const uint8_t *data,
151 struct vn_descriptor_set_update *update);
152
153 void
154 vn_descriptor_set_layout_destroy(struct vn_device *dev,
155 struct vn_descriptor_set_layout *layout);
156
157 static inline struct vn_descriptor_set_layout *
vn_descriptor_set_layout_ref(struct vn_device * dev,struct vn_descriptor_set_layout * layout)158 vn_descriptor_set_layout_ref(struct vn_device *dev,
159 struct vn_descriptor_set_layout *layout)
160 {
161 vn_refcount_inc(&layout->refcount);
162 return layout;
163 }
164
165 static inline void
vn_descriptor_set_layout_unref(struct vn_device * dev,struct vn_descriptor_set_layout * layout)166 vn_descriptor_set_layout_unref(struct vn_device *dev,
167 struct vn_descriptor_set_layout *layout)
168 {
169 if (vn_refcount_dec(&layout->refcount))
170 vn_descriptor_set_layout_destroy(dev, layout);
171 }
172
173 #endif /* VN_DESCRIPTOR_SET_H */
174