[vulkan] Add a cvar for oit fragment buffer size

My laptop can't have a buffer larger than 128MB, but 16M fragments wants
512MB. Also, someone running at 4k will probably want a larger buffer.
This commit is contained in:
Bill Currie 2022-12-02 13:29:15 +09:00
parent 1d84d54509
commit 17c3f12ba2
4 changed files with 16 additions and 4 deletions

View file

@ -40,6 +40,7 @@ typedef struct translucentctx_s {
struct qfv_resource_s *resources; struct qfv_resource_s *resources;
int maxFragments;
VkDescriptorPool pool; VkDescriptorPool pool;
VkDescriptorSetLayout setLayout; VkDescriptorSetLayout setLayout;
} translucentctx_t; } translucentctx_t;

View file

@ -100,5 +100,6 @@ struct plitem_s *Vulkan_GetConfig (struct vulkan_ctx_s *ctx, const char *name);
extern int vulkan_frame_width; extern int vulkan_frame_width;
extern int vulkan_frame_height; extern int vulkan_frame_height;
extern int vulkan_oit_fragments;
#endif // __QF_Vulkan_vid_h #endif // __QF_Vulkan_vid_h

View file

@ -59,8 +59,6 @@
#include "r_internal.h" #include "r_internal.h"
#include "vid_vulkan.h" #include "vid_vulkan.h"
#define MAX_FRAGMENTS (1<<24)
static const char * __attribute__((used)) translucent_pass_names[] = { static const char * __attribute__((used)) translucent_pass_names[] = {
"clear", "clear",
"blend", "blend",
@ -84,6 +82,8 @@ Vulkan_Translucent_Init (vulkan_ctx_t *ctx)
DARRAY_RESIZE (&tctx->frames, frames); DARRAY_RESIZE (&tctx->frames, frames);
tctx->frames.grow = 0; tctx->frames.grow = 0;
tctx->maxFragments = vulkan_oit_fragments * 1024 * 1024;
__auto_type setLayout = QFV_AllocDescriptorSetLayoutSet (frames, alloca); __auto_type setLayout = QFV_AllocDescriptorSetLayoutSet (frames, alloca);
for (size_t i = 0; i < frames; i++) { for (size_t i = 0; i < frames; i++) {
setLayout->a[i] = Vulkan_CreateDescriptorSetLayout (ctx, "oit_set"); setLayout->a[i] = Vulkan_CreateDescriptorSetLayout (ctx, "oit_set");
@ -201,7 +201,7 @@ Vulkan_Translucent_CreateBuffers (vulkan_ctx_t *ctx, VkExtent2D extent)
.name = va (ctx->va_ctx, "frags:%zd", i), .name = va (ctx->va_ctx, "frags:%zd", i),
.type = qfv_res_buffer, .type = qfv_res_buffer,
.buffer = { .buffer = {
.size = sizeof (qfv_transfrag_t) * MAX_FRAGMENTS, .size = sizeof (qfv_transfrag_t) * tctx->maxFragments,
.usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT, .usage = VK_BUFFER_USAGE_STORAGE_BUFFER_BIT,
}, },
}; };
@ -290,7 +290,7 @@ translucent_clear (qfv_renderframe_t *rFrame)
qfv_packet_t *packet = QFV_PacketAcquire (ctx->staging); qfv_packet_t *packet = QFV_PacketAcquire (ctx->staging);
qfv_transtate_t *state = QFV_PacketExtend (packet, 2 * sizeof (*state)); qfv_transtate_t *state = QFV_PacketExtend (packet, 2 * sizeof (*state));
*state = (qfv_transtate_t) { 0, MAX_FRAGMENTS }; *state = (qfv_transtate_t) { 0, tctx->maxFragments };
__auto_type bb = &bufferBarriers[qfv_BB_TransferWrite_to_ShaderRW]; __auto_type bb = &bufferBarriers[qfv_BB_TransferWrite_to_ShaderRW];
QFV_PacketCopyBuffer (packet, tframe->state, bb); QFV_PacketCopyBuffer (packet, tframe->state, bb);
QFV_PacketSubmit (packet); QFV_PacketSubmit (packet);

View file

@ -82,6 +82,15 @@ static cvar_t vulkan_frame_height_cvar = {
.flags = CVAR_NONE, .flags = CVAR_NONE,
.value = { .type = &cexpr_int, .value = &vulkan_frame_height }, .value = { .type = &cexpr_int, .value = &vulkan_frame_height },
}; };
int vulkan_oit_fragments;
static cvar_t vulkan_oit_fragments_cvar = {
.name = "vulkan_oit_fragments",
.description =
"Size of fragment buffer (M) for order independent transparency.",
.default_value = "16",
.flags = CVAR_ROM,
.value = { .type = &cexpr_int, .value = &vulkan_oit_fragments },
};
static const char *instance_extensions[] = { static const char *instance_extensions[] = {
VK_KHR_SURFACE_EXTENSION_NAME, VK_KHR_SURFACE_EXTENSION_NAME,
@ -101,6 +110,7 @@ Vulkan_Init_Common (vulkan_ctx_t *ctx)
Cvar_Register (&vulkan_frame_width_cvar, 0, 0); Cvar_Register (&vulkan_frame_width_cvar, 0, 0);
Cvar_Register (&vulkan_frame_height_cvar, 0, 0); Cvar_Register (&vulkan_frame_height_cvar, 0, 0);
Cvar_Register (&vulkan_oit_fragments_cvar, 0, 0);
Vulkan_Init_Cvars (); Vulkan_Init_Cvars ();
R_Init_Cvars (); R_Init_Cvars ();
Vulkan_Script_Init (ctx); Vulkan_Script_Init (ctx);