feat(vk): RX_VK_PRESENT_PROBE and RX_VK_QUEUE_PRIORITY, switches to see where a present waits on the GPU #2182

Open
Jiro113 wants to merge 2 commits from Jiro113/Longshot:feat/fg-present-wait-diag into main
Contributor

Summary

With frame generation (DLSS Frame Gen 2x at 60 fps, V-Sync on/FIFO, a 240 Hz VRR display) the frames reach the screen
unevenly: the game frame and the generated frame do not share the 16.7 ms between two game frames evenly. To see where
the game frame's present waits on the GPU, this adds three diagnosis switches, all off unless set:

  • RX_VK_PRESENT_PROBE=<file>: one CSV line a probed present (its header names the columns). Timestamps are submitted
    alone on the present's queue right before and right after vkQueuePresentKHR, and one at the end of its image's copy,
    with the CPU clock (QueryPerformanceCounter ticks on Windows) at the submits, the call, the return and each probe's
    fence, and whether the copy's fence was signalled at the call and at the return. A thread of the probe's own waits for
    the fences and writes the file.
    • Which presents. Only those present_commit makes are probed: a fixed multiplier's sets presented ahead
      (present_ahead_wanted: pace && shown >= 2 && swap_spare >= shown), the game frame included. In the 2x run of
      this PR's head, 12,256 probe lines over 105 s against 12,259 presents in RX_VK_FG_LATENCY_LOG's file over the same
      clock range, half with the game frame's Reflex id. What present_image hands to the presenter thread (on every PC
      since #1763: no frame generation, or sets not presented
      ahead) is not probed.
    • Not wait durations. call/return bracket the CPU call, copy_done_at_* are booleans, and
      before_seen/after_seen are when the probe's thread saw its own fences. The present's waits are in frames.csv
      (slot_wait_ms, gpu_behind_ms, shown_ms).
  • RX_VK_QUEUE_PRIORITY=low|medium|high|realtime: the global priority asked for the replay's queue
    (VK_KHR_global_priority, else VK_EXT_global_priority), where the queue's family lists that level. With
    VK_EXT_global_priority alone (neither VK_KHR_global_priority nor VK_EXT_global_priority_query) the levels cannot
    be listed, and the level is asked unlisted. A device refused with it is made again without it, and the log says what
    was asked and what the device was made with.
  • RX_VK_PRESENT_QUEUE_PRIORITY: the same for the presents' own queue (RX_VK_PRESENT_QUEUE=1).

Unset, the device is made as on main (no pNext, no extension) and no present is probed. Set, the probe adds two
submits and two fences a probed present, and RX_VK_QUEUE_PRIORITY changes how the GPU schedules the replay's queue
against other work: that is what it is for.

These are what found the wait the follow-up pull request #2183 fixes (the replay's queue at global priority low
with a fixed frame generation multiplier on NVIDIA's Windows driver). That pull request carries these two commits too,
so the one merged first brings them.

Read first: gpu/vk/vk_replay.cpp (PresentProbe, probe_present, probe_copy_stamp) and gpu/vk/vk_main.cpp
(create_device: the levels asked, the device made again without them).

Testing

Tested: Windows 11, RTX 4090, NVIDIA 621.24, a 240 Hz VRR display; DLSS Frame Gen 2x, the game capped at 60 fps,
V-Sync on, full screen, Hyrule Field with the camera panning, PresentMon recording. Six runs with the switches unset and two with RX_VK_QUEUE_PRIORITY=low and
RX_VK_PRESENT_PROBE set, against six of main (Measurements). With
RX_VK_PRESENT_PROBE set the file had one line a present; with RX_VK_QUEUE_PRIORITY=low the log said
the device was made with the queues' global priority asked (VK_KHR_global_priority; the replay's low, the presents' own unasked). No device was lost. This PR's head, on main a2dc53859, ran again 30 s in a window
with both switches set, in Hyrule Field: the same line, frame interpolation ready at 2x, the probe file written (5467
lines), no device lost.

mise run test (tests/run_all.py --strict) on this PC, Windows with llvm-mingw's clang++: 37 checks fail on main
a2dc53859 here (listed below), and the same 37 fail here, on the same lines, and no other (test_sampler_admission's
concurrent cases fail a varying number of times from run to run on main: 2 of 147 in its full run, 3 in this PR's). The four checks this PR changes, test_present_acquire_ahead,
test_present_device_loss (with and without the probe), test_present_semaphores and test_present_thread, pass
with clang++ and with g++ (11.4, Linux). The renderer builds on Linux (RX_VK_ONLY=1).

The 37 checks that fail on main a2dc53859 on this PC

nx2/test_import_windows, test_auto_handheld, test_bug_report, test_close_waits_for_save, test_compile_zero_byte, test_crash_dialog, test_damaged_rom_files, test_dev_ab, test_dev_build, test_dev_migrate, test_dev_packs, test_draw_stream_visibility, test_fs_save_commit, test_fsr3fi_hud_layer, test_fsr3fi_hudless_colour, test_fsr_uniform_ownership, test_game_menu_mouse_buttons, test_guest_copies, test_hold_toggle, test_input_movie, test_linux_preflight, test_lower_atomg_cas, test_menu_i18n, test_menu_keys, test_menu_slider_ends, test_pads_after_menu, test_perf_report, test_portable_builder_home, test_portable_builder_startup, test_recording_admission, test_sampler_admission, test_sdiv_overflow, test_sim_turf_pools, test_switch_table, test_tls_objects, test_vibration_menu, test_work_lock

Still to test:

  • AMD and Intel on Windows and Linux: RX_VK_QUEUE_PRIORITY=low and RX_VK_PRESENT_PROBE=probe.csv with frame
    generation at a fixed 2x, expecting the log's line of the level asked and made, and a probe file of one line a present
    where the sets are presented ahead (that needs the surface to give minImageCount + 2 images or more, and the pacing
    on: still to confirm on those surfaces) (Test Farm)
  • A driver that refuses the device with the level asked (none here does: this RTX 4090 lists low and medium only and
    takes either): RX_VK_QUEUE_PRIORITY=realtime, expecting the device made again without it and the log saying so
    (by hand)

Measurements

Verdict: unset, no change beyond the runs' spread. Over six runs each, 8.4 % of the intervals on screen were within
0.5 ms of 8.33 ms (6.0 to 10.6) against 10.0 % on main (7.3 to 12.3). The runs of both fall in two groups, the
intervals' standard deviation near 2.3 ms (9.3 to 12.3 % within 0.5 ms) or near 3.0 ms (6.0 to 7.3 %): main had one
run of six in the second group, this PR three, which is where the means differ. Set, RX_VK_QUEUE_PRIORITY=low (with
RX_VK_PRESENT_PROBE) took it to 26.4 % (26.0 and 26.8, two runs): what #2183 builds on.

Setup: Windows 11, RTX 4090, NVIDIA 621.24, 240 Hz VRR display; DLSS Frame Gen 2x, 60 fps cap, FIFO, full screen,
Hyrule Field with the camera panning for 60 s after a teleport, PresentMon over the pan (the frames' intervals on
screen: the share within 0.5 ms of 8.33 ms, and their standard deviation); every run with the same logging switches on
(HOS_PRESENT_TRACE, RX_VK_FG_LATENCY_LOG, RX_VK_REFLEX_LOG), RX_VK_PRESENT_QUEUE=0. Runs interleaved with the
other heads of this work, after one warm-up run each; the mean of each head's runs, (lowest-highest). One more run of
main was left out: PresentMon saw 5309 of its 13240 frames composed by the desktop (Composed: Flip), not flipped
straight to the display.

Before: main @ 8aa749834 After: this PR @ eb135e974, switches unset
Intervals on screen within 0.5 ms of 8.33 ms, % 10.0 (7.3-12.3) 8.4 (6.0-10.6)
Within 1 ms, % 21.3 (15.6-25.9) 18.0 (12.8-22.8)
Intervals on screen, standard deviation, ms 2.43 (2.27-2.94) 2.70 (2.26-3.14)
Game frames on screen, their intervals' standard deviation, ms 2.36 (2.27-2.44) 2.41 (2.37-2.47)
Game frame to generated frame, minus generated to game frame, mean, ms -3.46 (-4.56 to -2.97) -4.09 (-5.08 to -3.14)
Game frame on screen after its present, median, ms 22.68 (22.58-23.01) 22.89 (22.55-23.26)
Runs 6 6

The frame rate with the switches unset, by dev.py ab (this PR's pack and main's on the same base, three interleaved
pairs, 60 s of the frame trace each, in a window, uncapped with HOS_FPS_MAX=1000, frame generation and V-Sync off,
Render resolution 67 %): no difference shown, 136.9 against 133.8 fps (the median of three runs; main 128.7 to 137.4,
this PR 133.0 to 137.9), within the runs' spread. The runs' logs list none of the three switches. (dev.py ab refused
its write-up because the control bridge's pipe name, HOS_CONTROL, differs from run to run; the write-up was made
again from its results with that one left out of the comparison.)

Before: main @ 8aa74983 After: this PR @ eb135e97
fps (each run) 133.8 / 128.7 / 137.4 133.0 / 136.9 / 137.9
Median frame time, ms 7.40 7.27
p99 frame time, ms 9.61 8.95

Measured on main 8aa749834 with this PR's two commits on it (eb135e974). This PR is now on main a2dc53859, its
commits' changes the same (checked with git range-diff) but in test_present_device_loss, which now takes main's
list of the present routine's calls and adds the probe's to it; main's commits since change neither the presents'
timing nor the queues; in the renderer, one keeps the HUD's colours with FSR 3.1 frame generation in Native HDR (DLSS
here), one starts the replay's threads through a guard that reports their C++ exceptions, one logs fewer memory
imports, #2171 moves two includes, spells rx_nvn.h's static assertions
so g++ builds them and changes menu texts, and #2174 keeps the simulated-turf lists at the game's own size in areas without turf, so that Hyrule
Field, the scene measured, no longer stalls 250 ms at a time on the way in: that changes frame times there, and both
sides above ran without it. #1722 adds a save.

Risks

Nothing changes unless a switch is set. The probe sees only the sets presented ahead (Summary): a run without frame
generation, or whose sets are not presented ahead, makes no file, and its log has no vk: present probe: line (the
probe is made at the first present it sees). Set, RX_VK_QUEUE_PRIORITY (or RX_VK_PRESENT_QUEUE_PRIORITY) at low makes the
replay give the GPU up to other programs, and a device refused with it costs one more vkCreateDevice. The probe adds
two submits and two fences a present, and a thread writing the file. Nothing in longshot_options.ini, the saves or
the caches changes.

Checklist

Ready for review

  • One topic, on current main; the title is a Conventional Commit.
  • Tested on my own PC, in the game for a change the game runs, as Testing says.
  • mise run test passes (any failure that also fails on main is named).
  • Measured against main, or Measurements says why there is nothing to measure.
  • No game files, build output or hand-edited generated files; third_party/ untouched; nothing GPL-incompatible.

When it applies

  • A switch added or changed: it ships at the default the measurements chose, with its row in gpu/vk/switches.def.
  • A check under tests/ that reads changed source is updated, not weakened.
  • Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths.
  • AI assistance recorded with Assisted-by: / Co-Authored-By: trailers.

No screenshots: nothing on screen changes with the switches unset. No docs: diagnosis switches are documented by their
rows in gpu/vk/switches.def.

Ready to merge

  • Everything in Still to test has run, its results in Tested.
  • Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers").
  • Approved in review, every comment answered.
  • CI passes on the head; on current main, measured again or a comment says why the numbers still hold.

🤖 Generated with Claude Code

## Summary With frame generation (DLSS Frame Gen 2x at 60 fps, V-Sync on/FIFO, a 240 Hz VRR display) the frames reach the screen unevenly: the game frame and the generated frame do not share the 16.7 ms between two game frames evenly. To see where the game frame's present waits on the GPU, this adds three diagnosis switches, all off unless set: - `RX_VK_PRESENT_PROBE=<file>`: one CSV line a probed present (its header names the columns). Timestamps are submitted alone on the present's queue right before and right after `vkQueuePresentKHR`, and one at the end of its image's copy, with the CPU clock (QueryPerformanceCounter ticks on Windows) at the submits, the call, the return and each probe's fence, and whether the copy's fence was signalled at the call and at the return. A thread of the probe's own waits for the fences and writes the file. - **Which presents.** Only those `present_commit` makes are probed: a fixed multiplier's sets presented ahead (`present_ahead_wanted`: `pace && shown >= 2 && swap_spare >= shown`), the game frame included. In the 2x run of this PR's head, 12,256 probe lines over 105 s against 12,259 presents in `RX_VK_FG_LATENCY_LOG`'s file over the same clock range, half with the game frame's Reflex id. What `present_image` hands to the presenter thread (on every PC since https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1763: no frame generation, or sets not presented ahead) is not probed. - **Not wait durations.** `call`/`return` bracket the CPU call, `copy_done_at_*` are booleans, and `before_seen`/`after_seen` are when the probe's thread saw its own fences. The present's waits are in `frames.csv` (`slot_wait_ms`, `gpu_behind_ms`, `shown_ms`). - `RX_VK_QUEUE_PRIORITY=low|medium|high|realtime`: the global priority asked for the replay's queue (`VK_KHR_global_priority`, else `VK_EXT_global_priority`), where the queue's family lists that level. With `VK_EXT_global_priority` alone (neither `VK_KHR_global_priority` nor `VK_EXT_global_priority_query`) the levels cannot be listed, and the level is asked unlisted. A device refused with it is made again without it, and the log says what was asked and what the device was made with. - `RX_VK_PRESENT_QUEUE_PRIORITY`: the same for the presents' own queue (`RX_VK_PRESENT_QUEUE=1`). Unset, the device is made as on `main` (no `pNext`, no extension) and no present is probed. Set, the probe adds two submits and two fences a probed present, and `RX_VK_QUEUE_PRIORITY` changes how the GPU schedules the replay's queue against other work: that is what it is for. These are what found the wait the follow-up pull request https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2183 fixes (the replay's queue at global priority low with a fixed frame generation multiplier on NVIDIA's Windows driver). That pull request carries these two commits too, so the one merged first brings them. Read first: `gpu/vk/vk_replay.cpp` (`PresentProbe`, `probe_present`, `probe_copy_stamp`) and `gpu/vk/vk_main.cpp` (`create_device`: the levels asked, the device made again without them). ## Testing **Tested:** Windows 11, RTX 4090, NVIDIA 621.24, a 240 Hz VRR display; DLSS Frame Gen 2x, the game capped at 60 fps, V-Sync on, full screen, Hyrule Field with the camera panning, PresentMon recording. Six runs with the switches unset and two with `RX_VK_QUEUE_PRIORITY=low` and `RX_VK_PRESENT_PROBE` set, against six of `main` (Measurements). With `RX_VK_PRESENT_PROBE` set the file had one line a present; with `RX_VK_QUEUE_PRIORITY=low` the log said `the device was made with the queues' global priority asked (VK_KHR_global_priority; the replay's low, the presents' own unasked)`. No device was lost. This PR's head, on `main` a2dc53859, ran again 30 s in a window with both switches set, in Hyrule Field: the same line, frame interpolation ready at 2x, the probe file written (5467 lines), no device lost. `mise run test` (`tests/run_all.py --strict`) on this PC, Windows with llvm-mingw's clang++: 37 checks fail on `main` a2dc53859 here (listed below), and the same 37 fail here, on the same lines, and no other (`test_sampler_admission`'s concurrent cases fail a varying number of times from run to run on `main`: 2 of 147 in its full run, 3 in this PR's). The four checks this PR changes, `test_present_acquire_ahead`, `test_present_device_loss` (with and without the probe), `test_present_semaphores` and `test_present_thread`, pass with clang++ and with g++ (11.4, Linux). The renderer builds on Linux (`RX_VK_ONLY=1`). <details><summary>The 37 checks that fail on <code>main</code> a2dc53859 on this PC</summary> `nx2/test_import_windows`, `test_auto_handheld`, `test_bug_report`, `test_close_waits_for_save`, `test_compile_zero_byte`, `test_crash_dialog`, `test_damaged_rom_files`, `test_dev_ab`, `test_dev_build`, `test_dev_migrate`, `test_dev_packs`, `test_draw_stream_visibility`, `test_fs_save_commit`, `test_fsr3fi_hud_layer`, `test_fsr3fi_hudless_colour`, `test_fsr_uniform_ownership`, `test_game_menu_mouse_buttons`, `test_guest_copies`, `test_hold_toggle`, `test_input_movie`, `test_linux_preflight`, `test_lower_atomg_cas`, `test_menu_i18n`, `test_menu_keys`, `test_menu_slider_ends`, `test_pads_after_menu`, `test_perf_report`, `test_portable_builder_home`, `test_portable_builder_startup`, `test_recording_admission`, `test_sampler_admission`, `test_sdiv_overflow`, `test_sim_turf_pools`, `test_switch_table`, `test_tls_objects`, `test_vibration_menu`, `test_work_lock` </details> **Still to test:** - AMD and Intel on Windows and Linux: `RX_VK_QUEUE_PRIORITY=low` and `RX_VK_PRESENT_PROBE=probe.csv` with frame generation at a fixed 2x, expecting the log's line of the level asked and made, and a probe file of one line a present where the sets are presented ahead (that needs the surface to give `minImageCount + 2` images or more, and the pacing on: still to confirm on those surfaces) (Test Farm) - A driver that refuses the device with the level asked (none here does: this RTX 4090 lists low and medium only and takes either): `RX_VK_QUEUE_PRIORITY=realtime`, expecting the device made again without it and the log saying so (by hand) ## Measurements **Verdict:** unset, no change beyond the runs' spread. Over six runs each, 8.4 % of the intervals on screen were within 0.5 ms of 8.33 ms (6.0 to 10.6) against 10.0 % on `main` (7.3 to 12.3). The runs of both fall in two groups, the intervals' standard deviation near 2.3 ms (9.3 to 12.3 % within 0.5 ms) or near 3.0 ms (6.0 to 7.3 %): `main` had one run of six in the second group, this PR three, which is where the means differ. Set, `RX_VK_QUEUE_PRIORITY=low` (with `RX_VK_PRESENT_PROBE`) took it to 26.4 % (26.0 and 26.8, two runs): what https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2183 builds on. Setup: Windows 11, RTX 4090, NVIDIA 621.24, 240 Hz VRR display; DLSS Frame Gen 2x, 60 fps cap, FIFO, full screen, Hyrule Field with the camera panning for 60 s after a teleport, PresentMon over the pan (the frames' intervals on screen: the share within 0.5 ms of 8.33 ms, and their standard deviation); every run with the same logging switches on (`HOS_PRESENT_TRACE`, `RX_VK_FG_LATENCY_LOG`, `RX_VK_REFLEX_LOG`), `RX_VK_PRESENT_QUEUE=0`. Runs interleaved with the other heads of this work, after one warm-up run each; the mean of each head's runs, (lowest-highest). One more run of `main` was left out: PresentMon saw 5309 of its 13240 frames composed by the desktop (Composed: Flip), not flipped straight to the display. | | Before: main @ 8aa749834 | After: this PR @ eb135e974, switches unset | |---|---|---| | Intervals on screen within 0.5 ms of 8.33 ms, % | 10.0 (7.3-12.3) | 8.4 (6.0-10.6) | | Within 1 ms, % | 21.3 (15.6-25.9) | 18.0 (12.8-22.8) | | Intervals on screen, standard deviation, ms | 2.43 (2.27-2.94) | 2.70 (2.26-3.14) | | Game frames on screen, their intervals' standard deviation, ms | 2.36 (2.27-2.44) | 2.41 (2.37-2.47) | | Game frame to generated frame, minus generated to game frame, mean, ms | -3.46 (-4.56 to -2.97) | -4.09 (-5.08 to -3.14) | | Game frame on screen after its present, median, ms | 22.68 (22.58-23.01) | 22.89 (22.55-23.26) | | Runs | 6 | 6 | The frame rate with the switches unset, by `dev.py ab` (this PR's pack and `main`'s on the same base, three interleaved pairs, 60 s of the frame trace each, in a window, uncapped with `HOS_FPS_MAX=1000`, frame generation and V-Sync off, Render resolution 67 %): no difference shown, 136.9 against 133.8 fps (the median of three runs; `main` 128.7 to 137.4, this PR 133.0 to 137.9), within the runs' spread. The runs' logs list none of the three switches. (`dev.py ab` refused its write-up because the control bridge's pipe name, `HOS_CONTROL`, differs from run to run; the write-up was made again from its results with that one left out of the comparison.) | | Before: main @ 8aa74983 | After: this PR @ eb135e97 | |---|---|---| | fps (each run) | 133.8 / 128.7 / 137.4 | 133.0 / 136.9 / 137.9 | | Median frame time, ms | 7.40 | 7.27 | | p99 frame time, ms | 9.61 | 8.95 | Measured on `main` 8aa749834 with this PR's two commits on it (eb135e974). This PR is now on `main` a2dc53859, its commits' changes the same (checked with `git range-diff`) but in `test_present_device_loss`, which now takes `main`'s list of the present routine's calls and adds the probe's to it; `main`'s commits since change neither the presents' timing nor the queues; in the renderer, one keeps the HUD's colours with FSR 3.1 frame generation in Native HDR (DLSS here), one starts the replay's threads through a guard that reports their C++ exceptions, one logs fewer memory imports, https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2171 moves two includes, spells `rx_nvn.h`'s static assertions so g++ builds them and changes menu texts, and https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/2174 keeps the simulated-turf lists at the game's own size in areas without turf, so that Hyrule Field, the scene measured, no longer stalls 250 ms at a time on the way in: that changes frame times there, and both sides above ran without it. https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1722 adds a save. ## Risks Nothing changes unless a switch is set. The probe sees only the sets presented ahead (Summary): a run without frame generation, or whose sets are not presented ahead, makes no file, and its log has no `vk: present probe:` line (the probe is made at the first present it sees). Set, `RX_VK_QUEUE_PRIORITY` (or `RX_VK_PRESENT_QUEUE_PRIORITY`) at low makes the replay give the GPU up to other programs, and a device refused with it costs one more `vkCreateDevice`. The probe adds two submits and two fences a present, and a thread writing the file. Nothing in `longshot_options.ini`, the saves or the caches changes. ## Checklist ### Ready for review - [x] One topic, on current `main`; the title is a Conventional Commit. - [x] Tested on my own PC, in the game for a change the game runs, as Testing says. - [x] `mise run test` passes (any failure that also fails on `main` is named). - [x] Measured against `main`, or Measurements says why there is nothing to measure. - [x] No game files, build output or hand-edited generated files; `third_party/` untouched; nothing GPL-incompatible. ### When it applies - [x] A switch added or changed: it ships at the default the measurements chose, with its row in `gpu/vk/switches.def`. - [x] A check under `tests/` that reads changed source is updated, not weakened. - [x] Host code builds on Windows (llvm-mingw) and Linux, with UTF-8 paths. - [x] AI assistance recorded with `Assisted-by:` / `Co-Authored-By:` trailers. No screenshots: nothing on screen changes with the switches unset. No docs: diagnosis switches are documented by their rows in `gpu/vk/switches.def`. ### Ready to merge - [ ] Everything in Still to test has run, its results in Tested. - [ ] Tier 1 hardware it can affect is tested (docs/dev/standards.md, "Hardware tiers"). - [ ] Approved in review, every comment answered. - [ ] CI passes on the head; on current `main`, measured again or a comment says why the numbers still hold. 🤖 Generated with [Claude Code](https://claude.com/claude-code)
One CSV line a present: timestamps submitted alone on the present's queue right
before and right after vkQueuePresentKHR and at the end of its image's copy, with
the QPC clock at the submits, the call, the return and each probe's fence. For
where the game frame's present waits with frame generation. Off unless set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
diag(vk): RX_VK_QUEUE_PRIORITY and RX_VK_PRESENT_QUEUE_PRIORITY, the queues' global priority
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 9s
e4be36674c
low, medium, high or realtime through VK_KHR_global_priority (else the EXT), asked
only where the queue's family lists the level; a device refused with them is made
again without them, and the log says what was asked and what it was made with.
Off unless set.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Author
Contributor

Tested in game: Windows 11, RTX 4090, NVIDIA 621.24, a 240 Hz VRR display, full screen; DLSS Frame Gen 2x at a 60 fps cap, V-Sync on, Hyrule Field with the camera panning, PresentMon recording. Switches unset, six runs against six of main: the intervals on screen as on main within the runs' spread. With RX_VK_QUEUE_PRIORITY=low and RX_VK_PRESENT_PROBE set (two runs): the log said the device was made with the replay's queue at global priority low, the probe file had one line a present. No device was lost. The final head, on main a2dc53859, ran again 30 s in a window with both switches set: the same log line, frame interpolation ready at 2x, the probe file written, no device lost.

Tested in game: Windows 11, RTX 4090, NVIDIA 621.24, a 240 Hz VRR display, full screen; DLSS Frame Gen 2x at a 60 fps cap, V-Sync on, Hyrule Field with the camera panning, PresentMon recording. Switches unset, six runs against six of main: the intervals on screen as on main within the runs' spread. With RX_VK_QUEUE_PRIORITY=low and RX_VK_PRESENT_PROBE set (two runs): the log said the device was made with the replay's queue at global priority low, the probe file had one line a present. No device was lost. The final head, on main a2dc53859, ran again 30 s in a window with both switches set: the same log line, frame interpolation ready at 2x, the probe file written, no device lost.
Member

Possibly related, for context:

  • issue #1518 A frame is timed at six different moments, and none of them is when it reaches the screen — Related present and displayed-frame timing diagnostics
  • PR #1121 perf(vk): the render thread replays jobs as they come; whole frames are a test — Prior Vulkan replay/present scheduling change; present path context
Possibly related, for context: - issue #1518 A frame is timed at six different moments, and none of them is when it reaches the screen — Related present and displayed-frame timing diagnostics - PR #1121 perf(vk): the render thread replays jobs as they come; whole frames are a test — Prior Vulkan replay/present scheduling change; present path context
Jiro113 changed title from WIP: feat(vk): RX_VK_PRESENT_PROBE and RX_VK_QUEUE_PRIORITY, switches to see where a present waits on the GPU to feat(vk): RX_VK_PRESENT_PROBE and RX_VK_QUEUE_PRIORITY, switches to see where a present waits on the GPU 2026-11-22 02:07:40 +00:00
dazemc left a comment

The probe does not see the game frame's present on current main — read from the source, not run here.

present_out returns before the probe path whenever the copy is handed to the presenter thread:

  • gpu/vk/vk_replay.cpp:6924 const bool hand_off = present_copy_done && present_thread_on();
  • :6931 if (hand_off) { … return true; } — it returns before :6964 probe_ready(...) and :6968/:6970 probe_present.
  • present_image_with_trial always sets present_copy_done = probe.copy_fence = f.done (:6830) before calling present_out, so every normal game-frame present takes that return.
  • present_thread_on() (:7168) returns true on every PC: RX_VK_PRESENT_THREAD is GONE (gpu/vk/switches.def:797, since 11-19).

So probe_present is reached only from present_commit's direct presents, where present_copy_done is unset — the frame-generation paced presents, not the game frame's. The 5,467 lines in the Windows run are that set. The description says "the presenter thread's presents … are not probed", but does not say that on main the presenter thread owns the game frame's present. As written the probe cannot answer the question the PR asks (where the game frame's present waits). Could you wrap the presenter's vkQueuePresentKHR/copy-fence wait/present-wait, or carry the probe timestamps through the hand-off? And add a column that says which frame set a line belongs to: reflex_frame alone does not say game or generated.

Columns against frames.csv (the #1988 reads): no duplicate names, but call/return are host-clock brackets of the CPU call, copy_done_at_call/return are 0/1 booleans, and before_seen/after_seen are the probe's own fence observations — none is a wait duration. There is no acquire column and no present-shown column; frames.csv's shown_ms/shown_at_ns is the present-wait confirmation, and slot_wait_ms/gpu_behind_ms already name those waits. A reader joining the two files could take after_seen - call for the present's GPU wait; the header or description should say the probe is not a wait-duration source, or the copy-fence/present-wait durations should be added.

Tests: test_present_thread and test_present_acquire_ahead fail on main because they require the probe.copy_fence string; test_present_device_loss and test_present_semaphores only gain stubs/fields and pass on main. test_switch_table passes on main (no new names) and on the PR, so nothing fails on main for RX_VK_QUEUE_PRIORITY/RX_VK_PRESENT_QUEUE_PRIORITY; no test covers the level parse, the family gate or the device retry. A red-first check for one switch read and one gate would be cheap.

Minor, not the blocker: the probe setup returns false with no log when vkAllocateCommandBuffers/vkCreateFence fails (:6241, :6248), so a driver that refuses them silently leaves the probe off. And with only VK_EXT_global_priority (no _query), can_list is false and the code assumes the level is listed (in_list = true, vk_main.cpp:596) and asks anyway, so "only where the family lists that level" is not true on that driver; the device refusal is logged and retried, so that is a wording/gate gap rather than silence.

No fix claim in the title or description: it is diagnostic, and #2183 is named as the fix. The one wording to change is "With them set, nothing else the game does changes" — RX_VK_QUEUE_PRIORITY changes queue scheduling by design.

**The probe does not see the game frame's present on current main** — read from the source, not run here. `present_out` returns before the probe path whenever the copy is handed to the presenter thread: - `gpu/vk/vk_replay.cpp:6924` `const bool hand_off = present_copy_done && present_thread_on();` - `:6931` `if (hand_off) { … return true; }` — it returns before `:6964` `probe_ready(...)` and `:6968`/`:6970` `probe_present`. - `present_image_with_trial` always sets `present_copy_done = probe.copy_fence = f.done` (`:6830`) before calling `present_out`, so every normal game-frame present takes that return. - `present_thread_on()` (`:7168`) returns true on every PC: `RX_VK_PRESENT_THREAD` is `GONE` (`gpu/vk/switches.def:797`, since 11-19). So `probe_present` is reached only from `present_commit`'s direct presents, where `present_copy_done` is unset — the frame-generation paced presents, not the game frame's. The 5,467 lines in the Windows run are that set. The description says "the presenter thread's presents … are not probed", but does not say that on main the presenter thread owns the game frame's present. As written the probe cannot answer the question the PR asks (where the **game frame's** present waits). Could you wrap the presenter's `vkQueuePresentKHR`/copy-fence wait/present-wait, or carry the probe timestamps through the hand-off? And add a column that says which frame set a line belongs to: `reflex_frame` alone does not say game or generated. **Columns against `frames.csv`** (the #1988 reads): no duplicate names, but `call`/`return` are host-clock brackets of the CPU call, `copy_done_at_call/return` are 0/1 booleans, and `before_seen/after_seen` are the probe's own fence observations — none is a wait duration. There is no acquire column and no present-shown column; `frames.csv`'s `shown_ms`/`shown_at_ns` is the present-wait confirmation, and `slot_wait_ms`/`gpu_behind_ms` already name those waits. A reader joining the two files could take `after_seen - call` for the present's GPU wait; the header or description should say the probe is not a wait-duration source, or the copy-fence/present-wait durations should be added. **Tests:** `test_present_thread` and `test_present_acquire_ahead` fail on main because they require the `probe.copy_fence` string; `test_present_device_loss` and `test_present_semaphores` only gain stubs/fields and pass on main. `test_switch_table` passes on main (no new names) and on the PR, so nothing fails on main for `RX_VK_QUEUE_PRIORITY`/`RX_VK_PRESENT_QUEUE_PRIORITY`; no test covers the level parse, the family gate or the device retry. A red-first check for one switch read and one gate would be cheap. **Minor, not the blocker:** the probe setup returns `false` with no log when `vkAllocateCommandBuffers`/`vkCreateFence` fails (`:6241`, `:6248`), so a driver that refuses them silently leaves the probe off. And with only `VK_EXT_global_priority` (no `_query`), `can_list` is false and the code assumes the level is listed (`in_list = true`, `vk_main.cpp:596`) and asks anyway, so "only where the family lists that level" is not true on that driver; the device refusal is logged and retried, so that is a wording/gate gap rather than silence. No fix claim in the title or description: it is diagnostic, and #2183 is named as the fix. The one wording to change is "With them set, nothing else the game does changes" — `RX_VK_QUEUE_PRIORITY` changes queue scheduling by design.
Author
Contributor

@dazemc thanks, checked against the source and against the runs' files. You are right about the code path, and the description was wrong about it.

What the probe sees. Since #1763, present_thread_on() is always true. A present from present_image carries present_copy_done. It goes to the presenter thread, and present_out returns before probe_ready. Only present_commit's presents stay in present_out and are probed.

With a fixed multiplier whose sets are presented ahead (present_ahead_wanted: pace && shown >= 2 && swap_spare >= shown), present_commit presents the whole set, the game frame included. So in the case this PR was measured on, every present is probed. Counts from this PR's head, DLSS Frame Gen 2x:

  • 12,256 probe lines over 105 s;
  • 12,259 presents in RX_VK_FG_LATENCY_LOG's file over the same clock range;
  • 6,128 lines carry the game frame's Reflex id (one per game frame), and 6,128 carry 0.

FSR 3.1 and the built-in frame generation, in mailbox, give the same: 8,420 to 14,041 lines, 3 to 10 short of the presents.

Without frame generation, or when the sets are not presented ahead, nothing is probed. The description now says so, in place of the line about RX_VK_PRESENT_THREAD (a switch gone since #1763). The base the PR was measured on, main 8aa749834, already has #1763, so the measured runs behaved the same. The Measurements' numbers come from PresentMon, not from the probe.

Columns. Agreed: none is a wait duration.

  • call/return bracket the CPU call.
  • copy_done_at_* are booleans.
  • before_seen/after_seen are when the probe's thread saw its own fences.

The description now says the probe is not a source of wait durations, and points to frames.csv's slot_wait_ms, gpu_behind_ms and shown_ms for those.

Tests. Your reading matches mine:

  • test_present_thread and test_present_acquire_ahead fail on main.
  • The other two only gain stubs and fields.
  • Nothing here covers RX_VK_QUEUE_PRIORITY's parse, the family gate or the device made again.

Minor points. Both are true.

  • On 621.24, NVIDIA has VK_KHR_global_priority and VK_EXT_global_priority_query, so the runs here never took the can_list false path.
  • The description now says that with VK_EXT_global_priority alone the level is asked unlisted, and that a refusal makes the device again and is logged.
  • "Nothing else the game does changes" is gone. Set, RX_VK_QUEUE_PRIORITY changes the GPU's scheduling, which is its point.

Next, on this PR:

  • a column that says game frame or generated frame, and the set it belongs to. reflex_frame happens to be the game frame's id or 0 in these runs, but that is not a contract;
  • a log line saying whether the sets are presented ahead, so a run says whether the probe sees its presents;
  • a log line when the probe's command buffer or fence cannot be made;
  • the file's header saying the columns are brackets and observations, not waits;
  • a check that fails on main for the level's read and the family gate.

Probing the presenter thread (presenter_loop, or carrying the stamps through the hand-off) would cover the path without frame generation. That path is the one #1518 needs. This PR's question is the frame generation sets, and they are all probed, so I would rather make that a change of its own. Say if you think it belongs here.

@dazemc thanks, checked against the source and against the runs' files. You are right about the code path, and the description was wrong about it. **What the probe sees.** Since https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1763, `present_thread_on()` is always true. A present from `present_image` carries `present_copy_done`. It goes to the presenter thread, and `present_out` returns before `probe_ready`. Only `present_commit`'s presents stay in `present_out` and are probed. With a fixed multiplier whose sets are presented ahead (`present_ahead_wanted`: `pace && shown >= 2 && swap_spare >= shown`), `present_commit` presents the whole set, the game frame included. So in the case this PR was measured on, every present is probed. Counts from this PR's head, DLSS Frame Gen 2x: - 12,256 probe lines over 105 s; - 12,259 presents in `RX_VK_FG_LATENCY_LOG`'s file over the same clock range; - 6,128 lines carry the game frame's Reflex id (one per game frame), and 6,128 carry 0. FSR 3.1 and the built-in frame generation, in mailbox, give the same: 8,420 to 14,041 lines, 3 to 10 short of the presents. Without frame generation, or when the sets are not presented ahead, nothing is probed. The description now says so, in place of the line about `RX_VK_PRESENT_THREAD` (a switch gone since https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1763). The base the PR was measured on, `main` 8aa749834, already has https://git.magicbean.dev/MagicBeanDev/Longshot/pulls/1763, so the measured runs behaved the same. The Measurements' numbers come from PresentMon, not from the probe. **Columns.** Agreed: none is a wait duration. - `call`/`return` bracket the CPU call. - `copy_done_at_*` are booleans. - `before_seen`/`after_seen` are when the probe's thread saw its own fences. The description now says the probe is not a source of wait durations, and points to `frames.csv`'s `slot_wait_ms`, `gpu_behind_ms` and `shown_ms` for those. **Tests.** Your reading matches mine: - `test_present_thread` and `test_present_acquire_ahead` fail on `main`. - The other two only gain stubs and fields. - Nothing here covers `RX_VK_QUEUE_PRIORITY`'s parse, the family gate or the device made again. **Minor points.** Both are true. - On 621.24, NVIDIA has `VK_KHR_global_priority` and `VK_EXT_global_priority_query`, so the runs here never took the `can_list` false path. - The description now says that with `VK_EXT_global_priority` alone the level is asked unlisted, and that a refusal makes the device again and is logged. - "Nothing else the game does changes" is gone. Set, `RX_VK_QUEUE_PRIORITY` changes the GPU's scheduling, which is its point. **Next, on this PR:** - a column that says game frame or generated frame, and the set it belongs to. `reflex_frame` happens to be the game frame's id or 0 in these runs, but that is not a contract; - a log line saying whether the sets are presented ahead, so a run says whether the probe sees its presents; - a log line when the probe's command buffer or fence cannot be made; - the file's header saying the columns are brackets and observations, not waits; - a check that fails on `main` for the level's read and the family gate. Probing the presenter thread (`presenter_loop`, or carrying the stamps through the hand-off) would cover the path without frame generation. That path is the one https://git.magicbean.dev/MagicBeanDev/Longshot/issues/1518 needs. This PR's question is the frame generation sets, and they are all probed, so I would rather make that a change of its own. Say if you think it belongs here.
Author
Contributor

Description corrected after @dazemc's review (answered in the comment above):

  • Summary, RX_VK_PRESENT_PROBE: which presents are probed (only present_commit's, a fixed multiplier's sets presented ahead, the game frame included, with the counts that show it), in place of the line about RX_VK_PRESENT_THREAD, a switch gone since #1763. A second point says the columns are not wait durations, and where those are.
  • Summary, RX_VK_QUEUE_PRIORITY: with VK_EXT_global_priority alone the level is asked unlisted.
  • "With them set, nothing else the game does changes" replaced: set, RX_VK_QUEUE_PRIORITY changes the GPU's scheduling, which is its point.
  • Still to test: one line a present only where the sets are presented ahead.
  • Risks: a run whose presents are not probed makes no file and no log line.

No code changed. The code changes listed in the answer come as their own commits, with a note here.

Description corrected after @dazemc's review (answered in the comment above): - Summary, `RX_VK_PRESENT_PROBE`: which presents are probed (only `present_commit`'s, a fixed multiplier's sets presented ahead, the game frame included, with the counts that show it), in place of the line about `RX_VK_PRESENT_THREAD`, a switch gone since #1763. A second point says the columns are not wait durations, and where those are. - Summary, `RX_VK_QUEUE_PRIORITY`: with `VK_EXT_global_priority` alone the level is asked unlisted. - "With them set, nothing else the game does changes" replaced: set, `RX_VK_QUEUE_PRIORITY` changes the GPU's scheduling, which is its point. - Still to test: one line a present only where the sets are presented ahead. - Risks: a run whose presents are not probed makes no file and no log line. No code changed. The code changes listed in the answer come as their own commits, with a note here.
Some checks are pending
CI / Conventional Commit title (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 1/2) (pull_request) Blocked by required conditions
CI / Python source checks (ubuntu-24.04, part 2/2) (pull_request) Blocked by required conditions
CI / SPIR-V fixtures (global narrow load/store, direct surface atomics, F2I immediate) (pull_request) Blocked by required conditions
CI / Workflow lint (actionlint) (pull_request) Blocked by required conditions
CI / Website build and checks (pull_request) Blocked by required conditions
Guide screenshots / Guide images and local UI source review (pull_request) Blocked by required conditions
Third-party parts / The same as upstream (pull_request) Blocked by required conditions
Third-party parts / As their notes say (pull_request) Blocked by required conditions
Website / Website on Cloudflare (pull_request_target) Has been skipped
PR description / Description follows the template (pull_request_target) Successful in 9s
This pull request doesn't have enough approvals yet. 0 of 1 approvals granted.
Some workflows are waiting to be reviewed.
You are not authorized to merge this pull request.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u 'feat/fg-present-wait-diag:Jiro113-feat/fg-present-wait-diag'
git switch 'Jiro113-feat/fg-present-wait-diag'
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
3 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
MagicBeanDev/Longshot!2182
No description provided.