From c46e15af9b919e2d32171a0b7653626ab43163f2 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Tue, 15 Aug 2023 14:34:23 +0900 Subject: [PATCH] [vulkan] Up max lights to 2048 and quantize sizes This seems excessive, but gmsp3v2 map has 1399 lights. Worse, it has a lot of different light sizes that go up by small increments (generally around 10) resulting in 33 shadow map images (1 too many). Quantizing the sizes to 32 drops this nicely to 20, and reduces memory consumption slightly too (image buffer overhead, I guess). --- include/QF/Vulkan/qf_lighting.h | 2 +- libs/video/renderer/vulkan/vulkan_lighting.c | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/include/QF/Vulkan/qf_lighting.h b/include/QF/Vulkan/qf_lighting.h index 2112cf7a8..931f8fffb 100644 --- a/include/QF/Vulkan/qf_lighting.h +++ b/include/QF/Vulkan/qf_lighting.h @@ -42,7 +42,7 @@ typedef struct qfv_lightmatset_s DARRAY_TYPE (mat4f_t) qfv_lightmatset_t; -#define MaxLights 768 +#define MaxLights 2048 enum { ST_NONE, // no shadows diff --git a/libs/video/renderer/vulkan/vulkan_lighting.c b/libs/video/renderer/vulkan/vulkan_lighting.c index a9bd36c59..a38170a94 100644 --- a/libs/video/renderer/vulkan/vulkan_lighting.c +++ b/libs/video/renderer/vulkan/vulkan_lighting.c @@ -79,6 +79,7 @@ #include "vid_vulkan.h" #include "vkparse.h" +#define shadow_quanta 32 #define lnearclip 4 #define num_cascade 4 @@ -1555,7 +1556,9 @@ allocate_map (mapctx_t *mctx, int type, int (*getsize) (const light_t *light)) if (lr->mode != type) { continue; } - int light_size = getsize (&mctx->lights[li]); + int light_size = getsize (&mctx->lights[li]) + shadow_quanta - 1; + light_size = ((light_size + shadow_quanta - 1) / shadow_quanta) + * shadow_quanta; if (size != light_size || numLayers + layers > mctx->maxLayers) { if (numLayers) { mctx->maps[mctx->numMaps++] = (mapdesc_t) { @@ -1725,7 +1728,7 @@ build_shadow_maps (lightingctx_t *lctx, vulkan_ctx_t *ctx) int cube = maps[i].cube; lctx->map_cube[i] = cube; images[i] = (qfv_resobj_t) { - .name = va (ctx->va_ctx, "map:image:%d:%d", i, maps[i].size), + .name = va (ctx->va_ctx, "map:image:%02d:%d", i, maps[i].size), .type = qfv_res_image, .image = { .flags = cube ? VK_IMAGE_CREATE_CUBE_COMPATIBLE_BIT : 0, @@ -1740,7 +1743,7 @@ build_shadow_maps (lightingctx_t *lctx, vulkan_ctx_t *ctx) }, }; views[i] = (qfv_resobj_t) { - .name = va (ctx->va_ctx, "map:view:%d:%d", i, maps[i].size), + .name = va (ctx->va_ctx, "map:view:%02d:%d", i, maps[i].size), .type = qfv_res_image_view, .image_view = { .image = i,