From 0f7d57ac14cef1b0f92e3256171dafaa70f6ef9e Mon Sep 17 00:00:00 2001 From: ruckus7382sfgsgdf <355121112+ruckus7382sfgsgdf@users.noreply.github.com> Date: Sat, 28 Nov 2026 12:47:19 -0600 Subject: [PATCH] Triforce v0.8.5.1 Hotfix: the 0.8.5 readback wait (RX_VK_RB_REC_END) is off by default again; it cost up to 20 fps. --- docs/development.md | 2 +- gpu/vk/vk_replay.cpp | 2 +- gpu/vk/wb_rec_wait.h | 6 ++++-- tests/test_readback_rec_end.cpp | 4 ++-- tests/test_readback_rec_end.py | 2 +- 5 files changed, 9 insertions(+), 7 deletions(-) diff --git a/docs/development.md b/docs/development.md index 9f88a2b..107ea4f 100644 --- a/docs/development.md +++ b/docs/development.md @@ -201,7 +201,7 @@ case-sensitive, and an unknown one is ignored. | `RX_VK_SETTLE_GATE=1`, `=2` | (Triforce, 11-22, off by default; the performance audit's SYNC-29, after Source A's; `gpu/vk/settle_gate.h`) A CPU read that lets the stopped queues whose waits are met go on (the readback's look, which `RX_VK_RB_SETTLE=1` turns on, and the two looks made for a range a texture may be in) takes the order's lock whenever a queue is stopped, and that lock is held through whole replays and presents. With the gate a site looks only while a queue is stopped **and** the CPU has signalled an event since the last finished look, or a stopped queue waits on an event whose value is read from guest memory; any other met wait was met by a signal in the stream, and the thread that replayed it looked before it let the lock go. `1`: the readback's look; `2`: the texture sites' too (new ground: those looks order the exposure meter's readback, so `2` needs the lab's flicker count). Unset or `0`: every look as before. The `RX_VK_LAB_AB` knobs `settlegate` and `texgate` are `1` and `2` in their phases (`rbsettle+settlegate` is the pair the audit asks for). The 3000-readback line and the texture catch-ups' 300-call line count the looks made and skipped | | `RX_VK_READBACK_LATE=[,]`, `RX_VK_LOG_READBACK_RANGES=1` | (Triforce, 11-22, the performance audit's SYNC-19, after Source A's; `gpu/vk/readback_late.h`) Ranges the CPU reads back **without** the wait for their write-back, from what guest memory holds (the last write-back made): a rule is a size in hex (`3980`: every range of 0x3980 bytes, the culling camera block Source A reads late by default) or `newest` (a range whose writer is the newest submission handed out: the game cannot have waited for it). **Unset: no rule**, every readback waits as before, until the lab has run it where the waits are long (a handheld, an AMD iGPU, a weak discrete card); `=0`: none either. The `RX_VK_LAB_AB` knob `rblate` is `3980` in its phases. A late read hands the game the frame before's values, and when the CPU resets a range read late the pending write-back lands over its reset (the exposure meter's flashes): `newest` can catch that meter, so it is never a default. `RX_VK_LOG_READBACK_RANGES=1`: with every 3000-readback line, the 12 ranges that waited longest (readbacks, waits, ms, how often their writer was the newest submission, how often read late), to find such ranges on other hardware; nothing is noted without it | | `RX_VK_WB_WAIT_REC=1`, `=2` | (Triforce, off by default; the handoff's ยง12.9, `gpu/vk/wb_rec_wait.h`) A wait for a write-back still on the GPU (a capture's late pages on the game's submitting thread, a read or binding of a page put off) ends once the recording its submission was finished in is done on the GPU, not when the submissions' timeline reaches it: that timeline is held below any submission stopped at an event wait, and the lab's Market had 20-46 ms waits of the game's thread with the GPU 4 submissions behind. Whatever the switch, the wait for the recording comes first and the rest is counted: the stall line's `N of them X ms after their writer's recording was done`, the `late:` line's `ms of the wait after the recording that finished it was done`, the frame trace's `wb_held_ms`. Off: the captures' late-page wait orders something not known yet (`RX_VK_LATE_NEW`), so it is tried with the lab's flicker count first. (Triforce, 11-22, the performance audit's SYNC-122, after Source B's) The reads' side: a readback whose write-back is not recorded yet waited on the submissions' timeline with no bound and no second look; it is counted now (the 3000-readback line's second line), and the stall line names the held part by caller (takes, reads, binds, readbacks). The variable is a mode: `1` as above, and such a readback waits in 1 ms slices, looks its writer's recording up between them and ends with it; `2` is the check, where no wait ends earlier and the readback's slices count the part after the recording was done (what `1` would not have waited); unset, `0` or any other text: off, one wait as before. The check of the pages a later write-back changes (the audit's SYNC-101) is not built. `RX_VK_TL_REC=1` and the lab knob `tlrec` ended a capture's wait at a submission's first part, before its burst's write-backs were recorded: they now end it at the recording the submission was finished in, as `=1` here does; `RX_VK_TL_REC=2` keeps the old lookup | -| `RX_VK_RB_REC_END=0` | (Triforce, 11-27; `gpu/vk/wb_rec_wait.h` `readback_wait`, `tests/test_readback_rec_end.py`) A CPU readback of GPU results waits for the **last** part of the recording that writes it back. A recording made in parts (`RX_VK_CHUNK`'s counted parts, 240 draws on NVIDIA's driver, or Threaded rendering's pass-end parts) writes back at each part's end, all under the recording's one value, and the readback's wait looked that value up in a table that keeps the first part (`RX_VK_REC_LAST`, off, keeps a later one only when the value comes again). A read that came between the first part's submit and the last one's got what guest memory held then: OoT's exposure meter read as 0 where the GPU's sum was still to come, then the sum landed over the CPU's next 0 and the next frame added to it. In a still view the picture flashed brighter for a frame and stepped down: 3 times at Hyrule Field in a four-scene held-camera benchmark run (`HOS_BENCH_PAN=0`), on v0.8.4 too. Now the readback looks up the newest part submitted and whether it ended the recording: an ended recording's last part is waited for; one that goes on, the part found (the old wait), then 1 ms slices of the submissions' timeline between looks until it ends or the timeline reaches the value. A value not recorded yet goes to the fallback as before. `RX_VK_LOG_READBACK_ZERO=1` now says the writer's recording's first part, newest part and the recordings done at a zero read; the 3000-readback line counts the reads that waited past a part. Measured on an RTX 5090 (held camera): the meter's zero reads after a wait went from 0-10 a run to 0 in 4 runs, and Hyrule Field's flashes from 3 a run to 0. The rule waits 350-550 times a run, 2-5 ms each, on the game's worker threads, nearly all at a scene's load and in its first seconds. Frame rate unchanged (144.5 against 143.2 fps, 3 runs each); Hyrule Field's p99 frame time 9-13% higher. Waiting only for the part that wrote the range would be cheaper (not done). The rule's branches stay out of `invalidate` and submit_recording's registration, so that the renderer's play profile still matches them. `0`: the first part, as before | +| `RX_VK_RB_REC_END=1` | (Triforce, 0.8.5.1: OFF by default; =1 turns it on, its worker-thread reads waited ~5 ms each for the frame's whole recording, 70 fps at the owner's save for 85-91. 11-27; `gpu/vk/wb_rec_wait.h` `readback_wait`, `tests/test_readback_rec_end.py`) A CPU readback of GPU results waits for the **last** part of the recording that writes it back. A recording made in parts (`RX_VK_CHUNK`'s counted parts, 240 draws on NVIDIA's driver, or Threaded rendering's pass-end parts) writes back at each part's end, all under the recording's one value, and the readback's wait looked that value up in a table that keeps the first part (`RX_VK_REC_LAST`, off, keeps a later one only when the value comes again). A read that came between the first part's submit and the last one's got what guest memory held then: OoT's exposure meter read as 0 where the GPU's sum was still to come, then the sum landed over the CPU's next 0 and the next frame added to it. In a still view the picture flashed brighter for a frame and stepped down: 3 times at Hyrule Field in a four-scene held-camera benchmark run (`HOS_BENCH_PAN=0`), on v0.8.4 too. Now the readback looks up the newest part submitted and whether it ended the recording: an ended recording's last part is waited for; one that goes on, the part found (the old wait), then 1 ms slices of the submissions' timeline between looks until it ends or the timeline reaches the value. A value not recorded yet goes to the fallback as before. `RX_VK_LOG_READBACK_ZERO=1` now says the writer's recording's first part, newest part and the recordings done at a zero read; the 3000-readback line counts the reads that waited past a part. Measured on an RTX 5090 (held camera): the meter's zero reads after a wait went from 0-10 a run to 0 in 4 runs, and Hyrule Field's flashes from 3 a run to 0. The rule waits 350-550 times a run, 2-5 ms each, on the game's worker threads, nearly all at a scene's load and in its first seconds. Frame rate unchanged (144.5 against 143.2 fps, 3 runs each); Hyrule Field's p99 frame time 9-13% higher. Waiting only for the part that wrote the range would be cheaper (not done). The rule's branches stay out of `invalidate` and submit_recording's registration, so that the renderer's play profile still matches them. `0`: the first part, as before | | `RX_VK_LATE_QUEUE=1` or `0` | (Triforce, 11-20; 11-23) A capture's late pages (pages a submission still on the GPU writes back: OoT's exposure meter and the per-frame pools) waited for at the queue's next submit, not at the capture's take (`gpu/vk/vk_memory.cpp` `late_queue_on`). Unset: at the queue, except while the replay's submits are held (`RX_VK_BATCH`, on by default with Mesa's RADV): there a held submit applies no fix, the fixes wait for the batch's flush and copy guest memory the game has written again for its next frame, and the replay reads those slots live meanwhile: the lighting and exposure flicker on Linux AMD from 50-90 s into play in v0.7.0. `1`: at the queue with held submits too (v0.7.0 as shipped); `0`: at the take on every driver, as before 11-20. The log says `vk: late pages' wait ...` when it is first asked and when the answer changes | | `RX_VK_LATE_INLINE=1` | (Triforce, 11-22, the performance audit's MEM-80, after Source B's; `gpu/vk/late_inline.h`; **off unless set**, not yet run in the game) A late page (one the CPU wrote while a submission still on the GPU writes it back) is waited for and taken again by default (`RX_VK_LATE_QUEUE`: at the queue's next submit). `RX_VK_LATE_NEW=1` (knob `latenew`) turns four no-wait rules on, each of which brought brightness steps back at the Castle Town save. This turns on the partial rule alone (knob `lateinline`): a page only part of which a submission on the GPU writes back has its other parts synced from the capture, no wait; pages of pools with no mirror, texture storage, pages written back whole and pages whose write-backs' ranges are not known are waited for as by default. The partial rule, here and under `RX_VK_LATE_NEW`, now asks which ranges are still on the GPU against the progress the capture read before its copies, not a second read at the take: a write-back done between the two counts as in flight, and its range is not synced from the older copy. `RX_VK_LOG_LATE` shows the pages waited for | | `RX_VK_PASS_TIMING=1` or `2` | GPU time per pass (2: per program too), logged every 600 presents | diff --git a/gpu/vk/vk_replay.cpp b/gpu/vk/vk_replay.cpp index d872c0c..85c8811 100644 --- a/gpu/vk/vk_replay.cpp +++ b/gpu/vk/vk_replay.cpp @@ -6199,7 +6199,7 @@ bool rb_rec_end_on() { const bool on = ::mkwvk::wb_rec_wait::rec_end_on(getenv("RX_VK_RB_REC_END")); logf("vk: a readback waits for %s (RX_VK_RB_REC_END%s)", on ? "the last part of the recording that writes it back" : "the first part of the recording that writes it back, as before", - on ? "=0: the first part, as before" : "=0"); + on ? "=0 or unset: the first part, as before" : "=1: the last part; 0.8.5.1: off by default, its ~5 ms reads"); return on; }(); return v; diff --git a/gpu/vk/wb_rec_wait.h b/gpu/vk/wb_rec_wait.h index 93f8862..6333975 100644 --- a/gpu/vk/wb_rec_wait.h +++ b/gpu/vk/wb_rec_wait.h @@ -233,8 +233,10 @@ struct Parts { } }; -/// RX_VK_RB_REC_END's text: on unset or empty; set, its number (atoi, as the renderer's other switches: 0 or a word is off) -inline bool rec_end_on(const char* text) { return !(text && *text && std::atoi(text) == 0); } +/// RX_VK_RB_REC_END's text: ((Triforce, 0.8.5.1)) OFF unless set to a number other than 0. On, the game's worker threads' reads of +/// its double-buffered GPU results waited ~5 ms for the whole frame's recording (the owner's save: 70 fps for 85-91). The fix for +/// the brightness flashes comes back without that cost (only the GPU work the game waited for) +inline bool rec_end_on(const char* text) { return text && *text && std::atoi(text) != 0; } /// What a readback's wait by recordings did struct ReadbackWait { diff --git a/tests/test_readback_rec_end.cpp b/tests/test_readback_rec_end.cpp index 8b1f8ec..73af725 100644 --- a/tests/test_readback_rec_end.cpp +++ b/tests/test_readback_rec_end.cpp @@ -76,8 +76,8 @@ struct Gpu { int main() { // the switch: on unset or empty; set, it is its number (atoi, as the renderer's other switches: a word reads as 0, off) - CHECK("unset: on", wr::rec_end_on(nullptr)); - CHECK("empty: on", wr::rec_end_on("")); + CHECK("unset: off (0.8.5.1)", !wr::rec_end_on(nullptr)); + CHECK("empty: off (0.8.5.1)", !wr::rec_end_on("")); CHECK("0: off", !wr::rec_end_on("0")); CHECK("00: off", !wr::rec_end_on("00")); CHECK("1: on", wr::rec_end_on("1")); diff --git a/tests/test_readback_rec_end.py b/tests/test_readback_rec_end.py index 064f7f4..a9d71f9 100644 --- a/tests/test_readback_rec_end.py +++ b/tests/test_readback_rec_end.py @@ -114,7 +114,7 @@ def check_source(): "the 3000-readback line does not count the reads that waited past a part") dev = (ROOT / "docs/development.md").read_text(encoding="utf-8") - rows = [line for line in dev.splitlines() if line.startswith("| `RX_VK_RB_REC_END=0` |")] + rows = [line for line in dev.splitlines() if line.startswith("| `RX_VK_RB_REC_END=1` |")] check(len(rows) == 1, "docs/development.md: RX_VK_RB_REC_END is not in the switches table once") check("tests/test_readback_rec_end.py" in rows[0] and "wb_rec_wait.h" in rows[0], "docs/development.md: the row names neither the rule nor its test")