D3D12.X: clamp destination rows, slices, and buffer_bytes in footprint_plan and guard GetCopyableFootprints failure #3432
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3432"
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 ivall/xcl. Originally posted by Kalmarv on 2026-11-29T15:42:18Z.
What changed
buffer_bytes: u64toFootprintSide::Destinationincrates/xcl/src/hle/d3d12x/list_x.rsand passedbuffer.GetDesc().Widthfromcopy_texture_region_realigned.FootprintSide::Destinationrowsto..rows,slicesto..depth, and eachRowCopy's byte length tobuffer_bytes.saturating_sub(at)(breaking onceat >= buffer_bytes), matchingFootprintSide::Source.scratch_bytesinfootprint_plan(passing through on overflow) and saturating range arithmetic incopy_texture_region_realigned.copy_texture_region_realigned::unit()againstGetCopyableFootprintsfailure (rows == 0 || row_size == 0 || row_size == u64::MAX).footprint_plan_testscovering destination row/slice clamping toscratch_bytes, tight destinationbuffer_bytestruncation/omission, and overflowingscratch_bytes.Why
FootprintSide::Sourceclampedrows,slices, and per-row copy lengths againstbuffer_bytes, whileFootprintSide::Destinationiteratedysandzsunclamped with no destination buffer bound. A texture-to-bufferCopyTextureRegionwhose box or subresource extent exceeded the placed footprint'sHeight/Depthor targeted a tightly sized buffer emittedRowCopyregions pastscratch_bytesorbuffer_bytes, causing out-of-boundsCopyBufferRegioncalls.GetCopyableFootprintsfails (e.g. invalid subresource index), D3D12 writesu64::MAXintorow_size, whichunit()divided into a hugeper_blockvalue instead of returningNone.Tested
cargo check --workspace --all-targets(0 errors, 0 new warnings).cargo build --workspaceandcargo build --release -p xcl.footprint_plan_tests(10/10 passed;texture_to_buffer_clamps_rows_slices_and_buffer_bytesreproduced OOBRowCopypastscratch_bytesonorigin/main37be0959before the fix).cargo test --workspace -- --test-threads=4, exit 0, 0 failures across all crates).xcl-smokeon PR head (def60f8d) andmain-ancestor baseline (f0e8fdd5):Not tested
ea3b5e4d.GetCopyableFootprintscall insidecopy_texture_region_realigned.AI use
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T03:33:16Z.
merge-check
base:
d0832e614fhead:
def60f8dc2merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2891 passed, 0 failed, 51 ignored; SKIPPED: 28 (20 no wave64, 2 no d3d12SDKLayers.dll, 1 no D3D12 debug layer, 1 no heap windows, 1 cannot disable the driver cache, 3 others; the same set as on main); failing: none. The pipeline_library / warm_library tests that failed in this PR's CI run all pass here, so that CI failure doesn't come from this diff.
review: read the whole diff (list_x.rs, +53/-10). The clamp fixes a real out-of-bounds write-back: on main the Destination branch of
footprint_plandoesn't clamp rows or slices, sor = z*rows + ycan point at the next slice or past the scratch buffer, and stale scratch bytes are written over the title's buffer or the CopyBufferRegion goes out of bounds. Valid copies get the same copy list as on main; only copies whose box already runs past the footprint's Height/Depth or the buffer's end change. The new test's expected values are right (rows 6 and 7, then 32 and 20 bytes), and its logic would fail on main. Findings: (1) theunit()guard for a failed GetCopyableFootprints (~6770) relies onrow_sizecoming back as u64::MAX, which Microsoft doesn't document, and no test covers it; harmless as a fallback. (2)bytes: bx0..bx0 + w.div_ceil(bw) * per_blockis still not saturating while rows and slices now are (low risk with the guard). (3) Description: AI use names neither tool nor model; Tested has no passed/failed/ignored counts; both of the PR's smoke runs end atpresents per 2 s: 0 0 0, so the title had stopped presenting and the copy path is probably not reached there, which Not tested should say.performance: 60 s smoke of a retail title, main
d0832e61vs this merge (eb221f70): 1516 -> 1669 frames shown (110 %; 60 presents per 2 s in both), peak commit 18133 -> 16913 MB, no device removal, no crash. Valid copies get the same copy list as on main; one more GetDesc per scratch-path copy.verdict: safe to merge (after a CI rerun; the description should name the AI model and add the suite counts)
hardware / tool and model: RTX 5070 Ti (driver 621.14), Ryzen 7 7800X3D, Windows 11 26300 / Claude Code with Claude Opus 5.5
AI-written and posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:27Z.
Review: COMMENTED
Review of
def60f8d: 3 finding(s). 2 are inline. These are on lines outside the diff:crates/xcl/src/hle/d3d12x/list_x.rs:6687: The saturating math wasn't applied to the Source arm:offset + r0 * p(6687) andoffset + r * p(6696) are still unchecked. A buffer-to-texture copy with a junk title Offset (e.g. 0xFFFF_FFFF_FFFF_FF00) and pitch 100 panics in debug inside anextern "system"hook, which aborts the process. In release it wraps to a smallat,buffer_bytes.saturating_sub(at)is nonzero, and CopyBufferRegion reads the wrong bytes into the texture.These findings come from an AI-assisted review (Claude Code) and focus on correctness. Each is a candidate; please check it before acting on it.
Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:28Z.
Code review location:
crates/xcl/src/hle/d3d12x/list_x.rs; line 6707When a texture-to-buffer box runs past the footprint, the Destination arm cuts
rows/slicesdown to the footprint, but the PC texture copy into the scratch (~6817) still uses the original out-of-rangey/z/bx, and the clipped rows are still written back to the title's buffer. A CopyTextureRegion into a placed footprint with Height=4, dst y=2 and a box of height 4 (rows 2..6) has a scratch footprint with the same Height/Depth, so PC D3D12 rejects the copy or does something undefined.footprint_planstill returns ViaScratch with write-backs for rows 2..4, so whatever the scratch held from earlier copies overwrites the title's buffer. Returning PassThrough/false (with a warning) when the box goes past fp.Height/Depth/Width would avoid writing garbage.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T05:44:28Z.
Code review location:
crates/xcl/src/hle/d3d12x/list_x.rs; line 6674When
scratch_bytesoverflows,footprint_planreturns PassThrough, so the caller sends the misaligned footprint (Offset%512 != 0 or RowPitch%256 != 0) to PC D3D12 unchanged. That's invalid API use, and unlike thecopy_scratchfailure path nothing is logged, so the copy is dropped silently or the debug layer reports it. Returning a distinct skip/fail result with awarn(&N, W, ...)would match the other failure path.Imported from ivall/xcl. Originally posted by bmjask on 2026-12-02T14:13:53Z.
@Prime1997 could you take a look at this one for review and merge? My automated review notes are above, if any.
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.