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/util/vk_object.h"
30
31 #include <vulkan/vulkan.h>
32
33 struct radv_descriptor_set_binding_layout {
34 VkDescriptorType type;
35
36 /* Number of array elements in this binding */
37 uint32_t array_size;
38
39 uint32_t offset;
40 uint32_t buffer_offset;
41 uint16_t dynamic_offset_offset;
42
43 uint16_t dynamic_offset_count;
44 /* redundant with the type, each for a single array element */
45 uint32_t size;
46
47 /* Offset in the radv_descriptor_set_layout of the immutable samplers, or 0
48 * if there are no immutable samplers. */
49 uint32_t immutable_samplers_offset;
50 bool immutable_samplers_equal;
51 };
52
53 struct radv_descriptor_set_layout {
54 struct vk_object_base base;
55
56 /* The create flags for this descriptor set layout */
57 VkDescriptorSetLayoutCreateFlags flags;
58
59 /* Number of bindings in this descriptor set */
60 uint32_t binding_count;
61
62 /* Total size of the descriptor set with room for all array entries */
63 uint32_t size;
64
65 /* CPU size of this struct + all associated data, for hashing. */
66 uint32_t layout_size;
67
68 /* Shader stages affected by this descriptor set */
69 uint16_t shader_stages;
70 uint16_t dynamic_shader_stages;
71
72 /* Number of buffers in this descriptor set */
73 uint32_t buffer_count;
74
75 /* Number of dynamic offsets used by this descriptor set */
76 uint16_t dynamic_offset_count;
77
78 bool has_immutable_samplers;
79 bool has_variable_descriptors;
80
81 uint32_t ycbcr_sampler_offsets_offset;
82
83 /* Bindings in this descriptor set */
84 struct radv_descriptor_set_binding_layout binding[0];
85 };
86
87 struct radv_pipeline_layout {
88 struct vk_object_base base;
89 struct {
90 struct radv_descriptor_set_layout *layout;
91 uint32_t size;
92 uint16_t dynamic_offset_start;
93 uint16_t dynamic_offset_count;
94 VkShaderStageFlags dynamic_offset_stages;
95 } set[MAX_SETS];
96
97 uint32_t num_sets;
98 uint32_t push_constant_size;
99 uint32_t dynamic_offset_count;
100 uint16_t dynamic_shader_stages;
101
102 unsigned char sha1[20];
103 };
104
105 static inline const uint32_t *
radv_immutable_samplers(const struct radv_descriptor_set_layout * set,const struct radv_descriptor_set_binding_layout * binding)106 radv_immutable_samplers(const struct radv_descriptor_set_layout *set,
107 const struct radv_descriptor_set_binding_layout *binding) {
108 return (const uint32_t*)((const char*)set + binding->immutable_samplers_offset);
109 }
110
111 static inline unsigned
radv_combined_image_descriptor_sampler_offset(const struct radv_descriptor_set_binding_layout * binding)112 radv_combined_image_descriptor_sampler_offset(const struct radv_descriptor_set_binding_layout *binding)
113 {
114 return binding->size - ((!binding->immutable_samplers_equal) ? 16 : 0);
115 }
116
117 static inline const struct radv_sampler_ycbcr_conversion *
radv_immutable_ycbcr_samplers(const struct radv_descriptor_set_layout * set,unsigned binding_index)118 radv_immutable_ycbcr_samplers(const struct radv_descriptor_set_layout *set,
119 unsigned binding_index)
120 {
121 if (!set->ycbcr_sampler_offsets_offset)
122 return NULL;
123
124 const uint32_t *offsets = (const uint32_t*)((const char*)set + set->ycbcr_sampler_offsets_offset);
125
126 if (offsets[binding_index] == 0)
127 return NULL;
128 return (const struct radv_sampler_ycbcr_conversion *)((const char*)set + offsets[binding_index]);
129 }
130 #endif /* RADV_DESCRIPTOR_SET_H */
131