hle/xmem: honour exact 128-512 KiB alignment without rounding up to 2 MiB #4364
No reviewers
Labels
No labels
AMD
audio
bug
confirmed
crash
cutscene
dlss
documentation
duplicate
enhancement
fixed-on-main
frame-generation
good first issue
help wanted
input
INTEL
invalid
lighting
linux-proton
memory
needs-info
needs-logs
needs-rebase
NVIDIA
performance
pr-diagnostics
pr-docs
pr-feature
pr-fix
pr-performance
pr-refactor
pr-tests
question
RAYTRACING
rendering
report
series-s
shaders
spam
startup
upstream
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/trustno1-coder--VIctory-NVIDIA!4364
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-4363"
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?
@TheOriginalF on GitHub · 2026-11-30 19:21 UTC · original
TheOriginalF:feat/xmem-aligned-alloc-and-zero-memory-x→main· +93 −10 · 1 files · 1 commits · openWhat it changes
In
crates/victory-hle/src/modules/xmem.rs,virtual_alloc()previously setALIGN_2Mfor anyXMemAllocDefaultalignment larger than64 KiB, rounding128 KiB,256 KiB, and512 KiBrequests up to2 MiBboundaries and wasting 32-bit virtual address space whenALLOC_32BITis set.requested_alignment(kind, flags, min_alignment)and internalvirtual_alloc_aligned(...)sovirtual_alloc()passes the exact requested power-of-two alignment (128 / 256 / 512 KiB) toreserve_first_fit()/VirtualAlloc2without forcingALIGN_2M(whilePAGES_2Mand explicitALIGN_2Mstill align to2 MiB).alloc_32bit_uses_exact_large_alignment_without_2m_roundingthat verifies bothrequested_alignment()and that 4 simultaneousALLOC_32BITallocations at128 / 256 / 512 KiBstay below 4 GiB, honor the exact alignment, and place at least one block off a2 MiBboundary (failing onmainand passing here).(Scoped down after review: dropped
LastErrorin favor of #4318, and dropped the speculativeXMem*/D3D12ZeroMemoryXstubs.)How it was tested
--console series-s --execute), no DLSS / no frame generation, default software RT path,cache-paretomain(84bd61e2) rounded128 / 256 / 512 KiBXMemAllocDefaultreservations up to2 MiB(ALIGN_2M); live baseline run (baseline.log, 503.0 s): 0 errors, peak WS 25,132 MB.128 / 256 / 512 KiBalignment honored without2 MiBrounding, verified byalloc_32bit_uses_exact_large_alignment_without_2m_rounding; combined live run (all-prs.log, 430.5 s): 0 errors, no allocation failures.cargo testpassed for the crates it touches: yes (cargo test -p victory-hle --lib --locked xmem:: -- --test-threads=1— 51 passed, 0 failed, 1 ignored;cargo clippy— 0 new warnings;xtask policy --staged— ok)Checked for overlap
LastErroris removed), #3738, #3787 (different scope inxmem.rs)@babuakhil on GitHub · 2026-11-30 19:50 UTC · original
Checked on Windows 11 (Rust 1.98.1, pinned), applied on current
main(e1251c31); cherry-picks cleanly. Thed3d12xtests pass (5), as do thexmemtests on one thread (52 passed, 1 ignored), and Clippy's one note inxmem.rs(port_on) is onmaintoo. Not tested in the game.The "What it changes" bullets are empty. The PR does four separate things (large 32-bit alignment,
LastError, three new XMem exports,D3D12ZeroMemoryX), and the first two overlap #4318, so here's how they compare.LastError: #4318 covers cases this doesn't. It conflicts with #4318 inxmem.rs(cherry-picking one onto the other stops on the same lines). A throwaway test (not part of either PR) made a refused zero-byte commit throughXMemVirtualAllocand readGetLastError()right after:mainfmt()to stderr, INFO, base givenfmt()to stderr, TRACE, null baseHere the error is read at
if at.is_null()and restored before thebase.is_null()debug line and the rest of the function's logging, so with an ordinary stderr subscriber the title still gets 6 (ERROR_INVALID_HANDLE). #4318 reads each attempt's error when it happens and restores it at the end, and it keeps 87 in all four.Alignment:
mainalready gives aligned memory. Onmain,align > ALLOCATION_GRANULARITYsetsALIGN_2M, and a 2 MiB boundary is also a 128, 256 and 512 KiB one. With fields0x11–0x13andALLOC_32BIT,mainreturned addresses below 4 GiB aligned to each, soalloc_32bit_honours_large_alignmentpasses onmainas well. What this changes is that those blocks stop being rounded up to 2 MiB, which saves 32-bit address space. That's worth having, but it would help to say so, and the test doesn't distinguish the two.The new exports hand the title made-up values.
XMemGetPhysicalMemoryLayoutreports0x10_0000for both page numbers,XMemGetAllocationStatisticsreports zeros, andXMemMakeTagreturns 0. Without them a title importing these gets a generated stub, so it would help to say whether a title calls them and why these values are right for it. The same goes for whereD3D12ZeroMemoryX's decorated name and range layout come from. Separate PRs for these would also be easier to review than one with four unrelated changes.hle/xmem,d3d12x: honour large 32-bit alignment, preserve LastError, and add XMem/D3D12ZeroMemoryX exportsto hle/xmem: honour exact 128-512 KiB alignment without rounding up to 2 MiBe5446551f2tod3d2853afa@TheOriginalF on GitHub · 2026-11-30 21:09 UTC · original
Thanks for the thorough review and testing, @babuakhil!
I've updated and narrowed this PR based on every point you raised:
LastErrorpreservation so #4318 can handle it completely (including thestderrtracing cases) with zero merge conflict.XMem*stub exports andD3D12ZeroMemoryXsince no title currently needs them.2 MiBover-alignment for128 / 256 / 512 KiBXMemAllocDefaultallocations (saving 32-bit address space underALLOC_32BIT) and updated the description to explain the motivation clearly.alloc_32bit_uses_exact_large_alignment_without_2m_rounding) so it checksrequested_alignment()directly and allocates 4 live blocks simultaneously to assert that at least one lands off a2 MiBboundary (which fails onmainand passes here).d3d2853afato7bc1d7a087View 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.