diff --git a/runtime/cfg.c b/runtime/cfg.c index 7a802afe..10f55b78 100644 --- a/runtime/cfg.c +++ b/runtime/cfg.c @@ -52,8 +52,8 @@ 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", - "RENDER_SCALE", "REPLAY_ASYNC", "REPLAY_CHUNKS", "REPLAY_CHUNK_DRAWS", "REPLAY_SKEW_US", "REPLAY_STATE_CHECK", "REPLAY_WORKERS", "REFLEX", + "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", "SHADER_MEMO", "SHADOW_DEFER", "SHADOW_RANGE", "SHADOW_RES", "SHADOW_SCALE", "SHADOW_SNAP", "SHARED_FONTS", "SHARPNESS", "SHOTS", "SHOTS_DIR", diff --git a/runtime/gfx_present.c b/runtime/gfx_present.c index 9692afc1..53d47e19 100644 --- a/runtime/gfx_present.c +++ b/runtime/gfx_present.c @@ -266,7 +266,16 @@ static PFN_vkLatencySleepNV g_reflex_sleep; static PFN_vkSetLatencyMarkerNV g_reflex_marker; static VkSemaphore g_reflex_sem; static uint64_t g_reflex_val; -static uint64_t g_reflex_present_id = 1; +// 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; @@ -318,16 +327,75 @@ int vk_has_reflex(void) { return c && c->has_nv_reflex; } -uint64_t vk_reflex_current_present_id(void) { - return __atomic_load_n(&g_reflex_present_id, __ATOMIC_RELAXED); +// 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; } -void vk_reflex_marker(int marker) { +// 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) { + 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) return; + 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) { - uint64_t pid = __atomic_load_n(&g_reflex_present_id, __ATOMIC_RELAXED); VkSetLatencyMarkerInfoNV mi = { .sType = VK_STRUCTURE_TYPE_SET_LATENCY_MARKER_INFO_NV, .presentID = pid, @@ -400,11 +468,14 @@ static void flip_locked(void) { uint64_t pid = 0; VkPresentIdKHR pid_info = {0}; if (c && c->has_nv_reflex) { - pid = __atomic_add_fetch(&g_reflex_present_id, 1, __ATOMIC_RELAXED); + // 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); // VK_LATENCY_MARKER_PRESENT_START_NV + 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, @@ -414,7 +485,8 @@ static void flip_locked(void) { vk_queue_lock(); VkResult r = vkQueuePresentKHR(c->gfx_queue, &pi); vk_queue_unlock(); - if (c && c->has_nv_reflex) vk_reflex_marker(5); // VK_LATENCY_MARKER_PRESENT_END_NV + 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); } @@ -502,6 +574,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; } @@ -872,6 +948,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); diff --git a/runtime/nvn_api_obj.c b/runtime/nvn_api_obj.c index 22fb03dd..8fc698bf 100644 --- a/runtime/nvn_api_obj.c +++ b/runtime/nvn_api_obj.c @@ -19,7 +19,9 @@ #include "nvn_tex.h" #include "platform/platform.h" -void vk_reflex_marker(int marker); +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 @@ -691,7 +693,7 @@ NVN_API(nvnWindowAcquireTexture) { perf_end(PERF_PACE, p0); } vk_reflex_sleep(); - vk_reflex_marker(0); // VK_LATENCY_MARKER_SIMULATION_START_NV + 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) { @@ -715,7 +717,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_LATENCY_MARKER_SIMULATION_END_NV + 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 ac38f9c9..2a2f34a3 100644 --- a/runtime/ov_input.c +++ b/runtime/ov_input.c @@ -17,7 +17,8 @@ #include "ov.h" #include "platform/platform.h" -void vk_reflex_marker(int marker); +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; @@ -95,7 +96,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_LATENCY_MARKER_INPUT_SAMPLE_NV + vk_reflex_marker(6, vk_reflex_frame()); // VK_LATENCY_MARKER_INPUT_SAMPLE_NV } *out = s; ret_x(c, 1); diff --git a/runtime/ui_text.c b/runtime/ui_text.c index 5b1be433..bf3f45f9 100644 --- a/runtime/ui_text.c +++ b/runtime/ui_text.c @@ -655,7 +655,7 @@ static const char *const text_ru[UI_TEXT_COUNT] = { [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. On + Boost удерживает высокие частоты GPU при упоре в процессор.", + [UI_MENU_REFLEX_DESC] = "Снижает задержку системы на видеокартах NVIDIA с помощью VK_NV_low_latency2. «Вкл + Ускорение» удерживает высокие частоты GPU при упоре в процессор.", [UI_MENU_REFLEX_OFF] = "Выкл", [UI_MENU_REFLEX_ON] = "Вкл", [UI_MENU_REFLEX_BOOST] = "Вкл + Ускорение", @@ -1497,7 +1497,7 @@ static const char *const text_pt_br[UI_TEXT_COUNT] = { [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. On + Boost mantém os clocks da GPU altos quando limitado pela CPU.", + [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", diff --git a/runtime/vk.h b/runtime/vk.h index 23d78fe8..c1185f54 100644 --- a/runtime/vk.h +++ b/runtime/vk.h @@ -148,10 +148,14 @@ 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); +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); -uint64_t vk_reflex_current_present_id(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 6a613450..c7f85a17 100644 --- a/runtime/vk_device.c +++ b/runtime/vk_device.c @@ -405,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_sync.c b/runtime/vk_sync.c index 40421122..f4e026b8 100644 --- a/runtime/vk_sync.c +++ b/runtime/vk_sync.c @@ -477,7 +477,7 @@ uint64_t vk_sync_submit(const uint64_t *handles, int n) { VkLatencySubmissionPresentIdNV lsid = { .sType = VK_STRUCTURE_TYPE_LATENCY_SUBMISSION_PRESENT_ID_NV, .pNext = NULL, - .presentID = vk_reflex_current_present_id() + .presentID = vk_reflex_submit_id() }; VkSubmitInfo2 si = {.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO_2, .pNext = (c->has_nv_reflex) ? &lsid : NULL, @@ -485,9 +485,9 @@ uint64_t vk_sync_submit(const uint64_t *handles, int n) { .pCommandBufferInfos = pro ? cbi : cbi + 1, .signalSemaphoreInfoCount = 1, .pSignalSemaphoreInfos = &sig}; ts_submitted(); - if (recorded && c->has_nv_reflex) vk_reflex_marker(2); // VK_LATENCY_MARKER_RENDERSUBMIT_START_NV + 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); // VK_LATENCY_MARKER_RENDERSUBMIT_END_NV + 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);