From 7fa727bbc5b1fce70775522576aeeabcf39d539b Mon Sep 17 00:00:00 2001 From: Valiantsin Dzerakh Date: Tue, 10 Nov 2026 23:24:11 +0300 Subject: [PATCH] Skip the present lock for the Reflex frame ID when nothing reads it, and declare the front end's Reflex calls in gfx.h vk_reflex_present_frame took g_pl on every present although only flip_locked's VkPresentIdKHR (Reflex) and latency_note (TOTK_TRACE=perf) read g_blit_pid. nvn_api_obj.c and ov_input.c declared vk_reflex_marker, vk_reflex_frame_begin, vk_reflex_frame and vk_reflex_sleep locally; they now come from gfx.h, the graphics layer's interface, which gfx_present.c also sees through vk.h, so a changed signature fails to compile. vk.h stays out of those two files: it brings in Vulkan, VMA and vk_rec.h's vkCmd* macros. Co-Authored-By: Claude Opus 5.5 --- runtime/gfx.h | 6 ++++++ runtime/gfx_present.c | 3 +++ runtime/nvn_api_obj.c | 5 ----- runtime/ov_input.c | 4 +--- runtime/vk.h | 4 ---- 5 files changed, 10 insertions(+), 12 deletions(-) diff --git a/runtime/gfx.h b/runtime/gfx.h index 0bed28d1..2475cc57 100644 --- a/runtime/gfx.h +++ b/runtime/gfx.h @@ -24,6 +24,12 @@ uint64_t gfx_vsync_time_ns(uint64_t tick); // kern_now_ns() time double gfx_window_refresh_hz(void); // refresh rate of the window's monitor; 0 unknown int gfx_window_focused(void); int gfx_picture_rect(float out[4]); // where the last present put the picture, fractions of the swapchain (x, y, w, h); 0 before one +// NVIDIA Reflex (gfx_present.c, VK_NV_low_latency2): the NVN front end and the input service mark a frame's stages. +// The markers and the sleep return at once with Reflex off or unsupported. +void vk_reflex_marker(int marker, uint64_t present_id); // present_id: the frame's (vk_reflex_frame_begin) +uint64_t vk_reflex_frame_begin(void); // SIMULATION_START: the new frame's present ID +uint64_t vk_reflex_frame(void); // the ID of the frame the game simulates now +void vk_reflex_sleep(void); // before SIMULATION_START: the driver's latency sleep // ---- shader service client (gfx_shader.c) enum { GFX_STAGE_VS, GFX_STAGE_TCS, GFX_STAGE_TES, GFX_STAGE_GS, GFX_STAGE_FS, GFX_STAGE_CS }; diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index 53d47e19..f63092e5 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -386,6 +386,9 @@ uint64_t vk_reflex_submit_id(void) { return t_reflex_submit ? t_reflex_submit : // The present thread, before the blit of frame id: the present of that blit carries id. void vk_reflex_present_frame(uint64_t id) { + // g_blit_pid feeds flip_locked's VkPresentIdKHR (Reflex) and latency_note (TOTK_TRACE=perf); with neither, the + // present skips the lock + if (!vk_has_reflex() && !(rt_trace & RT_TRACE_PERF)) return; plat_rmutex_lock(&g_pl); g_blit_pid = id; plat_rmutex_unlock(&g_pl); diff --git a/runtime/nvn_api_obj.c b/runtime/nvn_api_obj.c index 8fc698bf..8500a70b 100644 --- a/runtime/nvn_api_obj.c +++ b/runtime/nvn_api_obj.c @@ -19,11 +19,6 @@ #include "nvn_tex.h" #include "platform/platform.h" -void vk_reflex_marker(int marker, uint64_t present_id); -uint64_t vk_reflex_frame_begin(void); -uint64_t vk_reflex_frame(void); -void vk_reflex_sleep(void); - // ---------- Descriptor pools // NVNboolean nvnTexturePoolInitialize(NVNtexturePool *tp, const NVNmemoryPool *p, ptrdiff_t offset, int n) NVN_API(nvnTexturePoolInitialize) { diff --git a/runtime/ov_input.c b/runtime/ov_input.c index 2a2f34a3..e56c4eb0 100644 --- a/runtime/ov_input.c +++ b/runtime/ov_input.c @@ -12,14 +12,12 @@ #include #include "cfg.h" +#include "gfx.h" #include "host.h" #include "input.h" #include "ov.h" #include "platform/platform.h" -void vk_reflex_marker(int marker, uint64_t present_id); -uint64_t vk_reflex_frame(void); - typedef struct { int64_t sampling; uint64_t buttons; int32_t lx, ly, rx, ry; uint32_t attributes, pad; } NpadState; typedef struct { int64_t sampling; int32_t x, y, dx, dy, wx, wy; uint32_t buttons, attributes; } MouseState; typedef struct { int64_t sampling; uint32_t modifiers, attributes; uint64_t keys[4]; } KeyboardState; diff --git a/runtime/vk.h b/runtime/vk.h index c1185f54..82154bb8 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -148,13 +148,9 @@ void vk_present_blit(VkImage src, VkImageLayout layout, VkFormat fmt, int w, int int vk_fsr_record(VkCommandBuffer cb, unsigned slot, VkImage src, VkFormat fmt, int sw, int sh, const int crop[4], VkImage dst, const int out[4]); void vk_fsr_release(void); // before the device goes away -void vk_reflex_marker(int marker, uint64_t present_id); // present_id: the frame's (vk_reflex_frame_begin) -uint64_t vk_reflex_frame_begin(void); // SIMULATION_START: the new frame's present ID -uint64_t vk_reflex_frame(void); // the ID of the frame the game simulates now void vk_reflex_submit_frame(uint64_t id); // this thread's submissions belong to frame id (0: the game's current one) uint64_t vk_reflex_submit_id(void); void vk_reflex_present_frame(uint64_t id); // the present thread, before the blit of frame id -void vk_reflex_sleep(void); int vk_has_reflex(void); // Colour adjustment on the present (vk_color.c): with TOTK_COLOR_* away from their defaults, records a pass that writes // src's crop rectangle {x, y, w, h}, adjusted, into an RGBA16F image of that size in GENERAL and returns it (the caller