[vulkan] Get two render pass rendering working

Things are a bit of a mess with interdependence between sub-module
initialization and render pass initialization, and window resizing is
broken, but the main render pass rendering to an image that is then
post-processed (currently just blitted) is working. This will make it
possible to implement fisheye and water warp (and other effects, of
course).
This commit is contained in:
Bill Currie 2022-11-25 11:07:08 +09:00
parent 7f25c43472
commit d673887bf1
7 changed files with 42 additions and 20 deletions

View file

@ -48,6 +48,7 @@ typedef struct outputctx_s {
VkPipeline pipeline; VkPipeline pipeline;
VkPipelineLayout layout; VkPipelineLayout layout;
VkSampler sampler; VkSampler sampler;
qfv_output_t output;
} outputctx_t; } outputctx_t;
struct vulkan_ctx_s; struct vulkan_ctx_s;
@ -55,5 +56,6 @@ struct vulkan_ctx_s;
void Vulkan_Output_Init (struct vulkan_ctx_s *ctx); void Vulkan_Output_Init (struct vulkan_ctx_s *ctx);
void Vulkan_Output_Shutdown (struct vulkan_ctx_s *ctx); void Vulkan_Output_Shutdown (struct vulkan_ctx_s *ctx);
void Vulkan_Output_CreateRenderPasses (struct vulkan_ctx_s *ctx); void Vulkan_Output_CreateRenderPasses (struct vulkan_ctx_s *ctx);
qfv_output_t *Vulkan_Output_Get (struct vulkan_ctx_s *ctx)__attribute__((pure));
#endif//__QF_Vulkan_qf_output_h #endif//__QF_Vulkan_qf_output_h

View file

@ -72,6 +72,7 @@ typedef struct qfv_output_s {
VkExtent2D extent; VkExtent2D extent;
VkImageView view; VkImageView view;
VkFormat format; VkFormat format;
uint32_t frames;
VkImageView *view_list; // per frame VkImageView *view_list; // per frame
} qfv_output_t; } qfv_output_t;

View file

@ -175,7 +175,7 @@
format = $output.format; format = $output.format;
loadOp = clear; loadOp = clear;
storeOp = store; storeOp = store;
finalLayout = present_src_khr; finalLayout = shader_read_only_optimal;
}, },
); );
subpasses = ( subpasses = (

View file

@ -14,7 +14,7 @@
initialLayout = undefined; initialLayout = undefined;
}; };
images = { images = {
color = { ocolor = {
@inherit = $properties.flat_color_image_template; @inherit = $properties.flat_color_image_template;
format = r16g16b16a16_sfloat; format = r16g16b16a16_sfloat;
}; };
@ -34,10 +34,10 @@
}; };
}; };
imageViews = { imageViews = {
color = { ocolor = {
@inherit = $properties.flat_color_view_template; @inherit = $properties.flat_color_view_template;
image = color; image = ocolor;
format = $properties.images.color.format; format = $properties.images.ocolor.format;
}; };
}; };
framebuffer = { framebuffer = {

View file

@ -56,6 +56,7 @@
#include "QF/Vulkan/qf_lightmap.h" #include "QF/Vulkan/qf_lightmap.h"
#include "QF/Vulkan/qf_main.h" #include "QF/Vulkan/qf_main.h"
#include "QF/Vulkan/qf_matrices.h" #include "QF/Vulkan/qf_matrices.h"
#include "QF/Vulkan/qf_output.h"
#include "QF/Vulkan/qf_particles.h" #include "QF/Vulkan/qf_particles.h"
#include "QF/Vulkan/qf_renderpass.h" #include "QF/Vulkan/qf_renderpass.h"
#include "QF/Vulkan/qf_scene.h" #include "QF/Vulkan/qf_scene.h"
@ -175,14 +176,9 @@ main_draw (qfv_renderframe_t *rFrame)
void void
Vulkan_Main_CreateRenderPasses (vulkan_ctx_t *ctx) Vulkan_Main_CreateRenderPasses (vulkan_ctx_t *ctx)
{ {
qfv_output_t output = { qfv_output_t *output = Vulkan_Output_Get (ctx);
.extent = ctx->swapchain->extent,
.view = ctx->swapchain->imageViews->a[0],
.format = ctx->swapchain->format,
.view_list = ctx->swapchain->imageViews->a,
};
__auto_type rp = Vulkan_CreateRenderPass (ctx, "deferred", __auto_type rp = Vulkan_CreateRenderPass (ctx, "deferred",
&output, main_draw); output, main_draw);
rp->order = QFV_rp_main; rp->order = QFV_rp_main;
DARRAY_APPEND (&ctx->renderPasses, rp); DARRAY_APPEND (&ctx->renderPasses, rp);
} }

View file

@ -95,6 +95,8 @@ output_draw (qfv_renderframe_t *rFrame)
outputframe_t *oframe = &octx->frames.a[ctx->curFrame]; outputframe_t *oframe = &octx->frames.a[ctx->curFrame];
VkCommandBuffer cmd = oframe->cmd; VkCommandBuffer cmd = oframe->cmd;
DARRAY_APPEND (&rFrame->subpassCmdSets[0], cmd);
dfunc->vkResetCommandBuffer (cmd, 0); dfunc->vkResetCommandBuffer (cmd, 0);
VkCommandBufferInheritanceInfo inherit = { VkCommandBufferInheritanceInfo inherit = {
VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0, VK_STRUCTURE_TYPE_COMMAND_BUFFER_INHERITANCE_INFO, 0,
@ -133,18 +135,34 @@ output_draw (qfv_renderframe_t *rFrame)
void void
Vulkan_Output_CreateRenderPasses (vulkan_ctx_t *ctx) Vulkan_Output_CreateRenderPasses (vulkan_ctx_t *ctx)
{ {
outputctx_t *octx = calloc (1, sizeof (outputctx_t));
ctx->output_context = octx;
qfv_output_t output = { qfv_output_t output = {
.extent = ctx->swapchain->extent, .extent = ctx->swapchain->extent,
.view = ctx->swapchain->imageViews->a[0], .view = ctx->swapchain->imageViews->a[0],
.format = ctx->swapchain->format, .format = ctx->swapchain->format,
.frames = ctx->swapchain->numImages,
.view_list = ctx->swapchain->imageViews->a, .view_list = ctx->swapchain->imageViews->a,
}; };
__auto_type out = Vulkan_CreateRenderPass (ctx, "output", __auto_type out = Vulkan_CreateRenderPass (ctx, "output",
&output, output_draw); &output, output_draw);
out->order = QFV_rp_output;
DARRAY_APPEND (&ctx->renderPasses, out);
ctx->output_renderpass = out; ctx->output_renderpass = out;
out->order = QFV_rp_output;
octx->output = (qfv_output_t) {
.extent = ctx->swapchain->extent,
.view = out->attachment_views->a[0],
.format = VK_FORMAT_R16G16B16A16_SFLOAT,//FIXME
.frames = ctx->swapchain->numImages,
.view_list = malloc (sizeof (VkImageView) * ctx->swapchain->numImages),
};
for (int i = 0; i < ctx->swapchain->numImages; i++) {
octx->output.view_list[i] = octx->output.view;
}
DARRAY_APPEND (&ctx->renderPasses, out);
__auto_type pre = Vulkan_CreateFunctionPass (ctx, "preoutput", __auto_type pre = Vulkan_CreateFunctionPass (ctx, "preoutput",
update_input); update_input);
pre->order = QFV_rp_preoutput; pre->order = QFV_rp_preoutput;
@ -158,8 +176,7 @@ Vulkan_Output_Init (vulkan_ctx_t *ctx)
qfvPushDebug (ctx, "output init"); qfvPushDebug (ctx, "output init");
outputctx_t *octx = calloc (1, sizeof (outputctx_t)); outputctx_t *octx = ctx->output_context;
ctx->output_context = octx;
size_t frames = ctx->frames.size; size_t frames = ctx->frames.size;
DARRAY_INIT (&octx->frames, frames); DARRAY_INIT (&octx->frames, frames);
@ -210,3 +227,10 @@ Vulkan_Output_Shutdown (vulkan_ctx_t *ctx)
free (octx->frames.a); free (octx->frames.a);
free (octx); free (octx);
} }
qfv_output_t *
Vulkan_Output_Get (vulkan_ctx_t *ctx)
{
outputctx_t *octx = ctx->output_context;
return &octx->output;
}

View file

@ -37,7 +37,6 @@
#include "QF/Vulkan/debug.h" #include "QF/Vulkan/debug.h"
#include "QF/Vulkan/device.h" #include "QF/Vulkan/device.h"
#include "QF/Vulkan/image.h" #include "QF/Vulkan/image.h"
#include "QF/Vulkan/swapchain.h"
#include "QF/Vulkan/qf_renderpass.h" #include "QF/Vulkan/qf_renderpass.h"
#include "vid_vulkan.h" #include "vid_vulkan.h"
@ -93,6 +92,7 @@ Vulkan_CreateAttachments (vulkan_ctx_t *ctx, qfv_renderpass_t *renderpass)
qfv_device_t *device = ctx->device; qfv_device_t *device = ctx->device;
qfv_devfuncs_t *dfunc = device->funcs; qfv_devfuncs_t *dfunc = device->funcs;
__auto_type rp = renderpass; __auto_type rp = renderpass;
scriptctx_t *sctx = ctx->script_context;
plitem_t *item = get_rp_item (ctx, rp, "images"); plitem_t *item = get_rp_item (ctx, rp, "images");
if (!item) { if (!item) {
@ -156,10 +156,9 @@ Vulkan_CreateAttachments (vulkan_ctx_t *ctx, qfv_renderpass_t *renderpass)
return; return;
} }
rp->framebuffers = QFV_AllocFrameBuffers (ctx->swapchain->numImages, rp->framebuffers = QFV_AllocFrameBuffers (sctx->output.frames, malloc);
malloc);
for (size_t i = 0; i < rp->framebuffers->size; i++) { for (size_t i = 0; i < rp->framebuffers->size; i++) {
ctx->script_context->output.view = ctx->script_context->output.view_list[i]; sctx->output.view = sctx->output.view_list[i];
rp->framebuffers->a[i] = QFV_ParseFramebuffer (ctx, item, rp->framebuffers->a[i] = QFV_ParseFramebuffer (ctx, item,
rp->renderpassDef); rp->renderpassDef);
} }