mirror of
https://gitlab.freedesktop.org/mesa/mesa.git
synced 2026-04-26 00:20:37 +02:00
zink: use descriptor set index indirection in program init
should be no functional changes Reviewed-by: Dave Airlie <airlied@redhat.com> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/16645>
This commit is contained in:
parent
fe2ba184d8
commit
5ce79c679d
3 changed files with 44 additions and 24 deletions
|
|
@ -327,9 +327,10 @@ descriptor_pool_create(struct zink_screen *screen, enum zink_descriptor_type typ
|
|||
VkDescriptorPoolCreateInfo dpci = {0};
|
||||
dpci.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
|
||||
dpci.pPoolSizes = pool_key->sizes;
|
||||
dpci.poolSizeCount = pool_key->sizes[1].descriptorCount ? 2 : 1;
|
||||
dpci.poolSizeCount = pool_key->num_type_sizes;
|
||||
dpci.flags = 0;
|
||||
dpci.maxSets = ZINK_DEFAULT_MAX_DESCS;
|
||||
assert(pool_key->num_type_sizes);
|
||||
if (VKSCR(CreateDescriptorPool)(screen->dev, &dpci, 0, &pool->descpool) != VK_SUCCESS) {
|
||||
mesa_loge("ZINK: vkCreateDescriptorPool failed");
|
||||
goto fail;
|
||||
|
|
@ -464,8 +465,7 @@ hash_descriptor_pool_key(const void *key)
|
|||
uint32_t hash = 0;
|
||||
const struct zink_descriptor_pool_key *k = key;
|
||||
hash = XXH32(&k->layout, sizeof(void*), hash);
|
||||
const unsigned num_type_sizes = k->sizes[1].descriptorCount ? 2 : 1;
|
||||
for (unsigned i = 0; i < num_type_sizes; i++)
|
||||
for (unsigned i = 0; i < k->num_type_sizes; i++)
|
||||
hash = XXH32(&k->sizes[i], sizeof(VkDescriptorPoolSize), hash);
|
||||
|
||||
return hash;
|
||||
|
|
@ -476,8 +476,8 @@ equals_descriptor_pool_key(const void *a, const void *b)
|
|||
{
|
||||
const struct zink_descriptor_pool_key *a_k = a;
|
||||
const struct zink_descriptor_pool_key *b_k = b;
|
||||
const unsigned a_num_type_sizes = a_k->sizes[1].descriptorCount ? 2 : 1;
|
||||
const unsigned b_num_type_sizes = b_k->sizes[1].descriptorCount ? 2 : 1;
|
||||
const unsigned a_num_type_sizes = a_k->num_type_sizes;
|
||||
const unsigned b_num_type_sizes = b_k->num_type_sizes;
|
||||
return a_k->layout == b_k->layout &&
|
||||
a_num_type_sizes == b_num_type_sizes &&
|
||||
!memcmp(a_k->sizes, b_k->sizes, b_num_type_sizes * sizeof(VkDescriptorPoolSize));
|
||||
|
|
@ -490,9 +490,9 @@ zink_descriptor_util_pool_key_get(struct zink_context *ctx, enum zink_descriptor
|
|||
{
|
||||
uint32_t hash = 0;
|
||||
struct zink_descriptor_pool_key key;
|
||||
key.num_type_sizes = num_type_sizes;
|
||||
if (type != ZINK_DESCRIPTOR_TYPES) {
|
||||
key.layout = layout_key;
|
||||
key.sizes[1].descriptorCount = 0;
|
||||
memcpy(key.sizes, sizes, num_type_sizes * sizeof(VkDescriptorPoolSize));
|
||||
hash = hash_descriptor_pool_key(&key);
|
||||
struct set_entry *he = _mesa_set_search_pre_hashed(&ctx->desc_pool_keys[type], hash, &key);
|
||||
|
|
@ -502,6 +502,8 @@ zink_descriptor_util_pool_key_get(struct zink_context *ctx, enum zink_descriptor
|
|||
|
||||
struct zink_descriptor_pool_key *pool_key = rzalloc(ctx, struct zink_descriptor_pool_key);
|
||||
pool_key->layout = layout_key;
|
||||
pool_key->num_type_sizes = num_type_sizes;
|
||||
assert(pool_key->num_type_sizes);
|
||||
memcpy(pool_key->sizes, sizes, num_type_sizes * sizeof(VkDescriptorPoolSize));
|
||||
if (type != ZINK_DESCRIPTOR_TYPES)
|
||||
_mesa_set_add_pre_hashed(&ctx->desc_pool_keys[type], hash, pool_key);
|
||||
|
|
|
|||
|
|
@ -101,6 +101,7 @@ struct zink_descriptor_layout {
|
|||
|
||||
struct zink_descriptor_pool_key {
|
||||
unsigned use_count;
|
||||
unsigned num_type_sizes;
|
||||
struct zink_descriptor_layout_key *layout;
|
||||
VkDescriptorPoolSize sizes[2];
|
||||
};
|
||||
|
|
|
|||
|
|
@ -182,6 +182,7 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
|
|||
enum pipe_shader_type stage = pipe_shader_type_from_mesa(shader->nir->info.stage);
|
||||
VkShaderStageFlagBits stage_flags = zink_shader_stage(stage);
|
||||
for (int j = 0; j < ZINK_DESCRIPTOR_TYPES; j++) {
|
||||
unsigned desc_set = screen->desc_set_id[j] - 1;
|
||||
for (int k = 0; k < shader->num_bindings[j]; k++) {
|
||||
/* dynamic ubos handled in push */
|
||||
if (shader->bindings[j][k].type == VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC) {
|
||||
|
|
@ -191,8 +192,8 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
|
|||
continue;
|
||||
}
|
||||
|
||||
assert(num_bindings[j] < ARRAY_SIZE(bindings[j]));
|
||||
VkDescriptorSetLayoutBinding *binding = &bindings[j][num_bindings[j]];
|
||||
assert(num_bindings[desc_set] < ARRAY_SIZE(bindings[desc_set]));
|
||||
VkDescriptorSetLayoutBinding *binding = &bindings[desc_set][num_bindings[desc_set]];
|
||||
binding->binding = shader->bindings[j][k].binding;
|
||||
binding->descriptorType = shader->bindings[j][k].type;
|
||||
binding->descriptorCount = shader->bindings[j][k].size;
|
||||
|
|
@ -202,11 +203,11 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
|
|||
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;
|
||||
init_template_entry(shader, j, k, &entries[j][entry_idx[j]], &entry_idx[j], screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY);
|
||||
num_bindings[j]++;
|
||||
has_bindings |= BITFIELD_BIT(j);
|
||||
init_template_entry(shader, j, k, &entries[desc_set][entry_idx[desc_set]], &entry_idx[desc_set], screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY);
|
||||
num_bindings[desc_set]++;
|
||||
has_bindings |= BITFIELD_BIT(desc_set);
|
||||
}
|
||||
num_type_sizes[j] = descriptor_program_num_sizes(sizes, j);
|
||||
num_type_sizes[desc_set] = descriptor_program_num_sizes(sizes, j);
|
||||
}
|
||||
pg->dd->bindless |= shader->bindless;
|
||||
}
|
||||
|
|
@ -225,8 +226,8 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
|
|||
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++) {
|
||||
u_foreach_bit(desc_set, has_bindings) {
|
||||
for (unsigned i = 0; i < desc_set; i++) {
|
||||
/* push set is always 0 */
|
||||
if (!pg->dsl[i + 1]) {
|
||||
/* inject a null dsl */
|
||||
|
|
@ -235,29 +236,45 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
|
|||
}
|
||||
}
|
||||
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);
|
||||
pg->dd->layouts[pg->num_dsl] = zink_descriptor_util_layout_get(ctx, desc_set, bindings[desc_set], num_bindings[desc_set], &key);
|
||||
unsigned idx = screen->compact_descriptors ? zink_descriptor_type_to_size_idx_comp(desc_set) :
|
||||
zink_descriptor_type_to_size_idx(desc_set);
|
||||
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++;
|
||||
VkDescriptorPoolSize sz2[4];
|
||||
if (screen->compact_descriptors) {
|
||||
unsigned found = 0;
|
||||
while (found < num_type_sizes[desc_set]) {
|
||||
if (sz->descriptorCount) {
|
||||
memcpy(&sz2[found], sz, sizeof(VkDescriptorPoolSize));
|
||||
found++;
|
||||
}
|
||||
sz++;
|
||||
}
|
||||
sz = sz2;
|
||||
} else {
|
||||
if (!sz->descriptorCount)
|
||||
sz++;
|
||||
}
|
||||
pg->dd->pool_key[desc_set] = zink_descriptor_util_pool_key_get(ctx, desc_set, key, sz, num_type_sizes[desc_set]);
|
||||
pg->dd->pool_key[desc_set]->use_count++;
|
||||
pg->dsl[pg->num_dsl] = pg->dd->layouts[pg->num_dsl]->layout;
|
||||
pg->num_dsl++;
|
||||
}
|
||||
}
|
||||
/* TODO: make this dynamic? */
|
||||
if (pg->dd->bindless) {
|
||||
pg->num_dsl = ZINK_DESCRIPTOR_BINDLESS + 1;
|
||||
pg->dsl[ZINK_DESCRIPTOR_BINDLESS] = ctx->dd->bindless_layout;
|
||||
for (unsigned i = 0; i < ZINK_DESCRIPTOR_BINDLESS; i++) {
|
||||
unsigned desc_set = screen->desc_set_id[ZINK_DESCRIPTOR_BINDLESS];
|
||||
pg->num_dsl = desc_set + 1;
|
||||
pg->dsl[desc_set] = ctx->dd->bindless_layout;
|
||||
for (unsigned i = 0; i < desc_set; i++) {
|
||||
if (!pg->dsl[i]) {
|
||||
/* inject a null dsl */
|
||||
pg->dsl[i] = ctx->dd->dummy_dsl->layout;
|
||||
if (i != ZINK_DESCRIPTOR_TYPES)
|
||||
if (i != screen->desc_set_id[ZINK_DESCRIPTOR_TYPES])
|
||||
pg->dd->binding_usage |= BITFIELD_BIT(i);
|
||||
}
|
||||
}
|
||||
pg->dd->binding_usage |= BITFIELD_MASK(ZINK_DESCRIPTOR_TYPES);
|
||||
}
|
||||
|
||||
pg->layout = zink_pipeline_layout_create(screen, pg, &pg->compat_id);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue