GPU: give depth targets their unordered access through a twin texture #469
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!469
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/469/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?
@AnoHunted on GitHub · 2026-11-24 03:47 UTC · original
AnoHunted:depth-uav-twin→main· +431 −9 · 4 files · 1 commits · closed without mergingWhat
A title texture that is both a depth target and unordered access (flags
DEPTH | UNORDERED) now gets a secondhost texture, its twin, and its unordered access views are made on the twin. This is the plan in the code comment
in
resource::host_texture. The twin has the depth's description, withALLOW_UNORDERED_ACCESSin place ofALLOW_DEPTH_STENCIL, in the typeless format of the depth's family:R16_TYPELESSfor D16,R32_TYPELESSforD32.
Lists keep the two coherent where they already track texture states. That is
HostList::transition, whichensure_state, the title's transition barriers and every draw's and dispatch'sreadablego through:CopyResource), then moves the twin toUNORDERED_ACCESS. The depth itself is not touched while the twin is in use.and a title barrier out of
UNORDERED_ACCESS.HostList::close. Every list starts and ends with thedepth current, so the order lists are recorded and submitted in does not matter.
Also:
list::host_barrier).R16_UNORMfor D16,R32_FLOATfor D32. A view with no description becomes mip 0, every array slice. Otherformats of the family (
R16_FLOAT,R16_UINT,R32_UINT, ...) stay as the title asked.16-bit depth with stencil), for multisampled depth, or for depth that is not 2D. Those behave as before, with
one log line.
Files:
resource.rs(the twin,host_unordered),host.rs(transitionsplit intotrackandsync_twin/copy_texture, the copy-back inclose),descriptor/host.rs(views on the twin),list.rs(UAVbarriers).
Why
D3D12 does not allow
ALLOW_DEPTH_STENCILtogether withALLOW_UNORDERED_ACCESSon one resource. The consoleallows both, and the title's shadow maps ask for it (the code comment says so). Until now the host copy lost its
UAV use.
descriptor::host::fitsthen refused every unordered access view of it and loggedview the host does not allowwithunordered=true format=53 flags=2(R16_TYPELESS, depth only). The slotstayed a null view, and what compute shaders wrote through it was dropped.
Why plain copies: Microsoft's
CopyResourceandCopyTextureRegionpages allow copies between formats that are"identical or at least from the same type group", and say a depth-stencil resource can be the source or the
destination.
D16_UNORMis in theR16_TYPELESSgroup andD32_FLOATis inR32_TYPELESS. A depth texture thatshaders may read already has a typeless host copy (
DEPTH_FORMATS), so in that case the two textures have the sameformat. No full-screen pass writing
SV_Depthis needed. The test below checks that the bits survive bothdirections.
Why a typeless twin rather than
R16_UNORM/R32_FLOAT:fitsgives a view of a typed texture the texture's ownformat. A title view in
R16_UINTof aR16_UNORMtwin would be written as UNORM. A typeless twin keeps thetitle's view format. Only views with no color format get the one with the depth's bits.
Cost:
Optioncheck per state transition and nothing per draw.draw or dispatch.
Tested
Windows 11, NVIDIA GeForce RTX 5080, Rust 1.98.1; also WARP (
VICTORY_D3D12_WARP=1, diagnostics build).New host GPU test
resource::tests::unordered_writes_reach_a_depth_target:create_committed. ItsR16_UNORMUAV is made into a host heap by the same
makethat draws use. Acs_5_1shader (system compiler) writes avalue to its first N columns. Before each dispatch the test calls
list::ensure_state(.., UNORDERED_ACCESS), asreadabledoes.COPY_SOURCEand copies the depth texture itself toa readback buffer.
again by list 2), and 4-7 are 0.25 (the clear, kept through both copy-ins). It uses
HostListandHost::execute, so the preludes and state tracking are the real ones.texel (0, 0): 0x4000, wanted 0.5 (0x8000). The write is lost and the depth still holds the clear.Whole runs, main (
d2a4bae) and branch side by side in one job:cargo test --workspace(RTX 5080): main 264 passed, 0 failed, 4 ignored. Branch 265 passed, 0 failed,4 ignored (the new test).
cargo test -p victory-gpu --features diagnosticson WARP: main 45 passed, 0 failed, 1 ignored. Branch 46passed, 0 failed, 1 ignored.
cargo clippy -p victory-gpu --all-targets: the same single warning on both, inhost.rs:267, which thischange does not touch.
cargo xtask policy: 151 files ok on both.rustfmt --checkon the four files: the same number of reported spots on both, none on lines this change adds(the files were not rustfmt-clean before).
The test machine has no D3D12 debug layer (
D3D12GetDebugInterfacereturns0x887A002D), so there was nodebug-layer or GPU-based validation check of the copies and barriers.
Not tested
there.
with no description.
host_barrierkinds 0 and 2). The test goes throughensure_state, which ends in the sameHostList::transition.R16_UNORMneedTypedUAVLoadAdditionalFormats; stores do not.shortcut:insync_twin: a dispatch that reads the depth through a shader view after itsUAV was readied in the same dispatch loses its writes, because the read copies the twin back first. Whole-texture
states cannot hold both anyway. Views reached only by direct heap indexing are not transitioned, as before.
No game files were used.
The host refuses textures that are both depth targets and unordered access, so the host copy of such a title texture (the title's shadow maps) lost its UAV use, every unordered access view of it was refused ("view the host does not allow", unordered=true format=53 flags=2) and what compute shaders wrote through it never landed. Such a texture now gets a twin: the same description with unordered access instead of depth, in the typeless format of the depth's family (R16 for D16, R32 for D32), and its unordered access views and UAV barriers name the twin. Views that name a depth format or none take the color format with the depth's bits (R16_UNORM, R32_FLOAT). Lists keep the two coherent where they already track texture states (HostList::transition): unordered access after other use copies the depth into the twin, other use after it copies the twin back, and a list that ends with the twin ahead copies it back as it closes, so every list starts and ends with the depth current. CopyResource takes depth resources and formats of one type group, so plain copies keep the bits. Textures without a twin pay one check per transition.@DaviTostes on GitHub · 2026-11-24 03:51 UTC · original
Verified
c47c963on Arch Linux x86_64, Windows MSVC release build under Wine 11.22 (victory-gpu,--test-threads=1): 44 passed, 0 failed, 1 ignored.Not covered: a depth target actually sampled and written as UAV in the title (no game data here).
@Raxstreams on GitHub · 2026-11-24 04:05 UTC · original
Tested on a local integration with packed HDR aliases and native command-list continuations. The unordered_writes_reach_a_depth_target GPU readback passed, including the twin-to-depth copy. The combined GPU suite completed with 126 passed and four ignored.
@qntic on GitHub · 2026-11-24 09:30 UTC · original
I've independently implemented D32S8 depth-plane UAV support, as well as stencil-plane UAV support for both D24S8 and D32S8.
The stencil implementation preserves depth values while allowing stencil writes across command lists.
Both implementations pass hardware regression tests on an RX 6600 XT under native Windows, including D3D12 debug-layer validation, GPU-based validation and negative controls.
I noticed MichaelSmithAI's D32S8 PR. I'll compare our implementations to avoid duplicating work and share the additional stencil support.
@sambagarandawertanda on GitHub · 2026-11-24 10:44 UTC · original
An independent RTX 3080 check for the D16 twin texture approach. On native Windows with NVIDIA driver 621.14, the runtime rejected one
R16_TYPELESSresource with both depth and UAV flags (E_INVALIDARG). Separate depth and UAV resources allocated successfully, and the adapter reported typedR16_UNORMUAV load and store support.I cleared a 16×8
D16_UNORMdepth view to 0.25 with a 0.75 inset, then usedCopyResourceto bring it into theR16_UNORMUAV view. All 128 texels matched on GPU readback (16384 outside, 49151 inside). A compute shader complemented those values and copied the twin back to depth. All 128 matched again, with the two values swapped. The queue fence completed and the device stayed available.This was a standalone synthetic test of the copy path with explicit barriers. The debug layer was unavailable. VIctory’s list state tracking, shadow-map output, and copy cost in the title still need testing on this card.
@qntic on GitHub · 2026-11-24 11:11 UTC · original
ive published my d32s8 depth and stencil uav implementations here:
https://github.com/qntic/VIctory/tree/pub/depth-stencil-uav
346 tests passed, including hardware tests on rx 6600 xt, gpu-based validation and negative controls. clippy and warp tests also pass.
i cant open a pr because of the current repository restrictions, but feel free to review or cherry-pick my two commits if useful.
@qntic on GitHub · 2026-11-24 11:16 UTC · original
hey @Marvisak , would it be possible to get access to open PRs?
ive been contributing hardware regression tests, depth/stencil uav fixes and memory diagnostics on my rx 6600 xt. some of my tests have already been used by another contributor to identify issues on polaris.
i have two branches ready for review, with passing workspace tests and clippy checks:
https://github.com/qntic/VIctory/tree/pub/depth-stencil-uav
https://github.com/qntic/VIctory/tree/pub/memory-diagnostics
happy to keep contributing and testing on amd hardware.
Pull request closed