From 00ecb7d71aaacd268271ece0afc329422bd92b79 Mon Sep 17 00:00:00 2001 From: Bill Currie Date: Sat, 16 Dec 2023 14:00:01 +0900 Subject: [PATCH] [vulkan] Use separate tracy GPU context for light culling My efforts (especially the collect zone (what was I thinking)) got tracy's knickers in a twist resulting in vanishing zones in the server. It looks like there are some synchronisation issues between cpu and gpu, but I'm not *too* worried about it at this stage. --- include/QF/Vulkan/qf_lighting.h | 4 +++- include/vid_vulkan.h | 2 +- libs/video/renderer/vulkan/rp_main_def.plist | 6 ++--- libs/video/renderer/vulkan/vulkan_lighting.c | 24 ++++++++++++++------ 4 files changed, 24 insertions(+), 12 deletions(-) diff --git a/include/QF/Vulkan/qf_lighting.h b/include/QF/Vulkan/qf_lighting.h index d81ee2c3c..b1e48f476 100644 --- a/include/QF/Vulkan/qf_lighting.h +++ b/include/QF/Vulkan/qf_lighting.h @@ -56,7 +56,7 @@ enum { enum { lighting_main, lighting_shadow, - lighting_debug, + lighting_hull, }; typedef struct qfv_light_render_s { @@ -100,6 +100,8 @@ typedef struct lightingframe_s { light_queue_t stage_queue[LIGHTING_STAGES]; // map_id (0,5) first layer (5,11) uint16_t *stage_targets; + + qftVkCtx_t *qftVkCtx; } lightingframe_t; typedef struct lightingframeset_s diff --git a/include/vid_vulkan.h b/include/vid_vulkan.h index 0e4d9b48f..0691bb7ce 100644 --- a/include/vid_vulkan.h +++ b/include/vid_vulkan.h @@ -45,7 +45,7 @@ static inline void __qftVkZoneEnd (___tracy_vkctx_scope ***zone) #define qftCVkContextHostCalibrated(instance, physdev, device, instanceProcAddr, deviceProcAddr) #define qftCVkContextDestroy(ctx) #define qftCVkContextName(ctx, name, size) -#define qftCVkContextCollect(ctx, cmdbuf) +#define qftCVkCollect(ctx, cmdbuf) #define qftVkZone(ctx, cmdbuf, name) \ do { (void)(ctx); (void) (cmdbuf); } while (0) diff --git a/libs/video/renderer/vulkan/rp_main_def.plist b/libs/video/renderer/vulkan/rp_main_def.plist index 587f8e5f7..7cf8da955 100644 --- a/libs/video/renderer/vulkan/rp_main_def.plist +++ b/libs/video/renderer/vulkan/rp_main_def.plist @@ -1374,7 +1374,7 @@ renderpasses = { color = $color.lights; tasks = ( { func = lighting_bind_descriptors; - params = (debug, none); }, + params = (hull, none); }, { func = lighting_draw_hulls; }, ); @@ -1921,7 +1921,7 @@ renderpasses = { color = $color.lights; tasks = ( { func = lighting_bind_descriptors; - params = (debug, none); }, + params = (hull, none); }, { func = lighting_draw_splats; }, ); @@ -1975,7 +1975,7 @@ renderpasses = { color = $color.lights; tasks = ( { func = lighting_bind_descriptors; - params = (debug, none); }, + params = (hull, none); }, { func = lighting_draw_splats; }, ); diff --git a/libs/video/renderer/vulkan/vulkan_lighting.c b/libs/video/renderer/vulkan/vulkan_lighting.c index 98ff9cb71..f3c112aa2 100644 --- a/libs/video/renderer/vulkan/vulkan_lighting.c +++ b/libs/video/renderer/vulkan/vulkan_lighting.c @@ -927,7 +927,7 @@ lighting_bind_descriptors (const exprval_t **params, exprval_t *result, auto shadow_type = *(int *) params[0]->value; auto stage = *(int *) params[1]->value; - if (stage == lighting_debug) { + if (stage == lighting_hull) { VkDescriptorSet sets[] = { Vulkan_Matrix_Descriptors (ctx, ctx->curFrame), lframe->lights_set, @@ -1009,12 +1009,13 @@ lighting_cull_lights (const exprval_t **params, exprval_t *result, .sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO, .flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT, }); - { - qftVkScopedZoneC (taskctx->frame->qftVkCtx, cmd, "reset", 0xc0a000); - dfunc->vkCmdResetQueryPool (cmd, lframe->query, 0, MaxLights); - } + qftCVkCollect (lframe->qftVkCtx, cmd); + dfunc->vkCmdResetQueryPool (cmd, lframe->query, 0, MaxLights); + auto qftVkCtx = taskctx->frame->qftVkCtx; + taskctx->frame->qftVkCtx = lframe->qftVkCtx; auto renderpass = &render->renderpasses[0]; QFV_RunRenderPassCmd (cmd, ctx, renderpass, 0); + taskctx->frame->qftVkCtx = qftVkCtx; dfunc->vkEndCommandBuffer (cmd); qfMessageL ("submit"); @@ -1128,12 +1129,12 @@ static exprtype_t lighting_stage_type = { static int lighting_stage_values[] = { lighting_main, lighting_shadow, - lighting_debug, + lighting_hull, }; static exprsym_t lighting_stage_symbols[] = { {"main", &lighting_stage_type, lighting_stage_values + 0}, {"shadow", &lighting_stage_type, lighting_stage_values + 1}, - {"debug", &lighting_stage_type, lighting_stage_values + 2}, + {"hull", &lighting_stage_type, lighting_stage_values + 2}, {} }; static exprtab_t lighting_stage_symtab = { .symbols = lighting_stage_symbols }; @@ -1672,6 +1673,15 @@ Vulkan_Lighting_Setup (vulkan_ctx_t *ctx) .queryCount = MaxLights, }, 0, &lframe->query); lframe->fence = QFV_CreateFence (device, 1); +#ifdef TRACY_ENABLE + auto instance = ctx->instance->instance; + auto physdev = ctx->device->physDev->dev; + auto gipa = ctx->vkGetInstanceProcAddr; + auto gdpa = ctx->instance->funcs->vkGetDeviceProcAddr; + lframe->qftVkCtx = qftCVkContextHostCalibrated (instance, physdev, + device->dev, + gipa, gdpa); +#endif } size_t target_count = MaxLights * 6; size_t target_size = frames * sizeof (uint16_t[target_count]);