GPU: share live host textures across aliased addresses and canonicalize view descriptors #643
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!643
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/643/head"
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?
@nathanbzrr on GitHub · 2026-11-24 06:06 UTC · original
nathanbzrr:gpu/alias-live-host-textures→main· +1025 −30 · 2 files · 3 commits · closed without mergingSummary
Two texture aliasing and view deduplication bugs cause aliased render targets and placed SRVs to read back zeros and leak duplicate host resources/views:
hand_out_resourcecreates a fresh all-zeroHostTextureeven when a liveResourceat the same virtual address already owns the rendered GPU copy. DownstreamCreatePlacedShaderResourceViewX(texture_at) or aliasedCreatePlacedResource*calls then seeflags == 0, causingtexture::title_writtento overwrite the separate host copy with CPU zeros and isolating state tracking.ResourceDesc,D3D12_SHADER_RESOURCE_VIEW_DESC, andD3D12_UNORDERED_ACCESS_VIEW_DESCcontain struct padding words and unused union tail words; uncanonicalized stack bytes breakPLACED_TEXTURESandVIEWS.indexdeduplication.Changes (
crates/victory-gpu/src/resource.rs,crates/victory-gpu/src/descriptor.rs)canonical_resource_desc(zeroing offsets 4..8 and 52..56),canonical_srv_desc(zeroingd[3]alignment padding and per-ViewDimensionunused union words),canonical_uav_desc, andcanonical_placed_desc, verified with compile-timeoffset_of!/size_of!assertions againstwindows-0.62.2.texture_at,create_srv,create_uav,create_placed_srv, andcreate_placed_uavwhile preserving placeddesc[10..16].LIVE_TEXTURESVA registry (TextureKey,LiveTexture,find_live_texture,register_live_texture,unregister_live_texture) inresource.rs:hand_out_resourcereuses a compatible liveArc<HostTexture>at the same VA (preferring GPU-writable targets, enforcing geometry/family, usage-flag, typed-depth SRV, and non-typeless writable format compatibility) without resettingHostTexture::state.Drop for Resourceunregisters dropped resources fromLIVE_TEXTURES.texture_atupgrades non-writablePLACED_TEXTUREShits if a compatible live GPU-writableHostTexturebecomes active at that VA (without freeing priorThispointers, maintainingPLACED_TEXTURES->LIVE_TEXTURESlock order).Verification
Isolated verification on branch
gpu/alias-live-host-textures(5cab0f1):rustfmt --edition 2024 --config skip_children=true --check crates/victory-gpu/src/resource.rs crates/victory-gpu/src/descriptor.rs(passed)cargo test -p victory-gpu -- --test-threads=1(46 passed, 0 failed, 1 ignored; includescanonicalization_deduplicates_padding_and_unused_union_words,placed_srv_and_aliased_resource_see_rendered_target_pixels, andincompatible_alias_flags_or_geometry_do_not_share_host_texture)VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1(48 passed, 0 failed, 1 ignored; zero D3D12 debug layer errors)cargo clippy -p victory-gpu --all-targets(0 warnings inresource.rsanddescriptor.rs; 1 pre-existing warning athost.rs:267)cargo xtask policy(151 files ok)No game files. AI-assisted; reviewed and verified with the tests above.
@nathanbzrr on GitHub · 2026-11-24 06:34 UTC · original
Thanks @LAKSHYA-cmd-tech for catching the
0.5 * 255.0 = 127.5float-to-UNORM rounding variance!Updated
clearinplaced_srv_and_aliased_resource_see_rendered_target_pixels(commite7b2182) to[64.0f32 / 255.0, 128.0 / 255.0, 191.0 / 255.0, 1.0]so all channels hit exact integers regardless of hardware rounding vs truncation on 0.5 ties.Re-verified on branch
gpu/alias-live-host-textures:cargo test -p victory-gpu -- --test-threads=1(46 passed, 0 failed, 1 ignored)VICTORY_D3D12_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics -- --test-threads=1(48 passed, 0 failed, 1 ignored)cargo clippy -p victory-gpu --all-targets(0 warnings inresource.rs)cargo xtask policy(151 files ok)@YouKnowWh on GitHub · 2026-11-24 06:35 UTC · original
Tested 5cab0f1 on Windows 11 with an RTX 5070 Ti (driver 621.14), using synthetic textures in a diagnostics build.
I used two identical 4×4 placed textures in one guest heap, initialized B to a sentinel, uploaded a known pattern to A, and read 64 bytes back from B. This comparison checks host backing identity without issuing an aliasing barrier. On the
d2a4bae+ #322 baseline, B retained its sentinel at the same offset. On this PR it returned all 64 bytes of A's pattern for both R10G10B10A2_UNORM and R8G8B8A8_UNORM. The different-offset control retained the sentinel, and the same-object control returned the pattern on both versions. The incompatible-alias test also passed on the PR.One test portability finding: the unchanged assertion in
placed_srv_and_aliased_resource_see_rendered_target_pixelsfailed at pixel (0,0): got [64,127,191,255], expected [64,128,191,255]. Changing only the clear to [1.0,0.0,1.0,1.0] and the expected bytes to [255,0,255,255] made the full 16×16 test pass on the same machine. Endpoint colors keep the exact equality check while avoiding the midpoint conversion in this aliasing test.This verifies the synthetic case. We haven't established that the two textures seen during gameplay overlap in guest memory. AI-assisted test setup and reporting.
@nathanbzrr on GitHub · 2026-11-24 06:49 UTC · original
Thanks @YouKnowWh for verifying aliased host backing identity on RTX 5070 Ti across both
R10G10B10A2_UNORMandR8G8B8A8_UNORMand the controls!Note that commit
e7b2182(pushed right before your comment on5cab0f1) already updatedclearinplaced_srv_and_aliased_resource_see_rendered_target_pixelsfrom[0.25, 0.5, 0.75, 1.0]to exact[64.0f32 / 255.0, 128.0 / 255.0, 191.0 / 255.0, 1.0]so the green channel lands on an exact integer regardless of driver 0.5-tie rounding vs truncation.@DeerSilver on GitHub · 2026-11-24 10:36 UTC · original
Tested the current head
e7b2182e5(with the exactn / 255.0clear) merged ontomainffe310e(clean merge) on NVIDIA GeForce RTX 5060 Laptop GPU (Blackwell), driver 621.24, Windows 11 26300, Rust 1.98.1: pass. The earlier RTX 5070 Ti check was of5cab0f1. No game files: the test suite only.canonicalization_deduplicates_padding_and_unused_union_wordsplaced_srv_and_aliased_resource_see_rendered_target_pixelsincompatible_alias_flags_or_geometry_do_not_share_host_textureresource::testscases return early without a host GPU. Here they ran on the RTX 5060 (DXGI adapter 0 on this laptop). So the rendered-target pixels read through the placed SRV and the aliased resource match exactly on NVIDIA with the new clear values.cargo test --workspace --locked: 345 passed, 0 failed, 6 ignored, against 342 / 6 onmainat the same commit.cargo clippy --workspace --all-targets --locked -- -D warnings: clean.AI-assisted (Claude Code).
@rpmaster2 on GitHub · 2026-11-24 14:20 UTC · original
@nathanbzrr an AMD data point for this PR, because it changes what reaches the screen and I have not seen RDNA4 numbers in this thread.
I tested
main@ffe310ewith #878 + #585 + this PR + #581 stacked (all four merge cleanly; one semantic fix needed: #581 still saysUNORDEREDwhere this PR renamed itUNORDERED_FLAG). Diag build,VICTORY_D3D12_DRED=1, RX 9070 XT, Adrenalin 26.11.2, one 600 s run.What changed on screen for the first time with this stack:
Stability is unchanged: the run still lost the device at frame 1349 with the same
page fault ... inside freed ["texture 1024x1024 f98 ..."]seen on plainmain(that is #597's removal, not this PR's).One number that may matter to you: in a separate 240 s run with the draw trace on, exactly 20 slots were bound as null views because
makefound "no host texture and not a buffer" for the view's resource - zerofitsrefusals, zerotexture_atmisses, and zero host-texture creation failures in the log. If the alias work is meant to make a view of a re-aliased address resolve to the live host texture, those 20 are the ones that still do not.Not tested: NVIDIA, other titles,
cargo teston the stack. This is a game-run observation, not a correctness claim.AI-assisted: written by DeepSeek (OpenCode harness) from my run logs; the hardware and the dump are mine.
@nathanbzrr on GitHub · 2026-11-24 21:39 UTC · original
Thanks @rpmaster2 for the RX 9070 XT in-game report and for noting the constant rename against
#581!Updated branch
gpu/alias-live-host-textures(head23aace6, rebased ontomainffe310e):DEPTH,UNORDERED, andDENY_SHADER_RESOURCEconstant names incrates/victory-gpu/src/resource.rsso#581merges cleanly without semantic rename friction.texture_atmiss path so aResourcewithhost.is_none()is released (resource_release(out)) and not inserted intoPLACED_TEXTURES, preventing permanent caching of failed host-texture creations.About those 20
"no host texture and not a buffer"slots indescriptor/host.rs::make: with zero host-texture creation failures and zerotexture_atmisses,make'sView::Shader/View::Unorderedfallback hits whenresource == 0(explicit null-resourceCreateShaderResourceView(NULL, ...)/CreateUnorderedAccessView(NULL, ...)calls, which also don't go throughplaced_texture) or a buffer view hasdesc == None, rather than a missed live-texture alias.Re-verified on
23aace6(Windows MSVC):rustfmt --edition 2024 --check crates\victory-gpu\src\resource.rs: cleancargo clippy --workspace --all-targets --locked -- -D warnings: cleancargo clippy --workspace --all-targets --all-features --locked -- -D warnings: cleancargo test --workspace --locked: 345 passed, 0 failed, 6 ignored (victory-gpu: 53 passed, 0 failed, 1 ignored;xtask: 4 passed)@ghost on GitHub · 2026-11-24 21:51 UTC · original
AI-assisted (Claude Code). RTX 5080, Windows 11. A data point from the game for this PR; I have read the PR's code at
e7b2182and have not run it.An alias pair this PR's key leaves separate: resources written as
R32_UINTand read by address asR9G9B9E5_SHAREDEXP.While tracing why the world's light buffers read zero, I added a warning for the case this PR is about: a
CreatePlacedShaderResourceViewXview (texture_at) naming an address where a texture the host GPU renders or writes already lives. In the opening world scene it fires for 50 textures in one run (48 in another), and every one has the same shape:R32_UINT) withALLOW_UNORDERED_ACCESS(a few alsoALLOW_RENDER_TARGET), written by compute passes;R9G9B9E5_SHAREDEXP).So the title packs shared-exponent colours into a uint texture from compute and samples the same memory as
R9G9B9E5. Sizes seen: ten at 2560x1440, 1280x720, 2048x456, 2048x512, 2304x576, mip-like chains from 640x360 down to 40x23, 128x128x6 and 128x128x8, and five 80x45x64 volumes. Among the readers are the tiled-lighting pixel stages (two full-resolution ones each) and the scattering passes.Why I think this PR does not share them:
texture_keycomparesfamily(pc_format(desc.format)), andfamily(42)is 39 whilefamily(67)is 67 (not inFAMILIES), sofind_live_texturereturns nothing and the view keeps a separate host texture fed from title memory. Sharing one host texture would not work for this pair anyway, since no typeless family holds both formats.What I tried as an experiment on my own tree (not on this branch): before a list samples such a view,
CopyResourcefrom theR32_UINThost texture into theR9G9B9E5one. The Direct3D 10.1 format-conversion table listsR32_UINT/R32_SINTwithR9G9B9E5_SHAREDEXPas a copy that reinterprets the bits. On this card that ran over a thousand copies across 35 addresses with no device removal. I have no evidence yet that it changes the picture: 47 of the 50 source textures are themselves zero in my runs because the passes that fill them are dropped or produce zero, so treat the copy as untested for correctness.Two questions, if useful to you:
R9G9B9E5shader view on anR32_UINTresource? The pages I read do not say, which is why I copied.@nathanbzrr on GitHub · 2026-11-24 22:03 UTC · original
Closing this PR as superseded by recent
main(70564ae):13bbd6f(GPU: one host texture per texture memory, and writable twins for depth textures, decision 0007) now shares one host texture per texture memory across resource objects and placed views viaMemoryKey/MEMORY/shared_texture, usesCreateCommittedResource3castable format lists, adds writable twins for depth+UAV textures (twin.rs), and already clears padding words 1 and 13 intexture_at.683ad7abridges textures sharing memory under differing descriptions via host copies.Thank you @rpmaster2 for the earlier review feedback! The small
canonical_srv_desc/canonical_uav_descpadding-zeroing helper fromcrates/victory-gpu/src/descriptor.rscan be submitted as a standalone follow-up PR onmainif descriptor deduplication still needs it.Pull request closed