GPU: flush only overlapping shadow refreshes before Step::GpuWrite #1471
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/1472"
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?
Imported from Marvisak/VIctory. Originally posted by Sakura-Byte on 2026-11-24T18:17:34Z.
Summary
HostList::run_deferredcalledbatch.flush()on everyStep::GpuWrite(shadow, address, len), draining pendingStep::Refreshentries for all shadow buffers in the submission whenever shaders declared a write to any single buffer range.Batch::flush_one(shared withBatch::flush) and addedBatch::flush_gpu_write(shadow, address, len)incrates/victory-gpu/src/host.rs:len == 0returns without flushing.shadowwhose queued[from, to)range overlaps[address, address.saturating_add(len))beforeshadow.writing(address, len)snapshots title bytes.Shadowbuffers and disjoint ranges onshadowstay queued inBatch::refreshesso subsequentStep::Refreshsteps across the submission keep coalescing instead of flushing prematurely.host::batch::gpu_write_flushes_only_overlapping_shadow_refreshesverifying zero-length/disjoint no-ops, immediate flushing of overlapping same-shadow refreshes beforeShadow::writing, and continued coalescing of unrelated shadows acrossStep::GpuWrite.Verification
Ran cleanly on clean
origin/main(ffe310e) withCargo.lockuntouched:cargo xtask policy:asset policy: 154 files okcargo clippy --workspace --all-targets --locked -- -D warnings: passed (0 warnings)cargo clippy --workspace --all-targets --all-features --locked -- -D warnings: passed (0 warnings)VICTORY_D3D12_WARP=1 VICTORY_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked host::batch -- --test-threads=1:3 passed; 0 failed; 1 ignored(texture_checks_per_submissionbenchmark ignored)VICTORY_D3D12_WARP=1 VICTORY_WARP=1 VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --features diagnostics --locked -- --test-threads=1:54 passed; 0 failed; 1 ignored(only the existinghost::batch::texture_checks_per_submissionbenchmark ignored)AI-assisted; synthetic tests only, zero game assets.
Imported from Marvisak/VIctory. Originally posted by 0xKaji on 2026-11-24T19:52:35Z.
Tested
c00db2con Linux + Wine11.22+vkd3d-proton 3.2.0+ NVIDIA RTX 3060 8 GB (cross-built withcargo xwin):clippy -p victory-gpu --tests -D warningsis clean andgpu_write_flushes_only_overlapping_shadow_refreshespasses. But there's a regression in howflush_gpu_writeinteracts with the bounding-box snapshot inShadow::writing, and I've reproduced it with a unit test.What goes wrong
Shadow::writingkeeps one snapshot per copy and submission,[min(at, from), max(at + len, to)), and fills any gap between declared ranges from the copy (self.data). Onmain, everyStep::GpuWriterunsbatch.flush()first, so the gap bytes already include every queued refresh. With this PR, only refreshes that overlap the declared bytes get flushed. A queued refresh of the sameShadowthat sits in the gap gets snapshotted with its pre-refresh bytes:GpuWrite(s, 0, 256): snapshot[0, 256)Refresh(s, PAGE, 256): queuedGpuWrite(s, 2*PAGE, 256): disjoint, so the refresh stays queued, and the snapshot grows to[0, 2*PAGE+256)with stale bytes atPAGEGpuWrite(s, PAGE, 256): the refresh is flushed now, butwritingreturns early (the range is already inside the box), so the snapshot keeps the stale bytescopy_back(PAGE, 256)seescopy != snapshotand treats the refreshed title bytes as GPU-written. Any title write made to that range in the meantime gets overwritten with the older bytes. This is the scenario thecopy_backdoc comment warns about (title records broken by old bytes being put back).The PR's own test steps into the same state: the zero-length
GpuWrite(addr_a, 0)leavesbefore = Some((0, [])), so the nextGpuWrite(addr_a + PAGE, 256)grows the snapshot over the still-queued[0, 256)refresh. That test passes only because title memory doesn't change between the refresh andcopy_back.Repro (GPU test, NVIDIA +
vkd3d-proton 3.2.0)disjoint_refresh_is_in_the_snapshot_a_later_gpu_write_coversmain(ffe310e)c00db2c)copy_back treated refreshed bytes as GPU-written(left: 256, right: 0)Test (for
mod batchinhost.rs)Suggested fix
Flush the same-
Shadowrefreshes that overlap the range the snapshot will cover afterwriting, not just the declared bytes. This also covers thelen == 0case, which can still grow an existing snapshot. OtherShadows stay queued, so the cross-buffer coalescing this PR is after is kept:With this, the repro passes and
clippy -D warningsstays clean. As expected, the first assertion ofgpu_write_flushes_only_overlapping_shadow_refreshes(batch.refreshes.len() == 1after the zero-length and disjoint writes onshadow_a) now fails, because that queuedshadow_arefresh is exactly the one the grown snapshot covers. That test would needshadow_a's disjoint write to be the first range of the submission (or to drop the zero-length write in front of it) to keep checking the coalescing it's meant to check.Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T01:29:24Z.
Automated triage for the maintainers.
Needs rebase. This pull request conflicts with
main(conflicting:crates/victory-gpu/src/host.rs). It will be reviewed once it is rebased onto the currentmain.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.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.