GPU: reuse unaligned root CBV scratch fills within a command list #3113
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!3113
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-3113"
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?
@fuzeofficlal on GitHub · 2026-11-26 08:28 UTC · original
fuzeofficlal:perf/gpu-cache-unaligned-root-cbv-scratch→main· +252 −7 · 2 files · 1 commits · openSummary
In
draw::root_view, binding a root constant buffer whose host address is not 256-byte aligned allocated a fresh scratch upload slice (up to 64 KiB) and queued a newStep::Fillon every draw, even when the same(address, len)had already been queued for upload earlier in the same command list with no intervening title-memory write.This adds a per-list scratch fill cache on
HostList:HostList::fill_scratch(crates/victory-gpu/src/host.rs): Caches(source_title_address, len) -> scratch_gpu_addressinDeferred::filled. Repeated requests for the same(src, len)return the existing 256-byte-aligned scratch GPU address without allocating additional scratch space or queuing duplicateStep::Fillcopies. Scratch allocation runs outside theDeferredlock to preserve thescratch -> deferredlock ordering when oversized allocations spill intodeferred.uploads.crates/victory-gpu/src/host.rs):Deferred::title_written()clears bothrefreshedandfilledatomically under thedeferredlock indefer_copy(Step::Copy) anddefer(Step::Run), so later draws observe updated title bytes without clobbering earlier scratch copies in the same submission.HostList::reset()replacesDeferredwithDeferred::default(), clearing the cache along with the scratch cursor.crates/victory-gpu/src/draw.rs):root_viewuseslist.fill_scratch(address as usize, len as usize)for unaligned root constant buffers.Tests
host::tests::fill_scratch_reuses_same_range_and_invalidates_on_title_writes_and_resetcovering 256-byte alignment, cache hits without growing scratch orStep::Fillcount, distinct length/offset isolation,defer_hostpreservation,defer_copy/deferinvalidation, andreset().draw::tests::unaligned_root_cbv_caches_scratch_and_refreshes_after_title_copyverifying real GPU constant buffer readback before and after an in-listdefer_copyupdate.cargo test -p victory-gpu --locked -- fill_scratch_reuses_same_range unaligned_root_cbv_caches_scratch list_scratch_grows_to_fit(3 passed on RTX 5090)VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --locked(248 passed, 0 failed)cargo clippy --workspace --all-targets --locked -- -D warningscargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo test -p xtask --locked policy::tests::repository_passes_policy@oni-swr on GitHub · 2026-11-26 08:47 UTC · original
Independent test report for #3113 at head
394efa6a26d474dbd5517806ee6e30fd9c562723(parent63bcca43c6a00a758510398fa43096ce7e4f7df0). Claimed at #1633. This is a test report only, not a source review. Synthetic data only; no game files.Environment: Windows 11 (10.0.26100), rustc/cargo 1.98.1,
cargo --locked -j 4,--features diagnostics(needed:VICTORY_D3D12_WARPis ignored without it),VICTORY_D3D12_WARP=1, Windows SDK 10.0.26100.0dxil.dllonPATH. This machine does have a physical AMD adapter installed, so I did not rely on the default adapter. A temporary test, not part of the PR and since removed, requiredhost()to beSomeand checked the host device's LUID againstEnumWarpAdapter. Both wereMicrosoft Basic Render Driver, flags0x2(software), vendor0x1414, LUID{91142, 0}. The same check passed on the parent runs.Results at head (WARP-verified):
host::tests::fill_scratch_reuses_same_range_and_invalidates_on_title_writes_and_reset: okdraw::tests::unaligned_root_cbv_caches_scratch_and_refreshes_after_title_copy: okhost::tests::list_scratch_grows_to_fit_and_reuses_fenced_chunks: okcargo test -p victory-gpu --features diagnostics --locked: 248 passed, 0 failed, 1 ignored.Parent control (parent source plus only the PR's draw test, WARP-verified):
same unaligned root CBV reuses scratch copy. On the parent every draw gets its own scratch slice.initial, initial, updated, so title-visible output is the same before and after the PR.cbv1=0x300000000, cbv2=0x300000400, cbv3=0x300000800. The head gavecbv1=cbv2=0x300000000, cbv3=0x300000400.fill_scratch, so it cannot run on the parent.Mutation controls at head, one scratch edit at a time, each reverted. Each run covered both new tests:
title_writtenno longer clearsfilledlenreset()keepsfilled5 of 5 mutants were detected. The draw test caught only the invalidation mutant, and the host test caught all five.
Not covered: physical GPUs (adapter forced to WARP only), concurrent or multi-threaded access, and title-memory writes through paths other than
defer_copyanddefer. Those two are the only invalidation paths this test exercises.Tested by Claude Code (Claude Sonnet 5.5); the claim was coordinated by Codex (gpt-6.2-sol).
@Dukestar69 on GitHub · 2026-11-26 08:54 UTC · original · approved these changes
Verified on RTX 5090 & WARP against
origin/main(63bcca4):cargo test -p victory-gpu --lib draw:: -- --test-threads=1: 21/21 passed on RTX 5090 and WARP (includingunaligned_root_cbv_caches_scratch_and_refreshes_after_title_copy).cargo clippy -p victory-gpu --all-targets -- -D warnings: clean.cargo xtask policy: 191 files ok.Cleanly caches unaligned root CBV scratch fills within a command list and invalidates/refreshes after title copies.
Synthetic tests only (no game files used). AI-assisted (Gemini 4 Neon).
@Marvisak on GitHub · 2026-11-26 09:19 UTC · original
Automated triage for the maintainers.
Merge candidate.
HostList::fill_scratchcaches(source, len) -> scratch addressinDeferred::filled, sodraw::root_viewno longer allocates scratch and queues aStep::Fillfor every draw that binds the same unaligned root CBV. Onmain, everyStep::Fillcopies at submission. The only steps that write title memory in between areStep::CopyandStep::Run(fromdefer_copyanddefer), and both now callDeferred::title_written, so a reused copy holds the same bytes a fresh fill would.resetreplacesDeferredand rewinds the scratch cursor, so the cache cannot outlive its memory, and the insert keeps the existing lock order. The readback testunaligned_root_cbv_caches_scratch_and_refreshes_after_title_copychecks the actual result before and after an in-list copy. Note: #3114 adds its ownDeferred::title_written, so whichever lands second needs a small rebase that clears both caches.CI:
checkpassing.Generated by Claude Code
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.