GPU: fix Shadow::sparse_writing tile base for 4 KiB-aligned Map() pointers #100
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/Belobug--VIctory-Belobug-AMD!100
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-100"
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?
@luniiya on GitHub · 2026-11-25 14:04 UTC · original
luniiya:fix/sparse-writing-tile-alignment→main· +6 −1 · 1 files · 1 commits · openProblem
In
Shadow::sparse_writing(crates/victory-gpu/src/shadow.rs:1949), the start of the mapped 64 KiB tile was computed by masking the host pointer down to a 64 KiB boundary:On Windows WDDM,
ID3D12Resource::Map()on a 32 MiB tile heap returns 64 KiB-aligned pointers, so this happens to land on the tile base. Under Linux / Wine / vkd3d-proton,vkMapMemory/mmaponly guarantees 4 KiB alignment, so masking down to 64 KiB steps before the start of the mapping and crashes immediately with0xc0000005(STATUS_ACCESS_VIOLATION) on world entry when sparse copies are enabled.Fix
Compute the tile base relative to
at % PAGEinstead:data & !(PAGE - 1)whenever the mapping is 64 KiB-aligned (Windows unchanged).crates/victory-gpufor any similar!(PAGE - 1)mask on mapped host pointers; this was the only one.(Complementary to #69: even when sparse copies are turned off by default under Wine, explicitly enabling
VICTORY_SPARSE=1under Wine/vkd3d-proton will no longer segfault.)Tested
x86_64-pc-windows-msvcdiagnostics build withVICTORY_COPY_MEMORY=1and sparse copies enabled.0xc0000005inucrtbase.dll(memcpyfromShadow::sparse_writing) on world entry; with this fix, enters and renders live 3D gameplay cleanly.@TobiasFornell on GitHub · 2026-11-25 21:34 UTC · original
Independent confirmation on a different setup: CachyOS, RX 9070 XT (RDNA4, RADV), Proton Experimental,
x86_64-pc-windows-msvcbuild, Belobug base.Without this change we hit the same
0xc0000005inShadow::sparse_writing, about 3.5 minutes into the run. We arrived at the samedata - at % PAGEchange independently. With it: one 480 s run, 0 kernel GPU page faults, no crash (a single run, not a long-term test).@ -1950,0 +1951,4 @@// masking with `!(PAGE - 1)` lands on the tile base; under// Linux/vkd3d-proton, `vkMapMemory`/`mmap` is only 4 KiB-aligned// and masking reads before the mapping (`0xc0000005`).let whole = data as usize - at % PAGE;@gut0to on GitHub · 2026-11-25 14:53 UTC · original
Could this calculation get a regression test with a 4 KiB-aligned mapped pointer where at % PAGE != 0? That is the case where the old 64 KiB mask returned an address before the mapping, while this subtraction should recover the tile base. AI-assisted review.
@gut0to on GitHub · 2026-11-25 14:53 UTC · original · reviewed
AI-assisted review: I traced the old and new tile-base calculations against the reported alignment failure.
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.