GPU: zero-copy section-heap windows, lock-free HostHeap::mirror, VIEWS RwLock & Thin LTO #1117
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/fxceless--victory-fork!1117
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-1117"
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?
@RealAzemed on GitHub · 2026-11-25 20:12 UTC · original
RealAzemed:perf/section-heaps-lockfree-mirror-rwlock→main· +482 −56 · 7 files · 3 commits · openSummary
Four self-contained performance improvements independently rebased onto
main(orthogonal to #1097):1. Zero-Copy Section-Heap Windows (
VICTORY_INPLACE_SECTIONS=1, default on whenVICTORY_INPLACE>=1)crates/victory-gpu/src/inplace.rs&shadow.rs: opensSEC_COMMITphysical-page sections once viaOpenExistingHeapFromFileMapping(0 working-set lock, 0 pinned host copies, safe withVirtualProtectand view unmaps sincesection_outlives_views=true) and placesCreatePlacedResourcebuffers over maximal contiguous mapped runs inside 4 MiB cells.run_end == cell_endinfind_section_runandlongest_tailreuse for unsized root views (unsized_ask=true) so future mappings inside the same cell can never be truncated by a cached partial window.title_memory_section, and retires placed windows cleanly via existingtitle_memory_freeing/in_place_let_go.copiesfrom 76–127 ms -> 10 ms and peak swap by up to 5.1 GB before 16 GB system RAM saturation.2. Lock-Free
HostHeap::mirrorFast Path + Cachedgpu_handle(descriptor/host.rs)made_fast: Vec<AtomicU64>(Release/Acquire mirror ofmade) so the ~98% cache-hit path inHostHeap::mirrorreturns without lockingself.made(~50k mutex acquisitions/frame eliminated). Cleared atomically inunmake()and on null/deferred transitions.gpu: u64fromGetGPUDescriptorHandleForHeapStart()once at heap creation (~10k COM calls/frame eliminated).3. Zero-Alloc Stack Root Constants (
draw.rs)vec![0u32; dwords as usize]inState::bindwith a stack[0u32; 64]buffer (falling back to heap only ifdwords > 64), removing ~6k–10k small heap allocations/frame.4.
VIEWS: RwLock<Views>+ Thin LTO (inplace.rs,Cargo.toml)VIEWSfromMutex<Views>toRwLock<Views>so concurrent read queries inwatch,texture, andshadowno longer serialize against each other.lto = "thin"to[profile.release]for cross-crate inlining.Verification
cargo xtask policypasses (181 files ok).cargo check --target x86_64-pc-windows-gnu --tests -p victory-gpupasses cleanly.find_section_run_merges_contiguous_committed_views_and_respects_unsized_tailpasses under Proton.@UwUCammie on GitHub · 2026-11-25 21:11 UTC · original
The new section window can also be used for shader writes. At
3c85889,section_windows_on()checks the in-place level andVICTORY_INPLACE_SECTIONS, thenShadow::placedsetsplace.Shadow::gpu_writes(shadow.rs:2436) returns immediately for that shadow. With late waits or relay enabled, the CPU can therefore observe the section before the outstanding GPU write has completed, and the flight has no range recorded to make the CPU wait. This is the window case discussed on #358, extended to committed sections here.Could you gate the new placement on synchronous completion as well, or track those writes through completion? I’m testing the section path on RADV with
VICTORY_LATE_WAIT=0 VICTORY_RELAY=0.@zocram4cc on GitHub · 2026-11-25 21:21 UTC · original
A data point from RADV that bears on the section path. It was measured on an RX 6900 XT (Mesa 26.3.1, vkd3d-proton 3.2.0, Proton Experimental), not an NVIDIA card.
On Proton,
OpenExistingHeapFromFileMappingis vkd3d-proton's, and it maps a view, imports it and unmaps it at once (device.cd3d12_device_OpenExistingHeapFromFileMapping):Under Wine a section view is memfd-backed (shared) memory. On RADV/amdgpu I saw two outcomes with a 64 KiB
SEC_COMMITsection, a buffer placed in the heap, and a pattern written by the CPU through a view and read back by the GPU (and the reverse):vkd3d_import_host_memory: Failed to import host memory, hr 0x8007000e. libdrm setsAMDGPU_GEM_USERPTR_ANONONLYand the kernel refuses a VMA with a file. vkd3d-proton then silently allocates separate memory: the call returns S_OK, the placement works, and the GPU reads and writes bytes the title never sees (stale both ways).radv/amdgpu: The CS has been rejected ... (-14)) and the device is lost. The view it imported is already gone.So on RADV, "0 refused" and fewer copies can mean the windows are served from a private copy, not the title's pages. A byte check would tell. Write a pattern through the title's view after opening,
CopyBufferRegionfrom the placed buffer into a readback buffer, and compare; then the other way round. Your RTX 3070 driver may behave differently. If it pins the pages at import, the unmap might not matter there, but I haven't tested NVIDIA.What did alias both ways here:
OpenExistingHeapFromAddress/...Address1on privateVirtualAllocmemory. A section view that we keep mapped also aliases when opened by address, but on RADV only with ANONONLY dropped from libdrm.This adds to @UwUCammie's flight point above: there, writes through the window are not waited for; here, they may not reach title memory at all.
@RealAzemed on GitHub · 2026-11-25 21:30 UTC · original
Thanks @UwUCammie and @zocram4cc — both great catches! Updated in
ed0ac8c:VICTORY_INPLACE_SECTIONS=1is now strictly opt-in (off by default) and refused whenevercrate::host::late() || crate::host::relay()is active (logging a warning and falling back to copies), matching the#358/VICTORY_INPLACE=2synchronous-completion rule sinceShadow::placedskipsShadow::gpu_writes.place_section_window()now runs the existinginplace::section()probe on a temporarySEC_COMMITsection and cachessection_reads && section_writes && section_outlives_views(CPU write via view -> GPUCopyBufferRegionreadback, GPU write -> CPU read via view, and unmap -> GPU write -> remap read). Any driver/wrapper whereOpenExistingHeapFromFileMappingsilently falls back to non-aliasing private memory while returningS_OK(like stock libdrm/RADV withAMDGPU_GEM_USERPTR_ANONONLY) fails the byte check, logs a warning, and automatically falls back to copies.For reference on NVIDIA Linux/Proton (RTX 3070, driver 620.73.04, Proton Experimental / vkd3d-proton), our earlier
VICTORY_INPLACE_PROBE=1run passed all three (section_reads=true,section_writes=true,section_outlives_views=true), so NVIDIA's import pins/aliases the backing pages across theUnmapViewOfFile— while keepingVICTORY_INPLACE_SECTIONSopt-in + verified ensures RADV/amdgpu users are never silently given stale private buffers or an unrequested probe.@UwUCammie on GitHub · 2026-11-25 21:42 UTC · original
I finished a matched run on the RX 7900 XT (RADV 26.3.1, Wine 11.22, vkd3d-proton). Both runs used the same local build with the section patch from before
ed0ac8c, the same inputs,VICTORY_INPLACE=1, and synchronous submission (LATE_WAIT=0,RELAY=0).I counted complete reporting intervals inside seconds 150–225, including stalls. The enabled run reported 2,323 live section windows (420 MB) in one heap. That confirms the path was taken. One run each puts the frame rates close together. These measurements predate the new byte-coherence probe, so they don’t establish whether the imported bytes aliased on this driver.
@Proudnoob4 on GitHub · 2026-11-25 22:16 UTC · original
AI-assisted testing (Gemini in OpenCode); measured locally on my own machine.
Native Windows 10 / RTX 4080 data point (
ed0ac8c, bundled speed stack)Setup: Windows 10 Pro 22H2 (Agility SDK 1.620.2), i5-13600K (6P+8E), 32 GB RAM, RTX 4080 16 GB (driver 621.01), Series X profile, diagnostics release build (
9c184b3+#1117ed0ac8c+#1014+#1016+#1029+#1032+#1044+#1058+#1059+#1066+#1097+#1138+#1146+#1158+#1159), warm cache.#1097(a8bcf21d): orthogonal as noted; only minor conflict ininplace.rs(views()->views_read()in#1097's new helpers) andwatch.rs(BlockSet).42/42inplace/watch/plaincopy/queueunit tests passed, including bothfind_section_run_merges_contiguous_committed_views_and_respects_unsized_tailandplaceholder_fast_path_tracks_mapped_bytes_and_blocks.#1146:#1146introduces the same atomic mirror pattern (made_now) as#1117'smade_fast, plus shardedHostHeap::keptlocks; unified onmade_nowwhen bundling both.VICTORY_LATE_WAIT=3 VICTORY_RELAY=2, soVICTORY_INPLACE_SECTIONSstays off pered0ac8c):VIEWSRwLock+ lock-free mirror ran cleanly across 5 runs (330–360 s each, 0 crashes/device removals, crisp world frames throughframe-4096.png).fxnext_turbo): 8.50 fps median, 9.20 p90, 9.30 max,usual frame 113 ms, GPU title lists38.8 ms(cardmeter 40.8 ms),copy-back 23.2 ms.#1066/#1146(fxnext_cleanvsfx_stack3at similar ~170 MB/frame):copiesdropped from43.3 msto29.8 ms(bundled withc36971b64-bytechanged_runs).VICTORY_INPLACE_SECTIONS=1live aliasing self-test underLATE_WAIT=0 RELAY=0on native Win10/RTX 4080 is unmeasured so far; happy to run a dedicated sync probe if helpful.@Filip722 on GitHub · 2026-11-25 22:19 UTC · original · edited 2026-11-26 08:55 UTC
I tested the section-import path from
ed0ac8con main9c184b3with #830’s Wine file backing, using a synthetic 2 MiB writable file mapping with the same creation flags and lifetime. Bazzite 44, RTX 5060 Laptop 8 GB, NVIDIA 615.78.08, GE-Proton11-14 and vkd3d-protoncae8353ed7959c4+.The production pagefile-backed round-trip gate passed on this adapter. With the file mapping, both
OpenExistingHeapFromFileMappingand placed resource creation succeeded. GPU readback did not match the CPU view. GPU writes were absent in both the original CPU view and a replacement view. The section-range fixture passed, and the file-backed GPU fixture failed its first byte-coherence assertion. I did not run the title with section imports enabled.When this is combined with #830, the gate needs to account for the actual backing type. A safe narrow change is to keep file-backed sections on the existing copy path until their own aliasing test passes, while retaining the pagefile-backed fast path on devices that pass its gate.
Test and report prepared with assistance from OpenAI Codex (GPT-6.2-Sol High).
Follow-up verification: The failure also reproduced on the same direct-I/O ext4 scratch filesystem used by our #830 title runs. I tested a local guard that carries the actual
file_backedflag fromphysical_sectionintotitle_memory_sectionand rejects it infind_section_runbefore any D3D12 import. The same committed range was accepted with anonymous backing and refused with file backing. The two focused range tests, the Windows MSVC application check and the asset-policy check passed. This guard preserves the existing copy fallback for file-backed sections.@LeonardoS11 on GitHub · 2026-11-25 23:44 UTC · original
A data point from an NVIDIA card. We took the part that places windows outside buffers over the title's committed sections (no copy) onto an integration branch and measured it on an RTX 3080 Ti 12 GB, Windows 11 26200, Series S profile, fixed room of the prologue.
VICTORY_RELAY=0andVICTORY_LATE_WAIT=0, and running the submission synchronous costs about 80 ms a frame here (187 ms a frame against 110 ms with the relay on), so the net is a loss on this machine. If the in-place windows could live with the relay thread, the 9 ms would be a real gain.The lock-free
HostHeap::mirrorand the VIEWS RwLock we have not measured apart.Written with Claude Code.
@RealAzemed on GitHub · 2026-11-26 00:28 UTC · original
Thanks everyone for all the hardware data points — huge help! Pushed
8cc889caddressing both @LeonardoS11 / @UwUCammie and @Filip722:1. In-place section windows now work with
VICTORY_LATE_WAIT&VICTORY_RELAY(@LeonardoS11, @UwUCammie)Instead of blocking
VICTORY_INPLACE_SECTIONS=1whenever late waits or the relay thread are active,Shadow::gpu_writesnow tracks declared GPU write ranges for in-place shadows onto flights whenhost::late()is enabled:line.writtenand a dedicatedline.placed_writtenset (empty on the common read-only path, zero snapshot/compare/copy-back —hand_backandrelay_hand_backskipshadow.in_place()alongsideshadow.carded()).late_metsettles online.written,blocked_bynever bypassesline.placed_writtenviafill_ahead(since placed windows don't go throughcopy_back/relay_merge), andin_place_let_gocallssettle_if_placed_written(at, end)(waiting viarelay_waitor a direct fence wait without takinghost.submitted, so it is safe whilexmemholdsMAPPING) before remapping pages with an in-flight GPU write.VICTORY_INPLACE_SECTIONS=1remains opt-in and still requires the one-time live CPU<->GPU aliasing round-trip self-test (section_reads && section_writes && section_outlives_views).@LeonardoS11 — this should let you re-test the ~9 ms/frame savings with
VICTORY_RELAYandVICTORY_LATE_WAITenabled (without the ~80 ms synchronous penalty)!2. File-backed section guard for #830 (@Filip722)
pub fn title_memory_section_backing(section, bytes, committed, file_backed)(keepingtitle_memory_sectionunchanged asfile_backed = falsefor full backwards compatibility) and updatedfind_section_runto rejectfile_backed == truebefore any D3D12 import, with unit-test coverage infind_section_run_merges_contiguous_committed_views_and_respects_unsized_tail(passes under Proton,cargo xtask policy181 files ok).file_backed = truekeeps file-backed scratch sections safely on the copy path while anonymous pagefile-backed sections keep the fast path.3. @Proudnoob4 & @UwUCammie
made_fastwith #1146'smade_nowif #1146 lands first.8cc889cwithVICTORY_INPLACE_SECTIONS=1on RADV, the startup probe log line (section_reads,section_writes,section_outlives_views) will immediately show whether RADV aliased or fell back cleanly.@SkillIssueXO on GitHub · 2026-11-26 02:08 UTC · original
A local Series X census on RTX 5070 Ti with
64f3a82eplus local diagnostics found 116 title buffers covering 426 MiB that each span one contiguous run of section views. The same sample had 18 scattered title buffers covering 325 MiB. The whole-window census found one 4 MiB contiguous window outside title buffers. This census classifies the full existing window extent and does not count smaller runs eligible for the PR’s clipping logic. The Windows run registered three reserved sections of 185, 710 and 6,236 MiB.In the standalone fixture on the same RTX card, a 2 MiB anonymous
SEC_COMMITsection opened and accepted the cross-adapter UAV buffer at a nonzero aligned offset. CPU and GPU visibility survived replacing the CPU view. TheSEC_RESERVEcontrol returned0x80070057. For the fixture’s private-memory GPU copy, host write-watch reported 0 of the 16 written pages on NVIDIA and 16 on WARP. These are independent eligibility and coherence measurements. AI-assisted testing. Asset-free data.@Filip722 on GitHub · 2026-11-26 16:34 UTC · original · edited 2026-11-26 18:27 UTC
A follow-up test on an RTX 5060 Laptop GPU (8 GB, driver 615.78.08) with GE-Proton11-14 and vkd3d-proton 3.2.0 confirms a live import of a 174 MiB registered graphics buffer from a committed anonymous section. In a local adaptation, ordering fresh slices before mapping made the buffer contiguous within its section. The production CPU/GPU coherence check passed and the game rendered the prison view with visible camera movement.
In a matched 54-second replay with synchronous submission, enabling the import raised throughput from 3.05 to 3.60 completed Presents per second and reduced median copy-back from 108.3 to 61.1 ms per frame. Median/p95 intervals moved from 325/359 to 268/337 ms. Both arms used the same executable, ordered section and checkpoint. The import path required anonymous committed backing.
I also tested the import with overlapping submissions after carrying forward this PR's placed-write dependency checks. Across the same elapsed 54 seconds in the prison view, import off measured 5.53 FPS and import on measured 6.28 FPS. Median/p95 intervals were 176/212 ms and 156/179 ms. Median copy-back was 93.4 ms and 73.0 ms, respectively. Both measured runs had compilation idle.
On a newer baseline (main
52ac4ec0f8with the same Wine bring-up, the #1234 wait policy and the late-placement dependency port), I compared direct import disabled and enabled in a single executable. GE-Proton11-14, vkd3d-proton 3.2.0 and RTX 5060 Laptop 8 GB were unchanged. The coherence probe passed and the 174 MiB buffer was imported. In the same 37.9-second stationary window, disabled produced 148 Presents at 3.91 FPS and enabled 147 at 3.90 FPS. The separate 54-second view-matched windows gave 3.86 and 3.92 FPS. Median forward bytes fell from about 149 to 135 MB per frame. This run isolates the import switch with late placement waits enabled in both arms. Camera response and the three focused late-placement tests passed.Assisted by Codex (GPT-6.2-Sol High).
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.Merge
Merge the changes and update on Forgejo.