diff --git a/include/QF/Vulkan/qf_main.h b/include/QF/Vulkan/qf_main.h index 8d2da31d6..b666ce017 100644 --- a/include/QF/Vulkan/qf_main.h +++ b/include/QF/Vulkan/qf_main.h @@ -33,6 +33,7 @@ struct qfv_renderframe_s; struct entqueue_s; struct scene_s; +void Vulkan_Main_CreateRenderPasses (struct vulkan_ctx_s *ctx); void Vulkan_NewScene (struct scene_s *scene, struct vulkan_ctx_s *ctx); void Vulkan_RenderView (struct qfv_renderframe_s *rFrame); void Vulkan_RenderEntities (struct entqueue_s *queue, diff --git a/include/QF/Vulkan/qf_renderpass.h b/include/QF/Vulkan/qf_renderpass.h index 8a4d68a1b..ddbc70764 100644 --- a/include/QF/Vulkan/qf_renderpass.h +++ b/include/QF/Vulkan/qf_renderpass.h @@ -48,6 +48,7 @@ typedef struct qfv_renderpass_s { qfv_framebufferset_t *framebuffers; VkViewport viewport; VkRect2D scissor; + int order; size_t subpassCount; qfv_subpassset_t *subpass_info; diff --git a/include/QF/Vulkan/qf_vid.h b/include/QF/Vulkan/qf_vid.h index 04e4a49d6..eb12a2ce2 100644 --- a/include/QF/Vulkan/qf_vid.h +++ b/include/QF/Vulkan/qf_vid.h @@ -35,6 +35,10 @@ #endif #include +enum { + QFV_rp_main, +}; + //FIXME location typedef enum { QFV_passDepth, // geometry diff --git a/libs/video/renderer/vulkan/vulkan_main.c b/libs/video/renderer/vulkan/vulkan_main.c index 8fa6a91e3..fa0fcd53b 100644 --- a/libs/video/renderer/vulkan/vulkan_main.c +++ b/libs/video/renderer/vulkan/vulkan_main.c @@ -48,17 +48,21 @@ #include "QF/scene/entity.h" #include "QF/scene/scene.h" -#include "QF/Vulkan/qf_vid.h" #include "QF/Vulkan/qf_alias.h" #include "QF/Vulkan/qf_bsp.h" +#include "QF/Vulkan/qf_compose.h" +#include "QF/Vulkan/qf_draw.h" #include "QF/Vulkan/qf_iqm.h" #include "QF/Vulkan/qf_lighting.h" #include "QF/Vulkan/qf_lightmap.h" #include "QF/Vulkan/qf_main.h" +#include "QF/Vulkan/qf_matrices.h" #include "QF/Vulkan/qf_particles.h" #include "QF/Vulkan/qf_renderpass.h" #include "QF/Vulkan/qf_scene.h" #include "QF/Vulkan/qf_sprite.h" +#include "QF/Vulkan/qf_vid.h" +#include "QF/Vulkan/swapchain.h" #include "mod_internal.h" #include "r_internal.h" @@ -151,3 +155,28 @@ Vulkan_NewScene (scene_t *scene, vulkan_ctx_t *ctx) Vulkan_BuildDisplayLists (scene->models, scene->num_models, ctx); Vulkan_LoadLights (scene, ctx); } + +static void +main_draw (qfv_renderframe_t *rFrame) +{ + Vulkan_Matrix_Draw (rFrame); + Vulkan_RenderView (rFrame); + Vulkan_FlushText (rFrame);//FIXME delayed by a frame? + Vulkan_Lighting_Draw (rFrame); + Vulkan_Compose_Draw (rFrame); +} + +void +Vulkan_Main_CreateRenderPasses (vulkan_ctx_t *ctx) +{ + qfv_output_t output = { + .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", + &output, main_draw); + rp->order = QFV_rp_main; + DARRAY_APPEND (&ctx->renderPasses, rp); +} diff --git a/libs/video/renderer/vulkan/vulkan_vid_common.c b/libs/video/renderer/vulkan/vulkan_vid_common.c index d87e4ce72..f95aa3b43 100644 --- a/libs/video/renderer/vulkan/vulkan_vid_common.c +++ b/libs/video/renderer/vulkan/vulkan_vid_common.c @@ -39,23 +39,20 @@ #include "QF/cvar.h" #include "QF/dstring.h" #include "QF/hash.h" +#include "QF/heapsort.h" #include "QF/plist.h" #include "QF/va.h" #include "QF/scene/entity.h" #include "QF/Vulkan/capture.h" +#include "QF/Vulkan/command.h" #include "QF/Vulkan/debug.h" #include "QF/Vulkan/device.h" #include "QF/Vulkan/instance.h" #include "QF/Vulkan/staging.h" #include "QF/Vulkan/swapchain.h" -#include "QF/Vulkan/qf_alias.h" -#include "QF/Vulkan/qf_bsp.h" -#include "QF/Vulkan/qf_compose.h" -#include "QF/Vulkan/qf_draw.h" #include "QF/Vulkan/qf_lighting.h" #include "QF/Vulkan/qf_main.h" -#include "QF/Vulkan/qf_matrices.h" #include "QF/Vulkan/qf_renderpass.h" #include "QF/Vulkan/qf_vid.h" @@ -365,28 +362,21 @@ qfv_load_pipeline (vulkan_ctx_t *ctx, const char *name) return item; } -static void -renderpass_draw (qfv_renderframe_t *rFrame) +static int +renderpass_cmp (const void *_a, const void *_b) { - Vulkan_Matrix_Draw (rFrame); - Vulkan_RenderView (rFrame); - Vulkan_FlushText (rFrame);//FIXME delayed by a frame? - Vulkan_Lighting_Draw (rFrame); - Vulkan_Compose_Draw (rFrame); + const qfv_renderpass_t *a = _a; + const qfv_renderpass_t *b = _b; + return a->order - b->order; } void Vulkan_CreateRenderPasses (vulkan_ctx_t *ctx) { - qfv_output_t output = { - .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", - &output, renderpass_draw); - DARRAY_APPEND (&ctx->renderPasses, rp); + Vulkan_Main_CreateRenderPasses (ctx); + + heapsort (ctx->renderPasses.a, ctx->renderPasses.size, + sizeof (qfv_renderpass_t *), renderpass_cmp); } void