summaryrefslogtreecommitdiff
path: root/lib/mesa/src/gallium/drivers/zink/zink_descriptors_lazy.c
diff options
context:
space:
mode:
Diffstat (limited to 'lib/mesa/src/gallium/drivers/zink/zink_descriptors_lazy.c')
-rw-r--r--lib/mesa/src/gallium/drivers/zink/zink_descriptors_lazy.c111
1 files changed, 45 insertions, 66 deletions
diff --git a/lib/mesa/src/gallium/drivers/zink/zink_descriptors_lazy.c b/lib/mesa/src/gallium/drivers/zink/zink_descriptors_lazy.c
index 5243464e8..42bfc31b7 100644
--- a/lib/mesa/src/gallium/drivers/zink/zink_descriptors_lazy.c
+++ b/lib/mesa/src/gallium/drivers/zink/zink_descriptors_lazy.c
@@ -127,25 +127,6 @@ init_template_entry(struct zink_shader *shader, enum zink_descriptor_type type,
(*entry_idx)++;
}
-static uint16_t
-descriptor_program_num_sizes(VkDescriptorPoolSize *sizes, enum zink_descriptor_type type)
-{
- switch (type) {
- case ZINK_DESCRIPTOR_TYPE_UBO:
- return !!sizes[ZDS_INDEX_UBO].descriptorCount;
- case ZINK_DESCRIPTOR_TYPE_SAMPLER_VIEW:
- return !!sizes[ZDS_INDEX_COMBINED_SAMPLER].descriptorCount +
- !!sizes[ZDS_INDEX_UNIFORM_TEXELS].descriptorCount;
- case ZINK_DESCRIPTOR_TYPE_SSBO:
- return !!sizes[ZDS_INDEX_STORAGE_BUFFER].descriptorCount;
- case ZINK_DESCRIPTOR_TYPE_IMAGE:
- return !!sizes[ZDS_INDEX_STORAGE_IMAGE].descriptorCount +
- !!sizes[ZDS_INDEX_STORAGE_TEXELS].descriptorCount;
- default: break;
- }
- unreachable("unknown type");
-}
-
bool
zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program *pg)
{
@@ -155,8 +136,6 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
unsigned num_bindings[ZINK_DESCRIPTOR_TYPES] = {0};
uint8_t has_bindings = 0;
unsigned push_count = 0;
- uint16_t num_type_sizes[ZINK_DESCRIPTOR_TYPES];
- VkDescriptorPoolSize sizes[6] = {0}; //zink_descriptor_size_index
struct zink_shader **stages;
if (pg->is_compute)
@@ -205,8 +184,8 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
binding->pImmutableSamplers = NULL;
enum zink_descriptor_size_index idx = zink_vktype_to_size_idx(shader->bindings[j][k].type);
- sizes[idx].descriptorCount += shader->bindings[j][k].size;
- sizes[idx].type = shader->bindings[j][k].type;
+ pg->dd->sizes[idx].descriptorCount += shader->bindings[j][k].size;
+ pg->dd->sizes[idx].type = shader->bindings[j][k].type;
switch (shader->bindings[j][k].type) {
case VK_DESCRIPTOR_TYPE_COMBINED_IMAGE_SAMPLER:
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
@@ -225,14 +204,13 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
num_bindings[j]++;
has_bindings |= BITFIELD_BIT(j);
}
- num_type_sizes[j] = descriptor_program_num_sizes(sizes, j);
}
pg->dd->bindless |= shader->bindless;
}
if (pg->dd->bindless)
zink_descriptors_init_bindless(ctx);
pg->dd->binding_usage = has_bindings;
- if (!has_bindings && !push_count && !pg->dd->bindless) {
+ if (!has_bindings && !push_count) {
ralloc_free(pg->dd);
pg->dd = NULL;
@@ -242,8 +220,6 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
pg->dsl[pg->num_dsl++] = push_count ? ctx->dd->push_dsl[pg->is_compute]->layout : ctx->dd->dummy_dsl->layout;
if (has_bindings) {
- for (unsigned i = 0; i < ARRAY_SIZE(sizes); i++)
- sizes[i].descriptorCount *= screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY ? MAX_LAZY_DESCRIPTORS : ZINK_DEFAULT_MAX_DESCS;
u_foreach_bit(type, has_bindings) {
for (unsigned i = 0; i < type; i++) {
/* push set is always 0 */
@@ -253,17 +229,13 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
pg->dd->binding_usage |= BITFIELD_BIT(i);
}
}
- struct zink_descriptor_layout_key *key;
- pg->dd->layouts[pg->num_dsl] = zink_descriptor_util_layout_get(ctx, type, bindings[type], num_bindings[type], &key);
- enum zink_descriptor_size_index idx = zink_descriptor_type_to_size_idx(type);
- VkDescriptorPoolSize *sz = &sizes[idx];
- if (!sz->descriptorCount)
- sz++;
- pg->dd->pool_key[type] = zink_descriptor_util_pool_key_get(ctx, type, key, sz, num_type_sizes[type]);
- pg->dd->pool_key[type]->use_count++;
+ pg->dd->layouts[pg->num_dsl] = zink_descriptor_util_layout_get(ctx, type, bindings[type], num_bindings[type], &pg->dd->layout_key[type]);
+ pg->dd->layout_key[type]->use_count++;
pg->dsl[pg->num_dsl] = pg->dd->layouts[pg->num_dsl]->layout;
pg->num_dsl++;
}
+ for (unsigned i = 0; i < ARRAY_SIZE(pg->dd->sizes); i++)
+ pg->dd->sizes[i].descriptorCount *= screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY ? MAX_LAZY_DESCRIPTORS : ZINK_DEFAULT_MAX_DESCS;
}
/* TODO: make this dynamic? */
if (pg->dd->bindless) {
@@ -282,8 +254,7 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
pg->layout = zink_pipeline_layout_create(screen, pg, &pg->compat_id);
if (!pg->layout)
return false;
- /* TODO: figure out uncached+notemplate and return on screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_NOTEMPLATES */
- if (!screen->info.have_KHR_descriptor_update_template)
+ if (!screen->info.have_KHR_descriptor_update_template || screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_NOTEMPLATES)
return true;
VkDescriptorUpdateTemplateCreateInfo template[ZINK_DESCRIPTOR_TYPES + 1] = {0};
@@ -297,7 +268,7 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
if (push_count)
wd_count[0] = pg->is_compute ? 1 : (ZINK_SHADER_COUNT + !!ctx->dd->has_fbfetch);
for (unsigned i = 0; i < ZINK_DESCRIPTOR_TYPES; i++)
- wd_count[i + 1] = pg->dd->pool_key[i] ? pg->dd->pool_key[i]->layout->num_bindings : 0;
+ wd_count[i + 1] = pg->dd->layout_key[i] ? pg->dd->layout_key[i]->num_descriptors : 0;
VkDescriptorUpdateTemplateEntry *push_entries[2] = {
dd_lazy(ctx)->push_entries,
@@ -334,23 +305,19 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
}
void
-zink_descriptor_program_deinit_lazy(struct zink_context *ctx, struct zink_program *pg)
+zink_descriptor_program_deinit_lazy(struct zink_screen *screen, struct zink_program *pg)
{
- struct zink_screen *screen = zink_screen(ctx->base.screen);
- if (!pg->dd)
- return;
for (unsigned i = 0; pg->num_dsl && i < ZINK_DESCRIPTOR_TYPES; i++) {
- if (pg->dd->pool_key[i])
- pg->dd->pool_key[i]->use_count--;
+ if (pg->dd->layout_key[i])
+ pg->dd->layout_key[i]->use_count--;
}
if (pg->dd && pg->dd->push_template)
VKSCR(DestroyDescriptorUpdateTemplate)(screen->dev, pg->dd->push_template, NULL);
ralloc_free(pg->dd);
- pg->dd = NULL;
}
static VkDescriptorPool
-create_pool(struct zink_screen *screen, unsigned num_type_sizes, const VkDescriptorPoolSize *sizes, unsigned flags)
+create_pool(struct zink_screen *screen, unsigned num_type_sizes, VkDescriptorPoolSize *sizes, unsigned flags)
{
VkDescriptorPool pool;
VkDescriptorPoolCreateInfo dpci = {0};
@@ -360,7 +327,7 @@ create_pool(struct zink_screen *screen, unsigned num_type_sizes, const VkDescrip
dpci.flags = flags;
dpci.maxSets = MAX_LAZY_DESCRIPTORS;
if (VKSCR(CreateDescriptorPool)(screen->dev, &dpci, 0, &pool) != VK_SUCCESS) {
- mesa_loge("ZINK: vkCreateDescriptorPool failed");
+ debug_printf("vkCreateDescriptorPool failed\n");
return VK_NULL_HANDLE;
}
return pool;
@@ -423,10 +390,8 @@ check_push_pool_alloc(struct zink_context *ctx, struct zink_descriptor_pool *poo
return check_push_pool_alloc(ctx, bdd->push_pool[is_compute], bdd, is_compute);
}
if (!zink_descriptor_util_alloc_sets(screen, ctx->dd->push_dsl[is_compute]->layout,
- pool->pool, &pool->sets[pool->sets_alloc], sets_to_alloc)) {
- mesa_loge("ZINK: failed to allocate push set!");
+ pool->pool, &pool->sets[pool->sets_alloc], sets_to_alloc))
return NULL;
- }
pool->sets_alloc += sets_to_alloc;
}
return pool;
@@ -436,8 +401,7 @@ static struct zink_descriptor_pool *
get_descriptor_pool_lazy(struct zink_context *ctx, struct zink_program *pg, enum zink_descriptor_type type, struct zink_batch_descriptor_data_lazy *bdd, bool is_compute)
{
struct zink_screen *screen = zink_screen(ctx->base.screen);
- const struct zink_descriptor_pool_key *pool_key = pg->dd->pool_key[type];
- struct hash_entry *he = _mesa_hash_table_search(&bdd->pools[type], pool_key);
+ struct hash_entry *he = _mesa_hash_table_search(&bdd->pools[type], pg->dd->layout_key[type]);
struct zink_descriptor_pool *pool;
if (he) {
pool = he->data;
@@ -446,13 +410,17 @@ get_descriptor_pool_lazy(struct zink_context *ctx, struct zink_program *pg, enum
pool = rzalloc(bdd, struct zink_descriptor_pool);
if (!pool)
return NULL;
- const unsigned num_type_sizes = pool_key->sizes[1].descriptorCount ? 2 : 1;
- pool->pool = create_pool(screen, num_type_sizes, pool_key->sizes, 0);
+ unsigned idx = zink_descriptor_type_to_size_idx(type);
+ VkDescriptorPoolSize *size = &pg->dd->sizes[idx];
+ /* this is a sampler/image set with no images only texels */
+ if (!size->descriptorCount)
+ size++;
+ pool->pool = create_pool(screen, zink_descriptor_program_num_sizes(pg, type), size, 0);
if (!pool->pool) {
ralloc_free(pool);
return NULL;
}
- _mesa_hash_table_insert(&bdd->pools[type], pool_key, pool);
+ _mesa_hash_table_insert(&bdd->pools[type], pg->dd->layout_key[type], pool);
return check_pool_alloc(ctx, pool, he, pg, type, bdd, is_compute);
}
@@ -471,13 +439,13 @@ populate_sets(struct zink_context *ctx, struct zink_batch_descriptor_data_lazy *
struct zink_program *pg, uint8_t *changed_sets, VkDescriptorSet *sets)
{
u_foreach_bit(type, *changed_sets) {
- if (pg->dd->pool_key[type]) {
+ if (pg->dd->layout_key[type]) {
struct zink_descriptor_pool *pool = get_descriptor_pool_lazy(ctx, pg, type, bdd, pg->is_compute);
sets[type] = get_descriptor_set_lazy(pool);
- if (!sets[type])
- return false;
} else
- sets[type] = VK_NULL_HANDLE;
+ sets[type] = ctx->dd->dummy_set;
+ if (!sets[type])
+ return false;
}
return true;
}
@@ -509,7 +477,7 @@ zink_descriptors_update_lazy_masked(struct zink_context *ctx, bool is_compute, u
u_foreach_bit(type, changed_sets) {
assert(type + 1 < pg->num_dsl);
- if (pg->dd->pool_key[type]) {
+ if (pg->dd->layout_key[type]) {
VKSCR(UpdateDescriptorSetWithTemplate)(screen->dev, desc_sets[type], pg->dd->layouts[type + 1]->desc_template, ctx);
VKSCR(CmdBindDescriptorSets)(bs->cmdbuf,
is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
@@ -520,8 +488,8 @@ zink_descriptors_update_lazy_masked(struct zink_context *ctx, bool is_compute, u
}
}
u_foreach_bit(type, bind_sets & ~changed_sets) {
- if (!pg->dd->pool_key[type])
- continue;
+ if (!pg->dd->layout_key[type])
+ bdd->sets[is_compute][type + 1] = ctx->dd->dummy_set;
assert(bdd->sets[is_compute][type + 1]);
VKSCR(CmdBindDescriptorSets)(bs->cmdbuf,
is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
@@ -562,7 +530,7 @@ zink_descriptors_update_lazy(struct zink_context *ctx, bool is_compute)
bool batch_changed = !bdd->pg[is_compute];
if (batch_changed) {
/* update all sets and bind null sets */
- dd_lazy(ctx)->state_changed[is_compute] = pg->dd->binding_usage & BITFIELD_MASK(ZINK_DESCRIPTOR_TYPES);
+ dd_lazy(ctx)->state_changed[is_compute] = pg->dd->binding_usage;
dd_lazy(ctx)->push_state_changed[is_compute] = !!pg->dd->push_usage;
}
@@ -617,8 +585,14 @@ zink_descriptors_update_lazy(struct zink_context *ctx, bool is_compute)
pg->layout, 0, 1, push_set ? &push_set : &bdd->sets[is_compute][0],
0, NULL);
}
+ dd_lazy(ctx)->push_state_changed[is_compute] = false;
+ } else if (dd_lazy(ctx)->push_state_changed[is_compute] || bind_sets) {
+ VKCTX(CmdBindDescriptorSets)(bs->cmdbuf,
+ is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
+ pg->layout, 0, 1, &ctx->dd->dummy_set,
+ 0, NULL);
+ dd_lazy(ctx)->push_state_changed[is_compute] = false;
}
- dd_lazy(ctx)->push_state_changed[is_compute] = false;
zink_descriptors_update_lazy_masked(ctx, is_compute, changed_sets, bind_sets);
if (pg->dd->bindless && unlikely(!ctx->dd->bindless_bound)) {
VKCTX(CmdBindDescriptorSets)(ctx->batch.state->cmdbuf, is_compute ? VK_PIPELINE_BIND_POINT_COMPUTE : VK_PIPELINE_BIND_POINT_GRAPHICS,
@@ -629,7 +603,7 @@ zink_descriptors_update_lazy(struct zink_context *ctx, bool is_compute)
bdd->pg[is_compute] = pg;
ctx->dd->pg[is_compute] = pg;
bdd->compat_id[is_compute] = pg->compat_id;
- dd_lazy(ctx)->state_changed[is_compute] = 0;
+ dd_lazy(ctx)->state_changed[is_compute] = false;
}
void
@@ -677,7 +651,7 @@ zink_batch_descriptor_reset_lazy(struct zink_screen *screen, struct zink_batch_s
struct zink_batch_descriptor_data_lazy *bdd = bdd_lazy(bs);
for (unsigned i = 0; i < ZINK_DESCRIPTOR_TYPES; i++) {
hash_table_foreach(&bdd->pools[i], entry) {
- const struct zink_descriptor_pool_key *key = entry->key;
+ const struct zink_descriptor_layout_key *key = entry->key;
struct zink_descriptor_pool *pool = (void*)entry->data;
if (key->use_count)
pool->set_idx = 0;
@@ -761,6 +735,11 @@ zink_descriptors_init_lazy(struct zink_context *ctx)
ctx->dd->dummy_dsl = zink_descriptor_util_layout_get(ctx, 0, NULL, 0, &layout_key);
if (!ctx->dd->dummy_dsl)
return false;
+ VkDescriptorPoolSize null_size = {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, 1};
+ ctx->dd->dummy_pool = create_pool(screen, 1, &null_size, 0);
+ zink_descriptor_util_alloc_sets(screen, ctx->dd->dummy_dsl->layout,
+ ctx->dd->dummy_pool, &ctx->dd->dummy_set, 1);
+ zink_descriptor_util_init_null_set(ctx, ctx->dd->dummy_set);
return true;
}