Repository navigation
GPU: share live host textures across aliased addresses and canonicalize view descriptors - #643
Closed
nathanbzrr wants to merge 3 commits into
Closed
nathanbzrr wants to merge 3 commits into
nathanbzrr wants to merge 3 commits into
Summary
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.