zink: add ZINK_DESCRIPTORS env var to explicitly set a mode

currently this supports 3 modes, with the default being a hybrid between
caching and lazy

Reviewed-by: Hoe Hao Cheng <haochengho12907@gmail.com>
Acked-by: Dave Airlie <airlied@redhat.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/11188>
This commit is contained in:
Mike Blumenkrantz
2021-03-29 17:22:49 -04:00
parent 75c7619253
commit 4e3768914d
5 changed files with 47 additions and 20 deletions

View File

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

View File

@@ -340,8 +340,7 @@ descriptor_layout_create(struct zink_screen *screen, enum zink_descriptor_type t
dcslci.pNext = NULL;
VkDescriptorSetLayoutBindingFlagsCreateInfo fci = {0};
VkDescriptorBindingFlags flags[num_bindings];
if (screen->lazy_descriptors) {
/* FIXME */
if (screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY) {
dcslci.pNext = &fci;
if (t == ZINK_DESCRIPTOR_TYPES)
dcslci.flags = VK_DESCRIPTOR_SET_LAYOUT_CREATE_PUSH_DESCRIPTOR_BIT_KHR;
@@ -464,12 +463,14 @@ zink_descriptor_util_push_layouts_get(struct zink_context *ctx, VkDescriptorSetL
VkDescriptorSetLayoutBinding bindings[PIPE_SHADER_TYPES];
for (unsigned i = 0; i < PIPE_SHADER_TYPES; i++) {
bindings[i].binding = tgsi_processor_to_shader_stage(i);
bindings[i].descriptorType = screen->lazy_descriptors ? VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
bindings[i].descriptorType = screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY ?
VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
bindings[i].descriptorCount = 1;
bindings[i].stageFlags = zink_shader_stage(i);
bindings[i].pImmutableSamplers = NULL;
}
enum zink_descriptor_type dsl_type = screen->lazy_descriptors ? ZINK_DESCRIPTOR_TYPES : ZINK_DESCRIPTOR_TYPE_UBO;
enum zink_descriptor_type dsl_type = screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY &&
screen->info.have_KHR_push_descriptor ? ZINK_DESCRIPTOR_TYPES : ZINK_DESCRIPTOR_TYPE_UBO;
dsls[0] = zink_descriptor_util_layout_get(ctx, dsl_type, bindings, ZINK_SHADER_COUNT, &layout_keys[0]);
dsls[1] = zink_descriptor_util_layout_get(ctx, dsl_type, &bindings[PIPE_SHADER_COMPUTE], 1, &layout_keys[1]);
return dsls[0] && dsls[1];
@@ -1023,7 +1024,8 @@ zink_descriptor_program_init(struct zink_context *ctx, struct zink_program *pg)
return false;
zink_descriptor_pool_reference(screen, &pdd_cached(pg)->pool[i], pool);
if (screen->info.have_KHR_descriptor_update_template)
if (screen->info.have_KHR_descriptor_update_template &&
screen->descriptor_mode != ZINK_DESCRIPTOR_MODE_NOTEMPLATES)
create_descriptor_ref_template(ctx, pg, i);
}
@@ -1064,7 +1066,7 @@ zink_descriptor_pool_init(struct zink_context *ctx)
}
struct zink_screen *screen = zink_screen(ctx->base.screen);
VkDescriptorPoolSize sizes;
sizes.type = screen->lazy_descriptors ? VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
sizes.type = screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY ? VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC;
sizes.descriptorCount = ZINK_SHADER_COUNT * ZINK_DEFAULT_MAX_DESCS;
ctx->dd->push_pool[0] = descriptor_pool_get(ctx, 0, ctx->dd->push_layout_keys[0], &sizes, 1);
sizes.descriptorCount = ZINK_DEFAULT_MAX_DESCS;
@@ -1237,7 +1239,8 @@ update_descriptors_internal(struct zink_context *ctx, struct zink_descriptor_set
if (cache_hit[h] || !zds[h])
continue;
if (screen->info.have_KHR_descriptor_update_template) {
if (screen->info.have_KHR_descriptor_update_template &&
screen->descriptor_mode != ZINK_DESCRIPTOR_MODE_NOTEMPLATES) {
set_descriptor_set_refs(ctx, zds[h], pg, cache_hit[h]);
zink_descriptor_set_update_lazy(ctx, pg, h, zds[h]->desc_set);
continue;

View File

@@ -178,12 +178,12 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
case VK_DESCRIPTOR_TYPE_STORAGE_IMAGE:
case VK_DESCRIPTOR_TYPE_UNIFORM_TEXEL_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_TEXEL_BUFFER:
init_template_entry(shader, j, k, 0, &entries[j][entry_idx[j]], &entry_idx[j], screen->lazy_descriptors);
init_template_entry(shader, j, k, 0, &entries[j][entry_idx[j]], &entry_idx[j], screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY);
break;
case VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER:
case VK_DESCRIPTOR_TYPE_STORAGE_BUFFER:
for (unsigned l = 0; l < shader->bindings[j][k].size; l++)
init_template_entry(shader, j, k, l, &entries[j][entry_idx[j]], &entry_idx[j], screen->lazy_descriptors);
init_template_entry(shader, j, k, l, &entries[j][entry_idx[j]], &entry_idx[j], screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY);
break;
default:
break;
@@ -222,13 +222,13 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program
pg->layout = zink_pipeline_layout_create(screen, pg);
if (!pg->layout)
return false;
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] = {};
/* type of template */
VkDescriptorUpdateTemplateType types[ZINK_DESCRIPTOR_TYPES + 1] = {VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_DESCRIPTOR_SET};
if (have_push && screen->lazy_descriptors)
if (have_push && screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY)
types[0] = VK_DESCRIPTOR_UPDATE_TEMPLATE_TYPE_PUSH_DESCRIPTORS_KHR;
/* number of descriptors in template */
@@ -547,11 +547,14 @@ zink_batch_descriptor_init_lazy(struct zink_screen *screen, struct zink_batch_st
bool
zink_descriptors_init_lazy(struct zink_context *ctx)
{
struct zink_screen *screen = zink_screen(ctx->base.screen);
ctx->dd = (void*)rzalloc(ctx, struct zink_descriptor_data_lazy);
if (!ctx->dd)
return false;
if (zink_screen(ctx->base.screen)->info.have_KHR_descriptor_update_template) {
if (screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_NOTEMPLATES)
printf("ZINK: CACHED/NOTEMPLATES DESCRIPTORS\n");
else if (screen->info.have_KHR_descriptor_update_template) {
for (unsigned i = 0; i < PIPE_SHADER_TYPES; i++) {
VkDescriptorUpdateTemplateEntry *entry = &dd_lazy(ctx)->push_entries[i];
entry->dstBinding = tgsi_processor_to_shader_stage(i);
@@ -560,9 +563,9 @@ zink_descriptors_init_lazy(struct zink_context *ctx)
entry->offset = offsetof(struct zink_context, di.ubos[i][0]);
entry->stride = sizeof(VkDescriptorBufferInfo);
}
printf("ZINK: USING EXPERIMENTAL LAZY DESCRIPTORS\n");
if (screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY)
printf("ZINK: USING LAZY DESCRIPTORS\n");
}
struct zink_screen *screen = zink_screen(ctx->base.screen);
struct zink_descriptor_layout_key *layout_key;
if (!zink_descriptor_util_push_layouts_get(ctx, ctx->dd->push_dsl, ctx->dd->push_layout_keys))
return false;
@@ -585,7 +588,8 @@ zink_descriptors_deinit_lazy(struct zink_context *ctx)
struct zink_screen *screen = zink_screen(ctx->base.screen);
if (ctx->dd->dummy_pool)
vkDestroyDescriptorPool(screen->dev, ctx->dd->dummy_pool, NULL);
if (screen->lazy_descriptors) {
if (screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY &&
screen->info.have_KHR_push_descriptor) {
vkDestroyDescriptorSetLayout(screen->dev, ctx->dd->push_dsl[0], NULL);
vkDestroyDescriptorSetLayout(screen->dev, ctx->dd->push_dsl[1], NULL);
}

View File

@@ -64,6 +64,17 @@ DEBUG_GET_ONCE_FLAGS_OPTION(zink_debug, "ZINK_DEBUG", zink_debug_options, 0)
uint32_t
zink_debug;
static const struct debug_named_value
zink_descriptor_options[] = {
{ "auto", ZINK_DESCRIPTOR_MODE_AUTO, "Automatically detect best mode" },
{ "lazy", ZINK_DESCRIPTOR_MODE_LAZY, "Don't cache, do least amount of updates" },
{ "notemplates", ZINK_DESCRIPTOR_MODE_NOTEMPLATES, "Cache, but disable templated updates" },
DEBUG_NAMED_VALUE_END
};
DEBUG_GET_ONCE_FLAGS_OPTION(zink_descriptor_mode, "ZINK_DESCRIPTORS", zink_descriptor_options, ZINK_DESCRIPTOR_MODE_AUTO)
static const char *
zink_get_vendor(struct pipe_screen *pscreen)
{
@@ -1193,7 +1204,7 @@ zink_screen_init_descriptor_funcs(struct zink_screen *screen, bool fallback)
{
if (screen->info.have_KHR_descriptor_update_template &&
!fallback &&
!getenv("ZINK_CACHE_DESCRIPTORS")) {
screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY) {
#define LAZY(FUNC) screen->FUNC = zink_##FUNC##_lazy
LAZY(descriptor_program_init);
LAZY(descriptor_program_deinit);
@@ -1204,7 +1215,6 @@ zink_screen_init_descriptor_funcs(struct zink_screen *screen, bool fallback)
LAZY(descriptors_init);
LAZY(descriptors_deinit);
LAZY(descriptors_update);
screen->lazy_descriptors = true;
#undef LAZY
} else {
#define DEFAULT(FUNC) screen->FUNC = zink_##FUNC
@@ -1217,7 +1227,6 @@ zink_screen_init_descriptor_funcs(struct zink_screen *screen, bool fallback)
DEFAULT(descriptors_init);
DEFAULT(descriptors_deinit);
DEFAULT(descriptors_update);
screen->lazy_descriptors = false;
#undef DEFAULT
}
}
@@ -1576,6 +1585,11 @@ 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);
zink_debug = debug_get_option_zink_debug();
screen->descriptor_mode = debug_get_option_zink_descriptor_mode();
if (util_bitcount(screen->descriptor_mode) > 1) {
printf("Specify exactly one descriptor mode.\n");
abort();
}
screen->instance_info.loader_version = zink_get_loader_version();
screen->instance = zink_create_instance(&screen->instance_info);

View File

@@ -58,6 +58,12 @@ enum zink_descriptor_type;
#define ZINK_DEBUG_TGSI 0x4
#define ZINK_DEBUG_VALIDATION 0x8
enum zink_descriptor_mode {
ZINK_DESCRIPTOR_MODE_AUTO,
ZINK_DESCRIPTOR_MODE_LAZY,
ZINK_DESCRIPTOR_MODE_NOTEMPLATES,
};
struct zink_screen {
struct pipe_screen base;
bool threaded;
@@ -129,7 +135,7 @@ struct zink_screen {
void (*batch_descriptor_deinit)(struct zink_screen *screen, struct zink_batch_state *bs);
bool (*descriptors_init)(struct zink_context *ctx);
void (*descriptors_deinit)(struct zink_context *ctx);
bool lazy_descriptors;
enum zink_descriptor_mode descriptor_mode;
#if defined(MVK_VERSION)
PFN_vkGetMoltenVKConfigurationMVK vk_GetMoltenVKConfigurationMVK;