Skip to content

Recompiler: decode packed G16 gradients in direct DXIL - #2838

Closed
CryingLaughing wants to merge 1 commit into
xcl-dev:mainfrom
CryingLaughing:fix/direct-dxil-g16-gradients
Closed

CryingLaughing wants to merge 1 commit into
xcl-dev:mainfrom
CryingLaughing:fix/direct-dxil-g16-gradients

Conversation

@CryingLaughing

Copy link
Copy Markdown

Direct DXIL read each IMAGE_SAMPLE_*_G16 gradient as a 32-bit float. That also moved the coordinates to the wrong VGPRs. This fixes the direct path identified in the #436 review. #436 covers HLSL.

What is in it

  • In gpu/dxil/lower_image.rs, decode the gradients as packed 16-bit values, with each derivative group starting on a dword boundary.
  • Test coordinate slots in 2D, 2D array, and 3D, including A16 and ordinary SAMPLE_D controls. A pixel test gives both layouts the same coordinates, then verifies that a nonzero upper-half gradient selects mip 1 and zero selects mip 0. The fixtures call direct DXIL explicitly.

Tested

  • Head ef36b7dfe3eeb0a5c872dc667d6cdfc1d20033c9 on main 8b957bec6f82495aec940944c6bf47faa02db590. Windows 11 25H2 build 26200.9974, Core i5-13600K, RTX 4080 driver 621.01, Rust 1.100.0 x64 MSVC, DXC 1.8.2502.11, debug.
  • With the identical test overlay, clean main reported 0 passed, 3 failed, 0 ignored. The fixed head reported 3 passed, 0 failed, 0 ignored. Neither run skipped a capability. On main the nonzero gradient gave red mip 0 in all 16 pixels. The head selected green mip 1, and the zero-gradient control selected red mip 0 on both.
  • cargo build --workspace --locked -j 2 passed. With XCL_ADAPTER=4080, cargo test --workspace --locked -j 2 --no-fail-fast -- --test-threads=4 --show-output reported 1,449 passed, 0 failed, 47 ignored across 38 harnesses. The pass count includes 29 capability skips and 10 unset optional sample notices.

Regression run

Matched retail smoke is pending.

Not tested

  • Retail titles, AMD and Intel GPUs, and native wave64. The workspace suite used the default backend selection.

Start each packed derivative direction on a dword boundary and widen its half components before SampleGrad. This addresses the Direct DXIL counterpart noted in xcl-dev#436.
@MatyEjsr

MatyEjsr commented Nov 26, 2026 •

Copy link
Copy Markdown

Independent verification and source audit of PR #2838 at head ef36b7dfe3eeb0a5c872dc667d6cdfc1d20033c9 (merge-base main 8b957bec6f82495aec940944c6bf47faa02db590) on Windows 11 + NVIDIA GeForce RTX 3090.

Source & Triage Notes

  • Layout & ISA parity: crates/xcl/src/gpu/dxil/lower_image.rs (Lw::mimg) sets g16 = mods.contains(&"g16") and pushes (16, component == 0) for each of the two derivative directions (dx, dy), matching mimg_address_dwords in crates/xcl/src/gpu/rdna2.rs ((GRADIENTS[dim] / 2).next_multiple_of(2)) across 1D/1DArray (2 dwords), 2D/Cube/2DArray (2 dwords), and 3D (4 dwords), and matching the companion HLSL fix in open PR Recompiler: image_sample_*_g16 reads 16-bit gradients, packed in halves #436 (emit.rs on main still treats gradients as 32-bit). i_body keeps (h, !a16 || (grad_n != 0 && k == 0)) so body coordinates start on a dword boundary even with A16=1 and odd grad_n. Both UNORM=1 (mimg_unorm_sample) and CD_*_G16 opcodes share this shape/pos layout.
  • No duplicates: Campaign/branch checks show clean mergeability onto main and no duplicate open PRs or nvidia-dev overlap.
  • PR checks note: PR description currently fails because the description is missing the paired xcl-smoke v1 regression blocks and the required **AI use** section.

Tested

  • Environment: Windows 11 Pro for Workstations 25H2 (Build 26200), AMD Ryzen 7 7800X3D, NVIDIA GeForce RTX 3090 (24 GB, driver 32.0.16.1742, wave32), 31.4 GB RAM, rustc 1.100.0 (0ef1bc386 2026-11-09, stable-x86_64-pc-windows-msvc), DXC 1.9.2602.17 (dxcompiler / dxil, Windows SDK 10.0.26100.0), Windows Developer Mode ON, debug & release builds.
  • Debug build: cargo build --workspace -j 8 passed in 17.98s (0 warnings in touched files).
  • Targeted PR tests: cargo test -p xcl --lib -- direct_sample_grad_g16_widens_packed_gradients gpu_direct_sample_grad_g16_uses_packed_coordinate_slots gpu_direct_sample_grad_g16_nonzero_half_selects_mip --test-threads=1 --nocapture: 3 passed, 0 failed, 0 ignored, 0 SKIPPED (0.37s).
  • Direct DXIL opt-in check (XCL_DIRECT_DXIL=1): cargo test -p xcl --lib -- gpu_direct_sample_grad_g16 gpu_images_sample_load_store_atomic --test-threads=1 --nocapture: 3 passed, 0 failed, 0 ignored, 0 SKIPPED (0.31s).
  • Full workspace suite: cargo test --workspace -j 8 --no-fail-fast -- --test-threads=8 --show-output: Cargo reported 1,449 passed, 0 failed, 47 ignored across 38 harnesses (xcl lib: 1,321 passed, 0 failed, 27 ignored in 28.37s). Within those passes, 28 SKIPPED capability lines occurred across 17 tests (not counted as coverage: 15 wave64 / refused per-lane subcases across 6 lower_dxil::tests, 8 wave64-only GPU tests, heap_window_out_of_memory_falls_back_to_the_switch_form with no heap windows, uploads_start_from_each_subresources_state with no D3D12 debug layer, and the title under the debug layer dred: true/false with no d3d12SDKLayers.dll) plus 10 unset XCL_SAMPLE_* notices.
  • Release smoke attempt: cargo build --release -p xcl -j 8 passed in 40.92s; scripts/smoke.ps1 -Seconds 60 -Title c1cc91a4 on ef36b7df timed out before guest launch because base main 8b957bec started full-pack 26,503-shader startup preparation and exceeded smoke.ps1's default 120s startup timeout.

Not tested

  • Completed paired 60s retail smoke.ps1 regression run (main 8b957bec vs ef36b7df), AMD / Intel GPUs, native wave64 execution, D3D12 debug layer tests, heap-window OOM fallback, Linux / Wine, and optional XCL_SAMPLE_* tests (unset).

AI use

@DarkPanda69

Copy link
Copy Markdown

AMD run (listed as untested), with an RTX 3060 in the same PC: the new tests pass on both, and nothing else changes from main.

Tested: pass, head ef36b7d applied on main 8b957be, debug, Rust 1.100.0, Windows 11 Pro 26200, Ryzen 7 5800X, DXC 1.9.2602.17, card picked with XCL_ADAPTER.
XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4 --nocapture, main and this PR one after the other on each card:

On both cards the only result changes are the three new tests, all ok: direct_sample_grad_g16_widens_packed_gradients, gpu_direct_sample_grad_g16_uses_packed_coordinate_slots and gpu_direct_sample_grad_g16_nonzero_half_selects_mip. The SKIPPED sets are the same as on main.

On native wave64: the two new GPU tests build their kernel with direct_kernel_full(.., false) (wave64: false), so they run as wave32 on the RX 9070 XT too and don't cover a G16 sample in a 64-lane wave. The other native wave64 cases in gpu:: run on this card and are unchanged.

Not tested: a G16 sample in wave64, retail titles, release, Intel.

AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@SzczepanGrela

Copy link
Copy Markdown

RX 9070 / Linux-Wine verification of head ef36b7dfe3eeb0a5c872dc667d6cdfc1d20033c9 against main 8b957bec6f82495aec940944c6bf47faa02db590. The three original regressions reproduce on main and pass on the PR. Additional native-wave64 coordinate checks and both halves/directions of packed pixel gradients also pass on the PR.

This adds Linux/Wine and explicit native-wave64 sampling to the Windows RX 9070 XT report above.

Tested

RX 9070 (RADV GFX1201), Mesa 26.3.1-arch3.5, Ryzen 7 7700, CachyOS kernel 7.3.0-5-cachyos, GE-Proton11-12 / Wine 11.0 Staging, native d3d12/d3d12core/dxgi, vkd3d-proton 8293130ebe370b1+ (local asserts-disabled build), DXC 1.9.2602.17, Rust 1.97.1, release x86_64-pc-windows-gnu.

Separate source copies and targets, built with cargo test --offline --locked --release --target x86_64-pc-windows-gnu -p xcl --lib --no-run. Main received the same upstream test block. Both copies had identical test-only readback/IR observations; original assertions were retained. Production bytes were checked against the pinned sources after reversing those observations.

Wine libtest selection main PR
direct_sample_grad_g16 --nocapture --test-threads=1 0 passed, 3 failed 3 passed, 0 failed
direct_sample_grad_g16 --nocapture --test-threads=4 0 passed, 3 failed 3 passed, 0 failed
workflow_gpu_g16 --nocapture --test-threads=1, three fresh processes per source 0 passed, 2 failed each 2 passed, 0 failed each

All 10 harness invocations had 0 ignored and 0 capability skips. The main failures were the expected IR/layout/pixel assertions, with no device removal or unexpected execution failure.

The added workflow_gpu_g16 checks reused the original small, owned fixtures:

  • Native wave64: the original four coordinate cases, checking all 64 lanes instead of 32. This covers ordinary 2D SAMPLE_D, G16 2D, G16 2D array with A16, and G16 3D with A16. The captured DXIL has the explicit 64-lane wave property. Every PR lane returned the expected (x, y, z, 1) texel. Main retained the ordinary control and failed the G16 coordinate cases in every repetition.
  • Pixel mip matrix: zero gradients; low, high, both and negative-high halves of dx; low and high halves of dy; and a cross-direction case. Each draws 16 pixels from the same red mip 0 / green mip 1 texture. The PR returned red for zero and green for the seven nonzero cases. Main returned red in all eight. The matrix collects all cases before its final assertion.

Across original and added checks, there were 40 sampling dispatches and 56 pixel draws, including 24 native-wave64 dispatches. A separate verifier recomputed 8,192 coordinate words and 3,584 pixel words from the saved readbacks and the fixture's texel/gradient values. The PR had 0 mismatched words; main had 2,048 coordinate and 736 pixel mismatches. The ordinary SAMPLE_D shader containers stayed byte-identical between sources and repetitions for each control case.

Environment: XCL_ADAPTER=AMD Radeon RX 9070, XCL_REQUIRE_GPU=wave64, XCL_NETWORK=0, XCL_DIRECT_DXIL=1, XCL_DXC_THREADS=1, native DLL overrides and private enabled cache directories. The fixtures explicitly call the direct translator.

Not tested

Full workspace suite, retail data, smoke runs, HLSL G16 fixes, other image dimensions or opcode variants, native Windows, other GPUs, or title performance/FPS. Native wave64 coverage here is for the compute sampling kernels; the pixel draws do not establish a physical graphics wave size. These fixture results are not an independent console-ISA conformance result.

AI use

OpenAI Codex (GPT-6; exact serving variant not exposed) reviewed the change, prepared the additional fixtures and observations, built and ran both sources, independently checked source bytes, DXIL metadata and captured GPU values, and wrote this report. Publication authorized by the account owner.

@Gevroska

Copy link
Copy Markdown

I compared parent 8b957bec and PR head ef36b7df on an RTX 3080 using the Wave32 Direct DXIL path. I uploaded a two-layer texture with two mip levels and distinct colors for each layer and mip, then ran the same six draws on both revisions. Reading back the colors made it possible to identify which mip each draw actually sampled.

With packed 16-bit gradients, the parent sampled mip 0 in all 32 samples where mip 1 was expected. The PR returned the expected mip-1 colors in all 32 samples, including the correct green or yellow for each layer. The zero-gradient and full-width-gradient controls passed on both revisions. An independent repeat on the PR head reproduced the result with zero skips.

I used Codex GPT-6.2 Sol for the GPU fixture and comparison, and a separate GPT-6.2 Sol agent for independent verification. Codex GPT-6.2 Astra wrote this comment.

I reviewed and approved this comment before posting.

rootw0rm pushed a commit to rootw0rm/xcl that referenced this pull request Nov 26, 2026
…XIL (verbatim) + step-117 sync log

Upstream xcl-dev#2838 ef36b7d (single commit, still OPEN): packed G16
gradients start each derivative direction at a new dword. Fix hunk
context byte-identical in tree; all 4 additions (fix + helper + 3
tests) verified byte-identical to upstream head. recomp/tests.rs is
cfg(all(test, windows)) so new tests are parse-verified only here;
execution waits for Windows CI (pre-fix failure by construction: G16
cases expect 3/4/7/9 legacyF16ToF32 conversions, pre-fix emits 0).
Scan xcl-dev#2832..xcl-dev#2920: only xcl-dev#2838 new since step-116 (push race, not
builder fault). Gates: checks 0 errors (22+28 warnings); lib 783/0/1;
e2e 4/1 by design, 24 FAIL lines all D3D12.X; retail exit 139 at
exe+0x2237320, stubs 20, xgr XAsync/XNetworking/XUser HOLDS.
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