turnip: implement VK_KHR_sampler_ycbcr_conversion
[mesa.git] / src / freedreno / vulkan / tu_descriptor_set.h
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
21 * DEALINGS IN THE SOFTWARE.
22 */
23
24 #ifndef TU_DESCRIPTOR_SET_H
25 #define TU_DESCRIPTOR_SET_H
26
27 #include <vulkan/vulkan.h>
28
29 /* The hardware supports 5 descriptor sets, but we reserve 1 for dynamic
30 * descriptors and input attachments.
31 */
32 #define MAX_SETS 4
33
34 struct tu_descriptor_set_binding_layout
35 {
36 VkDescriptorType type;
37
38 /* Number of array elements in this binding */
39 uint32_t array_size;
40
41 /* The size in bytes of each Vulkan descriptor. */
42 uint32_t size;
43
44 uint32_t offset;
45
46 /* For descriptors that point to a buffer, index into the array of BO's to
47 * be added to the cmdbuffer's used BO list.
48 */
49 uint32_t buffer_offset;
50
51 /* Index into the pDynamicOffsets array for dynamic descriptors, as well as
52 * the array of dynamic descriptors (offsetted by
53 * tu_pipeline_layout::set::dynamic_offset_start).
54 */
55 uint32_t dynamic_offset_offset;
56
57 /* Index into the array of dynamic input attachment descriptors */
58 uint32_t input_attachment_offset;
59
60 /* Offset in the tu_descriptor_set_layout of the immutable samplers, or 0
61 * if there are no immutable samplers. */
62 uint32_t immutable_samplers_offset;
63
64 /* Offset in the tu_descriptor_set_layout of the ycbcr samplers, or 0
65 * if there are no immutable samplers. */
66 uint32_t ycbcr_samplers_offset;
67
68 /* Shader stages that use this binding */
69 uint32_t shader_stages;
70 };
71
72 struct tu_descriptor_set_layout
73 {
74 /* The create flags for this descriptor set layout */
75 VkDescriptorSetLayoutCreateFlags flags;
76
77 /* Number of bindings in this descriptor set */
78 uint32_t binding_count;
79
80 /* Total size of the descriptor set with room for all array entries */
81 uint32_t size;
82
83 /* Shader stages affected by this descriptor set */
84 uint16_t shader_stages;
85
86 /* Number of dynamic offsets used by this descriptor set */
87 uint16_t dynamic_offset_count;
88
89 /* Number of input attachments used by the descriptor set */
90 uint16_t input_attachment_count;
91
92 /* A bitfield of which dynamic buffers are ubo's, to make the
93 * descriptor-binding-time patching easier.
94 */
95 uint32_t dynamic_ubo;
96
97 uint32_t buffer_count;
98
99 bool has_immutable_samplers;
100 bool has_variable_descriptors;
101
102 /* Bindings in this descriptor set */
103 struct tu_descriptor_set_binding_layout binding[0];
104 };
105
106 struct tu_pipeline_layout
107 {
108 struct
109 {
110 struct tu_descriptor_set_layout *layout;
111 uint32_t size;
112 uint32_t dynamic_offset_start;
113 uint32_t input_attachment_start;
114 } set[MAX_SETS];
115
116 uint32_t num_sets;
117 uint32_t push_constant_size;
118 uint32_t dynamic_offset_count;
119 uint32_t input_attachment_count;
120
121 unsigned char sha1[20];
122 };
123
124 static inline const uint32_t *
125 tu_immutable_samplers(const struct tu_descriptor_set_layout *set,
126 const struct tu_descriptor_set_binding_layout *binding)
127 {
128 return (void *) ((const char *) set + binding->immutable_samplers_offset);
129 }
130
131 static inline const struct tu_sampler_ycbcr_conversion *
132 tu_immutable_ycbcr_samplers(const struct tu_descriptor_set_layout *set,
133 const struct tu_descriptor_set_binding_layout *binding)
134 {
135 if (!binding->ycbcr_samplers_offset)
136 return NULL;
137
138 return (void *) ((const char *) set + binding->ycbcr_samplers_offset);
139 }
140
141 #endif /* TU_DESCRIPTOR_SET_H */