Skip to content

fix(d3d12): Isolate AMD buffer size query handles - #2698

Open
Geovannisz wants to merge 3 commits into
ProjectLeonida:mainfrom
Geovannisz:geovannisz/fix/rdna4-buffer-size-handles
Open

Geovannisz wants to merge 3 commits into
ProjectLeonida:mainfrom
Geovannisz:geovannisz/fix/rdna4-buffer-size-handles

Conversation

@Geovannisz

@Geovannisz Geovannisz commented Nov 30, 2026 •

Copy link
Copy Markdown

Claimed in the coordination issue as D3D12-RDNA4-BUFFER-SIZE-HANDLE.

What and why

On my RX 9070 XT, AMD's DXIL compiler faults during compute pipeline creation. LEONIDA_SEPARATE_SIZE_HANDLES=1 makes the native translator emit a dedicated heap handle for buffer-size queries. The reuse pass keeps it separate from memory-access handles. Dead-code removal can still discard unused queries. Both handles address the same view.

The setting is opt-in and participates in the translation-cache fingerprint. The README explains activation and retrying keys recorded as bad by an earlier warm run. The native translator contract is documented in docs/design.md.

This adapts imjustprism's approach in Marvisak/VIctory#2122 to Mandy's lowering and optimiser. It is independent of #2694, which serializes concurrent driver calls. My reproducer uses one pipeline per fresh process.

Compatibility with #2687's handle hoisting was checked in the current main source. The hoist_handles eligibility check accepts only uniform createHandleFromHeap calls. This workaround emits dedicated size-query handles with the non-uniform flag set, so they are excluded from that pass. KelboLive independently tested the merged tree and reported passing regression and waterfall/descriptor subsets.

Tested

MEASURED locally. Profile M, Radeon RX 9070 XT 16 GB desktop, driver 32.0.32029.2010, Windows 11 build 26300, Rust 1.98.1, MSVC x64.

  • Baseline main at 1d22590 reproduced the access violation on two previously failing compute pipelines, individually in fresh processes.
  • PR implementation at 950fea2, same binary and settings for both arms. With LEONIDA_SEPARATE_SIZE_HANDLES=0, both selected pipelines faulted. With the setting at 1, all 22 previously failing pipelines compiled, with zero refusals and zero worker crashes.
  • An earlier local build using this approach precompiled 1,475 previously used pipelines with zero refusals and zero worker crashes. These earlier numbers are separate from the pinned PR A/B.
  • The synthetic buffer_size_handles_are_kept_separate_when_reusing_values regression fails against main's optimiser with only the test and marker declarations transplanted, and passes with the fix. It checks access-handle reuse, size-handle separation and removal of unused queries.
  • All 10 descriptor-size tests pass on WARP. A standalone native structured-buffer readback test still faults with either setting. Its native failure is unresolved.
  • Full leonida-shader library suite on WARP, opt-in enabled, one test thread. Main: 362 passed, 8 failed, 4 ignored. PR: 363 passed, the identical 8 failures, 4 ignored. The added regression passes. Existing waterfall tests retain readback and wave checks and account separately for temporary size-query handles.
  • Final head 1f188c4 builds with cargo build --locked --profile diag -p leonida --features diagnostics,mimalloc. Changed-file game-data check and git diff --check pass.
  • cargo xtask policy reports the same two pre-existing oversized files on main and this branch (leonida-gpu/src/host.rs and leonida-shader/src/emit/lower.rs). The latter grows with this patch. This policy failure remains outstanding.
  • Offline compilation and WARP checks do not establish gameplay stability or visual equivalence.

GPUs tested: AMD Radeon RX 9070 XT, driver 32.0.32029.2010, Windows 11 build 26300. WARP used for synthetic readback tests.

AI-assisted: OpenAI Codex. The hardware and crash report are mine. The commit author is Geovanni (@Geovannisz), with Codex assistance recorded and prior VIctory work credited.

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • Changed files pass scripts/check_no_game_data.py.
  • Native translator contract and opt-in setting documented.
  • Synthetic regression fails on the baseline optimiser and passes with the patch.

Add an opt-in DXIL workaround for an AMD shader compiler crash during
pipeline creation. Keep the size query's heap handle separate when
reusing values and allow the writer to discard unused queries.

Adapt the approach from imjustprism's Marvisak/VIctory#2122 to Mandy's
descriptor and raw-view paths.

Refs ProjectLeonida#2570
Co-authored-by: OpenAI Codex <noreply@openai.com>
Geovannisz and others added 2 commits November 30, 2026 02:37
Keep the opt-in size-handle setting in one resolver and include its
conservatively non-uniform temporary handle in pre-cleanup counters.
GPU readback and wave-operation assertions remain in place.

Co-authored-by: OpenAI Codex <noreply@openai.com>
Count dedicated size-query handles separately in test metadata so
waterfall assertions continue checking the per-lane resource handles.
This covers programs that emit several unused size queries before
dead-code cleanup.

Co-authored-by: OpenAI Codex <noreply@openai.com>
@Geovannisz
Geovannisz marked this pull request as ready for review November 30, 2026 05:41
Copilot AI balanced review requested due to automatic review settings November 30, 2026 05:41

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@Kal0s-design

Copy link
Copy Markdown
Contributor

Cross-vendor check on Windows of 1f188c4f7 on current main f9f3ec4c6 (merges without conflict, 82867d471). Native Windows 11, MSVC x64, Rust 1.98.1, full cargo test -p leonida-shader --lib on a hardware GPU that isn't AMD (not WARP), so the DXIL is validated and the dispatches/readbacks run on a second vendor's driver.

  • LEONIDA_SEPARATE_SIZE_HANDLES unset: 386 passed, 0 failed, 4 ignored.
  • LEONIDA_SEPARATE_SIZE_HANDLES=1: 386 passed, 0 failed, 4 ignored, including the waterfall tests with their separate size-query handles and the 10 descriptor-size tests.
  • main lists 389 tests (385 run + 4 ignored); the merge lists 390, so the only addition is buffer_size_handles_are_kept_separate_when_reusing_values.

So on this driver the opt-in changes no result, and leaving it off changes nothing either. That fits it being a workaround for the AMD compiler only. The 8 WARP-only failures in the description don't appear on hardware here in either mode. I can't reproduce the AMD fault itself, nor the standalone structured-buffer readback case.

AI-assisted: yes

@merzleckeier

Copy link
Copy Markdown
Contributor

Independent size-handle and cache-key check under Wine. 1f188c4f merged onto f9f3ec4c6 (tree 3a86abcd). Windows x64 MSVC-target Rust 1.98.1, Wine 11.22, and VKD3D-Proton 3.1.0 (0bb64c56c8f0dcc). Radeon 610M (RADV 26.3.1) and RTX 4070 SUPER (620.73.04), using the DXIL validator from DXC v1.8.2505.1.

MEASURED. One fresh process per mode per GPU compiled the synthetic structured-buffer count plus indexed-load fixture. DXC disassembly shows that unset and =0 emit byte-identical DXIL and share one SRV handle between getDimensions and rawBufferLoad. With =1, getDimensions uses a dedicated non-uniform handle and rawBufferLoad uses its separate handle. Both use the same descriptor index and resource properties. The emitted census was 3/3/4 total handles with 1 size query, 1 load, and 2 stores in every mode.

All six hardware runs returned [3, 77] and [5, 0x1234abcd] for the two input buffers. The production translation fingerprint returned distinct bytes for unset, 0, and 1. The only difference was the switch value in its environment record. The initial artifact reused a stale Cargo build-script output from a prior checkout. These results use a regenerated switch list.

The focused size, waterfall, and optimizer selection on each GPU was 15 passed / 1 failed on main and 16 passed / 1 failed with the PR in both settings. The added optimizer regression passed. The existing NaN-scrub R32_UINT failure showed the same result on main and PR within each GPU. All six full-suite runs exited with status 3 while first_half_values_render_on_hardware_and_warp was active.

Synthetic translation and Wine readback coverage. A second agent checked the raw results. AI-assisted.

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Verified 1f188c4f with an own target dir: cargo test -p leonida-shader with LEONIDA_SEPARATE_SIZE_HANDLES=1 gives 371 passed / 0 failed / 4 ignored, and the waterfall (22) and descriptor (21) subsets pass with the switch both on and unset. The separation is genuinely tested: deleting the Tag::SizeHandle guard in opt.rs:919 makes the new regression fail with the size query merged into the memory-access handle ([[Inst(0), Inst(0)]] vs [[Inst(0), Inst(1)]]), and the dead-query case still drops (body == 3 after REUSE | DEAD).

The mechanism is right: the buffer getDimensions path takes a fresh handle only for buffers with separate_size_handles() (lower.rs:8296-8306, :1662-1667), built from the same index and props as the access handle, and the tag is attached to createHandleFromHeap (shader.rs:682-684) and preserved in bitcode.rs:397-402 even with the census off, so it can neither be reused nor absorb a later access. The fingerprint claim checks out too: the build script's switch list contains the name and translation_fingerprint() hashes its value.

git merge-tree against current main is clean, and on the merged tree the regression plus the waterfall/descriptor subsets pass. The branch is now 1027 commits behind and main has gained #2687's hoist_handles; that pass only hoists uniform createHandleFromHeap calls, and these handles are emitted non-uniform, so the contract still holds — worth a sentence in the body so the interaction is on record.

One nit: tag == Tag::SizeHandle || census::enabled() in bitcode.rs:399 would read better as a Tag::needed_without_census() predicate, so the next optimisation tag does not have to edit that condition. The AMD amdxc64.dll fault and the 22-pipeline result cannot be reproduced here (no RX 9070 XT, no game data); the DXIL-level evidence above is what this machine can check.

@Geovannisz

Copy link
Copy Markdown
Author

Thanks @KelboLive for the independent verification and for checking the regression by removing its guard. I added the interaction with #2687's hoist_handles pass to the PR description after checking the current main source. The dedicated handles carry the non-uniform flag, which excludes them from its uniform-handle eligibility check.

Your Tag::needed_without_census() suggestion is noted as a readability improvement. The RX 9070 XT measurements remain scoped to the pinned offline A/B and the earlier warm run described in the PR.

AI-assisted: OpenAI Codex.

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.

5 participants