Shaders, GPU: a root UAV a shader only reads is not written back #2948
No reviewers
Labels
No labels
accessibility
area: build
area: formats
area: gpu
area: loader
area: runtime
area: shader
bug
documentation
duplicate
enhancement
good first issue
gpu: amd
gpu: intel
gpu: nvidia
help wanted
host: wine
invalid
out of scope
question
request
run report
triage: confirmed
triage: has patch
triage: merge candidate
triage: needs info
triage: needs rebase
triage: needs work
triage: proposed close
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/Marvisak--VIctory!2948
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-2948"
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?
@0xkn0wh3r3 on GitHub · 2026-11-26 01:19 UTC · original
0xkn0wh3r3:gpu/read-only-root-uavs-are-not-written-back→main· +193 −9 · 15 files · 2 commits · openWhat
A root UAV is bound for any shader that reads or writes it, and the host declared every bound one as written (
Shadow::gpu_writes, up to 1 MiB of its copy). That means a snapshot before the list runs and a compare of the bytes afterwards, even for root UAVs a shader only loads from.HostShader::written_root_uavs. InShader::op, any operation on the handle except BufferLoad, GetDimensions and RawBufferLoad counts as a write, so stores and atomics do.root_view) and to root views a stage reads as title memory.VSH2); aVSH1entry is translated again.Where it came from
From DexNom's fork, DexNom/VIctory@bc3cd4b ("track guest shader writes precisely":
written_root_uavsand its test), built on this tree's root views. Credited withCo-authored-by: DexNom. The other half of that commit, writes through the guest page directory, is already on main asmemory_writesplus write marks. DexNom measured the whole commit at 3,469 → 969 ms per frame on their Radeon build, with guest memory compared per frame dropping from 12.8 GB to 2.7 GB. Most of that is the half main already has, so I'm not claiming that number here.Tested
emit::shader::tests::only_root_uavs_stored_to_or_reached_by_atomics_are_written: of three root UAVs, the one only loaded from isn't written; the one stored to and the one an atomic reaches are.cargo test -p victory-gpu: 229 passed, plus the 2 known NVIDIA failures (#2121).cargo test -p victory-shader(withVICTORY_DXILset): 299 passed. The same four tests fail on main on this machine.cargo test -p victory-game: passes.cargo build --workspace --tests: builds.cargo clippy --all-targets -- -D warningson victory-shader, victory-gpu (with and withoutdiagnostics) and victory-game: clean.Not tested
Shader::op.github-bot referenced this pull request2026-11-26 07:27:02 +00:00
@oni-swr on GitHub · 2026-11-26 01:29 UTC · original
Independent Windows WARP verification
Tested PR head
95110f370b83a5e705dfc281e7a25502604626d9on Windows 11 Pro build 26200 with Rust 1.98.1. AI assistance used Codex (gpt-6.2-sol). The run used synthetic fixtures and the CPU software adapter. Coordination claimThe classification test recorded slots
[2, 3]for the store and atomic, excluding the load-only slot. The VSH2 tests preserved the written-root-UAV list across disk round-trip. The additional probe reconstructed the parent's VSH1 layout, placed it under the current key to exercise the format check, and observed a cache miss, VSH2 replacement, then a disk hit.The compute case validated DXIL and checked readback of a root UAV load and store through the emulated memory path, separate float min/max atomics, and page marks. Before device creation, the harness verified the adapter returned by
EnumWarpAdapterhad the software flag. It matched the created device's LUID to that adapter and independently queried the device by LUID again before each of the two dispatches. That LUID identifies Microsoft Basic Render Driver, vendor0x1414, device0x008c, flags0x02(DXGI_ADAPTER_FLAG_SOFTWARE), LUID0x0:0x16406, and zero dedicated video memory. The x64 SDK validator DLL has file version1.8.2502.11with SHA-25639DBD950F39F75F5C37BCD224C524ACCBA76686ADAA372B8287FACFC46892B1C.Coverage is limited to the selected tests. The compute fixture exercises the shader harness, so production draw binding, shadow snapshot and copy-back behavior, physical adapters, and game performance remain unmeasured. Temporary test code and the dedicated Cargo target were removed.
@fuzeofficlal on GitHub · 2026-11-26 01:31 UTC · original
Code review and RTX 5090 + WARP + DXIL verification at head
95110f370b83onmain(63bcca43c6a0;emit/lower.rs=520,724B,3,564B under the 512 KiB cap):68 | 72 | 139) inShader::op(shader.rs:245-251) is conservatively fail-safe for allbufferStore/rawBufferStore/atomicBinOp/atomicCompareExchangepaths throughroot_uav_handle, and bumpingshader_cache.rs:179fromVSH1toVSH2cleanly invalidates older cached shaders.self.root_memory == true+raw_viewwrites (lower.rs:1790-1813,draw.rs:763, 886-893):self.root_memory == true(e.g. due to computed pointers), raw root UAV writes go throughraw_view->root_address->self.memory(MEMORYpage table +memory_dirtybitmap) without callingroot_uav_handle(rp.slot)(lower.rs:5461only fires on structured/typed buffers going throughhandle()).t.host.written_root_uavsomitsrp.sloteven thoughraw_view(..., write=true)writes to that root UAV.draw.rs:763(written_root_uavs.contains(&u.slot)) then evaluatesfalse, skippingshadow.gpu_writes+map.precisebyte-level copyback (draw.rs:886-893) and falling back to 4 KiB whole-pagememory_dirtycopyback — which permemory.rs:79-85risks clobbering concurrent CPU/DirectStorage writes sharing the same 4 KiB page.rp.slotinwritten_root_uavswhenraw_viewhits aroot_addresswithwrite == truecloses that gap cleanly.!self.root_memory,lower.rs:5455routes throughROOT_UAV_VIEW->draw.rs:948-953rather thanstage.root_uavs, so read-only root UAVs on that path still keep the existingshadow.gpu_writes(..., true)snapshot path if unmarked.)dxil.dll10.0.26100.0,VICTORY_D3D12_DEBUG=1, Rust 1.98.1):cargo xtask policy:191 files ok;cargo clippy --locked -p victory-shader -p victory-gpu --tests -- -D warnings: 0 warningsemit::shader: 2/2 (includingonly_root_uavs_stored_to_or_reached_by_atomics_are_written);shader_cache: 4/4;draw::tests: 20/20 on both RTX 5090 and WARP; WARPmemory_tests: 5/5.@Marvisak on GitHub · 2026-11-26 04:29 UTC · original · edited 2026-11-26 07:18 UTC
Automated triage for the maintainers.
Merge candidate (recommending a look, not approving). Thanks for the fix in
9f392ad:Lower::root_written(emit/lower.rs) now records the slot whenraw_viewresolves a root address withwrite == true, and in the global store/atomic path whenroot_addressresolves. That closes the gap we raised, where inroot_memoryprogramswritten_root_uavsstayed empty and therootsloop indraw.rsdroppedshadow.gpu_writes/map.precise. The rest is unchanged:Shader::opcounts any op on a root UAV handle except the three reads as a write (the safe default),root_viewskips snapshot/compare only for read-only root UAVs, theROOT_UAV_VIEWheap-view path still marks writes, and the cache tag moves toVSH2.root_uavs_stored_to_as_title_memory_are_writtenchecks a store through a built descriptor against a load-only UAV, and the existing memory test now asserts its global store is recorded.CI: passing (
check).Generated by Claude Code
@0xkn0wh3r3 on GitHub · 2026-11-26 06:57 UTC · original
Good catch, fixed in
9f392ad.Lower::root_writtennow records the root UAV's slot in two cases: whenraw_viewresolves a root address withwrite == true, and for global stores and atomics at a root address. Those reachLower::memorywithout going throughraw_view, so they had the same gap.Tests:
root_uavs_stored_to_as_title_memory_are_written. It's aroot_memoryprogram that stores through a descriptor built around root UAV 2 and only loads from root UAV 3; only slot 2 is recorded.title_memory_is_read_and_written_at_computed_addressesnow also asserts that its global store to the root UAV marks it written.Both fail without the change and pass with it. Clippy is clean.
@Dukestar69 on GitHub · 2026-11-26 02:04 UTC · original · approved these changes
Tested merged onto
origin/main(63bcca4) on Windows 11 x64 (NVIDIA GeForce RTX 5090):cargo test -p victory-shader --lib emit::shader::tests: 2 passed, 0 failed (including newonly_root_uavs_stored_to_or_reached_by_atomics_are_written).cargo test -p victory-gpu --lib shader_cache::: 4 passed, 0 failed (VSH2cache round-trip and validation).cargo test -p victory-gpu --lib draw::: 20 passed, 0 failed on RTX 5090 hardware.cargo clippy -p victory-shader -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Tracking
written_root_uavsinShader::opby treating every opcode other than read-onlybufferLoad(68) /getDimensions(72) /rawBufferLoad(139) as a potential write is conservative and sound, and bumping the shader cache magic fromVSH1toVSH2cleanly invalidates stale cache entries.Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@kotekompotek on GitHub · 2026-11-26 02:29 UTC · original · reviewed
Verified: a root UAV the shader only reads still gets shadow.refresh (host needs fresh data) but skips gpu_writes, so no snapshot/compare write-back after submission. Both the dispatch path and the graphics root path gate on written_root_uavs, and the VSH1->VSH2 cache bump makes stale entries re-translate instead of silently missing the new field.
@fuzeofficlal on GitHub · 2026-11-26 11:47 UTC · original · approved these changes
Reviewed and verified
9f392adcagainstorigin/main(63bcca43;crates/victory-shader/src/emit/lower.rsis521,409bytes both at PR head and merged ontomain, staying2,879bytes below the 512 KiB limit).victory-shader:Shader::op(crates/victory-shader/src/emit/shader.rs:242-251) conservatively marks any operation on aroot_uavshandle as a write except the three read-only opcodes (68bufferLoad,72getDimensions,139rawBufferLoad), androot_uav_handlepushes the handle only aftercreateHandleFromBinding+annotateHandle.9f392adccloses theroot_memorygap viaLower::root_written(crates/victory-shader/src/emit/lower.rs:1822-1832), called on both theglobal_store_*/global_atomic_*path (lower.rs:995) andraw_view(..., write=true)(lower.rs:1809-1811, coveringbuffer_atomic_*, sub-dword stores, andbuffer_store_*). All remainingraw_viewandbvh.rspaths are read-only, and non-root_memoryshaders usingROOT_UAV_VIEWkeep the existing write-markedshadow.gpu_writespath.draw.rs:762-770anddraw.rs:841-843gate write-back onwritten_root_uavswhile still refreshing read-only root UAVs, andshader_cache.rs:179bumpsVSH1toVSH2(in addition toENCODINGhashingshader_cache.rs) so stale cache entries re-translate cleanly.Verification on Windows 11 (RTX 5090 + WARP +
VICTORY_D3D12_DEBUG=1+ Windows 11 SDKdxil.dll):cargo xtask policy(191 files ok) andcargo clippy -p victory-shader -p victory-gpu --tests -- -D warnings(default and--all-features): clean.victory-shader:emit::shader::tests2/2 andemit::memory_tests5/5 passed (includingroot_uavs_stored_to_as_title_memory_are_writtenandtitle_memory_is_read_and_written_at_computed_addresses; skipping the unrelated pre-existing NVIDIA baselineheap_direct_texture_reads_mark_their_heap_index).victory-gpu:shader_cache::tests4/4 anddraw::tests20/20 passed on RTX 5090 (default and Debug Layer) and on WARP + Debug Layer.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.