mirror of
https://git.code.sf.net/p/quake/quakeforge
synced 2025-02-17 01:11:45 +00:00
[vulkan] Rename vulkan_framebuffer_t
It turns out I had conflated frame buffers with frames and wound up making a minor mess when separating the number of frames the renderer could have in flight from the number of swap-chain images. This is the first step towards correcting that mistake.
This commit is contained in:
parent
7ffe197564
commit
1275067655
8 changed files with 60 additions and 63 deletions
|
@ -22,7 +22,7 @@ typedef struct vulkan_framebuffer_s {
|
|||
VkCommandBuffer cmdBuffer;
|
||||
|
||||
struct qfv_cmdbufferset_s *subCommand;
|
||||
} vulkan_framebuffer_t;
|
||||
} vulkan_frame_t;
|
||||
|
||||
typedef struct vulkan_matrices_s {
|
||||
VkBuffer buffer_2d;
|
||||
|
@ -34,8 +34,8 @@ typedef struct vulkan_matrices_s {
|
|||
float *sky_3d;
|
||||
} vulkan_matrices_t;
|
||||
|
||||
typedef struct vulkan_framebufferset_s
|
||||
DARRAY_TYPE (vulkan_framebuffer_t) vulkan_framebufferset_t;
|
||||
typedef struct vulkan_frameset_s
|
||||
DARRAY_TYPE (vulkan_frame_t) vulkan_frameset_t;
|
||||
|
||||
typedef struct vulkan_ctx_s {
|
||||
void (*load_vulkan) (struct vulkan_ctx_s *ctx);
|
||||
|
@ -76,7 +76,7 @@ typedef struct vulkan_ctx_s {
|
|||
struct qfv_stagebuf_s *staging;
|
||||
VkPipeline pipeline;
|
||||
size_t curFrame;
|
||||
vulkan_framebufferset_t framebuffers;
|
||||
vulkan_frameset_t frames;
|
||||
|
||||
struct qfv_tex_s *default_black;
|
||||
struct qfv_tex_s *default_white;
|
||||
|
|
|
@ -124,15 +124,14 @@ vulkan_R_RenderFrame (SCR_Func scr_3dfunc, SCR_Func *scr_funcs)
|
|||
VkDevice dev = device->dev;
|
||||
qfv_queue_t *queue = &vulkan_ctx->device->queue;
|
||||
|
||||
__auto_type framebuffer
|
||||
= &vulkan_ctx->framebuffers.a[vulkan_ctx->curFrame];
|
||||
__auto_type frame = &vulkan_ctx->frames.a[vulkan_ctx->curFrame];
|
||||
|
||||
dfunc->vkWaitForFences (dev, 1, &framebuffer->fence, VK_TRUE, 2000000000);
|
||||
if (framebuffer->framebuffer) {
|
||||
dfunc->vkDestroyFramebuffer (dev, framebuffer->framebuffer, 0);
|
||||
dfunc->vkWaitForFences (dev, 1, &frame->fence, VK_TRUE, 2000000000);
|
||||
if (frame->framebuffer) {
|
||||
dfunc->vkDestroyFramebuffer (dev, frame->framebuffer, 0);
|
||||
}
|
||||
QFV_AcquireNextImage (vulkan_ctx->swapchain,
|
||||
framebuffer->imageAvailableSemaphore,
|
||||
frame->imageAvailableSemaphore,
|
||||
0, &imageIndex);
|
||||
|
||||
int attachCount = vulkan_ctx->msaaSamples > 1 ? 3 : 2;
|
||||
|
@ -146,9 +145,8 @@ vulkan_R_RenderFrame (SCR_Func scr_3dfunc, SCR_Func *scr_funcs)
|
|||
}
|
||||
|
||||
VkRenderPass renderpass = vulkan_ctx->renderpass.renderpass;
|
||||
framebuffer->framebuffer = QFV_CreateFramebuffer (device, renderpass,
|
||||
attachments,
|
||||
sc->extent, 1);
|
||||
frame->framebuffer = QFV_CreateFramebuffer (device, renderpass,
|
||||
attachments, sc->extent, 1);
|
||||
|
||||
scr_3dfunc ();
|
||||
while (*scr_funcs) {
|
||||
|
@ -172,41 +170,40 @@ vulkan_R_RenderFrame (SCR_Func scr_3dfunc, SCR_Func *scr_funcs)
|
|||
3, clearValues
|
||||
};
|
||||
|
||||
dfunc->vkBeginCommandBuffer (framebuffer->cmdBuffer, &beginInfo);
|
||||
renderPassInfo.framebuffer = framebuffer->framebuffer;
|
||||
dfunc->vkCmdBeginRenderPass (framebuffer->cmdBuffer, &renderPassInfo,
|
||||
VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
|
||||
dfunc->vkBeginCommandBuffer (frame->cmdBuffer, &beginInfo);
|
||||
renderPassInfo.framebuffer = frame->framebuffer;
|
||||
dfunc->vkCmdBeginRenderPass (frame->cmdBuffer, &renderPassInfo,
|
||||
VK_SUBPASS_CONTENTS_SECONDARY_COMMAND_BUFFERS);
|
||||
|
||||
dfunc->vkCmdExecuteCommands (framebuffer->cmdBuffer,
|
||||
framebuffer->subCommand->size,
|
||||
framebuffer->subCommand->a);
|
||||
dfunc->vkCmdExecuteCommands (frame->cmdBuffer, frame->subCommand->size,
|
||||
frame->subCommand->a);
|
||||
// reset for next time around
|
||||
framebuffer->subCommand->size = 0;
|
||||
frame->subCommand->size = 0;
|
||||
|
||||
dfunc->vkCmdEndRenderPass (framebuffer->cmdBuffer);
|
||||
dfunc->vkEndCommandBuffer (framebuffer->cmdBuffer);
|
||||
dfunc->vkCmdEndRenderPass (frame->cmdBuffer);
|
||||
dfunc->vkEndCommandBuffer (frame->cmdBuffer);
|
||||
|
||||
VkPipelineStageFlags waitStage
|
||||
= VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
|
||||
VkSubmitInfo submitInfo = {
|
||||
VK_STRUCTURE_TYPE_SUBMIT_INFO, 0,
|
||||
1, &framebuffer->imageAvailableSemaphore, &waitStage,
|
||||
1, &framebuffer->cmdBuffer,
|
||||
1, &framebuffer->renderDoneSemaphore,
|
||||
1, &frame->imageAvailableSemaphore, &waitStage,
|
||||
1, &frame->cmdBuffer,
|
||||
1, &frame->renderDoneSemaphore,
|
||||
};
|
||||
dfunc->vkResetFences (dev, 1, &framebuffer->fence);
|
||||
dfunc->vkQueueSubmit (queue->queue, 1, &submitInfo, framebuffer->fence);
|
||||
dfunc->vkResetFences (dev, 1, &frame->fence);
|
||||
dfunc->vkQueueSubmit (queue->queue, 1, &submitInfo, frame->fence);
|
||||
|
||||
VkPresentInfoKHR presentInfo = {
|
||||
VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, 0,
|
||||
1, &framebuffer->renderDoneSemaphore,
|
||||
1, &frame->renderDoneSemaphore,
|
||||
1, &vulkan_ctx->swapchain->swapchain, &imageIndex,
|
||||
0
|
||||
};
|
||||
dfunc->vkQueuePresentKHR (queue->queue, &presentInfo);
|
||||
|
||||
vulkan_ctx->curFrame++;
|
||||
vulkan_ctx->curFrame %= vulkan_ctx->framebuffers.size;
|
||||
vulkan_ctx->curFrame %= vulkan_ctx->frames.size;
|
||||
|
||||
if (++count >= 100) {
|
||||
double currenTime = Sys_DoubleTime ();
|
||||
|
|
|
@ -55,25 +55,25 @@
|
|||
descriptorPools = {
|
||||
twod_pool = {
|
||||
flags = 0;
|
||||
maxSets = $framebuffers.size;
|
||||
maxSets = $frames.size;
|
||||
bindings = (
|
||||
{
|
||||
type = uniform_buffer;
|
||||
descriptorCount = $framebuffers.size;
|
||||
descriptorCount = $frames.size;
|
||||
},
|
||||
{
|
||||
type = combined_image_sampler;
|
||||
descriptorCount = $framebuffers.size;
|
||||
descriptorCount = $frames.size;
|
||||
},
|
||||
);
|
||||
};
|
||||
alias_pool = {
|
||||
flags = 0;
|
||||
maxSets = "2z * $framebuffers.size";
|
||||
maxSets = "2z * $frames.size";
|
||||
bindings = (
|
||||
{
|
||||
type = uniform_buffer;
|
||||
descriptorCount = "2z * $framebuffers.size";
|
||||
descriptorCount = "2z * $frames.size";
|
||||
},
|
||||
);
|
||||
};
|
||||
|
|
|
@ -606,19 +606,19 @@ exprtype_t qfv_swapchain_t_type = {
|
|||
&qfv_swapchain_t_symtab,
|
||||
};
|
||||
|
||||
static exprsym_t vulkan_framebufferset_t_symbols[] = {
|
||||
{"size", &cexpr_size_t, (void *)field_offset (vulkan_framebufferset_t, size)},
|
||||
static exprsym_t vulkan_frameset_t_symbols[] = {
|
||||
{"size", &cexpr_size_t, (void *)field_offset (vulkan_frameset_t, size)},
|
||||
{ }
|
||||
};
|
||||
static exprtab_t vulkan_framebufferset_t_symtab = {
|
||||
vulkan_framebufferset_t_symbols,
|
||||
static exprtab_t vulkan_frameset_t_symtab = {
|
||||
vulkan_frameset_t_symbols,
|
||||
};
|
||||
exprtype_t vulkan_framebufferset_t_type = {
|
||||
"framebufferset",
|
||||
sizeof (vulkan_framebufferset_t *),
|
||||
exprtype_t vulkan_frameset_t_type = {
|
||||
"frameset",
|
||||
sizeof (vulkan_frameset_t *),
|
||||
cexpr_struct_binops,
|
||||
0,
|
||||
&vulkan_framebufferset_t_symtab,
|
||||
&vulkan_frameset_t_symtab,
|
||||
};
|
||||
|
||||
typedef struct qfv_renderpass_s {
|
||||
|
@ -684,7 +684,7 @@ QFV_InitParse (vulkan_ctx_t *ctx)
|
|||
context.hashlinks = &ctx->hashlinks;
|
||||
vkgen_init_symtabs (&context);
|
||||
cexpr_init_symtab (&qfv_swapchain_t_symtab, &context);
|
||||
cexpr_init_symtab (&vulkan_framebufferset_t_symtab, &context);
|
||||
cexpr_init_symtab (&vulkan_frameset_t_symtab, &context);
|
||||
cexpr_init_symtab (&imageset_symtab, &context);
|
||||
|
||||
if (!ctx->setLayouts) {
|
||||
|
@ -711,7 +711,7 @@ parse_object (vulkan_ctx_t *ctx, plitem_t *plist,
|
|||
parsectx_t parsectx = { &exprctx, ctx };
|
||||
exprsym_t var_syms[] = {
|
||||
{"swapchain", &qfv_swapchain_t_type, ctx->swapchain},
|
||||
{"framebuffers", &vulkan_framebufferset_t_type, &ctx->framebuffers},
|
||||
{"frames", &vulkan_frameset_t_type, &ctx->frames},
|
||||
{"msaaSamples", &VkSampleCountFlagBits_type, &ctx->msaaSamples},
|
||||
{QFV_PROPERTIES, &cexpr_plitem, &ctx->pipelineDef},
|
||||
{}
|
||||
|
|
|
@ -153,7 +153,7 @@ Vulkan_AliasBegin (vulkan_ctx_t *ctx)
|
|||
dlight_t *lights[ALIAS_LIGHTS];
|
||||
//XXX quat_t fog;
|
||||
|
||||
__auto_type cframe = &ctx->framebuffers.a[ctx->curFrame];
|
||||
__auto_type cframe = &ctx->frames.a[ctx->curFrame];
|
||||
aliasframe_t *aframe = &actx->frames.a[ctx->curFrame];
|
||||
VkCommandBuffer cmd = aframe->cmd;
|
||||
DARRAY_APPEND (cframe->subCommand, cmd);
|
||||
|
@ -252,7 +252,7 @@ Vulkan_Alias_Init (vulkan_ctx_t *ctx)
|
|||
aliasctx_t *actx = calloc (1, sizeof (aliasctx_t));
|
||||
ctx->alias_context = actx;
|
||||
|
||||
size_t frames = ctx->framebuffers.size;
|
||||
size_t frames = ctx->frames.size;
|
||||
DARRAY_INIT (&actx->frames, frames);
|
||||
DARRAY_RESIZE (&actx->frames, frames);
|
||||
actx->frames.grow = 0;
|
||||
|
|
|
@ -838,7 +838,7 @@ bsp_begin (vulkan_ctx_t *ctx)
|
|||
bctx->default_color[3] = 1;
|
||||
QuatCopy (bctx->default_color, bctx->last_color);
|
||||
|
||||
__auto_type cframe = &ctx->framebuffers.a[ctx->curFrame];
|
||||
__auto_type cframe = &ctx->frames.a[ctx->curFrame];
|
||||
bspframe_t *bframe = &bctx->frames.a[ctx->curFrame];
|
||||
VkCommandBuffer cmd = bframe->bsp_cmd;
|
||||
DARRAY_APPEND (cframe->subCommand, cmd);
|
||||
|
@ -991,7 +991,7 @@ sky_begin (vulkan_ctx_t *ctx)
|
|||
|
||||
spin (ctx->matrices.sky_3d, bctx);
|
||||
|
||||
__auto_type cframe = &ctx->framebuffers.a[ctx->curFrame];
|
||||
__auto_type cframe = &ctx->frames.a[ctx->curFrame];
|
||||
bspframe_t *bframe = &bctx->frames.a[ctx->curFrame];
|
||||
VkCommandBuffer cmd = bframe->sky_cmd;
|
||||
DARRAY_APPEND (cframe->subCommand, cmd);
|
||||
|
@ -1443,7 +1443,7 @@ Vulkan_Bsp_Init (vulkan_ctx_t *ctx)
|
|||
|
||||
DARRAY_INIT (&bctx->texture_chains, 64);
|
||||
|
||||
size_t frames = ctx->framebuffers.size;
|
||||
size_t frames = ctx->frames.size;
|
||||
DARRAY_INIT (&bctx->frames, frames);
|
||||
DARRAY_RESIZE (&bctx->frames, frames);
|
||||
bctx->frames.grow = 0;
|
||||
|
|
|
@ -120,7 +120,7 @@ create_quad_buffers (vulkan_ctx_t *ctx)
|
|||
|
||||
size_t vert_size;
|
||||
size_t ind_size;
|
||||
size_t frames = ctx->framebuffers.size;
|
||||
size_t frames = ctx->frames.size;
|
||||
VkBuffer vbuf, ibuf;
|
||||
VkDeviceMemory vmem, imem;
|
||||
|
||||
|
@ -357,7 +357,7 @@ Vulkan_Draw_Init (vulkan_ctx_t *ctx)
|
|||
drawctx_t *dctx = calloc (1, sizeof (drawctx_t));
|
||||
ctx->draw_context = dctx;
|
||||
|
||||
size_t frames = ctx->framebuffers.size;
|
||||
size_t frames = ctx->frames.size;
|
||||
DARRAY_INIT (&dctx->frames, frames);
|
||||
DARRAY_RESIZE (&dctx->frames, frames);
|
||||
dctx->frames.grow = 0;
|
||||
|
@ -680,7 +680,7 @@ Vulkan_FlushText (vulkan_ctx_t *ctx)
|
|||
|
||||
qfv_device_t *device = ctx->device;
|
||||
qfv_devfuncs_t *dfunc = device->funcs;
|
||||
__auto_type cframe = &ctx->framebuffers.a[ctx->curFrame];
|
||||
__auto_type cframe = &ctx->frames.a[ctx->curFrame];
|
||||
drawctx_t *dctx = ctx->draw_context;
|
||||
drawframe_t *dframe = &dctx->frames.a[ctx->curFrame];
|
||||
|
||||
|
|
|
@ -168,7 +168,7 @@ Vulkan_Shutdown_Common (vulkan_ctx_t *ctx)
|
|||
if (ctx->pipeline) {
|
||||
QFV_DestroyPipeline (ctx->device, ctx->pipeline);
|
||||
}
|
||||
if (ctx->framebuffers.size) {
|
||||
if (ctx->frames.size) {
|
||||
Vulkan_DestroyFramebuffers (ctx);
|
||||
}
|
||||
if (ctx->renderpass.colorImage) {
|
||||
|
@ -496,18 +496,18 @@ Vulkan_CreateFramebuffers (vulkan_ctx_t *ctx)
|
|||
qfv_device_t *device = ctx->device;
|
||||
VkCommandPool cmdpool = ctx->cmdpool;
|
||||
|
||||
if (!ctx->framebuffers.grow) {
|
||||
DARRAY_INIT (&ctx->framebuffers, 4);
|
||||
if (!ctx->frames.grow) {
|
||||
DARRAY_INIT (&ctx->frames, 4);
|
||||
}
|
||||
|
||||
DARRAY_RESIZE (&ctx->framebuffers, 3);//FIXME cvar
|
||||
DARRAY_RESIZE (&ctx->frames, 3);//FIXME cvar
|
||||
|
||||
__auto_type cmdBuffers = QFV_AllocCommandBufferSet (ctx->framebuffers.size,
|
||||
__auto_type cmdBuffers = QFV_AllocCommandBufferSet (ctx->frames.size,
|
||||
alloca);
|
||||
QFV_AllocateCommandBuffers (device, cmdpool, 0, cmdBuffers);
|
||||
|
||||
for (size_t i = 0; i < ctx->framebuffers.size; i++) {
|
||||
__auto_type frame = &ctx->framebuffers.a[i];
|
||||
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);
|
||||
|
@ -526,13 +526,13 @@ Vulkan_DestroyFramebuffers (vulkan_ctx_t *ctx)
|
|||
qfv_devfuncs_t *df = device->funcs;
|
||||
VkDevice dev = device->dev;
|
||||
|
||||
for (size_t i = 0; i < ctx->framebuffers.size; i++) {
|
||||
__auto_type frame = &ctx->framebuffers.a[i];
|
||||
for (size_t i = 0; i < ctx->frames.size; i++) {
|
||||
__auto_type frame = &ctx->frames.a[i];
|
||||
df->vkDestroyFence (dev, frame->fence, 0);
|
||||
df->vkDestroySemaphore (dev, frame->imageAvailableSemaphore, 0);
|
||||
df->vkDestroySemaphore (dev, frame->renderDoneSemaphore, 0);
|
||||
df->vkDestroyFramebuffer (dev, frame->framebuffer, 0);
|
||||
}
|
||||
|
||||
DARRAY_CLEAR (&ctx->framebuffers);
|
||||
DARRAY_CLEAR (&ctx->frames);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue