diff --git a/docs/settings.md b/docs/settings.md index e1163426..da5ca279 100644 --- a/docs/settings.md +++ b/docs/settings.md @@ -178,6 +178,7 @@ Many rows below are developer tools that only act together with another setting | `mvprev_grow` (default `1`) | `0` keeps only three banks in the previous-frame tables. | Object motion that depends on the other banks is no longer tracked. | Caution | | `mvprev_skip` | Hex bank mask of banks left out of the previous-frame copy, replacing the default. | Different banks are tracked, which changes object motion. | Caution | | `mvprev_trust` | Hex bank mask of banks whose found previous-frame copy is taken without the check. | A copy that does not match is used anyway, which can give wrong motion. | Caution | +| `reflex` (default `off`) | `off`, `on`, or `boost`; enables NVIDIA Reflex Low Latency (`VK_NV_low_latency2`) to reduce system input latency. Read at start. | On NVIDIA GPUs supporting the extension, coordinates simulation and presentation cadence to lower latency; `boost` keeps GPU clocks high in CPU-bound scenes. Has no effect on non-NVIDIA GPUs. | Safe | ## Scheduling and host diff --git a/runtime/cfg.c b/runtime/cfg.c index dbb73f7d..10f55b78 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -52,7 +52,7 @@ static const char *const known[] = { "MV_SURVEY", "ONE_PER_CORE", "OPERATION_MODE", "OUTPUT_RES", "PAD_LAYOUT", "PASS_CRUMBS", "PATCH_OUTPUT", "PATCH_SCENE", "PCORE", "PCSS", "PCSS_K", "PERF_OVERLAY", "PERF_SLOW_MS", "PIPELINE_CACHE", "PIPE_MEMO", "PIPE_PREBUILD", "PIPE_SKIP", "PIPE_SYNC", "PIPE_WAIT", "PREWARM_XLATE", "PROBE_MOVIE", "PROBE_MOVIE_BENCH", "PROBE_MOVIE_SHOT", "PROFILE", "PROFILE_CHAINS", "PROFILE_DIR", "PROFILE_FRAMES", - "PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_ASYNC", "REC_END", "REC_SPIN_US", "REEXEC", + "PROFILE_MAIN", "PROFILE_RENDER", "PROMPTS", "PUSH_SKIP", "PUSH_STAGE", "RDOC", "RDOC_DIR", "RDOC_DLL", "REALTIME", "REC_ASYNC", "REC_END", "REC_SPIN_US", "REEXEC", "REFLEX", "RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHUNKS", "REPLAY_CHUNK_DRAWS", "REPLAY_SKEW_US", "REPLAY_STATE_CHECK", "REPLAY_WORKERS", "REPLAY_CHECK", "RESOLVE_CHECK", "RESTART_WAIT", "ROMFS", "ROMFS_INDEX", "ROMFS_MMAP", "ROMFS_MODS", "ROMFS_PATCHES", "ROMFS_PROOF_DIR", "ROMFS_VERIFY", "RSTICK_DEADZONE", "RUMBLE", "RUMBLE_CURVE", "RUMBLE_STRENGTH", "RUMBLE_TRIGGERS", "SHADER_CACHE", @@ -77,7 +77,7 @@ static const struct { const char *key, *section; } sections[] = { {"COLOR_BRIGHTNESS", "display"}, {"COLOR_CONTRAST", "display"}, {"COLOR_SATURATION", "display"}, {"COLOR_GAMMA", "display"}, {"HDR", "display"}, {"HDR_PEAK_NITS", "display"}, {"HDR_GAME_NITS", "display"}, {"HDR_UI_NITS", "display"}, {"HDR_HUE", "display"}, {"SHADOW_RES", "display"}, - {"DLAA", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_CHAR_MASK", "display"}, {"FXAA", "display"}, + {"DLAA", "display"}, {"DLSS", "display"}, {"DLSS_PRESET", "display"}, {"DLSS_CHAR_MASK", "display"}, {"REFLEX", "display"}, {"FXAA", "display"}, {"DEVICE_PROFILE", "display"}, {"ASSUME_FOCUS", "display"}, {"DISCORD_RPC", "discord"}, {"DISCORD_APP_ID", "discord"}, {"DISCORD_IMAGE", "discord"}, {"SHADOW_SCALE", "display"}, {"SHADOW_RANGE", "display"}, {"CONTACT_SHADOWS", "display"}, @@ -124,7 +124,7 @@ static const CfgMeta metas[] = { {"UPSCALER", "fsr", "fsr|bilinear", LIVE}, {"SHARPNESS", "80", "0..100", LIVE}, {"DLAA", "0", "0|1", RESTART}, {"DLSS", "dlaa", "dlaa|quality|balanced|performance|ultra_performance", LIVE}, {"DLSS_PRESET", "default", "default|k|j", LIVE}, - {"DLSS_CHAR_MASK", "65", "0|35|65|100", LIVE}, {"FXAA", "1", "0|1", LIVE}, + {"DLSS_CHAR_MASK", "65", "0|35|65|100", LIVE}, {"REFLEX", "off", "off|on|boost", RESTART}, {"FXAA", "1", "0|1", LIVE}, {"ASPECT", "fit", "fit|stretch", LIVE}, {"MOVIE_ASPECT", "keep", "keep|stretch", LIVE}, {"FOV", "100", "70..140", LIVE}, {"ANISO", "game", "game|2|4|8|16", RESTART}, // vk_texture.c sampler_features // colour adjustment (vk_color.c); the preset is the menu's, the four values are what the present uses 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 f936b721..f63092e5 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -239,6 +239,8 @@ unsigned gfx_window_focus_messages(void) { return (unsigned)g_focus_msgs; } // Present path (g_pl held): a settings change (cfg_version) reaches the window thread, which applies a changed size or // fullscreen; a changed TOTK_VK_PRESENT rebuilds the swapchain at this present. +static void reflex_apply_locked(void); + static void window_settings_live(void) { static unsigned seen; static int started; @@ -254,9 +256,185 @@ static void window_settings_live(void) { if (started) plat_xchg32(&g_dirty, 1); } if (started) gfx_window_apply_settings(); + reflex_apply_locked(); started = 1; } +// ---- NVIDIA Reflex Low Latency (VK_NV_low_latency2) +static PFN_vkSetLatencySleepModeNV g_reflex_set_mode; +static PFN_vkLatencySleepNV g_reflex_sleep; +static PFN_vkSetLatencyMarkerNV g_reflex_marker; +static VkSemaphore g_reflex_sem; +static uint64_t g_reflex_val; +// Present IDs (VK_KHR_present_id, VK_NV_low_latency2): each frame gets its ID once, when the game acquires its window +// texture (SIMULATION_START, vk_reflex_frame_begin), and the frame carries it to its input sample, its submissions +// (vk_reflex_submit_id: the game thread's current frame, or the frame a replay or present thread set for the work it +// does) and its present (PresentJob.pid, vk_reflex_present_frame, flip_locked), so the driver can match every marker +// of a frame to the present of that frame. +static uint64_t g_reflex_frame_next; // the last ID handed out +static uint64_t g_reflex_frame; // the frame the game simulates now +static _Thread_local uint64_t t_reflex_submit; // the frame whose work this thread submits; 0: g_reflex_frame +static uint64_t g_blit_pid, g_flip_pid; // the frame of the blit being made and of the present waiting (g_pl) +static uint64_t g_last_pid; // the last present ID presented (g_pl): present IDs only go up +static int g_reflex_mode = -1; // 0=off, 1=on, 2=boost +static uint32_t g_reflex_min_us = 1; + +static int reflex_mode_from_cfg(void) { + const char *v = cfg_value("TOTK_REFLEX"); + if (!v || !strcmp(v, "off") || !strcmp(v, "0")) return 0; + if (!strcmp(v, "boost") || !strcmp(v, "2")) return 2; + return 1; +} + +static void reflex_apply_locked(void) { + VkCtx *c = vk_ctx(); + if (!c || !c->has_nv_reflex || !g_sc) return; + if (!g_reflex_set_mode) { + g_reflex_set_mode = (PFN_vkSetLatencySleepModeNV)vkGetDeviceProcAddr(c->device, "vkSetLatencySleepModeNV"); + g_reflex_sleep = (PFN_vkLatencySleepNV)vkGetDeviceProcAddr(c->device, "vkLatencySleepNV"); + g_reflex_marker = (PFN_vkSetLatencyMarkerNV)vkGetDeviceProcAddr(c->device, "vkSetLatencyMarkerNV"); + } + if (!g_reflex_set_mode) return; + if (!g_reflex_sem) { + VkSemaphoreTypeCreateInfo ti = { + .sType = VK_STRUCTURE_TYPE_SEMAPHORE_TYPE_CREATE_INFO, + .semaphoreType = VK_SEMAPHORE_TYPE_TIMELINE, + .initialValue = 0 + }; + VkSemaphoreCreateInfo si = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO, .pNext = &ti}; + if (vkCreateSemaphore(c->device, &si, NULL, &g_reflex_sem) != VK_SUCCESS) return; + } + int mode = reflex_mode_from_cfg(); + uint32_t min_us = 0; + int limit = cfg_int("TOTK_FPS_LIMIT"); + if (limit > 0) min_us = (uint32_t)(1000000 / limit); + if (mode == g_reflex_mode && min_us == g_reflex_min_us) return; + g_reflex_mode = mode; + g_reflex_min_us = min_us; + VkLatencySleepModeInfoNV mi = { + .sType = VK_STRUCTURE_TYPE_LATENCY_SLEEP_MODE_INFO_NV, + .lowLatencyMode = mode > 0 ? VK_TRUE : VK_FALSE, + .lowLatencyBoost = mode == 2 ? VK_TRUE : VK_FALSE, + .minimumIntervalUs = min_us + }; + VkResult r = g_reflex_set_mode(c->device, g_sc, &mi); + rt_log("REFLEX: NVIDIA Reflex Low Latency -> %s (minInterval=%u us, VK_NV_low_latency2=%s)", + mode == 2 ? "ON + BOOST" : mode == 1 ? "ON" : "OFF", min_us, r == VK_SUCCESS ? "OK" : "ERR"); +} + +int vk_has_reflex(void) { + VkCtx *c = vk_ctx(); + return c && c->has_nv_reflex; +} + +// TOTK_TRACE=perf, every LAT_EVERY presents: the time from a frame's start (its window texture acquired) to its +// present call on the host, with Reflex off or on, and with Reflex on the driver's own reports of the same frames +// (vkGetLatencyTimingsNV): how many came back with every marker matched to their present, and their simulation start +// to GPU render end. The frame's start is kept by its ID, so it also shows that a present carries its frame's ID. +#define LAT_RING 64 +#define LAT_EVERY 600 +static struct { uint64_t id, start_ns; } g_lat_start[LAT_RING]; +static struct { uint64_t n, ns, presents; } g_lat; +static PFN_vkGetLatencyTimingsNV g_reflex_timings; + +uint64_t vk_reflex_frame_begin(void) { + uint64_t id = __atomic_add_fetch(&g_reflex_frame_next, 1, __ATOMIC_RELAXED); + __atomic_store_n(&g_reflex_frame, id, __ATOMIC_RELAXED); + if (rt_trace & RT_TRACE_PERF) g_lat_start[id % LAT_RING].start_ns = kern_now_ns(), g_lat_start[id % LAT_RING].id = id; + return id; +} + +// g_pl held, after the present of frame pid +static void latency_note(VkCtx *c, uint64_t pid) { + if (!(rt_trace & RT_TRACE_PERF) || !pid) return; + if (g_lat_start[pid % LAT_RING].id == pid) g_lat.n++, g_lat.ns += kern_now_ns() - g_lat_start[pid % LAT_RING].start_ns; + if (++g_lat.presents % LAT_EVERY) return; + char drv[200] = ""; + if (g_reflex_mode > 0 && g_sc) { + if (!g_reflex_timings) g_reflex_timings = (PFN_vkGetLatencyTimingsNV)vkGetDeviceProcAddr(c->device, "vkGetLatencyTimingsNV"); + static VkLatencyTimingsFrameReportNV rep[64]; + VkGetLatencyMarkerInfoNV gi = {.sType = VK_STRUCTURE_TYPE_GET_LATENCY_MARKER_INFO_NV}; + if (g_reflex_timings) { + g_reflex_timings(c->device, g_sc, &gi); // the count first + if (gi.timingCount > 64) gi.timingCount = 64; + for (uint32_t i = 0; i < gi.timingCount; i++) + rep[i] = (VkLatencyTimingsFrameReportNV){.sType = VK_STRUCTURE_TYPE_LATENCY_TIMINGS_FRAME_REPORT_NV}; + gi.pTimings = rep; + if (gi.timingCount) g_reflex_timings(c->device, g_sc, &gi); + uint32_t full = 0; + double sum = 0; + for (uint32_t i = 0; i < gi.timingCount; i++) { + const VkLatencyTimingsFrameReportNV *r = &rep[i]; + if (r->simStartTimeUs && r->simEndTimeUs && r->renderSubmitStartTimeUs && r->presentStartTimeUs && + r->gpuRenderEndTimeUs > r->simStartTimeUs) + full++, sum += (double)(r->gpuRenderEndTimeUs - r->simStartTimeUs); + } + snprintf(drv, sizeof drv, "; driver reports: %u of %u frames with every marker, simulation start to GPU render " + "end %.2f ms", full, gi.timingCount, full ? sum / full / 1000.0 : 0.0); + } + } + rt_log("reflex: frame start to present %.2f ms over %llu frames (reflex %s)%s", g_lat.n ? g_lat.ns / 1e6 / g_lat.n : 0.0, + (unsigned long long)g_lat.n, g_reflex_mode == 2 ? "boost" : g_reflex_mode == 1 ? "on" : "off", drv); + g_lat.n = g_lat.ns = 0; +} + +uint64_t vk_reflex_frame(void) { return __atomic_load_n(&g_reflex_frame, __ATOMIC_RELAXED); } + +void vk_reflex_submit_frame(uint64_t id) { t_reflex_submit = id; } + +uint64_t vk_reflex_submit_id(void) { return t_reflex_submit ? t_reflex_submit : vk_reflex_frame(); } + +// 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); +} + +void vk_reflex_marker(int marker, uint64_t pid) { + VkCtx *c = vk_ctx(); + if (!c || !c->has_nv_reflex || !g_reflex_marker || g_reflex_mode <= 0 || !g_sc || !pid) return; + plat_rmutex_lock(&g_pl); + if (g_sc && g_reflex_marker) { + VkSetLatencyMarkerInfoNV mi = { + .sType = VK_STRUCTURE_TYPE_SET_LATENCY_MARKER_INFO_NV, + .presentID = pid, + .marker = (VkLatencyMarkerNV)marker + }; + g_reflex_marker(c->device, g_sc, &mi); + } + plat_rmutex_unlock(&g_pl); +} + +void vk_reflex_sleep(void) { + VkCtx *c = vk_ctx(); + if (!c || !c->has_nv_reflex || !g_reflex_sleep || !g_reflex_sem || g_reflex_mode <= 0 || !g_sc) return; + uint64_t val = __atomic_add_fetch(&g_reflex_val, 1, __ATOMIC_RELAXED); + VkLatencySleepInfoNV si = { + .sType = VK_STRUCTURE_TYPE_LATENCY_SLEEP_INFO_NV, + .signalSemaphore = g_reflex_sem, + .value = val + }; + // vkLatencySleepNV uses the swapchain, which Vulkan wants externally synchronised with the acquire and the present + // (they run under g_pl on the present thread). The wait for the semaphore stays outside the lock. + VkResult r = VK_ERROR_INITIALIZATION_FAILED; + plat_rmutex_lock(&g_pl); + if (g_sc) r = g_reflex_sleep(c->device, g_sc, &si); + plat_rmutex_unlock(&g_pl); + if (r == VK_SUCCESS) { + VkSemaphoreWaitInfo wi = { + .sType = VK_STRUCTURE_TYPE_SEMAPHORE_WAIT_INFO, + .semaphoreCount = 1, + .pSemaphores = &g_reflex_sem, + .pValues = &val + }; + vkWaitSemaphores(c->device, &wi, 100000000ULL); + } +} + // ---- swapchain static const char *g_present_got = ""; // the TOTK_VK_PRESENT value of the mode the swapchain got; "" before one @@ -289,12 +467,29 @@ static void flip_locked(void) { if (!g_flip_on) return; g_flip_on = 0; if (!g_sc) return; - VkPresentInfoKHR pi = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, .waitSemaphoreCount = 1, + VkCtx *c = vk_ctx(); + uint64_t pid = 0; + VkPresentIdKHR pid_info = {0}; + if (c && c->has_nv_reflex) { + // The frame's own ID; a present without one (a probe, a skipped frame's neighbour) takes the next free value, + // as present IDs must grow on a swapchain + pid = g_flip_pid > g_last_pid ? g_flip_pid : g_last_pid + 1; + g_last_pid = pid; + pid_info.sType = VK_STRUCTURE_TYPE_PRESENT_ID_KHR; + pid_info.swapchainCount = 1; + pid_info.pPresentIds = &pid; + vk_reflex_marker(4, pid); // VK_LATENCY_MARKER_PRESENT_START_NV + } + VkPresentInfoKHR pi = {.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR, + .pNext = (c && c->has_nv_reflex) ? &pid_info : NULL, + .waitSemaphoreCount = 1, .pWaitSemaphores = &g_render_done[g_flip_idx], .swapchainCount = 1, .pSwapchains = &g_sc, .pImageIndices = &g_flip_idx}; vk_queue_lock(); - VkResult r = vkQueuePresentKHR(vk_ctx()->gfx_queue, &pi); + VkResult r = vkQueuePresentKHR(c->gfx_queue, &pi); vk_queue_unlock(); + if (c && c->has_nv_reflex) vk_reflex_marker(5, pid); // VK_LATENCY_MARKER_PRESENT_END_NV + if (c) latency_note(c, pid ? pid : g_flip_pid); vk_device_fault_report(r); if (r == VK_ERROR_OUT_OF_DATE_KHR || r == VK_SUBOPTIMAL_KHR) plat_xchg32(&g_dirty, 1); } @@ -338,8 +533,14 @@ static int build_swapchain(void) { vk_queue_lock(); vkDeviceWaitIdle(c->device); VkSwapchainKHR old = g_sc; + VkSwapchainLatencyCreateInfoNV sci = { + .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_LATENCY_CREATE_INFO_NV, + .latencyModeEnable = VK_TRUE + }; VkSwapchainCreateInfoKHR ci = { - .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, .surface = g_surface, .minImageCount = count, + .sType = VK_STRUCTURE_TYPE_SWAPCHAIN_CREATE_INFO_KHR, + .pNext = (c->has_nv_reflex) ? &sci : NULL, + .surface = g_surface, .minImageCount = count, .imageFormat = sf.format, .imageColorSpace = sf.colorSpace, .imageExtent = ext, .imageArrayLayers = 1, .imageUsage = VK_IMAGE_USAGE_TRANSFER_DST_BIT | VK_IMAGE_USAGE_TRANSFER_SRC_BIT | VK_IMAGE_USAGE_COLOR_ATTACHMENT_BIT, // every surface supports it (the menu overlay draws into it) @@ -376,6 +577,10 @@ static int build_swapchain(void) { } free_capture(); vk_queue_unlock(); + // The Reflex sleep mode belongs to the swapchain: a new one (resize, fullscreen, out of date) starts with low + // latency off, so the mode is set on it again even though the setting did not change. + g_reflex_mode = -1; + reflex_apply_locked(); return 1; } @@ -746,6 +951,7 @@ static void present_image(VkImage src, VkImageLayout layout, VkFormat fmt, int w if (r == VK_SUCCESS) { g_flip_on = 1; g_flip_idx = idx; + g_flip_pid = g_blit_pid; // the frame this blit shows (vk_reflex_present_frame) if (!defer) flip_locked(); } else { vk_device_fault_report(r); @@ -800,6 +1006,11 @@ void gfx_window_release_vk(void) { vk_color_release(); vk_hdr_release(); vk_contact_release(); + if (g_reflex_sem) { + vkDestroySemaphore(c->device, g_reflex_sem, NULL); + g_reflex_sem = VK_NULL_HANDLE; + } + g_reflex_mode = -1; free_capture(); free_thumbs(); for (int i = 0; i < FRAMES; i++) { diff --git a/runtime/nvn_api_obj.c b/runtime/nvn_api_obj.c index 644acc8d..8500a70b 100644 --- a/runtime/nvn_api_obj.c +++ b/runtime/nvn_api_obj.c @@ -687,6 +687,8 @@ NVN_API(nvnWindowAcquireTexture) { sleep_until(at); perf_end(PERF_PACE, p0); } + vk_reflex_sleep(); + vk_reflex_marker(0, vk_reflex_frame_begin()); // VK_LATENCY_MARKER_SIMULATION_START_NV: a new frame and its ID // The sync means "the display no longer reads this image". Presents are copies queued in submit order, so it is // already satisfied: fenced = 3 with fence 0. if (s) { @@ -710,6 +712,7 @@ NVN_API(nvnQueuePresentTexture) { if (o->magic != NVN_WIN_MAGIC || idx < 0 || idx >= o->ntex || idx >= 4 || !o->tex[idx]) rt_fatal("nvn: QueuePresentTexture of image %d on window %p", idx, (void *)o); o->presents++; + vk_reflex_marker(1, vk_reflex_frame()); // VK_LATENCY_MARKER_SIMULATION_END_NV const tex_t *t = (const tex_t *)o->tex[idx]; uint64_t period = present_period(o), now = kern_now_ns(); uint64_t slot = now + pace(&o->pace, now, period); diff --git a/runtime/ov_input.c b/runtime/ov_input.c index 3cbc6cfb..e56c4eb0 100644 --- a/runtime/ov_input.c +++ b/runtime/ov_input.c @@ -12,6 +12,7 @@ #include #include "cfg.h" +#include "gfx.h" #include "host.h" #include "input.h" #include "ov.h" @@ -93,6 +94,7 @@ static void npad_states(Cpu *c, uint32_t want) { if (live) { s.attributes = ATTR_CONNECTED; input_poll(&s.buttons, &s.lx, &s.ly, &s.rx, &s.ry); + vk_reflex_marker(6, vk_reflex_frame()); // VK_LATENCY_MARKER_INPUT_SAMPLE_NV } *out = s; ret_x(c, 1); diff --git a/runtime/ui/menu.cpp b/runtime/ui/menu.cpp index 2bed97ed..df366614 100644 --- a/runtime/ui/menu.cpp +++ b/runtime/ui/menu.cpp @@ -694,6 +694,8 @@ static void tab_screen(float scale) { static const UiTextId chars[] = {UI_MENU_DLSS_CHARS_OFF, UI_MENU_DLSS_CHARS_LIGHT, UI_MENU_DLSS_CHARS_MEDIUM, UI_MENU_DLSS_CHARS_FULL}; opt_choice("TOTK_DLSS_CHAR_MASK", UI_MENU_DLSS_CHARS, chars, 4, UI_MENU_DLSS_CHARS_DESC); + static const UiTextId reflex[] = {UI_MENU_REFLEX_OFF, UI_MENU_REFLEX_ON, UI_MENU_REFLEX_BOOST}; + opt_choice("TOTK_REFLEX", UI_MENU_REFLEX, reflex, 3, UI_MENU_REFLEX_DESC); opt_toggle("TOTK_FXAA", UI_MENU_FXAA, UI_MENU_FXAA_DESC); rows_color(); opt_group(UI_MENU_HDR_GROUP); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 690383b7..bf3f45f9 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -166,6 +166,11 @@ static const char *const text_en[UI_TEXT_COUNT] = { [UI_MENU_DLSS_PERFORMANCE] = "Performance", [UI_MENU_DLSS_ULTRA] = "Ultra Performance", [UI_MENU_FXAA] = "Game anti-aliasing (FXAA)", [UI_MENU_FXAA_DESC] = "The game's own FXAA edge smoothing. It blurs fine detail a little; with DLAA on it is not needed.", + [UI_MENU_REFLEX] = "NVIDIA Reflex Low Latency", + [UI_MENU_REFLEX_DESC] = "Reduces system latency on NVIDIA GPUs using VK_NV_low_latency2. On + Boost keeps GPU clocks high in CPU-bound scenes.", + [UI_MENU_REFLEX_OFF] = "Off", + [UI_MENU_REFLEX_ON] = "On", + [UI_MENU_REFLEX_BOOST] = "On + Boost", [UI_MENU_FPS_LIMIT] = "Frame rate limit", [UI_MENU_FPS_LIMIT_DESC] = "The most frames per second the game draws. Above 60 is experimental and needs Game speed " @@ -649,6 +654,11 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [UI_MENU_DLSS_PERFORMANCE] = "Производительность", [UI_MENU_DLSS_ULTRA] = "Макс. производительность", [UI_MENU_FXAA] = "Сглаживание игры (FXAA)", [UI_MENU_FXAA_DESC] = "Собственное сглаживание FXAA. Слегка размывает мелкие детали; с DLAA оно не нужно.", + [UI_MENU_REFLEX] = "NVIDIA Reflex Low Latency", + [UI_MENU_REFLEX_DESC] = "Снижает задержку системы на видеокартах NVIDIA с помощью VK_NV_low_latency2. «Вкл + Ускорение» удерживает высокие частоты GPU при упоре в процессор.", + [UI_MENU_REFLEX_OFF] = "Выкл", + [UI_MENU_REFLEX_ON] = "Вкл", + [UI_MENU_REFLEX_BOOST] = "Вкл + Ускорение", [UI_MENU_FPS_LIMIT] = "Ограничение частоты кадров", [UI_MENU_FPS_LIMIT_DESC] = "Наибольшее число кадров в секунду. Выше 60 — экспериментальный режим, нужна «Скорость " @@ -1486,6 +1496,11 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [UI_MENU_FXAA] = "Antisserrilhado do jogo (FXAA)", [UI_MENU_FXAA_DESC] = "A suavização de bordas FXAA do próprio jogo. Borra um pouco os detalhes finos; com o DLAA " "ligado não é necessária.", + [UI_MENU_REFLEX] = "NVIDIA Reflex Low Latency", + [UI_MENU_REFLEX_DESC] = "Reduz a latência do sistema em GPUs NVIDIA usando VK_NV_low_latency2. Ligado + Boost mantém os clocks da GPU altos quando limitado pela CPU.", + [UI_MENU_REFLEX_OFF] = "Desligado", + [UI_MENU_REFLEX_ON] = "Ligado", + [UI_MENU_REFLEX_BOOST] = "Ligado + Boost", [UI_MENU_TAB_CHEATS] = "Cheats", [UI_MENU_CHEATS_NONE] = "Nenhum cheat para esta versão do jogo. Os cheats de um mod são um arquivo de cheats do " "Atmosphere na pasta cheats dele, com o nome da build do jogo: mods\\\\cheats\\%s. " @@ -2096,6 +2111,11 @@ static const char *const text_zh_hans[UI_TEXT_COUNT] = { [UI_MENU_DLSS_CHARS_FULL] = "强", [UI_MENU_FXAA] = "游戏抗锯齿(FXAA)", [UI_MENU_FXAA_DESC] = "游戏自身的 FXAA 边缘平滑。会让细节略微模糊;开启 DLAA 时不需要。", + [UI_MENU_REFLEX] = "NVIDIA Reflex 低延迟", + [UI_MENU_REFLEX_DESC] = "在支持 VK_NV_low_latency2 的 NVIDIA 显卡上降低系统延迟。开 + 增强 (On + Boost) 会在 CPU 瓶颈时保持 GPU 高频率。", + [UI_MENU_REFLEX_OFF] = "关", + [UI_MENU_REFLEX_ON] = "开", + [UI_MENU_REFLEX_BOOST] = "开 + 增强", [UI_MENU_TAB_CHEATS] = "金手指", [UI_MENU_CHEATS_NONE] = "此游戏版本没有金手指。模组的金手指是它的 cheats 文件夹中以游戏构建命名的 Atmosphere " "金手指文件:mods\\<模组>\\cheats\\%s。重启游戏后才会读取。对于修改游戏代码的金手指," diff --git a/runtime/ui_text.h b/runtime/ui_text.h index 3bed8949..04093308 100644 --- a/runtime/ui_text.h +++ b/runtime/ui_text.h @@ -59,6 +59,7 @@ typedef enum { UI_MENU_DLSS_BALANCED, UI_MENU_DLSS_PERFORMANCE, UI_MENU_DLSS_ULTRA, UI_MENU_DLSS_PRESET, UI_MENU_DLSS_PRESET_DESC, UI_MENU_DLSS_PRESET_DEFAULT, UI_MENU_DLSS_PRESET_K, UI_MENU_DLSS_PRESET_J, UI_MENU_DLSS_CHARS, UI_MENU_DLSS_CHARS_DESC, UI_MENU_DLSS_CHARS_OFF, UI_MENU_DLSS_CHARS_LIGHT, UI_MENU_DLSS_CHARS_MEDIUM, UI_MENU_DLSS_CHARS_FULL, UI_MENU_FXAA, UI_MENU_FXAA_DESC, + UI_MENU_REFLEX, UI_MENU_REFLEX_DESC, UI_MENU_REFLEX_OFF, UI_MENU_REFLEX_ON, UI_MENU_REFLEX_BOOST, // Game UI_MENU_FPS_LIMIT, UI_MENU_FPS_LIMIT_DESC, UI_MENU_FPS_30, UI_MENU_FPS_40, UI_MENU_FPS_45, UI_MENU_FPS_60, UI_MENU_FPS_90, diff --git a/runtime/vk.h b/runtime/vk.h index bb705ebd..82154bb8 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -36,7 +36,8 @@ typedef struct VkCtx { has_nv_checkpoints, // VK_NV_device_diagnostic_checkpoints (TOTK_PASS_CRUMBS=1, vk_crumbs.c) has_astc_ldr, // textureCompressionASTC_LDR (enabled when reported) has_calibrated, // VK_KHR/EXT_calibrated_timestamps (GPU idle split in the perf line) - has_hdr_metadata; // VK_EXT_hdr_metadata (vk_hdr.c vk_hdr_metadata) + has_hdr_metadata, // VK_EXT_hdr_metadata (vk_hdr.c vk_hdr_metadata) + has_nv_reflex; // VK_NV_low_latency2 (NVIDIA Reflex Low Latency) // Feedback loops (maxwell.md 1.9, vk_exec_draw.c feedback_prepare): a draw samples a target of its open pass that // an earlier draw of the pass wrote. TOTK_FEEDBACK=0: VK_FEEDBACK_OFF (sampled in GENERAL without a barrier, the // old behaviour); VK_FEEDBACK_LAYOUT with VK_EXT_attachment_feedback_loop_layout and dynamicRenderingLocalRead @@ -147,6 +148,10 @@ 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_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 +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 // scales that one instead, crop {0, 0, w, h}); VK_NULL_HANDLE = nothing recorded. src is in GENERAL, fmt its format. diff --git a/runtime/vk_backend.c b/runtime/vk_backend.c index cf4f4d94..26df8391 100644 --- a/runtime/vk_backend.c +++ b/runtime/vk_backend.c @@ -33,7 +33,7 @@ #define WEAK __attribute__((weak)) -typedef struct { VkImage image; VkFormat format; int w, h, has_crop, crop[4]; uint64_t frame, at, queued, value; } PresentJob; +typedef struct { VkImage image; VkFormat format; int w, h, has_crop, crop[4]; uint64_t frame, at, queued, value, pid; } PresentJob; // pid: the frame's present ID (vk_reflex_frame) static PlatMutex pl = PLAT_MUTEX_INIT; static PlatCond pcv = PLAT_COND_INIT; // job queued, job taken, job submitted @@ -60,6 +60,8 @@ static void present_main(void *arg) { plat_cond_broadcast(&pcv); plat_mutex_unlock(&pl); if (flight_on) vk_thumbs_frame(j.frame); + vk_reflex_present_frame(j.pid); // the present of this blit, and the submission after it, are the frame's + vk_reflex_submit_frame(j.pid); vk_present_blit(j.image, VK_IMAGE_LAYOUT_GENERAL, j.format, j.w, j.h, j.has_crop ? j.crop : NULL); uint64_t f = vk_sync_submit(NULL, 0); // a timeline value after the blit: deferred destruction waits for the blit too if (j.value && f != j.value) @@ -99,7 +101,7 @@ void vk_present_drain(void) { // The present after the frame count: resolves the image and hands the blit to the present thread. queued: when the game // presented; value: the timeline value queued for this present (asynchronous replay), 0 for the next one (synchronous). static void present_image(const tex_t *t, const int crop[4], uint64_t at_ns, uint64_t queued, uint64_t frame, - uint64_t value) { + uint64_t value, uint64_t pid) { static volatile int32_t n_skipped; vk_exec_frame_log(t, frame); vk_dlaa_frame(); @@ -120,7 +122,7 @@ static void present_image(const tex_t *t, const int crop[4], uint64_t at_ns, uin return; } PresentJob j = {.image = img->image, .format = img->format, .w = (int)img->width, .h = (int)img->height, .frame = frame, - .at = at_ns, .queued = queued, .value = value}; + .at = at_ns, .queued = queued, .value = value, .pid = pid}; vk_hdr_present_source(img, &j.image, &j.format); // TOTK_HDR: the float picture the game copied into it, same size if (crop) { j.has_crop = 1; @@ -144,7 +146,7 @@ static void present_image(const tex_t *t, const int crop[4], uint64_t at_ns, uin enum { RI_SUBMIT, RI_PRESENT, RI_RELEASE }; typedef struct { int kind, n, has_crop, crop[4]; - uint64_t value, submit_no, at, queued; + uint64_t value, submit_no, at, queued, pid; // pid: the game's frame when it queued the item (present ID) uint64_t *h; const tex_t *tex; // RI_RELEASE: a copy the item owns (the game may reuse the object's memory) } ReplayItem; @@ -223,6 +225,7 @@ static void replay_main(void *arg) { plat_cond_broadcast(&rcv); plat_mutex_unlock(&rl); if (it.kind == RI_SUBMIT) { + vk_reflex_submit_frame(it.pid); // the replay thread submits the frame the game was on when it queued it uint64_t f = submit_sync(it.h, it.n); if (f != it.value) rt_fatal("vk: replayed submission signalled %llu, queued as %llu", (unsigned long long)f, @@ -234,7 +237,7 @@ static void replay_main(void *arg) { free((void *)it.tex); } else { uint64_t frame = __atomic_add_fetch(&gfx_counters.frames, 1, __ATOMIC_RELAXED); - present_image(it.tex, it.has_crop ? it.crop : NULL, it.at, it.queued, frame, it.value); + present_image(it.tex, it.has_crop ? it.crop : NULL, it.at, it.queued, frame, it.value, it.pid); } plat_mutex_lock(&rl); if (it.kind != RI_RELEASE) r_value_done = it.value; @@ -345,7 +348,7 @@ static void vk_be_present(const tex_t *t, const int crop[4], uint64_t at_ns) { if (!gfx_replay_async()) { uint64_t frame = __atomic_add_fetch(&gfx_counters.frames, 1, __ATOMIC_RELAXED); perf_present(frame); // before vk_exec_frame_log, which resets the frame's exec counts the flight recorder reads - present_image(t, crop, at_ns, kern_now_ns(), frame, 0); + present_image(t, crop, at_ns, kern_now_ns(), frame, 0, vk_reflex_frame()); return; } // Frame bound: the replay thread handled the previous present before this one is queued. @@ -361,7 +364,7 @@ static void vk_be_present(const tex_t *t, const int crop[4], uint64_t at_ns) { uint64_t frame = ++game_frames; perf_present(frame); if (frame % 1800 == 0) replay_log(frame, 0); - ReplayItem it = {.kind = RI_PRESENT, .tex = t, .at = at_ns, .queued = kern_now_ns()}; + ReplayItem it = {.kind = RI_PRESENT, .tex = t, .at = at_ns, .queued = kern_now_ns(), .pid = vk_reflex_frame()}; if (crop) { it.has_crop = 1; for (int i = 0; i < 4; i++) it.crop[i] = crop[i]; @@ -408,7 +411,7 @@ static void vk_be_program_release(const prog_t *p) { replay_drain(DR_PROG_RELEAS static uint64_t vk_be_submit(const uint64_t *handles, int n) { if (!gfx_replay_async()) return submit_sync(handles, n); vk_sync_start(); - ReplayItem it = {.kind = RI_SUBMIT, .n = n, .submit_no = nvn_submit_count()}; + ReplayItem it = {.kind = RI_SUBMIT, .n = n, .submit_no = nvn_submit_count(), .pid = vk_reflex_frame()}; if (n > 0) { it.h = malloc(sizeof *it.h * (size_t)n); if (!it.h) rt_fatal("vk: out of memory (replay queue)"); diff --git a/runtime/vk_device.c b/runtime/vk_device.c index 760a3a46..c7f85a17 100644 --- a/runtime/vk_device.c +++ b/runtime/vk_device.c @@ -283,6 +283,7 @@ typedef struct { VkPhysicalDeviceAttachmentFeedbackLoopLayoutFeaturesEXT fbl; VkPhysicalDeviceDynamicRenderingLocalReadFeaturesKHR lr; VkPhysicalDeviceAddressBindingReportFeaturesEXT abr; + VkPhysicalDevicePresentIdFeaturesKHR pid; } FeatureChain; static int create_device(void) { @@ -290,7 +291,7 @@ static int create_device(void) { vkEnumerateDeviceExtensionProperties(g_vk.phys, NULL, &ne, NULL); VkExtensionProperties *ep = calloc(ne ? ne : 1, sizeof *ep); vkEnumerateDeviceExtensionProperties(g_vk.phys, NULL, &ne, ep); - const char *ext[48]; + const char *ext[52]; uint32_t n_ext = 0; for (size_t i = 0; i < sizeof k_required_ext / sizeof *k_required_ext; i++) ext[n_ext++] = k_required_ext[i]; @@ -334,7 +335,7 @@ static int create_device(void) { CHAIN(fbl, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_ATTACHMENT_FEEDBACK_LOOP_LAYOUT_FEATURES_EXT); CHAIN(lr, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_DYNAMIC_RENDERING_LOCAL_READ_FEATURES_KHR); } - vk_dlaa_device_exts(ep, ne, ext, &n_ext, 40); // NGX's; the eight slots after it stay for the seven below + vk_dlaa_device_exts(ep, ne, ext, &n_ext, 40); // NGX's; the twelve slots after it stay for the nine below if (has_ext(ep, ne, VK_EXT_MEMORY_BUDGET_EXTENSION_NAME)) { g_vk.has_memory_budget = 1; ext[n_ext++] = VK_EXT_MEMORY_BUDGET_EXTENSION_NAME; } // GPU timestamps on the CPU clock (vk_sync.c): the perf line splits GPU idle time into waiting for a submission or not. if (has_ext(ep, ne, VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME)) { g_vk.has_calibrated = 2; ext[n_ext++] = VK_KHR_CALIBRATED_TIMESTAMPS_EXTENSION_NAME; } @@ -351,6 +352,18 @@ static int create_device(void) { g_vk.has_nv_checkpoints = 1; ext[n_ext++] = VK_NV_DEVICE_DIAGNOSTIC_CHECKPOINTS_EXTENSION_NAME; } + // NVIDIA Reflex Low Latency (VK_NV_low_latency2 requires VK_KHR_present_id) + const char *rv = cfg_value("TOTK_REFLEX"); + if (rv && strcmp(rv, "off") != 0 && strcmp(rv, "0") != 0) { + if (has_ext(ep, ne, VK_KHR_PRESENT_ID_EXTENSION_NAME) && has_ext(ep, ne, "VK_NV_low_latency2")) { + g_vk.has_nv_reflex = 1; + ext[n_ext++] = VK_KHR_PRESENT_ID_EXTENSION_NAME; + ext[n_ext++] = "VK_NV_low_latency2"; + CHAIN(pid, VK_STRUCTURE_TYPE_PHYSICAL_DEVICE_PRESENT_ID_FEATURES_KHR); + } else { + rt_log("Reflex: VK_NV_low_latency2 not available"); + } + } // Graphics pipeline library: chained last so it can be dropped again when vk_caps_gpl declines it. void **gpl_link = NULL; if (has_ext(ep, ne, VK_KHR_PIPELINE_LIBRARY_EXTENSION_NAME) && has_ext(ep, ne, VK_EXT_GRAPHICS_PIPELINE_LIBRARY_EXTENSION_NAME)) { @@ -392,6 +405,11 @@ static int create_device(void) { : !ab_want ? "off (TOTK_ADDR_REPORT=0 or no VK_EXT_debug_utils)" : "unavailable (no VK_EXT_device_address_binding_report)"); g_vk.has_buffer_device_address = c->f12.bufferDeviceAddress; + // VkPresentIdKHR on a present needs the presentId feature, not just the extension + if (g_vk.has_nv_reflex && !c->pid.presentId) { + g_vk.has_nv_reflex = 0; + rt_log("Reflex: VK_NV_low_latency2 not available (no presentId feature)"); + } g_vk.has_astc_ldr = h->textureCompressionASTC_LDR; { const char *e = cfg_get("TOTK_FEEDBACK"); diff --git a/runtime/vk_rec.c b/runtime/vk_rec.c index f0fa9835..ee664c29 100644 --- a/runtime/vk_rec.c +++ b/runtime/vk_rec.c @@ -318,8 +318,14 @@ int rec_end_cb(VkCommandBuffer cb, int crumb, uint64_t n) { return 1; } -// At most two command buffers and one signal: the shape vk_sync.c submits. -typedef struct { uint32_t ncb, nsig; VkCommandBufferSubmitInfo cbi[2]; VkSemaphoreSubmitInfo sig; } A_Submit; +// At most two command buffers and one signal: the shape vk_sync.c submits. The only pNext it chains is Reflex's +// VkLatencySubmissionPresentIdNV (vk_sync_submit), carried as its present ID. +typedef struct { + uint32_t ncb, nsig, has_pid; + uint64_t present_id; + VkCommandBufferSubmitInfo cbi[2]; + VkSemaphoreSubmitInfo sig; +} A_Submit; VkResult rec_submit(const VkSubmitInfo2 *si) { if (!sub_pending) { vk_queue_lock(); @@ -328,12 +334,16 @@ VkResult rec_submit(const VkSubmitInfo2 *si) { return r; } sub_pending = 0; - if (si->commandBufferInfoCount > 2 || si->signalSemaphoreInfoCount > 1 || si->waitSemaphoreInfoCount || si->pNext) + const VkBaseInStructure *nx = si->pNext; + int pid = nx && nx->sType == VK_STRUCTURE_TYPE_LATENCY_SUBMISSION_PRESENT_ID_NV && !nx->pNext; + if (si->commandBufferInfoCount > 2 || si->signalSemaphoreInfoCount > 1 || si->waitSemaphoreInfoCount || + (nx && !pid)) rt_fatal("vk_rec: a submission of %u command buffers, %u waits and %u signals the recorder cannot carry", si->commandBufferInfoCount, si->waitSemaphoreInfoCount, si->signalSemaphoreInfoCount); A_Submit *a = put(R_Submit, sizeof *a); memset(a, 0, sizeof *a); a->ncb = si->commandBufferInfoCount, a->nsig = si->signalSemaphoreInfoCount; + if (pid) a->has_pid = 1, a->present_id = ((const VkLatencySubmissionPresentIdNV *)nx)->presentID; for (uint32_t i = 0; i < a->ncb; i++) a->cbi[i] = si->pCommandBufferInfos[i]; if (a->nsig) a->sig = si->pSignalSemaphoreInfos[0]; __atomic_store_n(&q_subs, q_subs + 1, __ATOMIC_RELEASE); @@ -354,7 +364,10 @@ VkResult rec_submit(const VkSubmitInfo2 *si) { } static void submit_run(const A_Submit *a) { - VkSubmitInfo2 si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2, .commandBufferInfoCount = a->ncb, + VkLatencySubmissionPresentIdNV lsid = {.sType = VK_STRUCTURE_TYPE_LATENCY_SUBMISSION_PRESENT_ID_NV, + .presentID = a->present_id}; + VkSubmitInfo2 si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2, .pNext = a->has_pid ? &lsid : NULL, + .commandBufferInfoCount = a->ncb, .pCommandBufferInfos = a->cbi, .signalSemaphoreInfoCount = a->nsig, .pSignalSemaphoreInfos = a->nsig ? &a->sig : NULL}; vk_queue_lock(); diff --git a/runtime/vk_sync.c b/runtime/vk_sync.c index 6626e96f..f4e026b8 100644 --- a/runtime/vk_sync.c +++ b/runtime/vk_sync.c @@ -474,12 +474,20 @@ uint64_t vk_sync_submit(const uint64_t *handles, int n) { {.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_SUBMIT_INFO, .commandBuffer = s->cb}}; VkSemaphoreSubmitInfo sig = {.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO, .semaphore = c->timeline, .value = fence, .stageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT}; + VkLatencySubmissionPresentIdNV lsid = { + .sType = VK_STRUCTURE_TYPE_LATENCY_SUBMISSION_PRESENT_ID_NV, + .pNext = NULL, + .presentID = vk_reflex_submit_id() + }; VkSubmitInfo2 si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2, + .pNext = (c->has_nv_reflex) ? &lsid : NULL, .commandBufferInfoCount = (pro ? 1u : 0u) + (recorded ? 1u : 0u), .pCommandBufferInfos = pro ? cbi : cbi + 1, .signalSemaphoreInfoCount = 1, .pSignalSemaphoreInfos = &sig}; ts_submitted(); + if (recorded && c->has_nv_reflex) vk_reflex_marker(2, lsid.presentID); // VK_LATENCY_MARKER_RENDERSUBMIT_START_NV VkResult r = rec_submit(&si); // by the recorder when it recorded the part + if (recorded && c->has_nv_reflex) vk_reflex_marker(3, lsid.presentID); // VK_LATENCY_MARKER_RENDERSUBMIT_END_NV if (r != VK_SUCCESS) { vk_device_fault_report(r); rt_fatal("vk: vkQueueSubmit2 of value %llu failed (%d)", (unsigned long long)fence, (int)r); diff --git a/totk.ini.example b/totk.ini.example index 2c986cb9..929e45bb 100644 --- a/totk.ini.example +++ b/totk.ini.example @@ -261,6 +261,9 @@ # frame before, DLSS is told to favour the current frame by this percentage (0, 35, 65 or 100; 0 off). Higher removes # more of the trails and leaves those edges a little less smooth. Changes while the game runs take effect at once. # dlss_char_mask = 65 +# NVIDIA Reflex Low Latency (NVIDIA GPUs supporting VK_NV_low_latency2): off, on, or boost. +# Reduces system input latency; boost keeps GPU clocks high in CPU-bound scenes. Read at start. +# reflex = off # The game's own FXAA after the post effects; with DLAA on it is not needed. Changes while the game runs take effect at # once. # fxaa = 1