2
* Copyright © 2020 Mike Blumenkrantz
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:
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
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
24
* Mike Blumenkrantz <michael.blumenkrantz@gmail.com>
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"
34
#include "zink_batch.h"
39
#ifndef ZINK_SHADER_COUNT
40
#define ZINK_SHADER_COUNT (PIPE_SHADER_TYPES - 1)
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
ZINK_DESCRIPTOR_BINDLESS,
52
#define ZINK_MAX_DESCRIPTORS_PER_TYPE (32 * ZINK_SHADER_COUNT)
54
#define ZINK_BINDLESS_IS_BUFFER(HANDLE) (HANDLE >= ZINK_MAX_BINDLESS_HANDLES)
56
struct zink_descriptor_refs {
57
struct util_dynarray refs;
61
/* hashes of all the named types in a given state */
62
struct zink_descriptor_state {
63
bool valid[ZINK_DESCRIPTOR_TYPES];
64
uint32_t state[ZINK_DESCRIPTOR_TYPES];
67
enum zink_descriptor_size_index {
69
ZDS_INDEX_COMBINED_SAMPLER,
70
ZDS_INDEX_UNIFORM_TEXELS,
71
ZDS_INDEX_STORAGE_BUFFER,
72
ZDS_INDEX_STORAGE_IMAGE,
73
ZDS_INDEX_STORAGE_TEXELS,
79
struct zink_image_view;
83
struct zink_sampler_view;
88
struct zink_descriptor_state_key {
89
bool exists[ZINK_SHADER_COUNT];
90
uint32_t state[ZINK_SHADER_COUNT];
93
struct zink_descriptor_layout_key {
94
unsigned num_bindings;
95
VkDescriptorSetLayoutBinding *bindings;
98
struct zink_descriptor_layout {
99
VkDescriptorSetLayout layout;
100
VkDescriptorUpdateTemplateKHR desc_template;
103
struct zink_descriptor_pool_key {
105
struct zink_descriptor_layout_key *layout;
106
VkDescriptorPoolSize sizes[2];
109
struct zink_descriptor_reference {
114
struct zink_descriptor_data {
115
struct zink_descriptor_state gfx_descriptor_states[ZINK_SHADER_COUNT]; // keep incremental hashes here
116
struct zink_descriptor_state descriptor_states[2]; // gfx, compute
117
struct hash_table *descriptor_pools[ZINK_DESCRIPTOR_TYPES];
119
struct zink_descriptor_layout_key *push_layout_keys[2]; //gfx, compute
120
struct zink_descriptor_pool *push_pool[2]; //gfx, compute
121
struct zink_descriptor_layout *push_dsl[2]; //gfx, compute
122
uint8_t last_push_usage[2];
124
uint32_t push_state[2];
125
bool gfx_push_valid[ZINK_SHADER_COUNT];
126
uint32_t gfx_push_state[ZINK_SHADER_COUNT];
127
struct zink_descriptor_set *last_set[2];
129
VkDescriptorPool dummy_pool;
130
struct zink_descriptor_layout *dummy_dsl;
131
VkDescriptorSet dummy_set;
133
VkDescriptorSetLayout bindless_layout;
134
VkDescriptorPool bindless_pool;
135
VkDescriptorSet bindless_set;
138
bool changed[2][ZINK_DESCRIPTOR_TYPES + 1];
140
struct zink_program *pg[2]; //gfx, compute
143
struct zink_program_descriptor_data {
147
uint8_t binding_usage;
148
struct zink_descriptor_pool_key *pool_key[ZINK_DESCRIPTOR_TYPES]; //push set doesn't need one
149
struct zink_descriptor_layout *layouts[ZINK_DESCRIPTOR_TYPES + 1];
150
VkDescriptorUpdateTemplateKHR push_template;
153
struct zink_batch_descriptor_data {
154
struct set *desc_sets;
157
static inline enum zink_descriptor_size_index
158
zink_vktype_to_size_idx(VkDescriptorType type)
161
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
162
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC:
163
return ZDS_INDEX_UBO;
164
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
165
return ZDS_INDEX_COMBINED_SAMPLER;
166
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
167
return ZDS_INDEX_UNIFORM_TEXELS;
168
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
169
return ZDS_INDEX_STORAGE_BUFFER;
170
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
171
return ZDS_INDEX_STORAGE_IMAGE;
172
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
173
return ZDS_INDEX_STORAGE_TEXELS;
176
unreachable("unknown type");
179
static inline enum zink_descriptor_size_index
180
zink_descriptor_type_to_size_idx(enum zink_descriptor_type type)
183
case ZINK_DESCRIPTOR_TYPE_UBO:
184
return ZDS_INDEX_UBO;
185
case ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW:
186
return ZDS_INDEX_COMBINED_SAMPLER;
187
case ZINK_DESCRIPTOR_TYPE_SSBO:
188
return ZDS_INDEX_STORAGE_BUFFER;
189
case ZINK_DESCRIPTOR_TYPE_IMAGE:
190
return ZDS_INDEX_STORAGE_IMAGE;
193
unreachable("unknown type");
196
zink_descriptor_layouts_init(struct zink_context *ctx);
199
zink_descriptor_layouts_deinit(struct zink_context *ctx);
202
zink_get_sampler_view_hash(struct zink_context *ctx, struct zink_sampler_view *sampler_view, bool is_buffer);
204
zink_get_image_view_hash(struct zink_context *ctx, struct zink_image_view *image_view, bool is_buffer);
206
zink_descriptor_util_alloc_sets(struct zink_screen *screen, VkDescriptorSetLayout dsl, VkDescriptorPool pool, VkDescriptorSet *sets, unsigned num_sets);
207
struct zink_descriptor_layout *
208
zink_descriptor_util_layout_get(struct zink_context *ctx, enum zink_descriptor_type type,
209
VkDescriptorSetLayoutBinding *bindings, unsigned num_bindings,
210
struct zink_descriptor_layout_key **layout_key);
211
struct zink_descriptor_pool_key *
212
zink_descriptor_util_pool_key_get(struct zink_context *ctx, enum zink_descriptor_type type,
213
struct zink_descriptor_layout_key *layout_key,
214
VkDescriptorPoolSize *sizes, unsigned num_type_sizes);
216
zink_descriptor_util_init_fbfetch(struct zink_context *ctx);
218
zink_descriptor_util_push_layouts_get(struct zink_context *ctx, struct zink_descriptor_layout **dsls, struct zink_descriptor_layout_key **layout_keys);
220
zink_descriptor_util_image_layout_eval(const struct zink_context *ctx, const struct zink_resource *res, bool is_compute);
222
zink_descriptors_init_bindless(struct zink_context *ctx);
224
zink_descriptors_deinit_bindless(struct zink_context *ctx);
226
zink_descriptors_update_bindless(struct zink_context *ctx);
227
/* these two can't be called in lazy mode */
229
zink_descriptor_set_refs_clear(struct zink_descriptor_refs *refs, void *ptr);
231
zink_descriptor_set_recycle(struct zink_descriptor_set *zds);
238
zink_descriptor_program_init(struct zink_context *ctx, struct zink_program *pg);
241
zink_descriptor_program_deinit(struct zink_context *ctx, struct zink_program *pg);
244
zink_descriptors_update(struct zink_context *ctx, bool is_compute);
248
zink_context_invalidate_descriptor_state(struct zink_context *ctx, enum pipe_shader_type shader, enum zink_descriptor_type type, unsigned, unsigned);
251
zink_get_sampler_view_hash(struct zink_context *ctx, struct zink_sampler_view *sampler_view, bool is_buffer);
253
zink_get_image_view_hash(struct zink_context *ctx, struct zink_image_view *image_view, bool is_buffer);
254
struct zink_resource *
255
zink_get_resource_for_descriptor(struct zink_context *ctx, enum zink_descriptor_type type, enum pipe_shader_type shader, int idx);
258
zink_batch_descriptor_deinit(struct zink_screen *screen, struct zink_batch_state *bs);
260
zink_batch_descriptor_reset(struct zink_screen *screen, struct zink_batch_state *bs);
262
zink_batch_descriptor_init(struct zink_screen *screen, struct zink_batch_state *bs);
265
zink_descriptors_init(struct zink_context *ctx);
268
zink_descriptors_deinit(struct zink_context *ctx);
272
zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program *pg);
275
zink_descriptor_program_deinit_lazy(struct zink_context *ctx, struct zink_program *pg);
278
zink_descriptors_update_lazy(struct zink_context *ctx, bool is_compute);
282
zink_context_invalidate_descriptor_state_lazy(struct zink_context *ctx, enum pipe_shader_type shader, enum zink_descriptor_type type, unsigned, unsigned);
285
zink_batch_descriptor_deinit_lazy(struct zink_screen *screen, struct zink_batch_state *bs);
287
zink_batch_descriptor_reset_lazy(struct zink_screen *screen, struct zink_batch_state *bs);
289
zink_batch_descriptor_init_lazy(struct zink_screen *screen, struct zink_batch_state *bs);
292
zink_descriptors_init_lazy(struct zink_context *ctx);
295
zink_descriptors_deinit_lazy(struct zink_context *ctx);
298
zink_descriptor_set_update_lazy(struct zink_context *ctx, struct zink_program *pg, enum zink_descriptor_type type, VkDescriptorSet set);
300
zink_descriptors_update_lazy_masked(struct zink_context *ctx, bool is_compute, uint8_t changed_sets, uint8_t bind_sets);
302
zink_descriptors_alloc_lazy_push(struct zink_context *ctx);