Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mesa
Path: blob/21.2-virgl/src/gallium/drivers/zink/zink_descriptors.h
4570 views
1
/*
2
* Copyright © 2020 Mike Blumenkrantz
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
* Authors:
24
* Mike Blumenkrantz <[email protected]>
25
*/
26
27
#ifndef ZINK_DESCRIPTOR_H
28
# define ZINK_DESCRIPTOR_H
29
#include <vulkan/vulkan.h>
30
#include "util/u_dynarray.h"
31
#include "util/u_inlines.h"
32
#include "util/simple_mtx.h"
33
34
#include "zink_batch.h"
35
#ifdef __cplusplus
36
extern "C" {
37
#endif
38
39
#ifndef ZINK_SHADER_COUNT
40
#define ZINK_SHADER_COUNT (PIPE_SHADER_TYPES - 1)
41
#endif
42
43
enum zink_descriptor_type {
44
ZINK_DESCRIPTOR_TYPE_UBO,
45
ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW,
46
ZINK_DESCRIPTOR_TYPE_SSBO,
47
ZINK_DESCRIPTOR_TYPE_IMAGE,
48
ZINK_DESCRIPTOR_TYPES,
49
};
50
51
#define ZINK_MAX_DESCRIPTORS_PER_TYPE 32
52
53
struct zink_descriptor_refs {
54
struct util_dynarray refs;
55
};
56
57
58
/* hashes of all the named types in a given state */
59
struct zink_descriptor_state {
60
bool valid[ZINK_DESCRIPTOR_TYPES];
61
uint32_t state[ZINK_DESCRIPTOR_TYPES];
62
};
63
64
enum zink_descriptor_size_index {
65
ZDS_INDEX_UBO,
66
ZDS_INDEX_COMBINED_SAMPLER,
67
ZDS_INDEX_UNIFORM_TEXELS,
68
ZDS_INDEX_STORAGE_BUFFER,
69
ZDS_INDEX_STORAGE_IMAGE,
70
ZDS_INDEX_STORAGE_TEXELS,
71
};
72
73
struct hash_table;
74
75
struct zink_context;
76
struct zink_image_view;
77
struct zink_program;
78
struct zink_resource;
79
struct zink_sampler;
80
struct zink_sampler_view;
81
struct zink_shader;
82
struct zink_screen;
83
84
85
struct zink_descriptor_state_key {
86
bool exists[ZINK_SHADER_COUNT];
87
uint32_t state[ZINK_SHADER_COUNT];
88
};
89
90
struct zink_descriptor_layout_key {
91
unsigned num_descriptors;
92
VkDescriptorSetLayoutBinding *bindings;
93
unsigned use_count;
94
};
95
96
struct zink_descriptor_layout {
97
VkDescriptorSetLayout layout;
98
VkDescriptorUpdateTemplateKHR desc_template;
99
};
100
101
struct zink_descriptor_pool_key {
102
struct zink_descriptor_layout_key *layout;
103
unsigned num_type_sizes;
104
VkDescriptorPoolSize *sizes;
105
};
106
107
struct zink_descriptor_reference {
108
void **ref;
109
bool *invalid;
110
};
111
112
113
struct zink_descriptor_data {
114
struct zink_descriptor_state gfx_descriptor_states[ZINK_SHADER_COUNT]; // keep incremental hashes here
115
struct zink_descriptor_state descriptor_states[2]; // gfx, compute
116
struct hash_table *descriptor_pools[ZINK_DESCRIPTOR_TYPES];
117
118
struct zink_descriptor_layout_key *push_layout_keys[2]; //gfx, compute
119
struct zink_descriptor_pool *push_pool[2]; //gfx, compute
120
struct zink_descriptor_layout *push_dsl[2]; //gfx, compute
121
uint8_t last_push_usage[2];
122
bool push_valid[2];
123
uint32_t push_state[2];
124
bool gfx_push_valid[ZINK_SHADER_COUNT];
125
uint32_t gfx_push_state[ZINK_SHADER_COUNT];
126
struct zink_descriptor_set *last_set[2];
127
128
VkDescriptorPool dummy_pool;
129
struct zink_descriptor_layout *dummy_dsl;
130
VkDescriptorSet dummy_set;
131
132
bool changed[2][ZINK_DESCRIPTOR_TYPES + 1];
133
struct zink_program *pg[2]; //gfx, compute
134
};
135
136
struct zink_program_descriptor_data {
137
uint8_t push_usage;
138
VkDescriptorPoolSize sizes[6]; //zink_descriptor_size_index
139
struct zink_descriptor_layout_key *layout_key[ZINK_DESCRIPTOR_TYPES]; //push set doesn't need one
140
uint8_t binding_usage;
141
struct zink_descriptor_layout *layouts[ZINK_DESCRIPTOR_TYPES + 1];
142
VkDescriptorUpdateTemplateKHR push_template;
143
};
144
145
struct zink_batch_descriptor_data {
146
struct set *desc_sets;
147
};
148
149
static inline enum zink_descriptor_size_index
150
zink_vktype_to_size_idx(VkDescriptorType type)
151
{
152
switch (type) {
153
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
154
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
155
return ZDS_INDEX_UBO;
156
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
157
return ZDS_INDEX_COMBINED_SAMPLER;
158
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
159
return ZDS_INDEX_UNIFORM_TEXELS;
160
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
161
return ZDS_INDEX_STORAGE_BUFFER;
162
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
163
return ZDS_INDEX_STORAGE_IMAGE;
164
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
165
return ZDS_INDEX_STORAGE_TEXELS;
166
default: break;
167
}
168
unreachable("unknown type");
169
}
170
171
static inline enum zink_descriptor_size_index
172
zink_descriptor_type_to_size_idx(enum zink_descriptor_type type)
173
{
174
switch (type) {
175
case ZINK_DESCRIPTOR_TYPE_UBO:
176
return ZDS_INDEX_UBO;
177
case ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW:
178
return ZDS_INDEX_COMBINED_SAMPLER;
179
case ZINK_DESCRIPTOR_TYPE_SSBO:
180
return ZDS_INDEX_STORAGE_BUFFER;
181
case ZINK_DESCRIPTOR_TYPE_IMAGE:
182
return ZDS_INDEX_STORAGE_IMAGE;
183
default: break;
184
}
185
unreachable("unknown type");
186
}
187
unsigned
188
zink_descriptor_program_num_sizes(struct zink_program *pg, enum zink_descriptor_type type);
189
bool
190
zink_descriptor_layouts_init(struct zink_context *ctx);
191
192
void
193
zink_descriptor_layouts_deinit(struct zink_context *ctx);
194
195
uint32_t
196
zink_get_sampler_view_hash(struct zink_context *ctx, struct zink_sampler_view *sampler_view, bool is_buffer);
197
uint32_t
198
zink_get_image_view_hash(struct zink_context *ctx, struct zink_image_view *image_view, bool is_buffer);
199
bool
200
zink_descriptor_util_alloc_sets(struct zink_screen *screen, VkDescriptorSetLayout dsl, VkDescriptorPool pool, VkDescriptorSet *sets, unsigned num_sets);
201
struct zink_descriptor_layout *
202
zink_descriptor_util_layout_get(struct zink_context *ctx, enum zink_descriptor_type type,
203
VkDescriptorSetLayoutBinding *bindings, unsigned num_bindings,
204
struct zink_descriptor_layout_key **layout_key);
205
bool
206
zink_descriptor_util_push_layouts_get(struct zink_context *ctx, struct zink_descriptor_layout **dsls, struct zink_descriptor_layout_key **layout_keys);
207
void
208
zink_descriptor_util_init_null_set(struct zink_context *ctx, VkDescriptorSet desc_set);
209
struct zink_resource *
210
zink_get_resource_for_descriptor(struct zink_context *ctx, enum zink_descriptor_type type, enum pipe_shader_type shader, int idx);
211
VkImageLayout
212
zink_descriptor_util_image_layout_eval(const struct zink_resource *res, bool is_compute);
213
214
/* these two can't be called in lazy mode */
215
void
216
zink_descriptor_set_refs_clear(struct zink_descriptor_refs *refs, void *ptr);
217
void
218
zink_descriptor_set_recycle(struct zink_descriptor_set *zds);
219
220
221
222
223
224
bool
225
zink_descriptor_program_init(struct zink_context *ctx, struct zink_program *pg);
226
227
void
228
zink_descriptor_program_deinit(struct zink_screen *screen, struct zink_program *pg);
229
230
void
231
zink_descriptors_update(struct zink_context *ctx, bool is_compute);
232
233
234
void
235
zink_context_invalidate_descriptor_state(struct zink_context *ctx, enum pipe_shader_type shader, enum zink_descriptor_type type, unsigned, unsigned);
236
237
uint32_t
238
zink_get_sampler_view_hash(struct zink_context *ctx, struct zink_sampler_view *sampler_view, bool is_buffer);
239
uint32_t
240
zink_get_image_view_hash(struct zink_context *ctx, struct zink_image_view *image_view, bool is_buffer);
241
struct zink_resource *
242
zink_get_resource_for_descriptor(struct zink_context *ctx, enum zink_descriptor_type type, enum pipe_shader_type shader, int idx);
243
244
void
245
zink_batch_descriptor_deinit(struct zink_screen *screen, struct zink_batch_state *bs);
246
void
247
zink_batch_descriptor_reset(struct zink_screen *screen, struct zink_batch_state *bs);
248
bool
249
zink_batch_descriptor_init(struct zink_screen *screen, struct zink_batch_state *bs);
250
251
bool
252
zink_descriptors_init(struct zink_context *ctx);
253
254
void
255
zink_descriptors_deinit(struct zink_context *ctx);
256
257
//LAZY
258
bool
259
zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program *pg);
260
261
void
262
zink_descriptor_program_deinit_lazy(struct zink_screen *screen, struct zink_program *pg);
263
264
void
265
zink_descriptors_update_lazy(struct zink_context *ctx, bool is_compute);
266
267
268
void
269
zink_context_invalidate_descriptor_state_lazy(struct zink_context *ctx, enum pipe_shader_type shader, enum zink_descriptor_type type, unsigned, unsigned);
270
271
void
272
zink_batch_descriptor_deinit_lazy(struct zink_screen *screen, struct zink_batch_state *bs);
273
void
274
zink_batch_descriptor_reset_lazy(struct zink_screen *screen, struct zink_batch_state *bs);
275
bool
276
zink_batch_descriptor_init_lazy(struct zink_screen *screen, struct zink_batch_state *bs);
277
278
bool
279
zink_descriptors_init_lazy(struct zink_context *ctx);
280
281
void
282
zink_descriptors_deinit_lazy(struct zink_context *ctx);
283
284
void
285
zink_descriptor_set_update_lazy(struct zink_context *ctx, struct zink_program *pg, enum zink_descriptor_type type, VkDescriptorSet set);
286
#ifdef __cplusplus
287
}
288
#endif
289
290
#endif
291
292