Module: Mesa Branch: main Commit: 08050b7e987d6d4602393083f1c9a6cbb1c6611a URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=08050b7e987d6d4602393083f1c9a6cbb1c6611a
Author: Mike Blumenkrantz <[email protected]> Date: Tue Jul 27 14:03:23 2021 -0400 zink: add an input attachment to the gfx push set layout to handle fbfetch Reviewed-by: Dave Airlie <[email protected]> Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/12603> --- src/gallium/drivers/zink/zink_descriptors.c | 35 ++++++++++++++++------ src/gallium/drivers/zink/zink_descriptors_lazy.c | 38 ++++++++++++++++-------- 2 files changed, 52 insertions(+), 21 deletions(-) diff --git a/src/gallium/drivers/zink/zink_descriptors.c b/src/gallium/drivers/zink/zink_descriptors.c index f950c3298c5..ca0ef1ca7c4 100644 --- a/src/gallium/drivers/zink/zink_descriptors.c +++ b/src/gallium/drivers/zink/zink_descriptors.c @@ -478,6 +478,12 @@ zink_descriptor_util_push_layouts_get(struct zink_context *ctx, struct zink_desc for (unsigned i = 0; i < ZINK_SHADER_COUNT; i++) init_push_binding(&bindings[i], i, vktype); init_push_binding(&compute_binding, PIPE_SHADER_COMPUTE, vktype); + /* fbfetch */ + bindings[ZINK_SHADER_COUNT].binding = ZINK_FBFETCH_BINDING; + bindings[ZINK_SHADER_COUNT].descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; + bindings[ZINK_SHADER_COUNT].descriptorCount = 1; + bindings[ZINK_SHADER_COUNT].stageFlags = VK_SHADER_STAGE_FRAGMENT_BIT; + bindings[ZINK_SHADER_COUNT].pImmutableSamplers = NULL; 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] = create_layout(ctx, dsl_type, bindings, ARRAY_SIZE(bindings), &layout_keys[0]); @@ -1086,12 +1092,14 @@ zink_descriptor_pool_init(struct zink_context *ctx) return false; } struct zink_screen *screen = zink_screen(ctx->base.screen); - VkDescriptorPoolSize sizes; - 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; - ctx->dd->push_pool[1] = descriptor_pool_get(ctx, 0, ctx->dd->push_layout_keys[1], &sizes, 1); + 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].descriptorCount = ZINK_SHADER_COUNT * ZINK_DEFAULT_MAX_DESCS; + sizes[1].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; + sizes[1].descriptorCount = ZINK_DEFAULT_MAX_DESCS; + ctx->dd->push_pool[0] = descriptor_pool_get(ctx, 0, ctx->dd->push_layout_keys[0], sizes, 2); + sizes[0].descriptorCount = ZINK_DEFAULT_MAX_DESCS; + ctx->dd->push_pool[1] = descriptor_pool_get(ctx, 0, ctx->dd->push_layout_keys[1], sizes, 1); return ctx->dd->push_pool[0] && ctx->dd->push_pool[1]; } @@ -1174,7 +1182,8 @@ init_write_descriptor(struct zink_shader *shader, struct zink_descriptor_set *zd wd->dstBinding = shader ? shader->bindings[type][idx].binding : idx; wd->dstArrayElement = 0; wd->descriptorCount = shader ? shader->bindings[type][idx].size : 1; - wd->descriptorType = shader ? shader->bindings[type][idx].type : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; + wd->descriptorType = shader ? shader->bindings[type][idx].type : + idx == ZINK_FBFETCH_BINDING ? VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT : VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER_DYNAMIC; wd->dstSet = zds->desc_set; return num_wds + 1; } @@ -1184,9 +1193,10 @@ update_push_ubo_descriptors(struct zink_context *ctx, struct zink_descriptor_set bool is_compute, bool cache_hit, uint32_t *dynamic_offsets) { struct zink_screen *screen = zink_screen(ctx->base.screen); - VkWriteDescriptorSet wds[ZINK_SHADER_COUNT]; + VkWriteDescriptorSet wds[ZINK_SHADER_COUNT + 1]; VkDescriptorBufferInfo buffer_infos[ZINK_SHADER_COUNT]; struct zink_shader **stages; + bool fbfetch = false; unsigned num_stages = is_compute ? 1 : ZINK_SHADER_COUNT; struct zink_program *pg = is_compute ? &ctx->curr_compute->base : &ctx->curr_program->base; @@ -1230,9 +1240,16 @@ update_push_ubo_descriptors(struct zink_context *ctx, struct zink_descriptor_set wds[i].pBufferInfo = &buffer_infos[i]; } } + if (unlikely(!cache_hit && !is_compute && ctx->fbfetch_outputs)) { + struct zink_resource *res = zink_resource(ctx->fb_state.cbufs[0]->texture); + init_write_descriptor(NULL, zds, 0, MESA_SHADER_STAGES, &wds[ZINK_SHADER_COUNT], 0); + desc_set_res_add(zds, res, ZINK_SHADER_COUNT, cache_hit); + wds[ZINK_SHADER_COUNT].pImageInfo = &ctx->di.fbfetch; + fbfetch = true; + } if (!cache_hit) - vkUpdateDescriptorSets(screen->dev, num_stages, wds, 0, NULL); + vkUpdateDescriptorSets(screen->dev, num_stages + !!fbfetch, wds, 0, NULL); return num_stages; } diff --git a/src/gallium/drivers/zink/zink_descriptors_lazy.c b/src/gallium/drivers/zink/zink_descriptors_lazy.c index 7f05a86552f..fde735c4917 100644 --- a/src/gallium/drivers/zink/zink_descriptors_lazy.c +++ b/src/gallium/drivers/zink/zink_descriptors_lazy.c @@ -36,7 +36,8 @@ struct zink_descriptor_data_lazy { struct zink_descriptor_data base; - VkDescriptorUpdateTemplateEntry push_entries[PIPE_SHADER_TYPES]; + VkDescriptorUpdateTemplateEntry push_entries[PIPE_SHADER_TYPES]; //gfx+fbfetch + VkDescriptorUpdateTemplateEntry compute_push_entry; bool push_state_changed[2]; //gfx, compute uint8_t state_changed[2]; //gfx, compute }; @@ -129,19 +130,22 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program VkDescriptorUpdateTemplateEntry entries[ZINK_DESCRIPTOR_TYPES][PIPE_SHADER_TYPES * 32]; unsigned num_bindings[ZINK_DESCRIPTOR_TYPES] = {0}; uint8_t has_bindings = 0; + unsigned push_count = 0; struct zink_shader **stages; if (pg->is_compute) stages = &((struct zink_compute_program*)pg)->shader; - else + else { stages = ((struct zink_gfx_program*)pg)->shaders; + if (stages[PIPE_SHADER_FRAGMENT]->nir->info.fs.uses_fbfetch_output) + push_count = 1; + } if (!pg->dd) pg->dd = (void*)rzalloc(pg, struct zink_program_descriptor_data); if (!pg->dd) return false; - unsigned push_count = 0; unsigned entry_idx[ZINK_DESCRIPTOR_TYPES] = {0}; unsigned num_shaders = pg->is_compute ? 1 : ZINK_SHADER_COUNT; @@ -238,13 +242,13 @@ zink_descriptor_program_init_lazy(struct zink_context *ctx, struct zink_program /* number of descriptors in template */ unsigned wd_count[ZINK_DESCRIPTOR_TYPES + 1]; if (push_count) - wd_count[0] = pg->is_compute ? 1 : ZINK_SHADER_COUNT; + wd_count[0] = pg->is_compute ? 1 : (ZINK_SHADER_COUNT + 1); for (unsigned i = 0; i < ZINK_DESCRIPTOR_TYPES; i++) 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, - &dd_lazy(ctx)->push_entries[PIPE_SHADER_COMPUTE], + &dd_lazy(ctx)->compute_push_entry, }; for (unsigned i = 0; i < pg->num_dsl; i++) { bool is_push = i == 0; @@ -334,13 +338,16 @@ static struct zink_descriptor_pool * create_push_pool(struct zink_screen *screen, struct zink_batch_descriptor_data_lazy *bdd, bool is_compute) { struct zink_descriptor_pool *pool = rzalloc(bdd, struct zink_descriptor_pool); - VkDescriptorPoolSize sizes; - sizes.type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; + VkDescriptorPoolSize sizes[2]; + sizes[0].type = VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER; if (is_compute) - sizes.descriptorCount = ZINK_DEFAULT_MAX_DESCS; - else - sizes.descriptorCount = ZINK_SHADER_COUNT * ZINK_DEFAULT_MAX_DESCS; - pool->pool = create_pool(screen, 1, &sizes, 0); + sizes[0].descriptorCount = ZINK_DEFAULT_MAX_DESCS; + else { + sizes[0].descriptorCount = ZINK_SHADER_COUNT * ZINK_DEFAULT_MAX_DESCS; + sizes[1].type = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; + sizes[1].descriptorCount = ZINK_DEFAULT_MAX_DESCS; + } + pool->pool = create_pool(screen, 1 + !is_compute, sizes, 0); return pool; } @@ -625,10 +632,17 @@ zink_descriptors_init_lazy(struct zink_context *ctx) 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++) { + for (unsigned i = 0; i < ZINK_SHADER_COUNT; i++) { VkDescriptorUpdateTemplateEntry *entry = &dd_lazy(ctx)->push_entries[i]; init_push_template_entry(entry, i); } + init_push_template_entry(&dd_lazy(ctx)->compute_push_entry, PIPE_SHADER_COMPUTE); + VkDescriptorUpdateTemplateEntry *entry = &dd_lazy(ctx)->push_entries[ZINK_SHADER_COUNT]; //fbfetch + entry->dstBinding = ZINK_FBFETCH_BINDING; + entry->descriptorCount = 1; + entry->descriptorType = VK_DESCRIPTOR_TYPE_INPUT_ATTACHMENT; + entry->offset = offsetof(struct zink_context, di.fbfetch); + entry->stride = sizeof(VkDescriptorImageInfo); if (screen->descriptor_mode == ZINK_DESCRIPTOR_MODE_LAZY) printf("ZINK: USING LAZY DESCRIPTORS\n"); }
