Port 2: ~98% of the fallback's "view records no store told of" have the same 12-byte head as before; the memcpy/memmove hook marks 0 records #519

Open
opened 2026-11-27 08:15:28 +00:00 by github-bot · 0 comments
Owner

@⁠adrianmjim on GitHub · 2026-11-27 08:10 UTC · original

Follow-up to #338 and #354. On RDNA3 with #354, the port 2 fallback still reports ~138 view records no store told of per frame (see my last comment on #338). I added counters to see which records those are. Almost none have a new head. The slot still holds the same 12-byte head port 2 saw last time, and only bytes after the head changed.

Links are to a-publier 4eb6cfd.

Setup

  • Machine and settings as in my #338 runs: RX 7900 XT (RDNA3), driver 32.0.32029.2010, Windows 11 26300, --console series-s, scripts/play.ps1 defaults plus the five VICTORY_PORT_*=1, warm pipeline cache.
  • Build: cd8dfc0 + #354 (4ad8527) + a local patch on port_descriptors.rs and descriptor.rs. The patch only adds counters. Which slots are made, and how, is unchanged.
  • Route: title screen, then the opening cutscene for ~4 min with no input, then close the window. One run.
  • Window: from the first frame of 500 draws or more to window closed. 262.8 s, 3,893 frames by the frame counter, median 15.15 fps. No ERROR, panic or device removal.

What the patch counts

  • Head key. record() writes 12 bytes: [VIEW_TAG, i, generation] (descriptor.rs:1461). For placed and constant views, words 1-2 hold an address payload and the kind instead.
    • The sync loop flags a slot when any of its 32 bytes differ from the last-seen copy. The fallback then counts it as a view if word 0 is VIEW_TAG (descriptor.rs:541-543).
    • The patch keeps one key per slot: words 1-2 of the head as port 2 last saw them. The sync loop updates it for every changed slot, marked or not.
    • In missed(), after the existing marked() check, a view whose key equals the last one counts as "same head" and returns. Everything else reaches CHECKED[1], MISSED_ALL, WRITERS and the WARN as before. Keys start at 0, meaning "not seen yet", so a head port 2 sees for the first time also counts as changed.
  • Exact writer. faulted() also stores the fault address per 64 KiB block. A missed record counts as "exact" when the latest opening fault of its block fell inside its 12-byte head.
  • Copy offsets. In the memcpy/memmove hook (copied()), each copy into the heap is sorted by where it starts in its 32-byte slot. For copies that start mid-slot, it also counts those whose slot has VIEW_TAG in word 0 after the copy.

Results

Per-line values are medians of the port 2 lines in the window. Since-start values are the counter deltas over the window divided by 3,893 frames.

per frame
views found with the same head as last seen 134.8 (since start: 525,737, i.e. 135.0)
views with a changed head: what now counts as missed 2.0 (since start: 8,344, i.e. 2.14)
of the changed-head ones, of draws' tables 0.59
same + changed 136.9 (the #354 run without the patch: 138.3)
hooked title memcpy/memmove calls landing in the heap 2,932
of them starting at slot +0 / +16 / any other offset (separate medians) 1,288 / 1,684 / 0
of the +16 ones, in a slot with VIEW_TAG in word 0 after the copy 1,017
records the hook marked 0, in every port 2 line of this run and of both #338 runs (326 + 308 + 3,287 lines)
changed heads whose block's latest opening fault was in the head 2 in the whole run, both at 0x7ffc69f3c2ca (not the title's)
fallback time 0.68 ms

What I read from it

  1. ~98.4% of what port 2 has been counting as missed view records keep the same head. This is 525,737 of 534,081 over the window. Their 12-byte head equals the one port 2 last saw in that slot, and only bytes 12..31 changed.

    • This fits the title's memcpy/memmove. All ~1,700 hooked copies a frame that start mid-slot start at +16, and ~1,000 of them land in a slot that holds a view head.
    • I did not tie these copies to the slots the fallback found, so other writers can't be excluded.
    • mirror() reads only bytes 0..11, so remaking such a view makes the same view again. It is lock-free when the host slot was made at once from that key (host.rs:3282-3288).
    • Otherwise it takes the locked path again: buffer, constant or placed views, or textures still waiting. I have not measured that cost.
    • The count, the their writers list and the WARN lines are built on these same-head records, so they overstate what port 2 misses by ~64x (534,081 / 8,344).
  2. The memcpy/memmove hook has not marked a single record in any of my runs. It is bound and called: it sees ~2,900 copies into the heap a frame.

    • Its 32-byte grid and MARKS map are the ones the stubs and the fallback use, so this is not a stride bug.
    • None of the copies it sees leaves a view head at a slot start. That includes ~1,300 a frame that start at +0.
    • The reason for it, in the doc comment at port_descriptors.rs:451-455, is that the runtime's memcpy was among the last writers of the blocks. That list keeps one writer per 64 KiB block and says nothing about the record itself.
    • On this boot, the non-title writer that topped the list in the #338 runs (0x7ffc69f3c26f) falls inside System32 VCRUNTIME140.dll. The DLL's base is 0x7ffc69f20000, and its memcpy export at +0x1f020 jumps to +0x1c010. The entries at +0x1c141..+0x1c2ca are in that routine.
    • VIctory's own Rust code and host DLLs call the same routine, and the hook cannot see those calls. So a fault rip there does not mean the title's imported memcpy did the write.
    • After the patch, the top writer for changed heads is title+0x18849c, at 3,744 against 1,414 at the end of the window.
  3. The ~2 changed heads per frame do not look like new record() writes. 29 WARN lines in the run carry old_key/new_key; 27 fall in the window. They are the first 20 plus powers of two, so the sample is front-loaded. In 21 of the 27 window lines the old head is a placed or constant view, where words 1-2 are an address payload. In those 27 lines:

    • In 20, word 1 became 0 or a small value (2..0xa). For the 3 table views among them, word 1 is the entry index. Example: 0x804eab000fbfc280 → 0x804eab0000000000.
    • In 5, word 2 became an address inside the heap, 0x18 below the end of a 64 KiB block: the slot's own block in 3, the next one in 2. Example: 0x1000016fc → 0xe55ffe8000016fc.
    • In 2, word 2 became a value outside the heap.
    • Several of the old heads already named memory next to their own slot inside the heap. So these slots may hold other data, not descriptors, both before and after. That is a hypothesis.

    What the current code makes of them:

    • A placed or constant head goes to the wait list and later decodes to a view of the new address. constant_of accepts any words, and placed_of only checks that the shape number exists.
    • An overwritten word 2 makes the kind 0 with a bogus generation, so view_at fails and the slot is nulled.
    • A table head whose index became 0 decodes to entry 0's view if entry 0 is still at that generation. That could put an unrelated view in the slot, if the title ever reads it as a descriptor. I have not checked whether it does.

Suggestions

  • Count a view as missed only when its head changed. This is a counting change only. The per-slot key above is ~25 lines without the diagnostics. It costs 8 bytes per slot, ~9.5 MiB for this heap's 1,245,184 slots, leaked like the other maps. The alternative is to have changed_records/safecopy::changed report a head change themselves, since they overwrite the last-seen copy as they compare. Either way, view records missed, their writers and the WARN would then mean what they say.
  • Consider a switch for the memcpy/memmove hook that defaults to off. It has marked nothing on the title screen and in the opening cutscene. If gameplay copies whole records with memcpy, removing it would leave those to the fallback, so check gameplay before deleting it. Every title memcpy/memmove call goes through the wrapper, not only the ~2,900 into the heap; I did not measure the cost.
  • A question: should the fallback leave alone a slot whose head changed in a way no record() call could have written? view_at/constant_of/placed_of cannot tell that from the head alone, so it would need another signal.

I can open a PR against a-publier with the counting change and the counters, if that helps.

Not tested

  • One run, opening cutscene only, RDNA3 only.
  • Which writer changes bytes 12..31 of each same-head slot, slot by slot.
  • Whether a draw reads any of the changed-head slots afterwards.
**@⁠adrianmjim** on GitHub · 2026-11-27 08:10 UTC · [original](https://github.com/Belobug/VIctory-Belobug-AMD/issues/519) Follow-up to #338 and #354. On RDNA3 with #354, the port 2 fallback still reports ~138 `view records no store told of` per frame (see my last comment on #338). I added counters to see which records those are. Almost none have a new head. The slot still holds the same 12-byte head port 2 saw last time, and only bytes after the head changed. Links are to a-publier 4eb6cfd. ### Setup - Machine and settings as in my #338 runs: RX 7900 XT (RDNA3), driver 32.0.32029.2010, Windows 11 26300, `--console series-s`, `scripts/play.ps1` defaults plus the five `VICTORY_PORT_*=1`, warm pipeline cache. - Build: cd8dfc0 + #354 (4ad8527) + a local patch on `port_descriptors.rs` and `descriptor.rs`. The patch only adds counters. Which slots are made, and how, is unchanged. - Route: title screen, then the opening cutscene for ~4 min with no input, then close the window. One run. - Window: from `the first frame of 500 draws or more` to `window closed`. 262.8 s, 3,893 frames by the frame counter, median 15.15 fps. No ERROR, panic or device removal. ### What the patch counts - **Head key.** `record()` writes 12 bytes: `[VIEW_TAG, i, generation]` ([descriptor.rs:1461](https://github.com/Belobug/VIctory-Belobug-AMD/blob/4eb6cfd/crates/victory-gpu/src/descriptor.rs#L1461)). For placed and constant views, words 1-2 hold an address payload and the kind instead. - The sync loop flags a slot when any of its 32 bytes differ from the last-seen copy. The fallback then counts it as a view if word 0 is `VIEW_TAG` ([descriptor.rs:541-543](https://github.com/Belobug/VIctory-Belobug-AMD/blob/4eb6cfd/crates/victory-gpu/src/descriptor.rs#L541-L543)). - The patch keeps one key per slot: words 1-2 of the head as port 2 last saw them. The sync loop updates it for every changed slot, marked or not. - In `missed()`, after the existing `marked()` check, a view whose key equals the last one counts as "same head" and returns. Everything else reaches `CHECKED[1]`, `MISSED_ALL`, `WRITERS` and the WARN as before. Keys start at 0, meaning "not seen yet", so a head port 2 sees for the first time also counts as changed. - **Exact writer.** `faulted()` also stores the fault address per 64 KiB block. A missed record counts as "exact" when the latest opening fault of its block fell inside its 12-byte head. - **Copy offsets.** In the memcpy/memmove hook (`copied()`), each copy into the heap is sorted by where it starts in its 32-byte slot. For copies that start mid-slot, it also counts those whose slot has `VIEW_TAG` in word 0 after the copy. ### Results Per-line values are medians of the port 2 lines in the window. Since-start values are the counter deltas over the window divided by 3,893 frames. | | per frame | |---|---| | views found with the **same head** as last seen | 134.8 (since start: 525,737, i.e. 135.0) | | views with a **changed head**: what now counts as missed | 2.0 (since start: 8,344, i.e. 2.14) | | of the changed-head ones, of draws' tables | 0.59 | | same + changed | 136.9 (the #354 run without the patch: 138.3) | | hooked title memcpy/memmove calls landing in the heap | 2,932 | | of them starting at slot +0 / +16 / any other offset (separate medians) | 1,288 / 1,684 / 0 | | of the +16 ones, in a slot with `VIEW_TAG` in word 0 after the copy | 1,017 | | records the hook marked | 0, in every port 2 line of this run and of both #338 runs (326 + 308 + 3,287 lines) | | changed heads whose block's latest opening fault was in the head | 2 in the whole run, both at `0x7ffc69f3c2ca` (not the title's) | | fallback time | 0.68 ms | ### What I read from it 1. **~98.4% of what port 2 has been counting as missed view records keep the same head.** This is 525,737 of 534,081 over the window. Their 12-byte head equals the one port 2 last saw in that slot, and only bytes 12..31 changed. - This fits the title's memcpy/memmove. All ~1,700 hooked copies a frame that start mid-slot start at +16, and ~1,000 of them land in a slot that holds a view head. - I did not tie these copies to the slots the fallback found, so other writers can't be excluded. - `mirror()` reads only bytes 0..11, so remaking such a view makes the same view again. It is lock-free when the host slot was made at once from that key ([host.rs:3282-3288](https://github.com/Belobug/VIctory-Belobug-AMD/blob/4eb6cfd/crates/victory-gpu/src/descriptor/host.rs#L3282-L3288)). - Otherwise it takes the locked path again: buffer, constant or placed views, or textures still waiting. I have not measured that cost. - The count, the `their writers` list and the WARN lines are built on these same-head records, so they overstate what port 2 misses by ~64x (534,081 / 8,344). 2. **The memcpy/memmove hook has not marked a single record in any of my runs.** It is bound and called: it sees ~2,900 copies into the heap a frame. - Its 32-byte grid and `MARKS` map are the ones the stubs and the fallback use, so this is not a stride bug. - None of the copies it sees leaves a view head at a slot start. That includes ~1,300 a frame that start at +0. - The reason for it, in the doc comment at [port_descriptors.rs:451-455](https://github.com/Belobug/VIctory-Belobug-AMD/blob/4eb6cfd/crates/victory-gpu/src/port_descriptors.rs#L451-L455), is that the runtime's `memcpy` was among the last writers of the blocks. That list keeps one writer per 64 KiB block and says nothing about the record itself. - On this boot, the non-title writer that topped the list in the #338 runs (`0x7ffc69f3c26f`) falls inside System32 `VCRUNTIME140.dll`. The DLL's base is `0x7ffc69f20000`, and its `memcpy` export at +0x1f020 jumps to +0x1c010. The entries at +0x1c141..+0x1c2ca are in that routine. - VIctory's own Rust code and host DLLs call the same routine, and the hook cannot see those calls. So a fault rip there does not mean the title's imported memcpy did the write. - After the patch, the top writer for changed heads is `title+0x18849c`, at 3,744 against 1,414 at the end of the window. 3. **The ~2 changed heads per frame do not look like new `record()` writes.** 29 WARN lines in the run carry `old_key`/`new_key`; 27 fall in the window. They are the first 20 plus powers of two, so the sample is front-loaded. In 21 of the 27 window lines the old head is a placed or constant view, where words 1-2 are an address payload. In those 27 lines: - In 20, word 1 became 0 or a small value (2..0xa). For the 3 table views among them, word 1 is the entry index. Example: `0x804eab000fbfc280` → `0x804eab0000000000`. - In 5, word 2 became an address inside the heap, 0x18 below the end of a 64 KiB block: the slot's own block in 3, the next one in 2. Example: `0x1000016fc` → `0xe55ffe8000016fc`. - In 2, word 2 became a value outside the heap. - Several of the old heads already named memory next to their own slot inside the heap. So these slots may hold other data, not descriptors, both before and after. That is a hypothesis. What the current code makes of them: - A placed or constant head goes to the wait list and later decodes to a view of the new address. `constant_of` accepts any words, and `placed_of` only checks that the shape number exists. - An overwritten word 2 makes the kind 0 with a bogus generation, so `view_at` fails and the slot is nulled. - A table head whose index became 0 decodes to entry 0's view if entry 0 is still at that generation. That could put an unrelated view in the slot, if the title ever reads it as a descriptor. I have not checked whether it does. ### Suggestions - **Count a view as missed only when its head changed.** This is a counting change only. The per-slot key above is ~25 lines without the diagnostics. It costs 8 bytes per slot, ~9.5 MiB for this heap's 1,245,184 slots, leaked like the other maps. The alternative is to have `changed_records`/`safecopy::changed` report a head change themselves, since they overwrite the last-seen copy as they compare. Either way, `view records missed`, `their writers` and the WARN would then mean what they say. - **Consider a switch for the memcpy/memmove hook that defaults to off.** It has marked nothing on the title screen and in the opening cutscene. If gameplay copies whole records with memcpy, removing it would leave those to the fallback, so check gameplay before deleting it. Every title memcpy/memmove call goes through the wrapper, not only the ~2,900 into the heap; I did not measure the cost. - **A question:** should the fallback leave alone a slot whose head changed in a way no `record()` call could have written? `view_at`/`constant_of`/`placed_of` cannot tell that from the head alone, so it would need another signal. I can open a PR against a-publier with the counting change and the counters, if that helps. ### Not tested - One run, opening cutscene only, RDNA3 only. - Which writer changes bytes 12..31 of each same-head slot, slot by slot. - Whether a draw reads any of the changed-head slots afterwards.
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-27 08:15:28 +00:00
This discussion has been locked. Commenting is limited to contributors.
No description provided.