Repository navigation
D3D12.X: copy texture regions with unaligned footprints through scratch - #2873
tiagonleal wants to merge 1 commit into
Conversation
PC D3D12 requires a placed footprint's Offset to be a multiple of D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT (512) and its RowPitch a multiple of D3D12_TEXTURE_DATA_PITCH_ALIGNMENT (256), unless the device reports OPTIONS13.UnrestrictedBufferTextureCopyPitchSupported, in which case both only need to be multiples of the format's unit size. CopyTextureRegion with an invalid footprint is undefined behaviour (incorrect rendering, no copy, or device removal). Console footprints can be packed tighter. copy_texture_region_x noticed this only under XCL_TRACE_FRAME and still passed the footprint to the PC. footprint_plan (pure) decides between passing the call through and copying through the list's copy scratch at offset 0 with the pitch rounded up to 256. It passes the call through when the footprint is aligned, or when the device has the unrestricted capability (probed once; a failed query counts as unsupported) and offset and pitch are whole units. For buffer->texture only the rows and slices of the source box are copied: one buffer copy when only the offset is off, one per row of blocks otherwise, clamped to the end of the source buffer. For texture->buffer only the bytes the copy writes are copied back, so bytes between rows and outside the box keep their contents. With no scratch large enough the call goes as before, with a warning. Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com> Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Ran the unaligned-footprint planning tests at Environment: Windows 11 Pro build 26200 x64, NVIDIA GeForce RTX 5070 Ti (Blackwell, wave32 only, 16 GB) driver 32.0.16.2124, Intel Core i5-12400F, 64 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09), MSVC 14.44.35207, DXC 1.9.2609.5, debug build. All ten tests matching Not tested: a real AI-assisted (OpenCode), model: DeepSeek V4.1 Flash Free - checked out the PR's head commit in a detached worktree, built it, ran the tests, wrote this report; the worktree was not modified; no game data was used. |
|
Independent desktop NVIDIA verification of PR #2873 at head Environment
Targeted release tests & build (
|
| Command | Result |
|---|---|
cargo test --release -p xcl --lib <each of the 9 new footprint_plan_tests> -- --nocapture (9 individual runs: unrestricted_copy_pitch_takes_unit_aligned_footprints, a_source_box_copies_only_its_rows_and_slices, an_aligned_footprint_goes_as_it_is, an_odd_pitch_copies_each_row_to_a_256_byte_pitch, an_odd_offset_with_an_aligned_pitch_is_one_copy, an_odd_offset_and_pitch_stop_at_the_end_of_the_buffer, block_compressed_rows_are_rows_of_blocks, depth_slices_follow_one_another, texture_to_buffer_writes_back_only_the_copied_bytes) |
1 passed; 0 failed; 0 ignored; 1350 filtered out each (0.00s each) |
cargo test --release -p xcl --lib hle::d3d12x::list_x:: (3 consecutive runs) |
49 passed; 0 failed; 0 ignored; 1302 filtered out × 3 (0.69s, 0.69s, 0.69s) |
cargo test --release -p xcl --lib hle::d3d12x::real:: |
63 passed; 0 failed; 0 ignored; 1288 filtered out (0.36s) |
cargo build --release -p xcl --bin xcl |
Clean build (1m 11s, exit 0) |
Paired quiet 60 s retail smoke (title: 29640639)
Exact parent & merge-base (e120925e3abc9956a8b9bae631969d32e8ccd43c, cached baseline on the same machine):
xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1602 (PresentX 1602)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 13979 MB
PR #2873 (1f3d506d0d87f72e3179e66c333e8e5f76935f9b):
xcl-smoke v1
commit: 1f3d506d0d87f72e3179e66c333e8e5f76935f9b
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1591 (PresentX 1591)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14012 MB
Runtime log observations (xcl.log)
9220log lines,0[ERROR]/ device-removal / panic lines.- Final draw/memory telemetry in log:
19507 draws with translated pipelines (0 skipped, 0 with PC pipelines), 1024 dispatches (0 skipped); last memory sample14011 MB committed by the process; video memory 6114 MB local, 4683 MB non-local.
Limits of coverage
- The 9 new
footprint_plan_testsare pure CPU layout/planning unit tests coveringOPTIONS13.UnrestrictedBufferTextureCopyPitchSupported, odd offset/pitch realignment, block-compressed rows, depth slices, and texture-to-buffer writeback; no dedicated on-GPU readback test executing an unalignedCopyTextureRegionthrough the scratch buffer and reading back pixels was run. - The 60 s retail smoke confirms end-to-end graphics stability and zero regression on
title: 29640639, though the 60 s menu capture was not confirmed to hit the scratch-realignment fallback path (and RTX 4060 may also allow unit-aligned footprints viaOPTIONS13.UnrestrictedBufferTextureCopyPitchSupported).
AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).
copy_texture_region_xpassed console placed footprints to the PC as they were. On PC D3D12, a placed footprint'sOffsetmust be aligned toD3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT(512) "unlessD3D12_FEATURE_DATA_D3D12_OPTIONS13::UnrestrictedBufferTextureCopyPitchSupportedis TRUE" (D3D12_PLACED_SUBRESOURCE_FOOTPRINT).RowPitchmust be a multiple ofD3D12_TEXTURE_DATA_PITCH_ALIGNMENT(256) (D3D12_SUBRESOURCE_FOOTPRINT). When the capability is present, offset and row pitch only need to be aligned to the format's unit size (DirectX-Specs, VulkanOn12). Invalid parameters toCopyTextureRegionare undefined behaviour and "might result in incorrect rendering, clipping, no copy, or even the removal of the rendering device" (CopyTextureRegion). The console accepts tighter footprints. The code already noticed these footprints, but only logged them underXCL_TRACE_FRAME, for the source side only and before adding the placement delta.Such a copy now goes through the list's copy scratch (
copy_scratch) at offset 0, with the pitch rounded up to 256. XCL queriesOPTIONS13once. If the device reportsUnrestrictedBufferTextureCopyPitchSupportedand the offset and pitch are whole units of the format, the call goes through unchanged. A failed query counts as FALSE.For buffer to texture, only the rows and slices in the source box are copied into the scratch. That is one
CopyBufferRegionwhen only the offset is unaligned, or one per row of blocks otherwise, stopping at the end of the source buffer. For texture to buffer, the texture is copied into the scratch and only the bytes the copy writes are copied back. Bytes per block come fromGetCopyableFootprintsof the texture subresource. Aligned footprints take the same path as before. If the list has no scratch large enough, the call is issued as before and a warning is logged. That happens in a bundle, when the 64 MiB budget is used up, or when the list already recorded a smaller scratch.Based on
e120925e, the lastmaincommit before #2555 (see Regression run).What is in it
crates/xcl/src/hle/d3d12x/list_x.rs:footprint_plan: pass through, or the scratch pitch, size and buffer copies; takes the unit size when the capability is presentunrestricted_copy_pitch: the cachedOPTIONS13probecopy_texture_region_realigned: the copies and scratch transitions, called fromcopy_texture_region_xafterpc_location; the box is clamped to the rows and slices it namesfootprint_plan_tests:Tested
cargo test -p xcl --lib footprint_plan: 9 passed, 0 failed, 3 of 3 runs on 1f3d506footprint_planforced to returnPassThrough(the old behaviour) in the working tree, the same command gives 1 passed, 8 failed. The 7 planner tests that expect a scratch copy fail at thepanic!("expected a scratch copy")in the test helper (list_x.rs:4491), andunrestricted_copy_pitch_takes_unit_aligned_footprintsfails at its assertion (list_x.rs:4505). Onlyan_aligned_footprint_goes_as_it_ispasses.cargo test --workspace --no-fail-fast -- --test-threads=4, run twice on 1f3d506: 1447 passed, 4 failed, 47 ignored both times (25SKIPPEDlines: 21no wave64, 1no heap windows, 3 recompiler cases refused as unsupported). The 4 failures aregpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3(CreateComputePipelineStatereturns E_OUTOFMEMORY, 0x8007000E). They fail the same way one120925eon this machine (cargo test -p xcl --lib fuzz_validate_and_gpu: 0 passed, 4 failed).Regression run
scripts/smoke.ps1 -Seconds 60 -Title 9cc6a39e, default settings, release builds of both commits in clean trees,mainfirst, one run each.main(e120925):This PR:
NVIDIA profile for xcl.exe: shader heap 1024 MB
Both runs are on
e120925e, the lastmaincommit before #2555; I could not finish a first launch preparation on a commit that has it (stopped after 2 h 20 min at about 23,860 of 26,503 records on this machine), so the preparation added by #2555 is not covered.Not tested
UnrestrictedBufferTextureCopyPitchSupportedTRUE (read with a standaloneCheckFeatureSupport(OPTIONS13)call on this machine). So the scratch path runs here only for footprints whose offset or pitch is not a whole unit of the format. The probe log line did not appear in the PR's smoke log, so no copy in that 60 s run reached it.console_list.rs:855) still passes footprints as they areGetCopyableFootprintsXCL_TRACE_FRAME, which our runs did not setmaincommit that contains xcl run: prepare shaders in the game window before title execution #2555AI use
🤖 Generated with Claude Code