zink: move descriptor_mode to be a global

this can't change once it's been set, so having it per-object is pointless

Reviewed-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/17636>
This commit is contained in:
Mike Blumenkrantz 2022-07-19 09:58:03 -04:00 committed by Marge Bot
parent d1e36634bd
commit 1c2bd27d81
5 changed files with 22 additions and 20 deletions

View File

@ -1282,7 +1282,7 @@ zink_set_constant_buffer(struct pipe_context *pctx,
zink_resource_buffer_barrier(ctx, new_res, VK_ACCESS_UNIFORM_READ_BIT, zink_resource_buffer_barrier(ctx, new_res, VK_ACCESS_UNIFORM_READ_BIT,
zink_pipeline_flags_from_pipe_stage(shader)); zink_pipeline_flags_from_pipe_stage(shader));
} }
update |= ((index || screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY) && ctx->ubos[shader][index].buffer_offset != offset) || update |= ((index || zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY) && ctx->ubos[shader][index].buffer_offset != offset) ||
!!res != !!buffer || (res && res->obj->buffer != new_res->obj->buffer) || !!res != !!buffer || (res && res->obj->buffer != new_res->obj->buffer) ||
ctx->ubos[shader][index].buffer_size != cb->buffer_size; ctx->ubos[shader][index].buffer_size != cb->buffer_size;

View File

@ -352,7 +352,7 @@ descriptor_layout_create(struct zink_screen *screen, enum zink_descriptor_type t
dcslci.pNext = NULL; dcslci.pNext = NULL;
VkDescriptorSetLayoutBindingFlagsCreateInfo fci = {0}; VkDescriptorSetLayoutBindingFlagsCreateInfo fci = {0};
VkDescriptorBindingFlags flags[ZINK_MAX_DESCRIPTORS_PER_TYPE]; VkDescriptorBindingFlags flags[ZINK_MAX_DESCRIPTORS_PER_TYPE];
if (screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY) { if (zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY) {
dcslci.pNext = &fci; dcslci.pNext = &fci;
if (t == ZINK_DESCRIPTOR_TYPES) if (t == ZINK_DESCRIPTOR_TYPES)
dcslci.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR; dcslci.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR;
@ -524,9 +524,9 @@ init_push_binding(VkDescriptorSetLayoutBinding *binding, unsigned i, VkDescripto
static VkDescriptorType static VkDescriptorType
get_push_types(struct zink_screen *screen, enum zink_descriptor_type *dsl_type) get_push_types(struct zink_screen *screen, enum zink_descriptor_type *dsl_type)
{ {
*dsl_type = screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY && *dsl_type = zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY &&
screen->info.have_KHR_push_descriptor ? ZINK_DESCRIPTOR_TYPES : ZINK_DESCRIPTOR_TYPE_UBO; screen->info.have_KHR_push_descriptor ? ZINK_DESCRIPTOR_TYPES : ZINK_DESCRIPTOR_TYPE_UBO;
return screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY ? return zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY ?
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
} }
@ -1134,7 +1134,7 @@ zink_descriptor_program_init(struct zink_context *ctx, struct zink_program *pg)
has_pools = true; has_pools = true;
} }
if (has_pools && screen->info.have_KHR_descriptor_update_template && if (has_pools && screen->info.have_KHR_descriptor_update_template &&
screen->descriptor_mode != ZINK_DESCRIPTOR_MODE_NOTEMPLATES) zink_descriptor_mode != ZINK_DESCRIPTOR_MODE_NOTEMPLATES)
create_descriptor_ref_template(ctx, pg); create_descriptor_ref_template(ctx, pg);
return true; return true;
@ -1170,9 +1170,8 @@ zink_descriptor_pool_init(struct zink_context *ctx)
if (!ctx->dd->descriptor_pools[i]) if (!ctx->dd->descriptor_pools[i])
return false; return false;
} }
struct zink_screen *screen = zink_screen(ctx->base.screen);
VkDescriptorPoolSize sizes[2]; VkDescriptorPoolSize sizes[2];
sizes[0].type = screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY ? VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; sizes[0].type = zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY ? VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
sizes[0].descriptorCount = ZINK_SHADER_COUNT * ZINK_DEFAULT_MAX_DESCS; sizes[0].descriptorCount = ZINK_SHADER_COUNT * ZINK_DEFAULT_MAX_DESCS;
sizes[1].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; sizes[1].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
sizes[1].descriptorCount = ZINK_DEFAULT_MAX_DESCS; sizes[1].descriptorCount = ZINK_DEFAULT_MAX_DESCS;
@ -1379,7 +1378,7 @@ update_descriptors_internal(struct zink_context *ctx, enum zink_descriptor_type
return; return;
if (screen->info.have_KHR_descriptor_update_template && if (screen->info.have_KHR_descriptor_update_template &&
screen->descriptor_mode != ZINK_DESCRIPTOR_MODE_NOTEMPLATES) { zink_descriptor_mode != ZINK_DESCRIPTOR_MODE_NOTEMPLATES) {
set_descriptor_set_refs(ctx, zds, pg, cache_hit); set_descriptor_set_refs(ctx, zds, pg, cache_hit);
zink_descriptor_set_update_lazy(ctx, pg, type, zds->desc_set); zink_descriptor_set_update_lazy(ctx, pg, type, zds->desc_set);
return; return;
@ -1527,7 +1526,7 @@ zink_descriptors_update(struct zink_context *ctx, bool is_compute)
zds = zink_descriptor_set_get(ctx, h, is_compute, &cache_hit); zds = zink_descriptor_set_get(ctx, h, is_compute, &cache_hit);
if (cache_hit) { if (cache_hit) {
pdd_cached(pg)->cache_misses[h] = 0; pdd_cached(pg)->cache_misses[h] = 0;
} else if (likely(zink_screen(ctx->base.screen)->descriptor_mode != ZINK_DESCRIPTOR_MODE_NOFALLBACK)) { } else if (likely(zink_descriptor_mode != ZINK_DESCRIPTOR_MODE_NOFALLBACK)) {
if (++pdd_cached(pg)->cache_misses[h] == MAX_CACHE_MISSES) { if (++pdd_cached(pg)->cache_misses[h] == MAX_CACHE_MISSES) {
#ifdef PRINT_DEBUG #ifdef PRINT_DEBUG
const char *set_names[] = { const char *set_names[] = {
@ -1908,7 +1907,7 @@ zink_descriptor_util_init_fbfetch(struct zink_context *ctx)
//ralloc_free(ctx->dd->push_layout_keys[0]); //ralloc_free(ctx->dd->push_layout_keys[0]);
ctx->dd->push_dsl[0] = create_gfx_layout(ctx, &ctx->dd->push_layout_keys[0], true); ctx->dd->push_dsl[0] = create_gfx_layout(ctx, &ctx->dd->push_layout_keys[0], true);
ctx->dd->has_fbfetch = true; ctx->dd->has_fbfetch = true;
if (screen->descriptor_mode != ZINK_DESCRIPTOR_MODE_LAZY) if (zink_descriptor_mode != ZINK_DESCRIPTOR_MODE_LAZY)
zink_descriptor_pool_init(ctx); zink_descriptor_pool_init(ctx);
} }

View File

@ -222,7 +222,7 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
zink_vktype_to_size_idx(shader->bindings[j][k].type); zink_vktype_to_size_idx(shader->bindings[j][k].type);
sizes[idx].descriptorCount += shader->bindings[j][k].size; sizes[idx].descriptorCount += shader->bindings[j][k].size;
sizes[idx].type = shader->bindings[j][k].type; sizes[idx].type = shader->bindings[j][k].type;
init_template_entry(shader, j, k, &entries[desc_set][entry_idx[desc_set]], &entry_idx[desc_set], screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY); init_template_entry(shader, j, k, &entries[desc_set][entry_idx[desc_set]], &entry_idx[desc_set], zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY);
num_bindings[desc_set]++; num_bindings[desc_set]++;
has_bindings |= BITFIELD_BIT(desc_set); has_bindings |= BITFIELD_BIT(desc_set);
pg->dd->real_binding_usage |= BITFIELD_BIT(j); pg->dd->real_binding_usage |= BITFIELD_BIT(j);
@ -247,7 +247,7 @@ 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; pg->dsl[pg->num_dsl++] = push_count ? ctx->dd->push_dsl[pg->is_compute]->layout : ctx->dd->dummy_dsl->layout;
if (has_bindings) { if (has_bindings) {
for (unsigned i = 0; i < ARRAY_SIZE(sizes); i++) 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; sizes[i].descriptorCount *= zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY ? MAX_LAZY_DESCRIPTORS : ZINK_DEFAULT_MAX_DESCS;
u_foreach_bit(desc_set, has_bindings) { u_foreach_bit(desc_set, has_bindings) {
for (unsigned i = 0; i < desc_set; i++) { for (unsigned i = 0; i < desc_set; i++) {
/* push set is always 0 */ /* push set is always 0 */
@ -302,14 +302,14 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
pg->layout = zink_pipeline_layout_create(screen, pg, &pg->compat_id); pg->layout = zink_pipeline_layout_create(screen, pg, &pg->compat_id);
if (!pg->layout) if (!pg->layout)
return false; return false;
/* TODO: figure out uncached+notemplate and return on screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_NOTEMPLATES */ /* TODO: figure out uncached+notemplate and return on zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_NOTEMPLATES */
if (!screen->info.have_KHR_descriptor_update_template) if (!screen->info.have_KHR_descriptor_update_template)
return true; return true;
VkDescriptorUpdateTemplateCreateInfo template[ZINK_DESCRIPTOR_TYPES + 1] = {0}; VkDescriptorUpdateTemplateCreateInfo template[ZINK_DESCRIPTOR_TYPES + 1] = {0};
/* type of template */ /* type of template */
VkDescriptorUpdateTemplateType types[ZINK_DESCRIPTOR_TYPES + 1] = {VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET}; VkDescriptorUpdateTemplateType types[ZINK_DESCRIPTOR_TYPES + 1] = {VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET};
if (have_push && screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY) if (have_push && zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY)
types[0] = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR; types[0] = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR;
/* number of descriptors in template */ /* number of descriptors in template */
@ -756,7 +756,7 @@ zink_descriptors_init_lazy(struct zink_context *ctx)
if (!ctx->dd) if (!ctx->dd)
return false; return false;
if (screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_NOTEMPLATES) if (zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_NOTEMPLATES)
printf("ZINK: CACHED/NOTEMPLATES DESCRIPTORS\n"); printf("ZINK: CACHED/NOTEMPLATES DESCRIPTORS\n");
else if (screen->info.have_KHR_descriptor_update_template) { else if (screen->info.have_KHR_descriptor_update_template) {
for (unsigned i = 0; i < ZINK_SHADER_COUNT; i++) { for (unsigned i = 0; i < ZINK_SHADER_COUNT; i++) {
@ -770,7 +770,7 @@ zink_descriptors_init_lazy(struct zink_context *ctx)
entry->descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; entry->descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT;
entry->offset = offsetof(struct zink_context, di.fbfetch); entry->offset = offsetof(struct zink_context, di.fbfetch);
entry->stride = sizeof(VkDescriptorImageInfo); entry->stride = sizeof(VkDescriptorImageInfo);
if (screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY) if (zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY)
printf("ZINK: USING LAZY DESCRIPTORS\n"); printf("ZINK: USING LAZY DESCRIPTORS\n");
} }
struct zink_descriptor_layout_key *layout_key; struct zink_descriptor_layout_key *layout_key;

View File

@ -98,6 +98,8 @@ zink_descriptor_options[] = {
DEBUG_GET_ONCE_FLAGS_OPTION(zink_descriptor_mode, "ZINK_DESCRIPTORS", zink_descriptor_options, ZINK_DESCRIPTOR_MODE_AUTO) DEBUG_GET_ONCE_FLAGS_OPTION(zink_descriptor_mode, "ZINK_DESCRIPTORS", zink_descriptor_options, ZINK_DESCRIPTOR_MODE_AUTO)
enum zink_descriptor_mode zink_descriptor_mode;
static const char * static const char *
zink_get_vendor(struct pipe_screen *pscreen) zink_get_vendor(struct pipe_screen *pscreen)
{ {
@ -1530,7 +1532,7 @@ zink_screen_init_descriptor_funcs(struct zink_screen *screen, bool fallback)
{ {
if (screen->info.have_KHR_descriptor_update_template && if (screen->info.have_KHR_descriptor_update_template &&
!fallback && !fallback &&
screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY) { zink_descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY) {
#define LAZY(FUNC) screen->FUNC = zink_##FUNC##_lazy #define LAZY(FUNC) screen->FUNC = zink_##FUNC##_lazy
LAZY(descriptor_program_init); LAZY(descriptor_program_init);
LAZY(descriptor_program_deinit); LAZY(descriptor_program_deinit);
@ -2104,8 +2106,8 @@ zink_internal_create_screen(const struct pipe_screen_config *config)
screen->threaded = util_get_cpu_caps()->nr_cpus > 1 && debug_get_bool_option("GALLIUM_THREAD", util_get_cpu_caps()->nr_cpus > 1); screen->threaded = util_get_cpu_caps()->nr_cpus > 1 && debug_get_bool_option("GALLIUM_THREAD", util_get_cpu_caps()->nr_cpus > 1);
zink_debug = debug_get_option_zink_debug(); zink_debug = debug_get_option_zink_debug();
screen->descriptor_mode = debug_get_option_zink_descriptor_mode(); zink_descriptor_mode = debug_get_option_zink_descriptor_mode();
if (screen->descriptor_mode > ZINK_DESCRIPTOR_MODE_NOTEMPLATES) { if (zink_descriptor_mode > ZINK_DESCRIPTOR_MODE_NOTEMPLATES) {
printf("Specify exactly one descriptor mode.\n"); printf("Specify exactly one descriptor mode.\n");
abort(); abort();
} }

View File

@ -82,6 +82,8 @@ enum zink_descriptor_mode {
ZINK_DESCRIPTOR_MODE_COMPACT, ZINK_DESCRIPTOR_MODE_COMPACT,
}; };
extern enum zink_descriptor_mode zink_descriptor_mode;
//keep in sync with zink_descriptor_type since headers can't be cross-included //keep in sync with zink_descriptor_type since headers can't be cross-included
#define ZINK_MAX_DESCRIPTOR_SETS 6 #define ZINK_MAX_DESCRIPTOR_SETS 6
@ -184,7 +186,6 @@ struct zink_screen {
void (*batch_descriptor_deinit)(struct zink_screen *screen, struct zink_batch_state *bs); void (*batch_descriptor_deinit)(struct zink_screen *screen, struct zink_batch_state *bs);
bool (*descriptors_init)(struct zink_context *ctx); bool (*descriptors_init)(struct zink_context *ctx);
void (*descriptors_deinit)(struct zink_context *ctx); void (*descriptors_deinit)(struct zink_context *ctx);
enum zink_descriptor_mode descriptor_mode;
struct { struct {
bool dual_color_blend_by_location; bool dual_color_blend_by_location;