Skip to content

D3D12.X: copy root constants without a temporary buffer - #3345

Draft
storrmzz wants to merge 1 commit into
xcl-dev:mainfrom
storrmzz:d3d12x/borrow-root-constant-bytes
Draft

storrmzz wants to merge 1 commit into
xcl-dev:mainfrom
storrmzz:d3d12x/borrow-root-constant-bytes

Conversation

@storrmzz

@storrmzz storrmzz commented Nov 29, 2026 •

Copy link
Copy Markdown

The graphics and compute multi-word root-constant setters allocate a temporary byte Vec and then copy it into the command-list state. Borrow the caller's bytes for the synchronous destination copy on Windows x64, where the words are already little-endian.

What is in it

Tested

  • AMD Ryzen 7 8840HS, Radeon 780M (32.0.31033.3), 16 GB RAM, Windows 11, rustc 1.100.0 MSVC; head 6603fdcb.
  • cargo test -p xcl --lib root_constants_ --jobs 2 -- --nocapture: 2 passed, 0 failed, 0 ignored, no skips.
  • cargo test -p xcl --lib hle::d3d12x::bind::tests --jobs 2 -- --test-threads=2 --nocapture: 116 Cargo passes, 0 failed, 0 ignored; one early-return SKIPPED test (two_pass_binds_set_the_shared_view_heap). Rerunning that exact test binary with XCL_HEAP_WINDOWS=1: 1 passed, no skips. These are 116 unique tests, including the two new tests.
  • A temporary, uncommitted release measurement harness compared the original setter bodies with the new real setters, including state lookup, locking and copying. Two process runs, nine alternating pairs of 300,000 calls per version for each path and 1/4/16/64 words: median 48–56 ns before, 14–18 ns after (68–74% lower setter time). Each run also passed both correctness tests. This measures hot, uncontended CPU setters, not game FPS. The harness was removed from the source before committing.
  • cargo build --workspace --jobs 2: passed.
  • cargo test --workspace --jobs 2 -- --test-threads=4 --nocapture: aborted in the library test process while restoring a coherent UMA window (Windows error 487, exit code 130088963); no complete suite totals from that run.
  • cargo test --workspace --no-fail-fast --jobs 2 -- --test-threads=1 --nocapture: 2595 passed, 2 failed, 49 ignored across 41 completed targets; 12 explicit SKIPPED messages (early returns remain included in Cargo passes).
Explicit SKIPPED test results

Failed tests: gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 and two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs (the latter also prints a nested child failure; counted once).

Targeted baseline comparison
Both failed tests were rerun individually on clean checkouts of PR head 6603fdcb7b28f7483a359479ed1d45863cdbc969 and its unchanged main base 227d2cb388f103268dac7635ea720eb3e5352d4e, on the same machine/toolchain above:

  • cargo test -p xcl --lib gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 --jobs 2 -- --exact --test-threads=1 --nocapture: on each commit, 0 passed, 1 failed, 0 ignored, no skips. Identical failure at fuzz_tests.rs:1171: seed 722, res[30] = 0x1, CPU expectation 0x7fffffff.
  • cargo test -p xcl --test gpu_two_pass_cache_e2e two_pass_driver_cache_reuses_both_passes_and_recovers_corrupt_blobs --jobs 2 -- --exact --test-threads=1 --nocapture: on each commit, 0 passed, 1 failed, 0 ignored, no skips. Identical assertion at gpu_two_pass_cache_e2e.rs:584: releasing the title PSOs leaves one two-pass state, expected zero. The nested child failure is counted once.

These two failures therefore also occur without this change. This was a targeted comparison against the PR's exact base, not a full baseline-suite rerun or a test of today's latest main. The original four-thread UMA restoration abort was not reproduced in the paired full-suite rerun below. Its cause remains unconfirmed; this is not a claim that it has been fixed. Draft pending paired retail regression runs. Tests requiring unavailable game samples do not provide game-data coverage.

Parallel workspace rerun
On the same machine/toolchain, ran cargo test --workspace --no-fail-fast --jobs 2 -- --test-threads=4 --nocapture sequentially on clean checkouts of PR head and its unchanged main base. --no-fail-fast lets Cargo continue to the other test binaries after a failing binary; the tests still use four threads.

Commit Passed Failed Ignored Completed targets Explicit SKIPPED messages
pr 6603fdcb7b28f7483a359479ed1d45863cdbc969 2595 2 49 41 12
base 227d2cb388f103268dac7635ea720eb3e5352d4e 2593 2 49 41 12

Both runs completed all test targets without the UMA restoration process abort. Both still failed the same Fuzz and two-pass cache tests documented above; the PR has two additional passing root-constant tests. The suites therefore did not pass completely. Early-return skips remain included in Cargo's pass counts and do not provide coverage. One complete parallel rerun was performed per commit; the earlier abort remains a recorded, currently non-reproduced event. No game regression or FPS result is implied.

Regression run
Not run: no retail title is available on this machine. Keeping this PR in draft pending paired main/head retail smoke results.

Not tested

  • Retail gameplay, FPS/frame-time impact, actual setter frequency, other CPUs/GPUs, concurrent contention and diagnostic tracing performance.
  • No claim that existing parameter-boundary issues are fixed.

AI use
This PR was created with AI assistance from OpenAI Codex (GPT-6).

@github-actions github-actions Bot added area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks) needs-pr-check Failing the PR description check (CONTRIBUTING.md) and removed needs-pr-check Failing the PR description check (CONTRIBUTING.md) labels Nov 29, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Review (head 6603fdc, diff read, not a merge-check; draft, PR description red):

Fine: a byte slice needs no alignment and n * 4 can't overflow on x64. Source (title memory) and destination (XCL's argument buffer) can't overlap, and put_in copies before returning. Null and bounds handling are unchanged. It reads only the part that fits, where the old code read all n words, so it is no worse when a title passes too large an n.

AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 6603fdc

No open or merged PR makes the same change. Main still builds a temporary Vec<u8> in set_graphics_root_constants/set_compute_root_constants. #3511 only adds tests for main's clipping in put_in and does not overlap. The byte view of the title's u32 words is equivalent on x64, and put_in copies the bytes before returning. The new tests stay inside each parameter's bounds, so they also pass with main's clipping put_in. No problems found in the diff.
Recommendation: keep open.

AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.

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

Labels

area:d3d12 D3D12.X runtime, command lists, resources, sparse memory gpu:both Code affects both AMD and NVIDIA GPUs (scope tag; see needs:*-test for remaining checks)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants