From 1d84d54509946a084db21dedce9680eb609ffed6 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Fri, 2 Dec 2022 13:17:07 +0900 Subject: [PATCH] [vulkan] Add cvars to control vulkan 3d frame buffer size Thanks to the 3d frame buffer output being separate from the swap chain, it's possible to have a different frame buffer size from the window size, allowing for a smaller buffer and thus my laptop can cope (mostly) with the vulkan renderer. --- include/QF/Vulkan/qf_vid.h | 3 +++ libs/video/renderer/vulkan/vulkan_main.c | 6 +++++ .../video/renderer/vulkan/vulkan_vid_common.c | 22 +++++++++++++++++++ 3 files changed, 31 insertions(+) diff --git a/include/QF/Vulkan/qf_vid.h b/include/QF/Vulkan/qf_vid.h index ff57d9853..8d0e414a1 100644 --- a/include/QF/Vulkan/qf_vid.h +++ b/include/QF/Vulkan/qf_vid.h @@ -98,4 +98,7 @@ void Vulkan_BeginEntityLabel (struct vulkan_ctx_s *ctx, VkCommandBuffer cmd, struct plitem_s *Vulkan_GetConfig (struct vulkan_ctx_s *ctx, const char *name); +extern int vulkan_frame_width; +extern int vulkan_frame_height; + #endif // __QF_Vulkan_vid_h diff --git a/libs/video/renderer/vulkan/vulkan_main.c b/libs/video/renderer/vulkan/vulkan_main.c index d06a526d5..f3d5084fa 100644 --- a/libs/video/renderer/vulkan/vulkan_main.c +++ b/libs/video/renderer/vulkan/vulkan_main.c @@ -181,6 +181,12 @@ Vulkan_Main_CreateRenderPasses (vulkan_ctx_t *ctx) .extent = ctx->swapchain->extent, .frames = ctx->swapchain->numImages, }; + if (vulkan_frame_width > 0) { + rp->output.extent.width = vulkan_frame_width; + } + if (vulkan_frame_height > 0) { + rp->output.extent.height = vulkan_frame_height; + } QFV_RenderPass_CreateAttachments (rp); QFV_RenderPass_CreateRenderPass (rp); QFV_RenderPass_CreateFramebuffer (rp); diff --git a/libs/video/renderer/vulkan/vulkan_vid_common.c b/libs/video/renderer/vulkan/vulkan_vid_common.c index f7df0a5b7..d504c5e3a 100644 --- a/libs/video/renderer/vulkan/vulkan_vid_common.c +++ b/libs/video/renderer/vulkan/vulkan_vid_common.c @@ -63,6 +63,26 @@ #include "vid_vulkan.h" #include "vkparse.h" +int vulkan_frame_width; +static cvar_t vulkan_frame_width_cvar = { + .name = "vulkan_frame_width", + .description = + "Width of 3D view buffer. Set to 0 for automatic sizing.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &vulkan_frame_width }, +}; + +int vulkan_frame_height; +static cvar_t vulkan_frame_height_cvar = { + .name = "vulkan_frame_height", + .description = + "Height of 3D view buffer. Set to 0 for automatic sizing.", + .default_value = "0", + .flags = CVAR_NONE, + .value = { .type = &cexpr_int, .value = &vulkan_frame_height }, +}; + static const char *instance_extensions[] = { VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_GET_PHYSICAL_DEVICE_PROPERTIES_2_EXTENSION_NAME, @@ -79,6 +99,8 @@ Vulkan_Init_Common (vulkan_ctx_t *ctx) { Sys_MaskPrintf (SYS_vulkan, "Vulkan_Init_Common\n"); + Cvar_Register (&vulkan_frame_width_cvar, 0, 0); + Cvar_Register (&vulkan_frame_height_cvar, 0, 0); Vulkan_Init_Cvars (); R_Init_Cvars (); Vulkan_Script_Init (ctx);