• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright © 2016 Bas Nieuwenhuizen
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  */
23 
24 #ifndef RADV_DESCRIPTOR_SET_H
25 #define RADV_DESCRIPTOR_SET_H
26 
27 #include "radv_constants.h"
28 
29 #include "vulkan/runtime/vk_descriptor_set_layout.h"
30 #include "vulkan/runtime/vk_object.h"
31 
32 #include <vulkan/vulkan.h>
33 
34 struct radv_descriptor_set_binding_layout {
35    VkDescriptorType type;
36 
37    /* Number of array elements in this binding */
38    uint32_t array_size;
39 
40    uint32_t offset;
41    uint32_t buffer_offset;
42    uint16_t dynamic_offset_offset;
43 
44    uint16_t dynamic_offset_count;
45    /* redundant with the type, each for a single array element */
46    uint32_t size;
47 
48    /* Offset in the radv_descriptor_set_layout of the immutable samplers, or 0
49     * if there are no immutable samplers. */
50    uint32_t immutable_samplers_offset;
51    bool immutable_samplers_equal;
52 };
53 
54 struct radv_descriptor_set_layout {
55    struct vk_descriptor_set_layout vk;
56 
57    /* Hash of all fields below */
58    uint8_t hash[SHA1_DIGEST_LENGTH];
59 
60    /* Everything below is hashed and shouldn't contain any pointers. Be careful when modifying this
61     * structure.
62     */
63 
64    /* The create flags for this descriptor set layout */
65    VkDescriptorSetLayoutCreateFlags flags;
66 
67    /* Number of bindings in this descriptor set */
68    uint32_t binding_count;
69 
70    /* Total size of the descriptor set with room for all array entries */
71    uint32_t size;
72 
73    /* Shader stages affected by this descriptor set */
74    uint16_t shader_stages;
75    uint16_t dynamic_shader_stages;
76 
77    /* Number of buffers in this descriptor set */
78    uint32_t buffer_count;
79 
80    /* Number of dynamic offsets used by this descriptor set */
81    uint16_t dynamic_offset_count;
82 
83    bool has_immutable_samplers;
84    bool has_variable_descriptors;
85 
86    uint32_t ycbcr_sampler_offsets_offset;
87 
88    /* Bindings in this descriptor set */
89    struct radv_descriptor_set_binding_layout binding[0];
90 };
91 
92 struct radv_descriptor_range {
93    uint64_t va;
94    uint32_t size;
95 };
96 
97 struct radv_descriptor_set_header {
98    struct vk_object_base base;
99    struct radv_descriptor_set_layout *layout;
100    uint32_t size;
101    uint32_t buffer_count;
102 
103    struct radeon_winsys_bo *bo;
104    uint64_t va;
105    uint32_t *mapped_ptr;
106    struct radv_descriptor_range *dynamic_descriptors;
107 };
108 
109 struct radv_descriptor_set {
110    struct radv_descriptor_set_header header;
111 
112    struct radeon_winsys_bo *descriptors[];
113 };
114 
115 struct radv_push_descriptor_set {
116    struct radv_descriptor_set_header set;
117    uint32_t capacity;
118 };
119 
120 struct radv_descriptor_pool_entry {
121    uint32_t offset;
122    uint32_t size;
123    struct radv_descriptor_set *set;
124 };
125 
126 struct radv_descriptor_pool {
127    struct vk_object_base base;
128    struct radeon_winsys_bo *bo;
129    uint8_t *host_bo;
130    uint8_t *mapped_ptr;
131    uint64_t current_offset;
132    uint64_t size;
133 
134    uint8_t *host_memory_base;
135    uint8_t *host_memory_ptr;
136    uint8_t *host_memory_end;
137 
138    uint32_t entry_count;
139    uint32_t max_entry_count;
140 
141    union {
142       struct radv_descriptor_set *sets[0];
143       struct radv_descriptor_pool_entry entries[0];
144    };
145 };
146 
147 struct radv_descriptor_update_template_entry {
148    VkDescriptorType descriptor_type;
149 
150    /* The number of descriptors to update */
151    uint32_t descriptor_count;
152 
153    /* Into mapped_ptr or dynamic_descriptors, in units of the respective array */
154    uint32_t dst_offset;
155 
156    /* In dwords. Not valid/used for dynamic descriptors */
157    uint32_t dst_stride;
158 
159    uint32_t buffer_offset;
160 
161    /* Only valid for combined image samplers and samplers */
162    uint8_t has_sampler;
163    uint8_t sampler_offset;
164 
165    /* In bytes */
166    size_t src_offset;
167    size_t src_stride;
168 
169    /* For push descriptors */
170    const uint32_t *immutable_samplers;
171 };
172 
173 struct radv_descriptor_update_template {
174    struct vk_object_base base;
175    uint32_t entry_count;
176    VkPipelineBindPoint bind_point;
177    struct radv_descriptor_update_template_entry entry[0];
178 };
179 
180 struct radv_pipeline_layout {
181    struct vk_object_base base;
182    struct {
183       struct radv_descriptor_set_layout *layout;
184       uint32_t dynamic_offset_start;
185    } set[MAX_SETS];
186 
187    uint32_t num_sets;
188    uint32_t push_constant_size;
189    uint32_t dynamic_offset_count;
190    uint16_t dynamic_shader_stages;
191 
192    bool independent_sets;
193 
194    unsigned char sha1[20];
195 };
196 
197 static inline const uint32_t *
radv_immutable_samplers(const struct radv_descriptor_set_layout * set,const struct radv_descriptor_set_binding_layout * binding)198 radv_immutable_samplers(const struct radv_descriptor_set_layout *set,
199                         const struct radv_descriptor_set_binding_layout *binding)
200 {
201    return (const uint32_t *)((const char *)set + binding->immutable_samplers_offset);
202 }
203 
204 static inline unsigned
radv_combined_image_descriptor_sampler_offset(const struct radv_descriptor_set_binding_layout * binding)205 radv_combined_image_descriptor_sampler_offset(const struct radv_descriptor_set_binding_layout *binding)
206 {
207    return binding->size - ((!binding->immutable_samplers_equal) ? 16 : 0);
208 }
209 
210 static inline const struct vk_ycbcr_conversion_state *
radv_immutable_ycbcr_samplers(const struct radv_descriptor_set_layout * set,unsigned binding_index)211 radv_immutable_ycbcr_samplers(const struct radv_descriptor_set_layout *set, unsigned binding_index)
212 {
213    if (!set->ycbcr_sampler_offsets_offset)
214       return NULL;
215 
216    const uint32_t *offsets = (const uint32_t *)((const char *)set + set->ycbcr_sampler_offsets_offset);
217 
218    if (offsets[binding_index] == 0)
219       return NULL;
220    return (const struct vk_ycbcr_conversion_state *)((const char *)set + offsets[binding_index]);
221 }
222 
223 struct radv_device;
224 
225 void radv_pipeline_layout_init(struct radv_device *device, struct radv_pipeline_layout *layout, bool independent_sets);
226 void radv_pipeline_layout_add_set(struct radv_pipeline_layout *layout, uint32_t set_idx,
227                                   struct radv_descriptor_set_layout *set_layout);
228 void radv_pipeline_layout_hash(struct radv_pipeline_layout *layout);
229 void radv_pipeline_layout_finish(struct radv_device *device, struct radv_pipeline_layout *layout);
230 
231 VkResult radv_create_descriptor_pool(struct radv_device *device, const VkDescriptorPoolCreateInfo *pCreateInfo,
232                                      const VkAllocationCallbacks *pAllocator, VkDescriptorPool *pDescriptorPool,
233                                      bool is_internal);
234 
235 #endif /* RADV_DESCRIPTOR_SET_H */
236