GPU: flush only overlapping shadow refreshes before Step::GpuWrite #1472
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!1472
Loading…
Reference in a new issue
No description provided.
Delete branch "github-bot/gh-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?
@Sakura-Byte on GitHub · 2026-11-24 18:17 UTC · original
Sakura-Byte:pr/scope-gpu-write-flush→main· +122 −8 · 1 files · 1 commits · openSummary
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.
github-bot referenced this pull request2026-11-26 04:55:46 +00:00
@0xKaji on GitHub · 2026-11-24 19:52 UTC · original
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.@Marvisak on GitHub · 2026-11-25 01:29 UTC · original
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
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.