Skip to content

D3D12.X: copy texture regions with unaligned footprints through scratch - #2873

Open
tiagonleal wants to merge 1 commit into
xcl-dev:mainfrom
tiagonleal:copy-texture-region-aligned-footprints
Open

tiagonleal wants to merge 1 commit into
xcl-dev:mainfrom
tiagonleal:copy-texture-region-aligned-footprints

Conversation

@tiagonleal

Copy link
Copy Markdown
Contributor

copy_texture_region_x passed console placed footprints to the PC as they were. On PC D3D12, a placed footprint's Offset must be aligned to D3D12_TEXTURE_DATA_PLACEMENT_ALIGNMENT (512) "unless D3D12_FEATURE_DATA_D3D12_OPTIONS13::UnrestrictedBufferTextureCopyPitchSupported is TRUE" (D3D12_PLACED_SUBRESOURCE_FOOTPRINT). RowPitch must be a multiple of D3D12_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 to CopyTextureRegion are 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 under XCL_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 queries OPTIONS13 once. If the device reports UnrestrictedBufferTextureCopyPitchSupported and 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 CopyBufferRegion when 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 from GetCopyableFootprints of 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 last main commit before #2555 (see Regression run).

What is in it

  • crates/xcl/src/hle/d3d12x/list_x.rs:
    • pure footprint_plan: pass through, or the scratch pitch, size and buffer copies; takes the unit size when the capability is present
    • unrestricted_copy_pitch: the cached OPTIONS13 probe
    • copy_texture_region_realigned: the copies and scratch transitions, called from copy_texture_region_x after pc_location; the box is clamped to the rows and slices it names
  • Tests in footprint_plan_tests:
    • aligned footprint
    • odd pitch
    • odd offset with aligned pitch
    • both odd, with the last row clamped
    • BC1 rows of blocks
    • 3D slices
    • texture to buffer
    • source box rows and slices
    • capability TRUE and FALSE

Tested

  • Windows 11 Pro 10.0.26300, NVIDIA GeForce RTX 5070 Ti 16 GB (driver 617.42), AMD Ryzen 7 9800X3D, 32 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09); debug tests, release build
  • cargo test -p xcl --lib footprint_plan: 9 passed, 0 failed, 3 of 3 runs on 1f3d506
  • With footprint_plan forced to return PassThrough (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 the panic!("expected a scratch copy") in the test helper (list_x.rs:4491), and unrestricted_copy_pitch_takes_unit_aligned_footprints fails at its assertion (list_x.rs:4505). Only an_aligned_footprint_goes_as_it_is passes.
  • cargo test --workspace --no-fail-fast -- --test-threads=4, run twice on 1f3d506: 1447 passed, 4 failed, 47 ignored both times (25 SKIPPED lines: 21 no wave64, 1 no heap windows, 3 recompiler cases refused as unsupported). The 4 failures are gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_0..3 (CreateComputePipelineState returns E_OUTOFMEMORY, 0x8007000E). They fail the same way on e120925e on 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, main first, one run each.

main (e120925):

xcl-smoke v1
commit: e120925e3abc9956a8b9bae631969d32e8ccd43c
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1607 (PresentX 1607)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16118 MB

This PR:

xcl-smoke v1
commit: 1f3d506d0d87f72e3179e66c333e8e5f76935f9b
gpu: NVIDIA GeForce RTX 5070 Ti
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1614 (PresentX 1614)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16195 MB

NVIDIA profile for xcl.exe: shader heap 1024 MB

Both runs are on e120925e, the last main commit 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

  • This adapter reports UnrestrictedBufferTextureCopyPitchSupported TRUE (read with a standalone CheckFeatureSupport(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.
  • The console-list replay path (console_list.rs:855) still passes footprints as they are
  • No device test of the realigned copy itself: the tests cover the planner, not the barriers, the scratch copies, the probe or GetCopyableFootprints
  • Planar formats
  • The capability probe is cached for the process, which assumes one device
  • Whether the retail title issues misaligned footprints is not known: the existing trace line prints only under XCL_TRACE_FRAME, which our runs did not set
  • A main commit that contains xcl run: prepare shaders in the game window before title execution #2555
  • AMD and Intel GPUs

AI use

  • Claude Code with Claude Fable 5.2 and Anthropic subagents (Claude Opus 5.5, Claude Sonnet 5.5) helped developing.

🤖 Generated with Claude Code

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>
@Aniseto

Aniseto commented Nov 26, 2026

Copy link
Copy Markdown

Ran the unaligned-footprint planning tests at 1f3d506d on an NVIDIA Blackwell desktop part:

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.

XCL_ADAPTER=NVIDIA cargo test -p xcl --lib footprint -- --test-threads=1
10 passed; 0 failed; 0 ignored; 0 measured; 1341 filtered out      (exit 0)

All ten tests matching footprint pass here, including the OPTIONS13 pass-through case and the odd-offset/aligned-pitch plan. They are pure planning tests; no CopyTextureRegion was issued on the real adapter, and this host's UnrestrictedBufferTextureCopyPitchSupported value was not part of the check. The PR has no comments yet, so this is the first datapoint in the thread.

Not tested: a real CopyTextureRegion with unaligned footprints on hardware, a paired smoke run, the full workspace suite, AMD and Intel GPUs, native wave64 hosts, Wine, release profile, game data.

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.

@Decodere

Copy link
Copy Markdown
Contributor

Independent desktop NVIDIA verification of PR #2873 at head 1f3d506d0d87f72e3179e66c333e8e5f76935f9b (1 commit; exact parent & merge-base: e120925e3abc9956a8b9bae631969d32e8ccd43c, pre-#2555 ancestor of main).

Environment

  • GPU: NVIDIA GeForce RTX 4060 (8 GB / 7956 MiB reported by D3D12), driver 32.0.16.2114 (NVIDIA 621.14, WDDM 3.2)
  • CPU / RAM / OS: Intel Core i5-11400F (6C / 12T), 32 GB RAM (31.9 GiB usable), Windows 11 Home 26200 (Developer Mode off)
  • Toolchain: rustc 1.100.0 (0ef1bc386 2026-11-09) MSVC, DXC 1.9.2609.5, --release

Targeted release tests & build (1f3d506d)

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)

  • 9220 log 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 sample 14011 MB committed by the process; video memory 6114 MB local, 4683 MB non-local.

Limits of coverage

  • The 9 new footprint_plan_tests are pure CPU layout/planning unit tests covering OPTIONS13.UnrestrictedBufferTextureCopyPitchSupported, odd offset/pitch realignment, block-compressed rows, depth slices, and texture-to-buffer writeback; no dedicated on-GPU readback test executing an unaligned CopyTextureRegion through 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 via OPTIONS13.UnrestrictedBufferTextureCopyPitchSupported).

AI disclosure: test execution and report drafting assisted by Google Antigravity (Gemini 4 Neon).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants