Skip to content

D3D12.X: warn when a root argument write runs past its parameter - #3512

Open
Pipodi wants to merge 1 commit into
xcl-dev:mainfrom
Pipodi:root-write-warn
Open

Pipodi wants to merge 1 commit into
xcl-dev:mainfrom
Pipodi:root-write-warn

Conversation

@Pipodi

@Pipodi Pipodi commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Logs a root argument write that runs past its parameter. A retail title's BVH builder writes 4 dwords into compute parameter 3, the last of a 9-dword table (3 fit); before #1319 (merged) the write was dropped whole and nothing in the log said so (with #1319 alone, in our diagnostic tree, the count of 24-byte corrupted runs in the title's vertex and index lists went from 80 to 0; test report on #1319; part of #2867). Two investigations each added the same line locally.

What is in it

  • D3D12.X: warn when a root argument write runs past its parameter (crates/xcl/src/hle/d3d12x/bind.rs, +19 lines): put_in logs one line per distinct shape (list kind, parameter, offset, dwords written, dwords that fit, table size in dwords), at most 8 shapes. No env switch, no change to what is written, no return-type change.
  • One compare per write when it does not overrun; the lock is taken only on an overrun, and not once 8 shapes are logged (an AtomicBool checked before the lock).

Tested

Regression run

The same retail title for 60 s on both sides, scripts/smoke.ps1 on clean trees, release builds, XCL_PREPARE=0 and XCL_PRESS_AT=16:A on both sides, RTX 4090 (driver 621.40).

main (6bfb5c51):

xcl-smoke v1
commit: 6bfb5c5153ccc23517daf30aa1071ddb0fadb53c
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1611 (PresentX 1611)
presents per 2 s (last 3): 60 60 61
device removals: 0
crashes: 0
peak commit: 17826 MB

This PR's head (006d650e, no uncommitted changes):

xcl-smoke v1
commit: 006d650e8742bfcf06e51dd82449262e3b0bca6b
gpu: NVIDIA GeForce RTX 4090
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1611 (PresentX 1611)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 17716 MB

The PR's run got 100.0 % of main's frames and 99.4 % of its peak commit.

Not tested

  • The 60 s smoke does not reach the BVH builder that triggers the warning, so the new line is not shown on a title; AMD / Intel.

AI use

  • Claude Code: Claude Opus 5.5 (diagnosis, plan, review) and Claude Sonnet 5.5 (code, tests)
  • The review fix on 006d650e: Claude Code, Claude Opus 5.5 (main session) orchestrated it and updated this description; a Claude Sonnet 5.5 subagent made the change; subagents ran the suite and the smoke pair.

@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-rebase Has merge conflicts with its base branch labels Nov 30, 2026
@github-actions github-actions Bot removed the needs-rebase Has merge conflicts with its base branch label Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

merge-check
base: 7d86c5d
head: a735454
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2896 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
review: read the whole diff (bind.rs, +16). Diagnostics only: one extra comparison per root write, and a warning for the first 8 shapes of a root-argument write that runs past its parameter. Findings: (1) SEEN.lock() (~1484) is taken on every overrun even after 8 shapes are logged, so a title that overruns on every dispatch takes a global mutex from every thread recording command lists; an atomic "full" flag checked first would avoid that. (2) A write to a parameter index the layout doesn't have still returns silently. The PR's CI failure is the intermittent access violation in the lib test binary during gpu::agility::tests (inside D3DSCache.dll) that this diff doesn't reach; see the run above. Fine: the bounds are right (constants up to at + count*4, descriptor 8 bytes, table 4), and the write itself is unchanged. No smoke run: a diagnostics change.
performance: no smoke run (the default path doesn't reach this change); not measured. Diagnostics only: one comparison per root write on the default path.
verdict: safe to merge (finding 1 is worth a follow-up if a title overruns on every dispatch)
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.

@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head a735454

No open or merged PR adds this warning; #3511 (same author) only adds tests of the same put_in clamping and does not overlap.
bind.rs:put_in: the check costs one compare per write and the lock is only taken on an overrun, capped at 8 distinct shapes. 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.

A retail title's BVH builder writes 4 dwords into compute parameter 3, the
last parameter of a 9-dword table (3 fit). The write was dropped whole until
the clip to the parameter's size; the radix pass then read a null BVH header
and the refit's box stores corrupted vertex and index lists. With the clip
alone (r262) L24 went 80 -> 0 and de5c's bad parent loads 30.7M -> 1. Nothing
in the log said the write had been cut, so two investigations each added the
same line locally.

put_in now logs one line for each distinct shape of an overrunning write (list
kind, parameter, offset, dwords written, dwords that fit, table size in
dwords), at most 8 shapes, so a title that does it every frame costs 8 lines.
No switch, no change to what is written, no return value. No test: it is a
log line.

An atomic flag, set once 8 shapes are logged, is checked before the lock, so a title
that overruns on every dispatch does not take the mutex from every recording
thread after the cap.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
@Pipodi

Pipodi commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Thanks. Finding 1 is right: SEEN.lock() was taken on every overrun, because the seen.len() < 8 test came after the lock, so after 8 shapes a title that overruns on every dispatch still took the mutex from each recording thread (the triage note that the lock is capped at 8 only counted the pushes, not the lock).

Added an AtomicBool FULL in put_in, set when the 8th shape is stored and checked before the lock, so after the cap an overrun costs one relaxed load. The warning output and the write are unchanged. No new test: the change is a lock-avoidance on a log path, and the existing behaviour (8 shapes at most) is unchanged.

Claude Code (Claude Sonnet 5.5) assisted with the change and this reply.

@Foniass

Foniass commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor

Follow-up review (head 006d650, since a735454, diff read, not a merge-check):

  • SEEN.lock() taken on every overrun after the cap: fixed. FULL (bind.rs ~1481) is checked before the lock and set once 8 shapes are logged (~1489), so later overruns cost one relaxed load.
  • A write to a parameter index the layout does not have returns silently: still open (bind.rs ~1474, unchanged); it was a follow-up suggestion, not a blocker.

New: none.

Fine: still diagnostics only; the bytes written and the clamp to limit are unchanged; the shape key and dword counts are right for constants, descriptors and tables, including an offset past count.

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

@fromthemoonx

fromthemoonx commented Dec 1, 2026 •

Copy link
Copy Markdown

merge-check
base: f07e426
head: 006d650
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2904 passed, 0 failed, 51 ignored (base 6bfb5c5 + README-only f07e426d: 2904 passed); SKIPPED: 25 (22 no wave64, 2 no heap windows, 1 no GPU_UPLOAD heaps), the same set as base; failing: none
review: read the whole diff (bind.rs, +19; diagnostics only). No findings beyond Foniass's follow-up review, whose open note (a write to a parameter index the layout does not have still returns silently) stands.

  • The line prints. hle::d3d12x::bind::tests::out_of_bounds_root_constants_do_not_clobber_adjacent_parameter with --nocapture logs three shapes:
    • compute parameter 0 offset 2 dwords: 1 dwords written, 0 fit; table 4 dwords
    • ... offset 1 dwords: 3 dwords written, 1 fit ...
    • ... offset 4294967295 dwords: 1 dwords written, 0 fit ...
  • What is written is unchanged (write_end = end.min(limit), as on main).
  • After 8 shapes, FULL skips the lock. Nothing tests the cap itself (a log line; none required).
  • No retail title on this machine.
    performance: one compare per root argument write; the lock and the log only on an overrun, until 8 shapes are logged.
    verdict: safe to merge
    hardware / tool and model: RTX 3060 12 GB (610.88), Ryzen 7 5700X, Windows 11 Pro 26300 / Claude Code (Claude Opus 5.5)

@github-actions github-actions Bot added needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) and removed needs-1st-check Passes gates; needs first independent merge-check (#3041) needs:nvidia-test Needs a test report or merge-check on an NVIDIA GPU labels Dec 1, 2026
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) needs:amd-test Needs a test report or merge-check on an AMD GPU needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants