perf(gpu,hle): add opt-in in-place section heap import #3470
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3470"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-27T04:23:09Z.
Summary
This PR is now scoped to the opt-in in-place section heap path only. The descriptor marks, raw CBV reads, fine write guards and sharded journal from the earlier bundled commits have been split out; the current head does not enable any of those paths.
The title creates its pagefile-backed physical-page sections lazily by default. With
VICTORY_PORT_CONSTANTS=1, on a non-low-memory host, sections that fit the bounded budget are committed whole, tracked against a 512 MiB reservation, imported once as D3D12 placed buffers from an owned mapped view, and their mapped title views are fed into the existing memory page table. CPU writes by the title and UAV writes by the emulator then land in the same physical pages, and pages served in place do not schedule a host copy-back. The mapped view is unmapped when the import is dropped; the heap is not opened from the title's file-mapping handle, which leaked commit on Windows 11 26300.Default path
With
VICTORY_PORT_CONSTANTSoff (the default):title_memory_reserve_section()returnsfalse; no whole-sectionSEC_COMMITis requested.title_memory_section(),title_memory_view(),title_memory_freeing()andtitle_memory_section_gone()are early returns.Changes
victory-gpu::port: replace the inert/leaky open-region hook with bounded reservation/release, committed-section and mapped-view tracking, subrange-preserving remap bookkeeping, generation reporting and default-off early returns.victory-gpu::memory: import eligible sections once as placed buffers from an owned mapped view, add their views to the page table with section-relative offsets, mark those pagesIN_PLACEso copy-back is skipped, combine section changes into the table generation, use typed owner keys so a recycled handle cannot reuse an old descriptor pair, and drop imports and unmap views when the runtime closes a section.victory-hle::xmem: reserve/commit eligible sections only under the opt-in, fall back to lazySEC_RESERVEif the whole commit is refused, skip per-viewVirtualAlloccommits for sections already committed whole, release reservations on creation failure, and report mapped views through the existing hook.victory-gpu::watch: use the remap hook as an idempotent invalidation funnel for in-place views, preserving compatibility with remaps that do not pass throughxmem::unmap.IN_PLACEpages.Verification
cargo test --locked -p victory-gpu -p victory-hle -p victory-loader -p victory-shader: 236 passed, 3 failed, 1 ignored. The five new tests pass. The same three WARP/descriptor-cap failures (dynamic_slots_are_held_until_released,a_texture_written_in_one_format_reads_in_another_through_a_placed_view,lists_share_a_table_and_copies_keep_their_views) also occur on the unmodified PR headfb52e2a; they are not introduced here.cargo check --all-targets --locked: passed.cargo clippy --locked -p victory-gpu -p victory-hle -p victory-loader -p victory-shader --all-targets --all-features -- -D warnings: passed.cargo xtask policy: passed (192 files ok).A local RDNA4/gameplay reproduction is not available here, so the visual findings still need a reviewer rerun on this head with the switch off and on.
Overlap with #2494
This patch and #2494 both touch
xmem.rsandmemory.rs. They use the same hook points (title_memory_view,title_memory_remapped) and both keep the section commit bounded; this PR does not changewatch.rs. If both land, the remaining work is to choose one section-commit policy rather than stack two reservations.AI-assisted: local validation, summaries and reviewer reply prepared with the OpenCode harness; all reported commands were run locally.
Imported from Marvisak/VIctory. Originally posted by borosf on 2026-11-27T07:21:31Z.
@legayclightning22 — I compared the three in-place PRs in #880 (comment 7212390146). Two overlaps from it: this PR and #2494 both touch
xmem.rsandwatch.rs(yours changes the guards' lock to shared and journals per-block writes, #2494 adds a section hook), and the in-place heap here cannot be judged against the other two while it is bundled with the descriptor marks, raw CBV and journal — splitting it would let each part be decided on its own.Imported from Marvisak/VIctory. Originally posted by oddmaniv on 2026-11-27T08:19:02Z.
Independent verification of the PR author's concurrent WARP pipeline/draw test at
616b6f903ce51aebd056de4b9fc2196d59085007.cargo test --locked -p victory-shader --lib emit::host::tests::parallel_warp_pipelines_and_draws -- --exact --nocaptureMain baseline pin:
63bcca43c6a00a758510398fa43096ce7e4f7df0.Windows x86_64 MSVC native runs. Local and remote source snapshots matched before and after each check. The adaptation applies the PR diff without additional source edits.
This is focused regression coverage, not the full workspace suite, a gameplay test, or an independent validation of every behavior in the PR. No new fix is claimed.
AI-assisted verification.
Imported from Marvisak/VIctory. Originally posted by futurepro62 on 2026-11-27T10:06:24Z.
NVIDIA full-suite run, to go with the reports above by oddmaniv, since none of them names a GPU run. Tested exact head
616b6f9(on its base63bcca4).Tested
dxil.dllfrom Windows SDK 10.0.26100 (the loader's default), debug.cargo build --workspace --locked, thencargo test --workspace --locked --no-fail-fast -- --test-threads=4 --skip emit::memory_tests::heap_direct_texture_reads_mark_their_heap_index --skip descriptor::host::tests::dynamic_slots_are_held_until_released --skip memory::tests::lists_share_a_table_and_copies_keep_their_views --skip emit::stride_tests::a_heap_buffer_read_by_element_takes_the_views_stride --skip emit::stride_tests::a_heap_buffer_read_where_no_buffer_view_is_reads_zeros --skip emit::synthetic_tests::gathers_at_a_level_match_the_hardware: 887 passed, 0 failed, 10 ignored.caps_disable_low_hosts,only_32_bit_graphics_memory_is_wanted_with_the_switch,a_stretch_of_one_committed_section_is_found,raw_table_views_need_sixteen_bytes,raw_reads_follow_the_shader_switch,marks_layout_matches_the_loader,marked_slots_are_taken_once_as_runs,audit_pages_are_bounded_and_round_robin,plan_parts_keeps_marked_runs_and_check_pages_disjoint,ranges_name_their_parts,claims_are_per_shard_and_per_generation,advancing_settles_old_claims,without_the_switch_every_page_is_fresh,test_flags_are_thread_local,busy_claims_are_per_block,shared_guards_yield_to_a_writer,the_sites_lea_their_stores_address,byte_check_gates_every_site,other_bytes_are_left_alone,raw_root_cbv_needs_the_switch_and_a_root_descriptor,constants_raw_is_opt_in.--skipleaves out tests that fail on main63bcca4on this card too, not because of this PR:heap_direct_texture_reads_mark_their_heap_indexends thevictory-shadertest process with0xc0000005(#2571), so without the skip the rest of that crate never reports;dynamic_slots_are_held_until_released,lists_share_a_table_and_copies_keep_their_viewsand the twostride_testshit the 1,000,000-view heap cap of NVIDIA drivers (#1835, #2317);gathers_at_a_level_match_the_hardwarefails on lane 0 (#1744).Not tested
AI use
Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-27T13:41:36Z.
Thanks @borosf for checking the overlap with #880 and #2494. Splitting this makes total sense—I will separate the in-place graphics heap (
port.rs/xmem.rs) into its own focused PR so it can be judged independently against the other #880 approaches, and keep this PR scoped cleanly to the opt-in descriptor marks, raw CBV reads, fine write guards, and sharded submit journal.Imported from Marvisak/VIctory. Originally posted by rpmaster2 on 2026-11-27T18:07:02Z.
RDNA4 (RX 9070 XT, 32 GB): the PR regresses the world even with every flag off; with the ports on it is unplayable and the copies balloon.
Setup
host wave lanes min=32 max=64616b6f9,cargo build --locked --profile diag -p victory --features diagnostics(27.6 s)--console series-x,VICTORY_PRESENT_TARGET=1x1:1, scripted keys, nothing elsecache-upstream, built bytranslate --cache --pipelines28,164 pipelines), the driver's own shader cache emptied and the machine rebooted before the pair, so both runs start from the same stateMethod: two runs of 300 s, base first (no flags) and then with
VICTORY_PORT_CBV=1 VICTORY_PORT_GUARD=1 VICTORY_PORT_JOURNAL=1; private bytes, working set, free RAM, commit and page-file usage sampled every 20 s.Results
PORT_CBV/_GUARD/_JOURNALmain63bcca4, same machineMemory, sampled every 20 s:
What was on screen
main.That is with all port flags at their default (off) in the first run, which is the part I would look at first: on this card the PR changes the world even when the switches are not set. The signature (black, then white, subtitle text drawn over itself, very low draw counts) is the same one I saw when testing the in-place sections of #2494, so my guess is that the in-place heap or the descriptor marks are taking effect outside their flag, or that they change the copy path for ranges the switch was meant to leave alone. That is a guess from the outside; the logs above are the facts.
Also worth noting for the ports run: copies go up, not down (235-609 MB a frame against 76-203 MB in the base run and 465-994 MB on
main), anddroppedstays at 314-455 a frame, so the switches are not doing here what they do in the AMD fork on the same card, wherePORT_CBVand the journal were worth ~10 ms and the copies fell.What would help me help you
PORT_CBValone,PORT_GUARDalone andPORT_JOURNALalone, 5 minutes each, on the same save — I have the machine and the warm caches, it is ~15 minutes of runs;PORT_*all on 48.7-51.1 ms in a scene of ~3,000 draws, with the copies halved. So the idea is sound; what I see here is that this implementation, on RDNA4, does not reach that state.AI-assisted: written by DeepSeek (OpenCode harness) from my run logs; counts, switches and driver version only, no game files or paths.
Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-28T04:41:29Z.
Thanks @rpmaster2 and @borosf — pushed an updated commit gating every in-place heap and descriptor-mark path strictly behind its opt-in switch so default-off execution is identical to
upstream/mainand preventing redundant copy inflation when ports are enabled.Imported from Marvisak/VIctory. Originally posted by rpmaster2 on 2026-11-28T08:35:55Z.
RDNA4 (RX 9070 XT, 32 GB): the gating commit helps the default path but does not make it
main, and the ports still leave the character materials wrong. Four runs, old and fresh save.Setup: RX 9070 XT 16 GB, Adrenalin 26.11.2 (32.0.32029.2010), Ryzen 5 5600, 32 GB DDR4-3600, Windows 11 10.0.26100.9974. This PR at
fb52e2a,cargo build --locked --profile diag -p victory --features diagnostics(35.9 s).--console series-x,VICTORY_PRESENT_TARGET=1x1:1, shader and pipeline caches warm, driver cache emptied after a reboot. Each run 300 s, memory sampled every 20 s, and a person watching the screen (draw counters alone have fooled me before — see my correction in #2428).Two saves: old = the state we have used all week (prologue/interior), fresh =
7952987Amoved aside so the title's own first-run setup is redone, then played with scripted keys (Enterat 4, 8, 12, 16, 20, 25, 30, 40, 50, 60 s).The four runs
PORT_CBV+_GUARD+_JOURNALControl on the same machine,
main63bcca4, old save: 0.5-1.2 fps, 810-2,126 ms, 2,004-7,195 draws, copies 137-492 ms / 465-994 MB, private 26.2-27.6 GB, 5 black frames.What I take from it
mainyet. The white screen and the 627-1,953-draw collapse of616b6f9are gone; the new head draws 3,142-6,664 on the old save likemaindoes. But it logs 48 black frames wheremainlogs 5, and the picture is grey/black with overlapping subtitles, whichmaindoes not do on the same save. So "default-off execution identical toupstream/main" is not what this card sees.What I would try next, if useful
PORT_CBValone, then_GUARD, then_JOURNAL), 5 min each: on the old save the three together stall the menus, and it would be good to know which one does it.VICTORY_SHADER_SAVE, and whatever the fork'sVICTORY_TEXTURE_STOREequivalent is here); if the draw is there and the texture is not, that is a different bug from the one I can see from outside.maincomparison on the fresh save too, I can do that — I only have the old-save control so far.I have the machine and warm caches, so any of these is a 20-40 minute loop.
AI-assisted: written by DeepSeek (OpenCode harness) from my run logs and the observations of the person at the screen; counts and versions only, no game files or paths.
Imported from Marvisak/VIctory. Originally posted by legayclightning22 on 2026-11-28T20:53:53Z.
Thanks @rpmaster2 and @borosf. I have narrowed this PR to the opt-in in-place section heap only. The descriptor marks, raw CBV, fine guard and sharded journal work from the earlier bundled commits is no longer in this branch, so
PORT_CBV/PORT_GUARD/PORT_JOURNALruns no longer exercise this PR.@rpmaster2 — yes: the in-place path is intended to be completely inert without
VICTORY_PORT_CONSTANTS=1. In the updated head,title_memory_reserve_section()returnsfalse, the section/view hooks early-return, nothing is imported into D3D12, and no page-table entry or copy-back decision changes. Wine keeps its existing whole-commit policy, and GPU import still requires the opt-in reservation. The default-off residual you saw atfb52e2acame from the old inert/leaky open-region hook, which has now been removed.Could you rerun this head on the RDNA4 machine with:
VICTORY_PORT_CONSTANTS=1only, same save and warm caches?If the grey/black image and excess black frames remain in run 1, that is not this patch and I will help bisect it against
main. If the black skin / missing police / missing buildings remain in run 2, please capture the translated shader and texture view for the skin draw (VICTORY_SHADER_SAVEplus the texture-store equivalent) at the moment the skin is black; that will tell us whether the section page table or the material/texture path is at fault. I do not have an RDNA4 host locally, so I cannot reproduce those visuals myself.@borosf — agreed on the overlap. This branch now deliberately uses the same
xmem.rs/memory.rshook points as #2494, keepswatch::title_memory_remappedas the invalidation funnel, and restores theSEC_COMMIT→SEC_RESERVEfallback so commit pressure does not fail the title's allocation. The remaining differences are intentional policy choices: this PR is off by default, low-host gated, and bounded to 512 MiB total instead of #2494's always-on per-section commit. If both land, we should choose one policy rather than stack two reservations.Local validation on this head:
cargo check --all-targets --locked, strict Clippy for the four affected crates, andcargo xtask policypass. The four-crate test suite adds five passing tests (231 → 236 passes); the same three WARP/descriptor-cap failures also occur on the untouched PR head.AI-assisted: comment prepared with the OpenCode harness from the local diff and validation logs; all reported commands were run locally.
Imported from Marvisak/VIctory. Originally posted by rpmaster2 on 2026-11-29T07:31:26Z.
Both runs on the RX 9070 XT, 600 s each, the same first-run save restored before each, warm caches,
--console series-x, scripted key presses:1. No flags: 3.4–4.3 fps, 230–292 ms a frame at 1,000–1,578 draws, 8,489 draws peak, 6 black frames; the dumps have content (512/1024 = 80 / 121 of 255). It crashed at 280 s with
0xc0000005 read 0xffffffffffffffffin the title image.2.
VICTORY_PORT_CONSTANTS=1only: 0.4–0.5 fps, 2,050–2,474 ms a frame at 1,144–2,350 draws, 9,261 draws peak, 3 black frames; the dumps have content as well, so it renders — it is an order of magnitude slower. Private bytes stay at 28.7 GB, but the process working set the OS reports grows from 6 GB to 1.1 TB over the run; that is not physical memory and looks like very large page mappings.On screen the loading is longer and lighting artifacts appear with the flag.
This pair has been tested several times, shorter windows included, and the result keeps repeating in the same direction: with the flag the frames are several times longer, never the other way round. The pair above is the first clean one — the earlier attempts were disturbed by the save state, which is why the setup was redone.
I have no NVIDIA host, so this is RDNA4 only, and it is one clean pair rather than repeated measurements; but an 8× frame-time cost is well outside noise. Is the in-place path expected to map title memory into the process, which would explain the working-set figure, and is there anything in it that could serialise frames like this on a card where the section heap is not native?
AI-assisted: written by DeepSeek (OpenCode harness) from the run logs; counts and versions only, no game files or paths.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.