[vulkan] Get multiple frame buffers working

Now each (high level) render pass can have its own frame buffer. The
current goal is to get the final output render pass to just transfer the
composed output to the swap chain image, potentially with scaling (my
laptop might be able to cope).
This commit is contained in:
Bill Currie 2022-11-21 17:25:55 +09:00
parent e50be73501
commit aac4c6ef7a
12 changed files with 19 additions and 26 deletions

View file

@ -22,6 +22,7 @@ typedef struct qfv_renderframe_s {
struct vulkan_ctx_s *vulkan_ctx;
struct qfv_renderpass_s *renderpass;
VkSubpassContents subpassContents;
VkFramebuffer framebuffer;
int subpassCount;
qfv_subpass_t *subpassInfo;
struct qfv_cmdbufferset_s *subpassCmdSets;

View file

@ -41,6 +41,7 @@
enum {
QFV_rp_shadowmap,
QFV_rp_main,
QFV_rp_output,
};
//FIXME location

View file

@ -18,7 +18,6 @@ typedef struct qfv_output_s {
} qfv_output_t;
typedef struct vulkan_frame_s {
VkFramebuffer framebuffer;
VkFence fence;
VkSemaphore imageAvailableSemaphore;
VkSemaphore renderDoneSemaphore;

View file

@ -333,14 +333,13 @@ vulkan_begin_frame (void)
static void
vulkan_render_view (void)
{
__auto_type frame = &vulkan_ctx->frames.a[vulkan_ctx->curFrame];
uint32_t imageIndex = vulkan_ctx->swapImageIndex;
for (size_t i = 0; i < vulkan_ctx->renderPasses.size; i++) {
__auto_type rp = vulkan_ctx->renderPasses.a[i];
__auto_type rpFrame = &rp->frames.a[vulkan_ctx->curFrame];
if (rp->framebuffers) {
frame->framebuffer = rp->framebuffers->a[imageIndex];
rpFrame->framebuffer = rp->framebuffers->a[imageIndex];
}
rp->draw (rpFrame);
}
@ -385,8 +384,9 @@ vulkan_end_frame (void)
VkDevice dev = device->dev;
qfv_devfuncs_t *dfunc = device->funcs;
qfv_queue_t *queue = &device->queue;
__auto_type frame = &vulkan_ctx->frames.a[vulkan_ctx->curFrame];
uint32_t imageIndex = vulkan_ctx->swapImageIndex;
uint32_t curFrame = vulkan_ctx->curFrame;
__auto_type frame = &vulkan_ctx->frames.a[curFrame];
uint32_t imageIndex = vulkan_ctx->swapImageIndex;
VkCommandBufferBeginInfo beginInfo
= { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO };
@ -402,7 +402,7 @@ vulkan_end_frame (void)
dfunc->vkBeginCommandBuffer (frame->cmdBuffer, &beginInfo);
for (size_t i = 0; i < vulkan_ctx->renderPasses.size; i++) {
__auto_type rp = vulkan_ctx->renderPasses.a[i];
__auto_type rpFrame = &rp->frames.a[vulkan_ctx->curFrame];
__auto_type rpFrame = &rp->frames.a[curFrame];
if (rp->primary_commands) {
for (int j = 0; j < rpFrame->subpassCount; j++) {
@ -417,7 +417,7 @@ vulkan_end_frame (void)
QFV_CmdBeginLabel (device, frame->cmdBuffer, rp->name, rp->color);
if (rpFrame->renderpass && rp->renderpass) {
renderPassInfo.framebuffer = frame->framebuffer,
renderPassInfo.framebuffer = rp->framebuffers->a[imageIndex];
renderPassInfo.renderPass = rp->renderpass;
renderPassInfo.clearValueCount = rp->clearValues->size;
renderPassInfo.pClearValues = rp->clearValues->a;
@ -464,7 +464,7 @@ vulkan_end_frame (void)
if (vulkan_ctx->capture_callback) {
VkImage srcImage = vulkan_ctx->swapchain->images->a[imageIndex];
VkCommandBuffer cmd = QFV_CaptureImage (vulkan_ctx->capture, srcImage,
vulkan_ctx->curFrame);
curFrame);
dfunc->vkCmdExecuteCommands (frame->cmdBuffer, 1, &cmd);
}
dfunc->vkEndCommandBuffer (frame->cmdBuffer);
@ -487,7 +487,7 @@ vulkan_end_frame (void)
dfunc->vkWaitForFences (device->dev, 1, &frame->fence, VK_TRUE,
1000000000ull);
vulkan_ctx->capture_callback (QFV_CaptureData (vulkan_ctx->capture,
vulkan_ctx->curFrame),
curFrame),
vulkan_ctx->capture->extent.width,
vulkan_ctx->capture->extent.height);
vulkan_ctx->capture_callback = 0;

View file

@ -186,15 +186,15 @@ alias_begin_subpass (QFV_AliasSubpass subpass, VkPipeline pipeline,
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
aliasctx_t *actx = ctx->alias_context;
__auto_type cframe = &ctx->frames.a[ctx->curFrame];
aliasframe_t *aframe = &actx->frames.a[ctx->curFrame];
uint32_t curFrame = ctx->curFrame;
aliasframe_t *aframe = &actx->frames.a[curFrame];
VkCommandBuffer cmd = aframe->cmdSet.a[subpass];
dfunc->vkResetCommandBuffer (cmd, 0);
VkCommandBufferInheritanceInfo inherit = {
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0,
rFrame->renderpass->renderpass, subpass_map[subpass],
cframe->framebuffer,
rFrame->framebuffer,
0, 0, 0,
};
VkCommandBufferBeginInfo beginInfo = {

View file

@ -793,7 +793,6 @@ bsp_begin_subpass (QFV_BspSubpass subpass, VkPipeline pipeline,
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
bspctx_t *bctx = ctx->bsp_context;
__auto_type cframe = &ctx->frames.a[ctx->curFrame];
bspframe_t *bframe = &bctx->frames.a[ctx->curFrame];
VkCommandBuffer cmd = bframe->cmdSet.a[subpass];
@ -801,7 +800,7 @@ bsp_begin_subpass (QFV_BspSubpass subpass, VkPipeline pipeline,
VkCommandBufferInheritanceInfo inherit = {
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0,
rFrame->renderpass->renderpass, subpass_map[subpass],
cframe->framebuffer,
rFrame->framebuffer,
0, 0, 0,
};
VkCommandBufferBeginInfo beginInfo = {

View file

@ -64,7 +64,6 @@ Vulkan_Compose_Draw (qfv_renderframe_t *rFrame)
qfv_renderpass_t *renderpass = rFrame->renderpass;
composectx_t *cctx = ctx->compose_context;
__auto_type frame = &ctx->frames.a[ctx->curFrame];
composeframe_t *cframe = &cctx->frames.a[ctx->curFrame];
VkCommandBuffer cmd = cframe->cmd;
@ -74,7 +73,7 @@ Vulkan_Compose_Draw (qfv_renderframe_t *rFrame)
VkCommandBufferInheritanceInfo inherit = {
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0,
renderpass->renderpass, QFV_passCompose,
frame->framebuffer,
rFrame->framebuffer,
0, 0, 0,
};
VkCommandBufferBeginInfo beginInfo = {

View file

@ -1137,7 +1137,6 @@ draw_begin_subpass (QFV_DrawSubpass subpass, qfv_renderframe_t *rFrame)
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
drawctx_t *dctx = ctx->draw_context;
__auto_type cframe = &ctx->frames.a[ctx->curFrame];
drawframe_t *dframe = &dctx->frames.a[ctx->curFrame];
VkCommandBuffer cmd = dframe->cmdSet.a[subpass];
@ -1145,7 +1144,7 @@ draw_begin_subpass (QFV_DrawSubpass subpass, qfv_renderframe_t *rFrame)
VkCommandBufferInheritanceInfo inherit = {
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0,
rFrame->renderpass->renderpass, subpass_map[subpass],
cframe->framebuffer,
rFrame->framebuffer,
0, 0, 0,
};
VkCommandBufferBeginInfo beginInfo = {

View file

@ -212,7 +212,6 @@ iqm_begin_subpass (QFV_IQMSubpass subpass, VkPipeline pipeline,
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
iqmctx_t *ictx = ctx->iqm_context;
__auto_type cframe = &ctx->frames.a[ctx->curFrame];
iqm_frame_t *aframe = &ictx->frames.a[ctx->curFrame];
VkCommandBuffer cmd = aframe->cmdSet.a[subpass];
@ -220,7 +219,7 @@ iqm_begin_subpass (QFV_IQMSubpass subpass, VkPipeline pipeline,
VkCommandBufferInheritanceInfo inherit = {
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0,
rFrame->renderpass->renderpass, subpass_map[subpass],
cframe->framebuffer,
rFrame->framebuffer,
0, 0, 0,
};
VkCommandBufferBeginInfo beginInfo = {

View file

@ -162,7 +162,6 @@ Vulkan_Lighting_Draw (qfv_renderframe_t *rFrame)
update_lights (ctx);
}
__auto_type cframe = &ctx->frames.a[ctx->curFrame];
lightingframe_t *lframe = &lctx->frames.a[ctx->curFrame];
VkCommandBuffer cmd = lframe->cmd;
@ -172,7 +171,7 @@ Vulkan_Lighting_Draw (qfv_renderframe_t *rFrame)
VkCommandBufferInheritanceInfo inherit = {
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0,
renderpass->renderpass, QFV_passLighting,
cframe->framebuffer,
rFrame->framebuffer,
0, 0, 0,
};
VkCommandBufferBeginInfo beginInfo = {

View file

@ -147,7 +147,6 @@ sprite_begin_subpass (QFV_SpriteSubpass subpass, VkPipeline pipeline,
qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs;
spritectx_t *sctx = ctx->sprite_context;
__auto_type cframe = &ctx->frames.a[ctx->curFrame];
spriteframe_t *sframe = &sctx->frames.a[ctx->curFrame];
VkCommandBuffer cmd = sframe->cmdSet.a[subpass];
@ -155,7 +154,7 @@ sprite_begin_subpass (QFV_SpriteSubpass subpass, VkPipeline pipeline,
VkCommandBufferInheritanceInfo inherit = {
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0,
rFrame->renderpass->renderpass, subpass_map[subpass],
cframe->framebuffer,
rFrame->framebuffer,
0, 0, 0,
};
VkCommandBufferBeginInfo beginInfo = {

View file

@ -548,7 +548,6 @@ Vulkan_CreateFrames (vulkan_ctx_t *ctx)
for (size_t i = 0; i < ctx->frames.size; i++) {
__auto_type frame = &ctx->frames.a[i];
frame->framebuffer = 0;
frame->fence = QFV_CreateFence (device, 1);
frame->imageAvailableSemaphore = QFV_CreateSemaphore (device);
frame->renderDoneSemaphore = QFV_CreateSemaphore (device);
@ -575,7 +574,6 @@ Vulkan_DestroyFrames (vulkan_ctx_t *ctx)
df->vkDestroyFence (dev, frame->fence, 0);
df->vkDestroySemaphore (dev, frame->imageAvailableSemaphore, 0);
df->vkDestroySemaphore (dev, frame->renderDoneSemaphore, 0);
frame->framebuffer = 0;
}
DARRAY_CLEAR (&ctx->frames);