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 /* Everything below is hashed and shouldn't contain any pointers. Be careful when modifying this
58 * structure.
59 */
60
61 /* The create flags for this descriptor set layout */
62 VkDescriptorSetLayoutCreateFlags flags;
63
64 /* Number of bindings in this descriptor set */
65 uint32_t binding_count;
66
67 /* Total size of the descriptor set with room for all array entries */
68 uint32_t size;
69
70 /* CPU size of this struct + all associated data, for hashing. */
71 uint32_t layout_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_pipeline_layout {
93 struct vk_object_base base;
94 struct {
95 struct radv_descriptor_set_layout *layout;
96 uint32_t dynamic_offset_start;
97 } set[MAX_SETS];
98
99 uint32_t num_sets;
100 uint32_t push_constant_size;
101 uint32_t dynamic_offset_count;
102 uint16_t dynamic_shader_stages;
103
104 bool independent_sets;
105
106 unsigned char sha1[20];
107 };
108
109 static inline const uint32_t *
radv_immutable_samplers(const struct radv_descriptor_set_layout * set,const struct radv_descriptor_set_binding_layout * binding)110 radv_immutable_samplers(const struct radv_descriptor_set_layout *set,
111 const struct radv_descriptor_set_binding_layout *binding)
112 {
113 return (const uint32_t *)((const char *)set + binding->immutable_samplers_offset);
114 }
115
116 static inline unsigned
radv_combined_image_descriptor_sampler_offset(const struct radv_descriptor_set_binding_layout * binding)117 radv_combined_image_descriptor_sampler_offset(
118 const struct radv_descriptor_set_binding_layout *binding)
119 {
120 return binding->size - ((!binding->immutable_samplers_equal) ? 16 : 0);
121 }
122
123 static inline const struct radv_sampler_ycbcr_conversion_state *
radv_immutable_ycbcr_samplers(const struct radv_descriptor_set_layout * set,unsigned binding_index)124 radv_immutable_ycbcr_samplers(const struct radv_descriptor_set_layout *set, unsigned binding_index)
125 {
126 if (!set->ycbcr_sampler_offsets_offset)
127 return NULL;
128
129 const uint32_t *offsets =
130 (const uint32_t *)((const char *)set + set->ycbcr_sampler_offsets_offset);
131
132 if (offsets[binding_index] == 0)
133 return NULL;
134 return (const struct radv_sampler_ycbcr_conversion_state *)((const char *)set +
135 offsets[binding_index]);
136 }
137
138 struct radv_device;
139
140 void radv_pipeline_layout_init(struct radv_device *device, struct radv_pipeline_layout *layout,
141 bool independent_sets);
142 void radv_pipeline_layout_add_set(struct radv_pipeline_layout *layout, uint32_t set_idx,
143 struct radv_descriptor_set_layout *set_layout);
144 void radv_pipeline_layout_hash(struct radv_pipeline_layout *layout);
145 void radv_pipeline_layout_finish(struct radv_device *device, struct radv_pipeline_layout *layout);
146
147 #endif /* RADV_DESCRIPTOR_SET_H */
148