~mmach/netext73/mesa-haswell

« back to all changes in this revision

Viewing changes to src/gallium/drivers/zink/zink_descriptors.h

  • Committer: mmach
  • Date: 2022-09-22 19:56:13 UTC
  • Revision ID: netbit73@gmail.com-20220922195613-wtik9mmy20tmor0i
2022-09-22 21:17:09

Show diffs side-by-side

added added

removed removed

Lines of Context:
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 <michael.blumenkrantz@gmail.com>
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
 
   ZINK_DESCRIPTOR_BINDLESS,
50
 
};
51
 
 
52
 
#define ZINK_MAX_DESCRIPTORS_PER_TYPE (32 * ZINK_SHADER_COUNT)
53
 
 
54
 
#define ZINK_BINDLESS_IS_BUFFER(HANDLE) (HANDLE >= ZINK_MAX_BINDLESS_HANDLES)
55
 
 
56
 
struct zink_descriptor_refs {
57
 
   struct util_dynarray refs;
58
 
};
59
 
 
60
 
 
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];
65
 
};
66
 
 
67
 
enum zink_descriptor_size_index {
68
 
   ZDS_INDEX_UBO,
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,
74
 
};
75
 
 
76
 
struct hash_table;
77
 
 
78
 
struct zink_context;
79
 
struct zink_image_view;
80
 
struct zink_program;
81
 
struct zink_resource;
82
 
struct zink_sampler;
83
 
struct zink_sampler_view;
84
 
struct zink_shader;
85
 
struct zink_screen;
86
 
 
87
 
 
88
 
struct zink_descriptor_state_key {
89
 
   bool exists[ZINK_SHADER_COUNT];
90
 
   uint32_t state[ZINK_SHADER_COUNT];
91
 
};
92
 
 
93
 
struct zink_descriptor_layout_key {
94
 
   unsigned num_bindings;
95
 
   VkDescriptorSetLayoutBinding *bindings;
96
 
};
97
 
 
98
 
struct zink_descriptor_layout {
99
 
   VkDescriptorSetLayout layout;
100
 
   VkDescriptorUpdateTemplateKHR desc_template;
101
 
};
102
 
 
103
 
struct zink_descriptor_pool_key {
104
 
   unsigned use_count;
105
 
   struct zink_descriptor_layout_key *layout;
106
 
   VkDescriptorPoolSize sizes[2];
107
 
};
108
 
 
109
 
struct zink_descriptor_reference {
110
 
   void **ref;
111
 
   bool *invalid;
112
 
};
113
 
 
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];
118
 
 
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];
123
 
   bool push_valid[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];
128
 
 
129
 
   VkDescriptorPool dummy_pool;
130
 
   struct zink_descriptor_layout *dummy_dsl;
131
 
   VkDescriptorSet dummy_set;
132
 
 
133
 
   VkDescriptorSetLayout bindless_layout;
134
 
   VkDescriptorPool bindless_pool;
135
 
   VkDescriptorSet bindless_set;
136
 
   bool bindless_bound;
137
 
 
138
 
   bool changed[2][ZINK_DESCRIPTOR_TYPES + 1];
139
 
   bool has_fbfetch;
140
 
   struct zink_program *pg[2]; //gfx, compute
141
 
};
142
 
 
143
 
struct zink_program_descriptor_data {
144
 
   uint8_t push_usage;
145
 
   bool bindless;
146
 
   bool fbfetch;
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;
151
 
};
152
 
 
153
 
struct zink_batch_descriptor_data {
154
 
   struct set *desc_sets;
155
 
};
156
 
 
157
 
static inline enum zink_descriptor_size_index
158
 
zink_vktype_to_size_idx(VkDescriptorType type)
159
 
{
160
 
   switch (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;
174
 
   default: break;
175
 
   }
176
 
   unreachable("unknown type");
177
 
}
178
 
 
179
 
static inline enum zink_descriptor_size_index
180
 
zink_descriptor_type_to_size_idx(enum zink_descriptor_type type)
181
 
{
182
 
   switch (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;
191
 
   default: break;
192
 
   }
193
 
   unreachable("unknown type");
194
 
}
195
 
bool
196
 
zink_descriptor_layouts_init(struct zink_context *ctx);
197
 
 
198
 
void
199
 
zink_descriptor_layouts_deinit(struct zink_context *ctx);
200
 
 
201
 
uint32_t
202
 
zink_get_sampler_view_hash(struct zink_context *ctx, struct zink_sampler_view *sampler_view, bool is_buffer);
203
 
uint32_t
204
 
zink_get_image_view_hash(struct zink_context *ctx, struct zink_image_view *image_view, bool is_buffer);
205
 
bool
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);
215
 
void
216
 
zink_descriptor_util_init_fbfetch(struct zink_context *ctx);
217
 
bool
218
 
zink_descriptor_util_push_layouts_get(struct zink_context *ctx, struct zink_descriptor_layout **dsls, struct zink_descriptor_layout_key **layout_keys);
219
 
VkImageLayout
220
 
zink_descriptor_util_image_layout_eval(const struct zink_context *ctx, const struct zink_resource *res, bool is_compute);
221
 
void
222
 
zink_descriptors_init_bindless(struct zink_context *ctx);
223
 
void
224
 
zink_descriptors_deinit_bindless(struct zink_context *ctx);
225
 
void
226
 
zink_descriptors_update_bindless(struct zink_context *ctx);
227
 
/* these two can't be called in lazy mode */
228
 
void
229
 
zink_descriptor_set_refs_clear(struct zink_descriptor_refs *refs, void *ptr);
230
 
void
231
 
zink_descriptor_set_recycle(struct zink_descriptor_set *zds);
232
 
 
233
 
 
234
 
 
235
 
 
236
 
 
237
 
bool
238
 
zink_descriptor_program_init(struct zink_context *ctx, struct zink_program *pg);
239
 
 
240
 
void
241
 
zink_descriptor_program_deinit(struct zink_context *ctx, struct zink_program *pg);
242
 
 
243
 
void
244
 
zink_descriptors_update(struct zink_context *ctx, bool is_compute);
245
 
 
246
 
 
247
 
void
248
 
zink_context_invalidate_descriptor_state(struct zink_context *ctx, enum pipe_shader_type shader, enum zink_descriptor_type type, unsigned, unsigned);
249
 
 
250
 
uint32_t
251
 
zink_get_sampler_view_hash(struct zink_context *ctx, struct zink_sampler_view *sampler_view, bool is_buffer);
252
 
uint32_t
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);
256
 
 
257
 
void
258
 
zink_batch_descriptor_deinit(struct zink_screen *screen, struct zink_batch_state *bs);
259
 
void
260
 
zink_batch_descriptor_reset(struct zink_screen *screen, struct zink_batch_state *bs);
261
 
bool
262
 
zink_batch_descriptor_init(struct zink_screen *screen, struct zink_batch_state *bs);
263
 
 
264
 
bool
265
 
zink_descriptors_init(struct zink_context *ctx);
266
 
 
267
 
void
268
 
zink_descriptors_deinit(struct zink_context *ctx);
269
 
 
270
 
//LAZY
271
 
bool
272
 
zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program *pg);
273
 
 
274
 
void
275
 
zink_descriptor_program_deinit_lazy(struct zink_context *ctx, struct zink_program *pg);
276
 
 
277
 
void
278
 
zink_descriptors_update_lazy(struct zink_context *ctx, bool is_compute);
279
 
 
280
 
 
281
 
void
282
 
zink_context_invalidate_descriptor_state_lazy(struct zink_context *ctx, enum pipe_shader_type shader, enum zink_descriptor_type type, unsigned, unsigned);
283
 
 
284
 
void
285
 
zink_batch_descriptor_deinit_lazy(struct zink_screen *screen, struct zink_batch_state *bs);
286
 
void
287
 
zink_batch_descriptor_reset_lazy(struct zink_screen *screen, struct zink_batch_state *bs);
288
 
bool
289
 
zink_batch_descriptor_init_lazy(struct zink_screen *screen, struct zink_batch_state *bs);
290
 
 
291
 
bool
292
 
zink_descriptors_init_lazy(struct zink_context *ctx);
293
 
 
294
 
void
295
 
zink_descriptors_deinit_lazy(struct zink_context *ctx);
296
 
 
297
 
void
298
 
zink_descriptor_set_update_lazy(struct zink_context *ctx, struct zink_program *pg, enum zink_descriptor_type type, VkDescriptorSet set);
299
 
void
300
 
zink_descriptors_update_lazy_masked(struct zink_context *ctx, bool is_compute, uint8_t changed_sets, uint8_t bind_sets);
301
 
VkDescriptorSet
302
 
zink_descriptors_alloc_lazy_push(struct zink_context *ctx);
303
 
#ifdef __cplusplus
304
 
}
305
 
#endif
306
 
 
307
 
#endif