Renderer port 2: tables the title fills whole mark every slot they overlap (#301) #359

Open
github-bot wants to merge 1 commit from github-bot/gh-359 into main AGit
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-26 18:47 UTC · original
Jesper-Andersson:port2-table-ranges → main · +444 −29 · 3 files · 1 commits · open

Fixes #301.

With VICTORY_PORT_DESCRIPTORS=1 (renderer port 2), port 2's fallback finds hundreds of view records a frame in the title's heap that no mark told of (#301: 250 a frame on a 7900 XTX, all indirect light black). Until the fallback reaches their page, those slots show stale views. Port 2 marks slots from six patched record stores (crates/victory-loader/src/descriptor_sites.rs), from our own calls, and from the title's imported memcpy/memmove. The title has other code that fills whole descriptor tables taken from its frame allocator (the memory of the placed view heap), and port 2 never sees those writes:

  • +0x4d9f200 copies a ready list of records into a new table: four vmovups [rbx+disp], ymm for 128 bytes (a form the search for the six stores does not find), the imported memcpy otherwise. This is the title+0x4d9f25f writer in #301's table.
  • +0x4e51a90, +0x248d6d0 and its twin +0x248d780 take a table and have a callback the caller passes fill it, so the filling code can be anything.

Of the other writers #301 names: title+0x18849c, +0x2474afc and +0x4e9b4e2 store 8-byte list-node links from the same allocator. 0x7ff9…0000 is our own first stub. The writers outside the image are vcruntime's memcpy behind our wrapper. They appear because the writer is recorded per 64 KiB block (the last fault on it), and the allocator mixes constants, nodes and tables in the same blocks.

Change

  • descriptor_sites.rs: a second kind of site, Kind::Range { table, size, moved }. It hooks the point where such a function goes on once the table is filled, and marks every slot that [table, table+size) overlaps: a table that begins half into a slot marks that slot too, and the range is cut at the heap's end. The hooked instructions are moved into the stub. A rip-relative mov eax, [rip+x] (the +0x248d6d0 sites) is done from its absolute address (Moved::LoadEax: mov rax, address ; mov eax, [rax], the same rax and flags). Four sites: +0x4d9f272, +0x4e51aee, +0x248d71b and +0x248d7cb, which are the joins where both paths of each function meet. As with the six stores, each window's bytes are compared before anything is written. All four were checked against the 1.0.2.1 executable.
  • port_descriptors.rs (diagnostics in the existing per-frame line):
    • It counts the memcpy calls into the heap that begin half into a slot, and the view records they put half into one.
    • A writer outside the title is named by module and offset (VCRUNTIME140.dll+0x1c26f). When the word on top of its stack is in the title, the title code that called it is named too.
    • watch.rs passes that word from the fault's context.
  • Switch: none new. All of this is under VICTORY_PORT_DESCRIPTORS=1, which is off by default.

Where it does nothing

  • Without VICTORY_PORT_DESCRIPTORS=1 nothing is patched (run.rs applies the sites only with the switch).
  • Another build of the title: a window whose bytes differ is left alone and logged, as for the six stores.
  • The hooked code runs after the fill, so the title's own writes are unchanged. Only port 2's marks are added. The tests check that each window leaves the same registers whether hooked or not.

Measured

RTX 2070 SUPER 8 GB, Ryzen 7 5800X, 32 GB, Windows 11, diag build, scripts\play.ps1 with VICTORY_PORT_CONSTANTS=1 VICTORY_PORT_DESCRIPTORS=1 VICTORY_PORT_CBV=1 VICTORY_PORT_GUARD=1 VICTORY_PORT_JOURNAL=1, 7 minutes from start (into the first world cell at 1-3 fps). Main was c9c932c. "After" had the +0x4d9f200 site only; the three callback sites came later and have not been run.

port 2's line main +0x4d9f200 site
view records missed / slots told 46,744 / 32.6 M (1.44 per 1000) 33,645 / 50.2 M (0.67 per 1000)
missed per line (every 8th frame looked at): mean, worst 103, 496 60, 234
memcpy calls into the heap a frame (records they marked) ~5,600 (0) ~5,900 (0)
of them half into a slot (view records put half into one) n/a ~3,300 (0)
  • The site halves the misses but does not remove them. No memcpy into the heap carries a view record, either at a slot's start or 16 bytes into one, so the copies the wrapper sees are other data. What is left has to be written by other code with its own stores. The callback sites are my best guess at that code, from reading the callers of the table allocator (+0x4d9f3e0).
  • The picture was not compared: at 1-3 fps, with about 1,100 draws a frame dropped for lack of a host pipeline, the run says nothing about indirect light.

Checks

  • cargo test -p victory-loader --locked: 54 passed. New tests:
    • a_range_site_marks_every_slot_its_table_overlaps runs each of the four windows in test code, plain and hooked, with all 16 registers set. It compares the registers both leave, checks that the moved rip-relative load reads the same value, and checks the marks for half-slot, past-the-end, outside-the-heap and zero-size tables.
    • a_moved_load_reads_the_same_address and a_range_stub_refuses_the_registers_it_uses.
  • cargo test -p victory-gpu --locked: 381 passed, 34 ignored.
  • cargo clippy --workspace --all-targets --locked -- -D warnings: stops on main's existing missing_transmute_annotations in the old a_hooked_site_stores_and_marks_its_slot test (descriptor_sites.rs:482), which this PR does not change. #169 and others fix it. Without -D warnings, nothing in the changed code.
  • cargo xtask policy: 265 files ok.
  • In game: the runs above (RTX 2070 SUPER). All sites reported patched, and the run with the first site had no crash or device loss.

Not checked

  • The three callback sites in game. One run like the one above would show whether the misses fall further. Without such a run, the main risk is cost: if those tables are mostly constants, port 2 compares some extra KB a frame.
  • The 7900 XTX of #301, and whether indirect light comes back there with ports 1, 2, 3, 6 and 7 on. That is the most useful check.
  • Further callers of the allocator, left out: +0x4f4371 (256-byte aligned, filled in a loop), +0x2490da0 (reached through a virtual table) and +0x555e570 (a fixed 100 bytes).
  • #273 (port 2: a heap that goes takes its fallback pages with it) edits let_go and the tests in port_descriptors.rs. This PR touches neither, and the two rebase onto each other without conflict (checked on a branch carrying both).

This change was made with AI assistance (Claude Code).

**@⁠Jesper-Andersson** on GitHub · 2026-11-26 18:47 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/359) `Jesper-Andersson:port2-table-ranges` → `main` · +444 −29 · 3 files · 1 commits · open Fixes #301. With `VICTORY_PORT_DESCRIPTORS=1` (renderer port 2), port 2's fallback finds hundreds of view records a frame in the title's heap that no mark told of (#301: 250 a frame on a 7900 XTX, all indirect light black). Until the fallback reaches their page, those slots show stale views. Port 2 marks slots from six patched record stores (`crates/victory-loader/src/descriptor_sites.rs`), from our own calls, and from the title's imported `memcpy`/`memmove`. The title has other code that fills whole descriptor tables taken from its frame allocator (the memory of the placed view heap), and port 2 never sees those writes: - **+0x4d9f200** copies a ready list of records into a new table: four `vmovups [rbx+disp], ymm` for 128 bytes (a form the search for the six stores does not find), the imported `memcpy` otherwise. This is the `title+0x4d9f25f` writer in #301's table. - **+0x4e51a90**, **+0x248d6d0** and its twin **+0x248d780** take a table and have a callback the caller passes fill it, so the filling code can be anything. Of the other writers #301 names: `title+0x18849c`, `+0x2474afc` and `+0x4e9b4e2` store 8-byte list-node links from the same allocator. `0x7ff9…0000` is our own first stub. The writers outside the image are vcruntime's `memcpy` behind our wrapper. They appear because the writer is recorded per 64 KiB block (the last fault on it), and the allocator mixes constants, nodes and tables in the same blocks. ## Change - `descriptor_sites.rs`: a second kind of site, `Kind::Range { table, size, moved }`. It hooks the point where such a function goes on once the table is filled, and marks every slot that `[table, table+size)` overlaps: a table that begins half into a slot marks that slot too, and the range is cut at the heap's end. The hooked instructions are moved into the stub. A `rip`-relative `mov eax, [rip+x]` (the +0x248d6d0 sites) is done from its absolute address (`Moved::LoadEax`: `mov rax, address ; mov eax, [rax]`, the same `rax` and flags). Four sites: +0x4d9f272, +0x4e51aee, +0x248d71b and +0x248d7cb, which are the joins where both paths of each function meet. As with the six stores, each window's bytes are compared before anything is written. All four were checked against the 1.0.2.1 executable. - `port_descriptors.rs` (diagnostics in the existing per-frame line): - It counts the `memcpy` calls into the heap that begin half into a slot, and the view records they put half into one. - A writer outside the title is named by module and offset (`VCRUNTIME140.dll+0x1c26f`). When the word on top of its stack is in the title, the title code that called it is named too. - `watch.rs` passes that word from the fault's context. - Switch: none new. All of this is under `VICTORY_PORT_DESCRIPTORS=1`, which is off by default. ## Where it does nothing - Without `VICTORY_PORT_DESCRIPTORS=1` nothing is patched (`run.rs` applies the sites only with the switch). - Another build of the title: a window whose bytes differ is left alone and logged, as for the six stores. - The hooked code runs after the fill, so the title's own writes are unchanged. Only port 2's marks are added. The tests check that each window leaves the same registers whether hooked or not. ## Measured RTX 2070 SUPER 8 GB, Ryzen 7 5800X, 32 GB, Windows 11, diag build, `scripts\play.ps1` with `VICTORY_PORT_CONSTANTS=1 VICTORY_PORT_DESCRIPTORS=1 VICTORY_PORT_CBV=1 VICTORY_PORT_GUARD=1 VICTORY_PORT_JOURNAL=1`, 7 minutes from start (into the first world cell at 1-3 fps). Main was c9c932c. "After" had the +0x4d9f200 site only; the three callback sites came later and have not been run. | port 2's line | main | +0x4d9f200 site | |---|---|---| | view records missed / slots told | 46,744 / 32.6 M (1.44 per 1000) | 33,645 / 50.2 M (0.67 per 1000) | | missed per line (every 8th frame looked at): mean, worst | 103, 496 | 60, 234 | | `memcpy` calls into the heap a frame (records they marked) | ~5,600 (0) | ~5,900 (0) | | of them half into a slot (view records put half into one) | n/a | ~3,300 (0) | - The site halves the misses but does not remove them. No `memcpy` into the heap carries a view record, either at a slot's start or 16 bytes into one, so the copies the wrapper sees are other data. What is left has to be written by other code with its own stores. The callback sites are my best guess at that code, from reading the callers of the table allocator (+0x4d9f3e0). - The picture was not compared: at 1-3 fps, with about 1,100 draws a frame dropped for lack of a host pipeline, the run says nothing about indirect light. ## Checks - `cargo test -p victory-loader --locked`: 54 passed. New tests: - `a_range_site_marks_every_slot_its_table_overlaps` runs each of the four windows in test code, plain and hooked, with all 16 registers set. It compares the registers both leave, checks that the moved `rip`-relative load reads the same value, and checks the marks for half-slot, past-the-end, outside-the-heap and zero-size tables. - `a_moved_load_reads_the_same_address` and `a_range_stub_refuses_the_registers_it_uses`. - `cargo test -p victory-gpu --locked`: 381 passed, 34 ignored. - `cargo clippy --workspace --all-targets --locked -- -D warnings`: stops on main's existing `missing_transmute_annotations` in the old `a_hooked_site_stores_and_marks_its_slot` test (`descriptor_sites.rs:482`), which this PR does not change. #169 and others fix it. Without `-D warnings`, nothing in the changed code. - `cargo xtask policy`: 265 files ok. - In game: the runs above (RTX 2070 SUPER). All sites reported patched, and the run with the first site had no crash or device loss. ## Not checked - The three callback sites in game. One run like the one above would show whether the misses fall further. Without such a run, the main risk is cost: if those tables are mostly constants, port 2 compares some extra KB a frame. - The 7900 XTX of #301, and whether indirect light comes back there with ports 1, 2, 3, 6 and 7 on. That is the most useful check. - Further callers of the allocator, left out: +0x4f4371 (256-byte aligned, filled in a loop), +0x2490da0 (reached through a virtual table) and +0x555e570 (a fixed 100 bytes). ## Related - #273 (port 2: a heap that goes takes its fallback pages with it) edits `let_go` and the tests in `port_descriptors.rs`. This PR touches neither, and the two rebase onto each other without conflict (checked on a branch carrying both). This change was made with AI assistance (Claude Code).
The fallback of VICTORY_PORT_DESCRIPTORS=1 found 290-410 view records a
frame that no mark told of. +0x4d9f200 copies a ready list of records into a
table of the frame allocator with four `vmovups [rbx+disp]` (128 bytes) or
the imported memcpy, and +0x4e51a90, +0x248d6d0 and +0x248d780 have a
callback fill one. Each is hooked where it goes on once the table is filled
(Kind::Range): every slot of [table, table+size) is marked. A moved
`mov eax, [rip+x]` is done from its address (Moved::LoadEax).

Diagnostics: port 2's line counts memcpy calls that begin half into a slot
and the view records they put there (run: ~3,300 calls a frame, 0 records),
and a writer outside the title is named by module, with the title code that
called it when the top of its stack is in the title.

RTX 2070, ports 1,2,5,6,7, 7 min: misses 1.44 per 1000 slots told on main,
0.67 with the first of the four sites.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 18:52:01 +00:00
Author
Owner

@⁠Sr-0w on GitHub · 2026-11-26 20:57 UTC · original

Tested on RDNA 3 (RX 7800 XT 16 GB, i9-12900K, 64 GB, Windows 11), Series X, ray tracing on, renderer ports 1, 2, 5, 6, 7 on, warm cache, diagnostics build of origin/main 2de9980 + this PR + #273, a retail game's opening and the boat scene (480 s runs).

  • All ten sites patched (0x4d9f059 0x4d9f117 0x4d9f1a8 0x4d9f272 0x4e51aee 0x248d71b 0x248d7cb 0x4eec968 0x4eeca12 0x4eeca8d), no "not patched", no crash or device loss.
  • Port 2's fallback, last 90 s on the boat: view records missed 191 → 101 a frame (main: 191; the +0x4d9f200 site alone, from a local build of mine: 122). Fallback time 5.47 → 5.37 ms a frame.
  • Frame: 9.7 fps / 103.0 ms (reference 9.8 / 102.8): no cost.
  • Picture: the boat scene is complete; no new defect seen.

About half the misses are left. On this machine they come one per 128 KiB of the frame allocator, at the same place in each block (slots 4096 apart), which looks like one more writer that starts each block. A hardware write watch armed on the next block's slot caught only the patched stores and the hooked memcpy (which mark), so the remaining writer is not found yet.

**@⁠Sr-0w** on GitHub · 2026-11-26 20:57 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/359#issuecomment-7203246794) Tested on RDNA 3 (RX 7800 XT 16 GB, i9-12900K, 64 GB, Windows 11), Series X, ray tracing on, renderer ports 1, 2, 5, 6, 7 on, warm cache, diagnostics build of `origin/main` 2de9980 + this PR + #273, a retail game's opening and the boat scene (480 s runs). - All ten sites patched (`0x4d9f059 0x4d9f117 0x4d9f1a8 0x4d9f272 0x4e51aee 0x248d71b 0x248d7cb 0x4eec968 0x4eeca12 0x4eeca8d`), no "not patched", no crash or device loss. - Port 2's fallback, last 90 s on the boat: **view records missed 191 → 101 a frame** (main: 191; the +0x4d9f200 site alone, from a local build of mine: 122). Fallback time 5.47 → 5.37 ms a frame. - Frame: 9.7 fps / 103.0 ms (reference 9.8 / 102.8): no cost. - Picture: the boat scene is complete; no new defect seen. About half the misses are left. On this machine they come one per 128 KiB of the frame allocator, at the same place in each block (slots 4096 apart), which looks like one more writer that starts each block. A hardware write watch armed on the next block's slot caught only the patched stores and the hooked `memcpy` (which mark), so the remaining writer is not found yet.
Author
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-26 21:02 UTC · original

Thanks, this is the run I couldn't do here (my card drops ~1,100 draws a frame, so the picture told me nothing). 191 → 101 with the +0x4d9f200 site alone at 122 is the first measurement of the three callback sites (+0x4e51aee, +0x248d71b, +0x248d7cb), so they carry about 20 a frame of the remainder.

Main has since moved under this PR: 4da7c0b and 8eaf2dc hook the same +0x4d9f200 copy (VICTORY_PORT_COPIES=1, opt-in since 4aeb6d0), and 8eaf2dc moved its hook off +0x4d9f272 after a privileged-instruction stop there. I'll rebase: drop this PR's +0x4d9f200 site in favour of main's and keep the three callback sites, then ask for a re-run on main with VICTORY_PORT_COPIES=1.

The one-per-128-KiB pattern at the same slot in each block is a good lead: it points at whatever starts a block of the frame allocator (+0x4d9f3e0's callers) writing a record at a fixed offset before handing it out. I'll look there next.

**@⁠Jesper-Andersson** on GitHub · 2026-11-26 21:02 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/359#issuecomment-7203322010) Thanks, this is the run I couldn't do here (my card drops ~1,100 draws a frame, so the picture told me nothing). 191 → 101 with the +0x4d9f200 site alone at 122 is the first measurement of the three callback sites (+0x4e51aee, +0x248d71b, +0x248d7cb), so they carry about 20 a frame of the remainder. Main has since moved under this PR: 4da7c0b and 8eaf2dc hook the same +0x4d9f200 copy (`VICTORY_PORT_COPIES=1`, opt-in since 4aeb6d0), and 8eaf2dc moved its hook off +0x4d9f272 after a privileged-instruction stop there. I'll rebase: drop this PR's +0x4d9f200 site in favour of main's and keep the three callback sites, then ask for a re-run on `main` with `VICTORY_PORT_COPIES=1`. The one-per-128-KiB pattern at the same slot in each block is a good lead: it points at whatever starts a block of the frame allocator (+0x4d9f3e0's callers) writing a record at a fixed offset before handing it out. I'll look there next.
Author
Owner

@⁠Sr-0w on GitHub · 2026-11-26 21:56 UTC · original

Follow-up: most of the misses left after this PR came from the memcpy wrapper itself. It marked a slot only when the copy wrote the slot's first word, so copies that rewrite a record's later words marked nothing, which is why 0 records they marked showed up. #384 fixes that: on top of this PR and #273 (RX 7800 XT), missed view records fall from 101 to 6 a frame. #385 adds the hardware-watch trace used to find it (stacked on this PR for place()).

**@⁠Sr-0w** on GitHub · 2026-11-26 21:56 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/359#issuecomment-7204202343) Follow-up: most of the misses left after this PR came from the `memcpy` wrapper itself. It marked a slot only when the copy wrote the slot's first word, so copies that rewrite a record's later words marked nothing, which is why `0 records they marked` showed up. #384 fixes that: on top of this PR and #273 (RX 7800 XT), missed view records fall from 101 to 6 a frame. #385 adds the hardware-watch trace used to find it (stacked on this PR for `place()`).
Author
Owner

@⁠Jesper-Andersson on GitHub · 2026-11-27 00:04 UTC · original

Thanks, that explains the 0 records they marked. This PR's own counters were pointing at the same copies: it counts the title's memcpy calls that begin half into a slot and the view records they put half into one, but only counts them and marks nothing new. #384 is the part that marks them.

Ran this PR + #384 on 8 GB NVIDIA: RTX 2070 SUPER (driver 621.14), Ryzen 7 5800X, 32 GB, Windows 11. Build: main 014d52d + this PR + #384 + #203 (DLSS), diagnostics, play.ps1 settings, Series S with DLSS, VICTORY_PORT_DESCRIPTORS=1, VICTORY_PORT_COPIES unset. One run, about 2 minutes in the world:

per frame, in the world here your RX 7800 XT (this PR + #273, then + #384)
view records no store told of 0-8.7, mostly 0 (876 over the run) 101 -> 6
records the title's copies marked 1,000-2,440 0 -> 1,844
fallback 0-1.6 ms 5.37 -> 3.96 ms
  • All ten sites patched, no "not patched", no crash.
  • 1,700-3,400 copies a frame begin half into a slot, but they put 0 view records half into one, so the misses #384 fixes are the copies into a record's later words, as you found.
  • On screen: some shading artifacts, not severe, and textures that turn black and then come back. Whether those are the few records still missed or something else (streaming), this run doesn't tell. 2.0-3.4 fps at 3,400-6,350 draws a frame.
  • Not run here: this PR alone on 014d52d, so this doesn't separate #384's share on this card.

Against current main, this PR needs the rebase announced above in two places: its counters for copies half into a slot (COPIES[2..3]) and main's TITLE_COPIES (4da7c0b) share the per-frame line, and main's COPY_128 site needs this PR's new kind field to build. #384 then applies on top with one small conflict, where its slot loop replaces the old one.

This comment was written with AI assistance (Claude Code).

**@⁠Jesper-Andersson** on GitHub · 2026-11-27 00:04 UTC · [original](https://github.com/avatarmanz/VIctory-7900XTX/pull/359#issuecomment-7206148429) Thanks, that explains the `0 records they marked`. This PR's own counters were pointing at the same copies: it counts the title's `memcpy` calls that begin half into a slot and the view records they put half into one, but only counts them and marks nothing new. #384 is the part that marks them. Ran this PR + #384 on 8 GB NVIDIA: RTX 2070 SUPER (driver 621.14), Ryzen 7 5800X, 32 GB, Windows 11. Build: main `014d52d` + this PR + #384 + #203 (DLSS), diagnostics, `play.ps1` settings, Series S with DLSS, `VICTORY_PORT_DESCRIPTORS=1`, `VICTORY_PORT_COPIES` unset. One run, about 2 minutes in the world: | per frame, in the world | here | your RX 7800 XT (this PR + #273, then + #384) | |---|---|---| | view records no store told of | 0-8.7, mostly 0 (876 over the run) | 101 -> 6 | | records the title's copies marked | 1,000-2,440 | 0 -> 1,844 | | fallback | 0-1.6 ms | 5.37 -> 3.96 ms | - All ten sites patched, no "not patched", no crash. - 1,700-3,400 copies a frame begin half into a slot, but they put 0 view records half into one, so the misses #384 fixes are the copies into a record's later words, as you found. - On screen: some shading artifacts, not severe, and textures that turn black and then come back. Whether those are the few records still missed or something else (streaming), this run doesn't tell. 2.0-3.4 fps at 3,400-6,350 draws a frame. - Not run here: this PR alone on `014d52d`, so this doesn't separate #384's share on this card. Against current main, this PR needs the rebase announced above in two places: its counters for copies half into a slot (`COPIES[2..3]`) and main's `TITLE_COPIES` (4da7c0b) share the per-frame line, and main's `COPY_128` site needs this PR's new `kind` field to build. #384 then applies on top with one small conflict, where its slot loop replaces the old one. This comment was written with AI assistance (Claude Code).
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/port_descriptors.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/359/head:github-bot/gh-359'
git switch 'github-bot/gh-359'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-359'
git switch 'github-bot/gh-359'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-359'
git switch 'github-bot/gh-359'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-359'
git switch 'main'
git merge --squash 'github-bot/gh-359'
git switch 'main'
git merge --ff-only 'github-bot/gh-359'
git switch 'main'
git merge 'github-bot/gh-359'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No description provided.