mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-03-22 02:11:19 +00:00
[vulkan] Use darray size to control cmd buffer count
This allows the array in which the command buffers are allocated to be allocated on the stack using alloca and thus remove the need to malloc/free of relatively small chunks.
This commit is contained in:
parent
cef81741eb
commit
ad9c3193fa
5 changed files with 23 additions and 23 deletions
|
@ -6,6 +6,9 @@
|
|||
typedef struct qfv_cmdbufferset_s
|
||||
DARRAY_TYPE (VkCommandBuffer) qfv_cmdbufferset_t;
|
||||
|
||||
#define QFV_AllocCommandBufferSet(num, allocator) \
|
||||
DARRAY_ALLOCFIXED (qfv_cmdbufferset_t, num, allocator)
|
||||
|
||||
typedef struct qfv_semaphoreset_s
|
||||
DARRAY_TYPE (VkSemaphore) qfv_semaphoreset_t;
|
||||
|
||||
|
@ -23,9 +26,11 @@ struct qfv_device_s;
|
|||
VkCommandPool QFV_CreateCommandPool (struct qfv_device_s *device,
|
||||
uint32_t queueFamily,
|
||||
int transient, int reset);
|
||||
qfv_cmdbufferset_t *QFV_AllocateCommandBuffers (struct qfv_device_s *device,
|
||||
VkCommandPool pool,
|
||||
int secondary, int count);
|
||||
/** Allocate bufferset->size command buffers
|
||||
*/
|
||||
int QFV_AllocateCommandBuffers (struct qfv_device_s *device,
|
||||
VkCommandPool pool, int secondary,
|
||||
qfv_cmdbufferset_t *bufferset);
|
||||
|
||||
VkSemaphore QFV_CreateSemaphore (struct qfv_device_s *device);
|
||||
VkFence QFV_CreateFence (struct qfv_device_s *device, int signaled);
|
||||
|
|
|
@ -389,11 +389,10 @@ vulkan_vid_render_choose_visual (void)
|
|||
vulkan_ctx->cmdpool = QFV_CreateCommandPool (vulkan_ctx->device,
|
||||
vulkan_ctx->device->queue.queueFamily,
|
||||
0, 1);
|
||||
__auto_type cmdset = QFV_AllocateCommandBuffers (vulkan_ctx->device,
|
||||
vulkan_ctx->cmdpool,
|
||||
0, 1);
|
||||
__auto_type cmdset = QFV_AllocCommandBufferSet (1, alloca);
|
||||
QFV_AllocateCommandBuffers (vulkan_ctx->device, vulkan_ctx->cmdpool, 0,
|
||||
cmdset);
|
||||
vulkan_ctx->cmdbuffer = cmdset->a[0];
|
||||
free (cmdset);
|
||||
vulkan_ctx->fence = QFV_CreateFence (vulkan_ctx->device, 1);
|
||||
Sys_Printf ("vk choose visual %p %p %d %p\n", vulkan_ctx->device->dev,
|
||||
vulkan_ctx->device->queue.queue,
|
||||
|
|
|
@ -87,9 +87,9 @@ QFV_CreateCommandPool (qfv_device_t *device, uint32_t queueFamily,
|
|||
return pool;
|
||||
}
|
||||
|
||||
qfv_cmdbufferset_t *
|
||||
int
|
||||
QFV_AllocateCommandBuffers (qfv_device_t *device, VkCommandPool pool,
|
||||
int secondary, int count)
|
||||
int secondary, qfv_cmdbufferset_t *bufferset)
|
||||
{
|
||||
VkDevice dev = device->dev;
|
||||
qfv_devfuncs_t *dfunc = device->funcs;
|
||||
|
@ -99,12 +99,10 @@ QFV_AllocateCommandBuffers (qfv_device_t *device, VkCommandPool pool,
|
|||
}
|
||||
VkCommandBufferAllocateInfo allocInfo = {
|
||||
VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO, 0,
|
||||
pool, level, count
|
||||
pool, level, bufferset->size
|
||||
};
|
||||
qfv_cmdbufferset_t *cmdbufferset;
|
||||
cmdbufferset = DARRAY_ALLOCFIXED (*cmdbufferset, count, malloc);
|
||||
dfunc->vkAllocateCommandBuffers (dev, &allocInfo, cmdbufferset->a);
|
||||
return cmdbufferset;
|
||||
int ret = dfunc->vkAllocateCommandBuffers (dev, &allocInfo, bufferset->a);
|
||||
return ret == VK_SUCCESS;
|
||||
}
|
||||
|
||||
VkSemaphore
|
||||
|
|
|
@ -355,12 +355,12 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
|
|||
QFV_ScrapImageView (draw_scrap),
|
||||
VK_IMAGE_LAYOUT_SHADER_READ_ONLY_OPTIMAL,
|
||||
};
|
||||
__auto_type cmdBuffers
|
||||
= QFV_AllocateCommandBuffers (device, ctx->cmdpool, 1,
|
||||
ctx->framebuffers.size);
|
||||
size_t frames = ctx->framebuffers.size;
|
||||
__auto_type cmdBuffers = QFV_AllocCommandBufferSet (frames, alloca);
|
||||
QFV_AllocateCommandBuffers (device, ctx->cmdpool, 1, cmdBuffers);
|
||||
|
||||
__auto_type sets = QFV_AllocateDescriptorSet (device, pool, layouts);
|
||||
for (size_t i = 0; i < ctx->framebuffers.size; i++) {
|
||||
for (size_t i = 0; i < frames; i++) {
|
||||
__auto_type frame = &ctx->framebuffers.a[i];
|
||||
frame->twodDescriptors = sets->a[i];
|
||||
|
||||
|
@ -379,7 +379,6 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
|
|||
DARRAY_APPEND (frame->subCommand, cmdBuffers->a[i]);
|
||||
}
|
||||
free (sets);
|
||||
free (cmdBuffers);
|
||||
}
|
||||
|
||||
static inline void
|
||||
|
|
|
@ -402,9 +402,9 @@ Vulkan_CreateFramebuffers (vulkan_ctx_t *ctx)
|
|||
attachments->a[0] = ctx->renderpass.colorImage->view;
|
||||
attachments->a[1] = ctx->renderpass.depthImage->view;
|
||||
|
||||
__auto_type cmdBuffers
|
||||
= QFV_AllocateCommandBuffers (device, cmdpool, 0,
|
||||
ctx->framebuffers.size);
|
||||
__auto_type cmdBuffers = QFV_AllocCommandBufferSet (ctx->framebuffers.size,
|
||||
alloca);
|
||||
QFV_AllocateCommandBuffers (device, cmdpool, 0, cmdBuffers);
|
||||
|
||||
for (size_t i = 0; i < ctx->framebuffers.size; i++) {
|
||||
attachments->a[2] = sc->imageViews->a[i];
|
||||
|
@ -420,7 +420,6 @@ Vulkan_CreateFramebuffers (vulkan_ctx_t *ctx)
|
|||
frame->subCommand = malloc (sizeof (qfv_cmdbufferset_t));
|
||||
DARRAY_INIT (frame->subCommand, 4);
|
||||
}
|
||||
free (cmdBuffers);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
Loading…
Reference in a new issue