gpu(replay): support in-place vtable hooks for Wine/vkd3d-proton recording #113

Manually merged
github merged 1 commit from gh-pr/113/head into gh-pr/113/base 2026-12-01 20:10:25 +00:00
Owner

@⁠Androtim on GitHub · 2026-11-29 11:45 UTC · original
Androtim:feat/iter114-replay-inplace-wine-hooks → main · +237 −6 · 2 files · 1 commits · merged 2026-11-29 14:32 UTC

Summary

  • Add in-place COM vtable hooking in crates/victory-gpu/src/replay/hook.rs (active automatically under Wine via ntdll!wine_get_version unless VICTORY_RECORD_HOOK=copy, or opt-in on native Windows via VICTORY_RECORD_HOOK=inplace) so vkd3d-proton objects retain their original vtable identity pointers during VICTORY_RECORD captures.
  • Add address-keyed state_of lookup and guard execute() / of() in crates/victory-gpu/src/replay/record.rs so unrecorded COM objects sharing the patched class vtable pass cleanly through to the original method.
  • Preserve copy-shim testing and add in_place_the_class_table_changes_and_the_old_methods_stay_callable.
  • Adapted from cool_fox commit df0b5e40 (GPL-3.0).

Verification

  • cargo +1.98.1-x86_64-pc-windows-gnu xtask policy -> asset policy: 303 files ok
  • cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib --features diagnostics --locked -- replay:: -> test result: ok. 29 passed; 0 failed; 0 ignored; 0 measured; 581 filtered out; finished in 0.24s
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings -> 0 warnings
  • cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics --locked -- -D warnings -> 0 warnings
**@⁠Androtim** on GitHub · 2026-11-29 11:45 UTC · [original](https://github.com/Androtim/MiniVI/pull/113) `Androtim:feat/iter114-replay-inplace-wine-hooks` → `main` · +237 −6 · 2 files · 1 commits · merged 2026-11-29 14:32 UTC ## Summary - Add in-place COM vtable hooking in `crates/victory-gpu/src/replay/hook.rs` (active automatically under Wine via `ntdll!wine_get_version` unless `VICTORY_RECORD_HOOK=copy`, or opt-in on native Windows via `VICTORY_RECORD_HOOK=inplace`) so `vkd3d-proton` objects retain their original vtable identity pointers during `VICTORY_RECORD` captures. - Add address-keyed `state_of` lookup and guard `execute()` / `of()` in `crates/victory-gpu/src/replay/record.rs` so unrecorded COM objects sharing the patched class vtable pass cleanly through to the original method. - Preserve copy-shim testing and add `in_place_the_class_table_changes_and_the_old_methods_stay_callable`. - Adapted from `cool_fox` commit `df0b5e40` (GPL-3.0). ## Verification - `cargo +1.98.1-x86_64-pc-windows-gnu xtask policy` -> `asset policy: 303 files ok` - `cargo +1.98.1-x86_64-pc-windows-gnu test -p victory-gpu --lib --features diagnostics --locked -- replay::` -> `test result: ok. 29 passed; 0 failed; 0 ignored; 0 measured; 581 filtered out; finished in 0.24s` - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --locked -- -D warnings` -> `0 warnings` - `cargo +1.98.1-x86_64-pc-windows-gnu clippy --workspace --all-targets --features diagnostics --locked -- -D warnings` -> `0 warnings`
Patch COM class method tables in place under Wine (or VICTORY_RECORD_HOOK=inplace; VICTORY_RECORD_HOOK=copy preserves per-object shims) so vkd3d-proton retains its expected vtable identity pointers, dispatch unhooked calls through saved original tables, look up object state safely with state_of, and guard ExecuteCommandLists/list hooks when unrecorded objects pass through.

Adapted from cool_fox commit df0b5e40 (GPL-3.0).
github-bot locked as GitHub sync and limited conversation to collaborators 2026-12-01 20:10:21 +00:00
github manually merged commit b8abfbe04f into gh-pr/113/base 2026-12-01 20:10:25 +00:00
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 12:05 UTC · original

Automated triage for the maintainers (not an approval).

Verdict: needs-gpu-test · CI (check): passing

Review Summary

PR #113 adds an in-place COM vtable hooking mode (inplace()) to crates/victory-gpu/src/replay/hook.rs and guards unrecorded-object state lookups in crates/victory-gpu/src/replay/record.rs (execute, of), enabling VICTORY_RECORD captures under Wine/vkd3d-proton where replacing an object's vtable pointer breaks vkd3d-proton's vtable-identity checks.

What looks good

  • Safe default on native Windows: inplace() only activates automatically when ntdll!wine_get_version is present (overridable via VICTORY_RECORD_HOOK=copy|inplace), leaving native Windows copy-shim behavior unchanged by default.
  • In-place patching & forwarding: install_inplace() snapshots readable slots into a leaked copy in CLASSES and populates NOTED_ORIG before calling write_table() (VirtualProtect + write_volatile), so concurrent calls through the patched vtable see valid orig() and noted_inplace::<AT>() targets. noted_inplace preserves all Windows x64 ABI argument registers and tail-jumps cleanly.
  • Unrecorded objects: state_of() returns None for objects sharing a patched class vtable that were not passed to install(), and execute() / of() in record.rs pass those calls straight through to the original method.
  • Tests & CI: CI is passing, and in_place_the_class_table_changes_and_the_old_methods_stay_callable covers in-place patching, orig(), noted_inplace counting/forwarding, and ours() / state_of() isolation.

Non-blocking edge-case notes

  • In hook::again() (inplace() branch), if an unrecorded object (absent from STATES) swaps its vtable pointer (e.g., via list_reset), install_inplace(this, null, patch) inserts (this, 0) into STATES. state_of() still returns None (because at != 0), but ours(this) becomes true and a subsequent install() on that address would return false.
  • NOTED_ORIG is indexed by class * SLOTS + slot; if two distinct vtables of the same class (e.g., open vs. closed command-list vtables on native D3D12 with VICTORY_RECORD_HOOK=inplace) have different original targets for the same unrecorded slot, the second table's patch overwrites NOTED_ORIG for the first.
  • STATES is keyed by raw COM pointer and never pruned on Release, so pointer reuse after object destruction in inplace mode would retain stale state.

Verdict

needs-gpu-test — logic, security, and CI look solid, and the D3D12 COM vtable patching (VirtualProtect on runtime .rdata vtables + VICTORY_RECORD capture under VICTORY_RECORD_HOOK=inplace / Wine) warrants a local real-GPU smoke test before merging.


Generated with Antigravity CLI (agy).

**@⁠Androtim** on GitHub · 2026-11-29 12:05 UTC · [original](https://github.com/Androtim/MiniVI/pull/113#issuecomment-7255558594) <!-- minivi-triage v1 head=b8abfbe04f8679d61e9b36072eee31aeb7a55655 verdict=needs-gpu-test ci=passing at=2026-11-29T12:05:54Z --> Automated triage for the maintainers (not an approval). **Verdict:** `needs-gpu-test` · **CI (`check`):** `passing` ### Review Summary PR #113 adds an in-place COM vtable hooking mode (`inplace()`) to `crates/victory-gpu/src/replay/hook.rs` and guards unrecorded-object state lookups in `crates/victory-gpu/src/replay/record.rs` (`execute`, `of`), enabling `VICTORY_RECORD` captures under Wine/`vkd3d-proton` where replacing an object's vtable pointer breaks `vkd3d-proton`'s vtable-identity checks. ### What looks good - **Safe default on native Windows**: `inplace()` only activates automatically when `ntdll!wine_get_version` is present (overridable via `VICTORY_RECORD_HOOK=copy|inplace`), leaving native Windows copy-shim behavior unchanged by default. - **In-place patching & forwarding**: `install_inplace()` snapshots readable slots into a leaked copy in `CLASSES` and populates `NOTED_ORIG` *before* calling `write_table()` (`VirtualProtect` + `write_volatile`), so concurrent calls through the patched vtable see valid `orig()` and `noted_inplace::<AT>()` targets. `noted_inplace` preserves all Windows x64 ABI argument registers and tail-jumps cleanly. - **Unrecorded objects**: `state_of()` returns `None` for objects sharing a patched class vtable that were not passed to `install()`, and `execute()` / `of()` in `record.rs` pass those calls straight through to the original method. - **Tests & CI**: CI is passing, and `in_place_the_class_table_changes_and_the_old_methods_stay_callable` covers in-place patching, `orig()`, `noted_inplace` counting/forwarding, and `ours()` / `state_of()` isolation. ### Non-blocking edge-case notes - In `hook::again()` (`inplace()` branch), if an unrecorded object (absent from `STATES`) swaps its vtable pointer (e.g., via `list_reset`), `install_inplace(this, null, patch)` inserts `(this, 0)` into `STATES`. `state_of()` still returns `None` (because `at != 0`), but `ours(this)` becomes `true` and a subsequent `install()` on that address would return `false`. - `NOTED_ORIG` is indexed by `class * SLOTS + slot`; if two distinct vtables of the same class (e.g., open vs. closed command-list vtables on native D3D12 with `VICTORY_RECORD_HOOK=inplace`) have different original targets for the same unrecorded slot, the second table's patch overwrites `NOTED_ORIG` for the first. - `STATES` is keyed by raw COM pointer and never pruned on `Release`, so pointer reuse after object destruction in `inplace` mode would retain stale state. ### Verdict `needs-gpu-test` — logic, security, and CI look solid, and the D3D12 COM vtable patching (`VirtualProtect` on runtime `.rdata` vtables + `VICTORY_RECORD` capture under `VICTORY_RECORD_HOOK=inplace` / Wine) warrants a local real-GPU smoke test before merging. --- _Generated with Antigravity CLI (`agy`)._
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 12:44 UTC · original

Ran a live RTX 4060 Ti (Series S) --features diagnostics smoke test forcing VICTORY_RECORD_HOOK=inplace (VICTORY_RECORD + VICTORY_RECORD_AT=60 + VICTORY_RECORD_FRAMES=1) to verify runtime COM vtable VirtualProtect patching, noted_inplace thunk forwarding, and unrecorded-object pass-through on real D3D12 hardware:

  • Boot & 3D World Stability: Reached the 3D world (max_draws=12406, 7755+ presents) with 0 crashes, 0 panics, and 0 DRED/host-texture errors.
  • In-Place Hook & Recorder Flow: victory_gpu::replay::record activated (frame recorder on), victory_gpu::replay::snap armed list recording at presents=7711 and started frame capture at presents=7755, writing shaders.bin (115.6 MB) and contents.bin (2061.8 MB) without faulting or breaking unrecorded COM calls.
  • Visual Output: 8/8 captured frames lit (luma=105.47, near_black=0.0%, edge_energy=14.99, magenta=0.0%); visually inspected frame-7745.png and frame-7753.png.
  • Note: The capture was stopped at the 75s verifier cutoff mid-snapshot (deltas.bin/present.bin 0 bytes), and FPS/queue deltas (3.3 fps across 2 windows, 24421 waiting) reflect --features diagnostics overhead + writing a 2.08 GB frame snapshot during the window rather than runtime regression.

Note: Wine/vkd3d-proton auto-detection (ntdll!wine_get_version) remains unit-tested (replay::hook — 29 replay tests passing) and was not exercised on Linux/Wine in this Windows run.

**@⁠Androtim** on GitHub · 2026-11-29 12:44 UTC · [original](https://github.com/Androtim/MiniVI/pull/113#issuecomment-7256031491) Ran a live RTX 4060 Ti (Series S) `--features diagnostics` smoke test forcing `VICTORY_RECORD_HOOK=inplace` (`VICTORY_RECORD` + `VICTORY_RECORD_AT=60` + `VICTORY_RECORD_FRAMES=1`) to verify runtime COM vtable `VirtualProtect` patching, `noted_inplace` thunk forwarding, and unrecorded-object pass-through on real D3D12 hardware: - **Boot & 3D World Stability**: Reached the 3D world (`max_draws=12406`, `7755+` presents) with **0 crashes, 0 panics, and 0 DRED/host-texture errors**. - **In-Place Hook & Recorder Flow**: `victory_gpu::replay::record` activated (`frame recorder on`), `victory_gpu::replay::snap` armed list recording at `presents=7711` and started frame capture at `presents=7755`, writing `shaders.bin` (`115.6 MB`) and `contents.bin` (`2061.8 MB`) without faulting or breaking unrecorded COM calls. - **Visual Output**: `8/8` captured frames lit (`luma=105.47`, `near_black=0.0%`, `edge_energy=14.99`, `magenta=0.0%`); visually inspected `frame-7745.png` and `frame-7753.png`. - *Note*: The capture was stopped at the 75s verifier cutoff mid-snapshot (`deltas.bin`/`present.bin` 0 bytes), and FPS/queue deltas (`3.3 fps` across 2 windows, `24421` waiting) reflect `--features diagnostics` overhead + writing a `2.08 GB` frame snapshot during the window rather than runtime regression. _Note: Wine/`vkd3d-proton` auto-detection (`ntdll!wine_get_version`) remains unit-tested (`replay::hook` — 29 replay tests passing) and was not exercised on Linux/Wine in this Windows run._
Author
Owner

@⁠Androtim on GitHub · 2026-11-29 14:32 UTC · original

Automated RTX 4060 Ti 8 GB Wave 3 A/B hardware verification passed (playtest/wave3 vs origin/main c7ed150 — 5/5 A/B gates PASS):

  • Hardware cargo test (RTX 4060 Ti): victory-gpu 542 passed, 0 failed (36 ignored); victory-shader 323 passed, 0 Wave 3 regressions (the 3 PSV0 validation failures in emit::rect::tests and emit::barycentric_tests also fail identically on origin/main c7ed150).
  • Automated 45s in-world A/B (scripts/verify-world.ps1, DLSS Quality + golden autosave):
    • FPS: median 10.25 fps vs 10.7 fps baseline (min FPS improved 6.9 vs 4.2, preparing 45.35 ms vs 50.3 ms)
    • Stability: 0 crashes / 0 DRED / 0 untranslated shaders
    • VRAM: max 5948 MB vs 6073 MB (-125 MB, 0 MB over budget)
    • Texture backlog: final_waiting=5487 vs 7350 (-1863); no room for new ones 38 vs 43
    • Residency stalls: mapped_rate=20.95 ms/s vs 37.22 ms/s (-44%)
    • Visual check: Clean rendered frames (frame-10645.png, frame-10669.png), luma 82.77 vs 23.2, edge energy 2.27 vs 1.81, magenta 0.0%.
**@⁠Androtim** on GitHub · 2026-11-29 14:32 UTC · [original](https://github.com/Androtim/MiniVI/pull/113#issuecomment-7257388550) Automated RTX 4060 Ti 8 GB Wave 3 A/B hardware verification passed (`playtest/wave3` vs `origin/main` `c7ed150` — **5/5 A/B gates PASS**): - **Hardware `cargo test` (RTX 4060 Ti):** `victory-gpu` **542 passed, 0 failed** (36 ignored); `victory-shader` **323 passed, 0 Wave 3 regressions** (the 3 PSV0 validation failures in `emit::rect::tests` and `emit::barycentric_tests` also fail identically on `origin/main` `c7ed150`). - **Automated 45s in-world A/B (`scripts/verify-world.ps1`, DLSS Quality + golden autosave):** - **FPS:** median `10.25 fps` vs `10.7 fps` baseline (min FPS improved **`6.9`** vs `4.2`, preparing **`45.35 ms`** vs `50.3 ms`) - **Stability:** **0** crashes / **0** DRED / **0** untranslated shaders - **VRAM:** max **`5948 MB`** vs `6073 MB` (**-125 MB**, `0 MB` over budget) - **Texture backlog:** `final_waiting=5487` vs `7350` (**-1863**); `no room for new ones` `38` vs `43` - **Residency stalls:** `mapped_rate=20.95 ms/s` vs `37.22 ms/s` (**-44%**) - **Visual check:** Clean rendered frames (`frame-10645.png`, `frame-10669.png`), luma `82.77` vs `23.2`, edge energy `2.27` vs `1.81`, magenta `0.0%`.
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
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
github/Androtim--MiniVI!113
No description provided.