vk/cmd_queue: handle descriptor layout refcounting

this enables supporting pnexted VkPipelineLayoutCreateInfo from vkCmdPushDescriptorSetWithTemplate2

Reviewed-by: Konstantin Seurer <konstantin.seurer@gmail.com>
Part-of: <https://gitlab.freedesktop.org/mesa/mesa/-/merge_requests/40268>
This commit is contained in:
Mike Blumenkrantz 2026-03-06 10:20:35 -05:00 committed by Marge Bot
parent 0c22630ba2
commit e3be0e23f9
2 changed files with 26 additions and 32 deletions

View file

@ -29,6 +29,7 @@
#include "vk_device.h"
#include "vk_pipeline_layout.h"
#include "vk_util.h"
#include "vk_descriptor_set_layout.h"
static inline unsigned
vk_descriptor_type_update_size(VkDescriptorType type)
@ -71,6 +72,14 @@ enqueue_pipeline_layout(struct vk_cmd_queue *queue, VkPipelineLayout layout)
util_dynarray_append(&queue->pipeline_layouts, vklayout);
}
static void
enqueue_descriptor_layout(struct vk_cmd_queue *queue, VkDescriptorSetLayout layout)
{
VK_FROM_HANDLE(vk_descriptor_set_layout, vklayout, layout);
vk_descriptor_set_layout_ref(vklayout);
util_dynarray_append(&queue->set_layouts, vklayout);
}
static void
enqueue_descriptor_template(struct vk_cmd_queue *queue, VkDescriptorUpdateTemplate templ)
{
@ -162,53 +171,32 @@ vk_cmd_enqueue_CmdPushDescriptorSetWithTemplate2(
if (pnext) {
switch ((int32_t)pnext->sType) {
/* TODO: The set layouts below would need to be reference counted. Punting
* until there's a cmd_enqueue-based driver implementing
* VK_NV_per_stage_descriptor_set.
*/
#if 0
case VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO:
info->pNext =
vk_zalloc(queue->alloc, sizeof(VkPipelineLayoutCreateInfo), 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (info->pNext == NULL)
goto err;
memcpy((void *)info->pNext, pnext,
info->pNext = linear_zalloc_child(cmd_buffer->cmd_queue.ctx, sizeof(VkPipelineLayoutCreateInfo));
memcpy((void*)info->pNext, pnext,
sizeof(VkPipelineLayoutCreateInfo));
VkPipelineLayoutCreateInfo *tmp_dst2 = (void *)info->pNext;
VkPipelineLayoutCreateInfo *tmp_src2 = (void *)pnext;
if (tmp_src2->pSetLayouts) {
tmp_dst2->pSetLayouts = vk_zalloc(
queue->alloc,
sizeof(*tmp_dst2->pSetLayouts) * tmp_dst2->setLayoutCount, 8,
VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (tmp_dst2->pSetLayouts == NULL)
goto err;
tmp_dst2->pSetLayouts = linear_zalloc_child(cmd_buffer->cmd_queue.ctx, sizeof(*tmp_dst2->pSetLayouts) * tmp_dst2->setLayoutCount);
memcpy(
(void *)tmp_dst2->pSetLayouts, tmp_src2->pSetLayouts,
sizeof(*tmp_dst2->pSetLayouts) * tmp_dst2->setLayoutCount);
typed_memcpy(tmp_dst2->pSetLayouts, tmp_src2->pSetLayouts, tmp_dst2->setLayoutCount);
for (unsigned i = 0; i < tmp_dst2->setLayoutCount; i++)
enqueue_descriptor_layout(queue, tmp_src2->pSetLayouts[i]);
}
if (tmp_src2->pPushConstantRanges) {
tmp_dst2->pPushConstantRanges =
vk_zalloc(queue->alloc,
sizeof(*tmp_dst2->pPushConstantRanges) *
tmp_dst2->pushConstantRangeCount,
8, VK_SYSTEM_ALLOCATION_SCOPE_OBJECT);
if (tmp_dst2->pPushConstantRanges == NULL)
goto err;
linear_zalloc_child(cmd_buffer->cmd_queue.ctx, sizeof(*tmp_dst2->pPushConstantRanges) *
tmp_dst2->pushConstantRangeCount);
memcpy((void *)tmp_dst2->pPushConstantRanges,
tmp_src2->pPushConstantRanges,
sizeof(*tmp_dst2->pPushConstantRanges) *
tmp_dst2->pushConstantRangeCount);
typed_memcpy(tmp_dst2->pPushConstantRanges,
tmp_src2->pPushConstantRanges,
tmp_dst2->pushConstantRangeCount);
}
break;
#endif
default:
goto err;

View file

@ -102,6 +102,7 @@ struct vk_cmd_queue {
struct list_head cmds;
struct util_dynarray pipeline_layouts;
struct util_dynarray update_templates;
struct util_dynarray set_layouts;
};
enum vk_cmd_type {
@ -195,6 +196,7 @@ vk_cmd_queue_init(struct vk_cmd_queue *queue)
list_inithead(&queue->cmds);
util_dynarray_init(&queue->pipeline_layouts, NULL);
util_dynarray_init(&queue->update_templates, NULL);
util_dynarray_init(&queue->set_layouts, NULL);
}
static inline void
@ -236,6 +238,7 @@ TEMPLATE_C = Template(COPYRIGHT + """
#include "vk_device.h"
#include "vulkan/runtime/vk_pipeline_layout.h"
#include "vulkan/runtime/vk_descriptor_update_template.h"
#include "vulkan/runtime/vk_descriptor_set_layout.h"
const char *vk_cmd_queue_type_names[] = {
% for c in commands:
@ -299,6 +302,9 @@ vk_free_queue(struct vk_cmd_queue *queue)
util_dynarray_foreach(&queue->update_templates, void*, templ)
vk_descriptor_update_template_unref(cmd_buffer->base.device, *templ);
util_dynarray_fini(&queue->update_templates);
util_dynarray_foreach(&queue->set_layouts, void*, layout)
vk_descriptor_set_layout_unref(cmd_buffer->base.device, *layout);
util_dynarray_fini(&queue->set_layouts);
linear_free_context(queue->ctx);
}