GPU: track texture subresource states #594
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!594
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-594"
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?
@broccolize on GitHub · 2026-11-24 05:17 UTC · original
broccolize:gpu/track-texture-subresource-states→main· +829 −416 · 11 files · 1 commits · openTrack texture states per subresource during command recording and submission.
CopyTextureRegioncan now keep two slices of the same texture inCOPY_SOURCEandCOPY_DESTat the same time. Whole-texture barriers handle mixed states.The synthetic regression copies slice 0 to slice 1, verifies the destination bytes, and checks that slice 2 stays in
COMMON. It fails when the old whole-texture copy transitions are restored.On Windows GNU, 44 GPU tests passed with default settings and 46 passed with diagnostics on WARP. Asset-policy checks passed. The workspace suite passed with one loader fixture skipped because its MSVC linker flag also fails on GNU at upstream
main. The D3D12 debug layer could not initialize on this machine.This touches state-tracking code also used by the render-view mip work in #559.
AI-assisted with Codex. All verification used synthetic inputs.
71bc6daea0toc6e6daaee8@fuzeofficlal on GitHub · 2026-11-24 05:39 UTC · original · edited 2026-11-24 07:15 UTC
I tried #559's synthetic draw on
3070871. The direct D3D12 control passed on RTX 5090 and WARP. Through normal draw setup, the debug layer still reported that the SRV's mip 0 was inRENDER_TARGETat the bind. That case stopped before submission.The small follow-up selects the mip ranges of plane-zero 2D color SRVs and RTVs using this PR's tracker. On both adapters and with both same-list and separate-list readback, all 64 pixels of mip 0 were preserved and all 16 pixels of mip 1 matched the sampled color. The D3D12 debug callback reported zero errors through submission. This PR's existing array-slice copy regression also passed on both adapters. Incremental commit on
3070871I tested the adjacent UAV case on top of that follow-up. The synthetic compute shader reads mip 0 through a restricted SRV and writes one texel in mip 1 through a UAV on the same 2D color texture. On
77a3e30, descriptor-table preparation put both mips inUNORDERED_ACCESS. The RTX 5090 debug layer reported the mip 0 state at bind, and I stopped that run before submission.The patch uses the existing tracker to transition only the mip selected by the UAV. On RTX 5090 and WARP, both descriptor orders now leave mip 0 shader-readable and mip 1 writable. All 64 source texels were preserved, the one intended write matched, the other 15 destination texels were unchanged, and the debug callback reported zero errors through submission. The diagnostics GPU suite passed (46 passed, one benchmark ignored). UAV follow-up commit
I also tested a 1×1
ClearRenderTargetViewon an explicit 2D-array view of mip 1 in slices 1 and 2. On3070871, the debug layer caught the untouched slice 0 leavingCOPY_SOURCE; the test stopped before submission. With the array-clear follow-up on top of1b333b3, only the two subresources in the view transitioned. RTX 5090 and WARP each read back both expected changes and all 58 untouched texels, with zero D3D12 errors. Array clear follow-up commit@broccolize on GitHub · 2026-11-24 07:29 UTC · original
Thanks @fuzeofficlal for verifying the array-slice regression on RTX 5090 and WARP and for sharing the three tested view-state fixes.
Would the maintainers prefer to include those fixes in this PR or land the tracker first and handle the view fixes in follow-up PRs? #559 already covers some of the SRV/RTV work.
@Marvisak on GitHub · 2026-11-25 00:29 UTC · original · edited 2026-11-26 07:20 UTC
Automated triage for the maintainers.
Merge candidate. Rebased; merges cleanly.
crates/victory-gpu/src/host/states.rsreplacesHostTexture's singleAtomicU32state with per-subresource tracking:Uniformuntil a command needs to split them.RecordedTexturekeeps each list's first and last state per subresource.reconcileadds prelude barriers and commits the final states in submission order.The subresource count includes plane count and treats 3D depth slices correctly. The array-slice copy test in
resource.rschecks mixedCOPY_SOURCE/COPY_DESTstates and an untouched slice, both on readback and in the committed states. Note for whoever merges: this overlaps #559 (mip ranges for SRV/RTV), and the view-state follow-ups mentioned in the comments are not part of this PR.CI: passing.
Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-26 14:15 UTC · original · approved these changes
Reviewed and verified head
c6e6daaee8ea288591decbbfdef5810b0e941cf1(clean merge withorigin/main63bcca43) on Windows 11 x64 with NVIDIA GeForce RTX 5090 and D3D12 WARP (VICTORY_D3D12_WARP=1,VICTORY_D3D12_DEBUG=1, Rust 1.98.1).Code review
crates/victory-gpu/src/host/states.rs:TextureStates(L8) andSubresources<T>(L79) keep uniform textures allocation-free until a command distinguishes subresources, andHostTexture::subresource_count(L23) properly treats 3D textures asarray_size = 1while queryingD3D12_FEATURE_FORMAT_INFOforPlaneCount(covering 2-plane depth-stencil formats).RecordedTexture::record(L117) andreconcile(L169) handle allUniform/Splitcombinations cleanly: first uses defer to the prelude, identical transitions emit zero barriers, out-of-range guest subresource indices are safely ignored (L146), andreconcilecollapses split committed states back toUniformonce all subresources match.crates/victory-gpu/src/host.rs&queue.rs:execute_texture_read(L1167) andpresent_with_compositor(L3225) now holdHost::submittedacross state snapshots throughexecute_locked, closing the prior locklesshost_transitionrace during present (andexecute_lockeddropssubmittedbeforedump_submission, so there is no self-deadlock).prelude(L1967) runs twin copies viatemporary_barriersbefore reconciling list start/end states, and multi-planepresenttransitions only subresource 0 (L3433-3439) to preserve other mips/slices.crates/victory-gpu/src/list.rs:host_barrier(L498) flushes pending barriers before routing a depth twin (L523-527), andcopy_texture_region(L801-804),read_back(L905), andresolve(L1000) transition individual subresources while sharing oneArc<HostTexture>for self-copies.capture.rswith open #2732/#2702 (which still readcopy.state), and overlaps #559 for view-range narrowing as already noted.Verification
cargo xtask policy:192 files ok;cargo clippy --locked -p victory-gpu --all-targets -- -D warnings(default &--all-features): 0 warnings--features diagnostics,--test-threads=1): 247 passed, 0 failed, 1 ignored; withVICTORY_D3D12_DEBUG=1(skippingcompositor_failure_presents_primary_in_the_same_frame, which already aborts with exit code 2173 underVICTORY_D3D12_DEBUG=1onorigin/main63bcca43due to a pre-existing 64×64 vs 32×32 fallbackCopyResourcemismatch): 246 passed, 0 failed, 1 ignoredvictory-gpu --lib --test-threads=1(skipping only the 2 pre-existing 1M view-heap tests): 230 passed, 0 failed, 1 ignored (includingtexture_copy_keeps_array_slice_states_separateandcompositor_failure_presents_primary_in_the_same_frame);diagnostics+VICTORY_D3D12_DEBUG=1core suites (draw,resource,texture,queue,twin,placed_uav_tests,host,bindless,list,capture): 101/101 passedbefore == afterbarriers,execute_texture_readstate preservation,ALL_SUBRESOURCEScollapse back toUniform, 2-planeD24_UNORM_S8_UINT, 3D 2-mip (depth=4) subresource count, and 64×64 multi-plane compositor present with a mixed-mip overlay — 0 D3D12 Debug Layer messages.Solid state-tracking foundation; approving.
@andrewpozdnakov7-jpg on GitHub · 2026-11-26 14:36 UTC · original
The conflict with the clear and MSAA capture changes is resolved in integration
5e2e85a. The standalone capture submission takes the existing state snapshot lock and restores only the captured slice. Your array-slice copy test and both capture regressions pass on app-local WARP. The maintainers can use the conflict resolution in whichever merge order they choose. WARP results and test details.Please retain the Git authors on pickup. If folding the resolution into another commit, use
Co-authored-by: andrewpozdnakov7-jpg <[email protected]>.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.