GPU: guard subresource and region bounds in texture copies and MSAA resolves #2047
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!2047
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/2047/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?
@fuzeofficlal on GitHub · 2026-11-25 04:06 UTC · original
fuzeofficlal:fix/gpu-copy-resolve-subresource-box-bounds→main· +1356 −29 · 1 files · 1 commits · closed without mergingSummary
D3D12_BOXregions, destination coordinates, sample counts, subresource dimensions, same-host-texture aliases, and element sizes before recordingCopyTextureRegion,CopyResource, orResolveSubresourceon the host command list.Testing
VICTORY_D3D12_DEBUG=1 cargo test -p victory-gpu --lib --locked -- copy_and_resolve_reject(verified on NVIDIA RTX 5090, AMD Radeon Graphics, and D3D12 WARP with 0 debug errors)VICTORY_D3D12_WARP=1 cargo test -p victory-gpu --features diagnostics --lockedcargo clippy --workspace --all-targets --all-features --locked -- -D warningscargo xtask policy@jeremygold02 on GitHub · 2026-11-25 04:15 UTC · original
Triage verdict — Keep the bounds checks, retain valid MSAA copies and regional resolves (
eb6f971)Evidence
CopyTextureRegionnow rejects every multisampled source or destination. D3D12 permits a whole copy between compatible multisampled subresources with matching sample counts, zero destination offsets, and a null source box. Wrapper guards · D3D12 copy contractResolveSubresource. Resolve check · Regional pathChecks and limits
Next step
This verification was AI-assisted.
@fuzeofficlal on GitHub · 2026-11-25 04:41 UTC · original
Updated in
af6e4a0e— thanks @jeremygold02 for catching both cases:CopyTextureRegionmultisampled whole-subresource copies:SUBRESOURCE -> SUBRESOURCEcopies withSampleDesc.Count > 1now run whenSampleDescmatches,source_boxis null,(x, y, z) == (0, 0, 0), and the source/destination subresource extents match (whileFOOTPRINTand sub-box/offset MSAA copies remain rejected).ResolveSubresourceRegionclipping:resolve_extentsnow returns(dst_size, src_size)for the selected subresources rather than requiring equal extents up front, routingdst_size == src_sizetoResolveSubresourceand mismatched extents toResolveSubresourceRegionclipped tomin(dst_size, src_size).CopyTextureRegionand both full and clippedResolveSubresourceRegionpaths across RTX 5090, AMD RDNA2, and WARP.@Marvisak on GitHub · 2026-11-25 09:19 UTC · original · edited 2026-11-25 16:18 UTC
Automated triage for the maintainers.
Recommended for a maintainer's look (re-reviewed after the rebase). In
crates/victory-gpu/src/list.rs,copy_resource,copy_texture_regionandresolvenow check subresource indices (subresource_extent, including the second plane of depth/stencil formats), footprint pitch and block alignment, source boxes and destination extents, sample counts and element sizes before recording, and log each kind of rejection once. I checked the subresource index formula, the block conversion for BC to 64/128-bit copies, that whole-subresource MSAA copies and the clippedResolveSubresourceRegionpath still run (the points raised earlier by @jeremygold02), and thatresolvenow clips by the selected mip's size rather than mip 0's. A contributor's comment also reports that the shared-host-texture guard removed a run of COPY_DEST state errors in a title run.One thing for the maintainer to decide:
copy_texture_regionnow drops copies between two different subresources of the same texture (the#594shortcut comment).mainrecords those today with a whole-texture state that the debug layer flags, so this trades a state error for a skipped copy until per-subresource tracking exists.CI:
checkpassing on this head.Generated by Claude Code
@fuzeofficlal on GitHub · 2026-11-25 10:04 UTC · original
Updated in
bd6b3f98per triage feedback:warn_once!):copy_resource,copy_texture_region,resolve_extents, andresolvenow logs once viatracing::warn!with structured fields (matchingcopy_buffer_region's"copy outside its buffer"pattern).source_box(left >= right || top >= bottom || front >= back) as a silent documented D3D12 no-op, and verified with a customtracingsubscriber incopy_and_resolve_reject_out_of_bounds_subresources_and_boxesthat empty boxes emit0warnings while repeated out-of-bounds boxes emit1warning.#594shortcut:resolve_extents(a.SampleDesc.Count != 1 || b.SampleDesc.Count <= 1already excludes resolving a texture to itself).// shortcut: ... (#594)comment on the shared-host-texture rejection incopy_texture_regionexplaining that copying between distinct subresources of one texture (or aliased title textures sharing aHostTextureviaresource::shared_texture) requires per-subresource state tracking (#594) becauseHostList::transitioncurrently tracks whole textures.resource::shared_texture/memory_key+takes) and#594whole-texture state transitions (dst.resource == src.resourceorptr::eq(to, texture)).pc_format118..=120->45..=47, changing plane counts and plane element byte sizes) andhost_desctypeless/castable format selection (subresource_extent,elemmatch, andresolve_extentsformat-family checks).resolve_extentsrouting mismatched extents toResolveSubresourceRegioninstead ofResolveSubresource).@Venom2054 on GitHub · 2026-11-25 10:28 UTC · original
Native Windows/NVIDIA evidence for the whole-resource shared-host-texture guard, plus two supplemental regression tests for bd6b3f986a8943225835309fb8ce02343988f973.
RTX 5070 Ti 16 GB, driver 621.01; i7-14700, 32 GB RAM, Windows 11 Pro 26200.
Runtime motivation: before the guard, a D3D12 debug run logged 48 ID 538 errors from CopyResource: the 2560x1440, format 19 depth texture destination was in COPY_SOURCE rather than COPY_DEST (planes/subresources 0 and 1). I independently narrowed this down to distinct title objects sharing one host resource, then found the equivalent guard already in this PR.
With only the equivalent whole-CopyResource early return added to the local integration stack, the guard's once-only diagnostic fired during the title run. The 345.7-second debug run had zero texture ID 538 errors and no logged device removal. It was stopped manually. This is evidence for this particular guard, not validation of every check in the larger PR. Frames reached differ, so these counts are observational, not a benchmark. Buffer state errors and shader translation refusals remain; rendering is still severely malformed and not playable. A preceding attempt ended early without a captured exit code or logged GPU-removal message; it is not counted as a successful stability run.
Synthetic validation, independently on this PR's exact head plus the two tests below:
The same two tests also pass on main
940d32fwith only the narrow guard added (hardware and WARP). Separately, the combined local stack passes 752 workspace tests (11 ignored) and 166 GPU debug tests (3 ignored), build, Clippy with -D warnings, and asset policy. Those combined-stack counts are not claimed for this PR alone.Runtime stack for reproducibility: main
940d32f, #2177 plus a local fallback fix, GPU commit93c4e181from #1926, #1762, #1906, #2098, #89, #189, #1152, #1803, #2276 and #2155, then the narrow equivalent guard. Wave64 auto selected Emulate; GPU timing off, default loop limit, no skipped pipelines. The full #2047 was used for the isolated synthetic tests, not for this title run.The patch below adds only the two synthetic tests to bd6b3f98. No game data, private paths, screenshots or raw logs are included. This is supplemental evidence for the existing PR, not a claim to have originated its guard. Integration and test authoring were assisted by OpenAI Codex.
Supplemental test-only patch against bd6b3f98
@Marvisak on GitHub · 2026-11-25 22:05 UTC · original
Automated triage for the maintainers, second look (a review against current
main, with builds and tests where they could change the verdict).Closing because it is too broad for its evidence. It rewrites the copy path the title uses most so that about 25 kinds of command are dropped, and only one of them has a case from the title (the
copy_resourceguard for two title textures that share one host texture, tested in the thread). One of the others is a likely regression: copies between two subresources of one texture are now skipped, wheremainrecords them. Two parts would be welcome separately: thecopy_resourceskip when source and destination are the same host texture, with its test, and the resolve mip-extent fix, which #652 does in 40 lines.If this is mistaken, reply here with what was missed and it will be looked at again. Thank you for the contribution.
Pull request closed