Skip to content

Direct DXIL: reject directed f32 rounding on ENC_VINTRP interpolation - #2814

Open
safesearch77 wants to merge 1 commit into
xcl-dev:mainfrom
safesearch77:fix/dxil-vintrp-f32-round
Open

safesearch77 wants to merge 1 commit into
xcl-dev:mainfrom
safesearch77:fix/dxil-vintrp-f32-round

Conversation

@safesearch77

@safesearch77 safesearch77 commented Nov 26, 2026 •

Copy link
Copy Markdown

Reject 32-bit ENC_VINTRP encodings of V_INTERP_P1_F32 and V_INTERP_P2_F32 when a shader directs MODE[1:0] single-precision rounding in the Direct DXIL backend, matching the existing 64-bit ENC_VOP3 path.

lower_round::f32_round_unsupported (crates/xcl/src/gpu/dxil/lower_round.rs:481-483) lists "v_interp_p1_f32" | "v_interp_p2_f32" so pixel shaders that direct f32 rounding fail Direct DXIL translation ("directed f32 rounding of this instruction") rather than silently emitting nearest-even rasteriser interpolation. Previously, that check lived at the top of Lw::valu (lower_valu.rs:336), which is only reached by ENC_VOP* / VOP* encodings (lower.rs:975); standard 32-bit ENC_VINTRP encodings dispatched directly from Lw::inst (lower.rs:972) to Lw::interp_gfx and bypassed the guard.

Part of #1269

What is in it

  • crates/xcl/src/gpu/dxil/lower.rs, crates/xcl/src/gpu/dxil/lower_valu.rs: hoist the self.f32_rm && super::lower_round::f32_round_unsupported(&name) check into Lw::inst right before encoding dispatch and remove the redundant check from Lw::valu (+3 / -3).
  • crates/xcl/src/gpu/dxil/round_tests.rs: direct_f32_round_mode_vintrp_p1_p2_rejected, checking S_ROUND_MODE (1, 2, 3), S_SETREG_IMM32_B32 (0x0801), and S_SETREG_B32 (0x0801) against V_INTERP_P1_F32 and V_INTERP_P2_F32 in both ENC_VINTRP and ENC_VOP3 across wave64: false and wave64: true, plus positive controls (S_ROUND_MODE 0, S_ROUND_MODE 0xC f16/f64 RTZ with default f32 RNE, and V_INTERP_MOV_F32 under directed S_ROUND_MODE 1).

Tested

  • @retrope13 (#2814 (comment)) — Windows 11 26H2 (26300.9818), NVIDIA GeForce RTX 4060 Laptop GPU (8 GB, driver 32.0.16.2140, wave32), Intel Core i5-14500HX, 24 GB RAM, rustc 1.100.0 (stable-x86_64-pc-windows-msvc), Windows SDK 10.0.26100.0 DXC 1.9.2602.17, XCL_ADAPTER=NVIDIA:
    • cargo build --workspace --locked + cargo test --workspace --locked --no-fail-fast -- --test-threads=4 (debug): 1436 passed, 0 failed, 47 ignored on 15e88d74 (vs 1435 passed, 0 failed, 47 ignored on b49be183).
    • cargo test --locked -p xcl --lib -- gpu::dxil::round_tests --test-threads=4 --nocapture (debug & --release): 9 passed, 0 failed, 0 ignored, 0 skipped (all 5 GPU rounding tests + direct_f32_round_mode_vintrp_p1_p2_rejected).
  • @ettehn (#2814 (comment)) — Windows 11 26200, Ryzen 9 8945HX, NVIDIA GeForce RTX 5070 Ti Laptop (12 GB, driver 621.24), rustc 1.97.1 MSVC debug, DXC 1.8.2502.11, XCL_ADAPTER=NVIDIA XCL_REQUIRE_GPU=wave64: reproduced RED failure on b49be183 (expected error for ("S_ROUND_MODE", "V_INTERP_P1_F32", "ENC_VINTRP", false)) and 9 passed, 0 failed, 0 ignored, 0 skipped on 15e88d74.
  • Linux x86_64 host cross-check (x86_64-pc-windows-gnu, cargo check --offline --workspace --tests: 0 errors) and native rustc --edition 2021 --test RED (8/9) → GREEN (9/9) harness over gpu::dxil::round_tests.

Regression run

60 s scripts/smoke.ps1 pair (XCL_NETWORK=0, release builds) reported by @Anon64 (#2814 (comment)) on NVIDIA GeForce RTX 3060 12 GB (driver 581.80), Intel Core i9-14900KF, Windows 11 26200:

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1461 (PresentX 1462)
presents per 2 s (last 3): 10 1 1
device removals: 0
crashes: 0
peak commit: 23855 MB

this PR:

xcl-smoke v1
commit: 15e88d74df3ae653a6cda85fa0538acbe2554731
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1474 (PresentX 1474)
presents per 2 s (last 3): 12 2 4
device removals: 0
crashes: 0
peak commit: 24771 MB

Not tested

  • AMD / Intel GPUs and native wave64 hardware, the 47 #[ignore] / SKIPPED tests on wave32 NVIDIA adapters, and whether the retail title reaches directed-rounding ENC_VINTRP pixel shaders under XCL_DIRECT_DXIL=all during the 60 s smoke window (PR authored on a Linux CPU host; Windows GPU suite and retail smoke runs provided by @retrope13, @ettehn, and @Anon64).

AI use

  • Antigravity (Gemini 4 Carbon): implemented the Lw::inst hoist, wrote direct_f32_round_mode_vintrp_p1_p2_rejected and the Linux host rustc --test RED-to-GREEN harness, and updated this description (bug isolated during upstream triage with Claude Opus 5.5). Windows test and smoke verifications reported by @retrope13 (Antigravity / Gemini 4 Neon), @ettehn (OpenAI Codex), and @Anon64 (Claude Code / Claude Opus 5.5).

lower_round::f32_round_unsupported lists v_interp_p1_f32 and
v_interp_p2_f32 so pixel shaders that direct MODE[1:0] fail translation
rather than silently emitting nearest-even interpolation. That guard
lived at the top of Lw::valu, which only 64-bit ENC_VOP3 encodings
reached; standard 32-bit ENC_VINTRP encodings dispatched straight from
Lw::inst to Lw::interp_gfx and bypassed it.

Hoist the f32_round_unsupported check into Lw::inst before encoding
dispatch and drop the redundant check in Lw::valu.

Assisted-by: Antigravity (Gemini 4 Carbon)
@ettehn

ettehn commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Native Windows A/B on 15e88d74df3ae653a6cda85fa0538acbe2554731 (clean) vs b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7 (the new regression test copied over, no production edits). Windows 11 build 26200, Ryzen 9 8945HX, RTX 5070 Ti Laptop (12 GB, driver 621.24), Rust 1.97.1 MSVC debug, DXC/DXIL 1.8.2502.11. XCL_ADAPTER=NVIDIA XCL_REQUIRE_GPU=wave64.

  • Main reproduced the defect: the test failed with expected error for ("S_ROUND_MODE", "V_INTERP_P1_F32", "ENC_VINTRP", false). This arm ran only the new test.
  • cargo test --locked --offline -p xcl --lib -j 2 -- gpu::dxil::round_tests:: --test-threads=1 --nocapture on PR head: 9 passed, 0 failed, 0 ignored, with no reported skips. The new pixel translation rejection and positive controls passed. All five existing GPU arithmetic tests in the module ran on the laptop, including the dynamic/denormal cases.

The new pixel cases check translation; the GPU runs cover existing arithmetic cases. Full workspace testing and a retail title were outside this run.

OpenAI Codex assisted with the Windows verification.

@retrope13

Copy link
Copy Markdown

Independent Windows/MSVC + NVIDIA GPU (RTX 4060 Laptop 8 GB, DXC 1.9.2602.17) verification and diff review of #2814 (15e88d74) against main (b49be183): full debug workspace suite + release round_tests green, 0 failures. No title was run.

Tested

  • Hardware / Env: NVIDIA GeForce RTX 4060 Laptop GPU (8 GB, Ada Lovelace, driver 32.0.16.2140, wave32), Intel Core i5-14500HX (14C/20T), 24 GB RAM, Windows 11 26H2 (build 26300.9818), rustc 1.100.0 (stable-x86_64-pc-windows-msvc), Windows SDK 10.0.26100.0 DXC 1.9.2602.17, XCL_ADAPTER=NVIDIA.
  • Targeted gpu::dxil::round_tests:
    • Debug (cargo test --locked -p xcl --lib -- gpu::dxil::round_tests --test-threads=4 --nocapture): 9 passed, 0 failed, 0 ignored, 0 skipped (0.49 s; all 5 GPU rounding tests + direct_f32_round_mode_vintrp_p1_p2_rejected ran and passed).
    • Release (cargo test --release --locked -p xcl --lib -- gpu::dxil::round_tests --test-threads=4 --nocapture): 9 passed, 0 failed, 0 ignored, 0 skipped (0.65 s).
  • Full workspace (debug): cargo build --workspace --locked, then cargo test --workspace --locked --no-fail-fast -- --test-threads=4:
    • Clean main (b49be183): 1435 passed, 0 failed, 47 ignored
    • PR #2814 (15e88d74): 1436 passed, 0 failed, 47 ignored (+1 new test, 0 failures)

Diff Check (b49be183..15e88d74)

  • Verified lw.f32_rm is computed upfront over the whole program (kernel.rs:266), so hoisting self.f32_rm && lower_round::f32_round_unsupported(&name) into Lw::inst (lower.rs:965) closes the ENC_VINTRP → interp_gfx bypass regardless of block lowering order.
  • Verified f32_round_unsupported only matches v_fma_mix_f32, v_dot2_f32_f16, v_dot2c_f32_f16, v_interp_p1_f32, and v_interp_p2_f32, so hoisting out of Lw::valu introduces no false positives on non-VALU encodings while keeping V_INTERP_MOV_F32 and MODE[1:0] == 0 controls unaffected.

Not Tested

  • Live retail title scripts/smoke.ps1 runs, AMD / Intel GPUs, native wave64 hardware, and the 47 #[ignore] / SKIPPED tests.

AI disclosure: Antigravity (Gemini 4 Neon, XHigh) ran the builds/tests, checked the diff, and drafted this report.

@Anon64

Anon64 commented Nov 26, 2026

Copy link
Copy Markdown

Regression run of 15e88d7 on a newer retail title: no device removal, no crash, frames and commit within the limits.

Setup: RTX 3060 12 GB (NVIDIA 581.80), i9-14900KF, Windows 11 26200, release builds of main b49be18 (this PR's base) and of this PR's exact head, scripts/smoke.ps1 -Game <title> for 60 s with XCL_NETWORK=0 and A pressed every 4 s from 20 s. Main ran before and after a batch of 11 PRs and peaked at 23,855 and 23,844 MB, so the baseline held steady over the batch.

main:

xcl-smoke v1
commit: b49be1836844fe0b0cdb3211dce3cb7fb4e21ac7
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1461 (PresentX 1462)
presents per 2 s (last 3): 10 1 1
device removals: 0
crashes: 0
peak commit: 23855 MB

this PR:

xcl-smoke v1
commit: 15e88d74df3ae653a6cda85fa0538acbe2554731
gpu: NVIDIA GeForce RTX 3060
title: 21222967
seconds: 60
exit: 0x0
frames shown: 1474 (PresentX 1474)
presents per 2 s (last 3): 12 2 4
device removals: 0
crashes: 0
peak commit: 24771 MB

100 % of main's frames, 103 % of its peak commit. One run each.

Not tested: the suite on this head; whether the title reaches the code this PR changes in its first 60 s; AMD.

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

@safesearch77

Copy link
Copy Markdown
Author

Huge thanks to @ettehn, @retrope13, and @Anon64 for the native Windows GPU test runs, source diff audit, and 60 s scripts/smoke.ps1 regression pair on 15e88d74! Added the suite and xcl-smoke results to the PR description and marking Ready for Review.

AI use: Antigravity (Gemini 4 Carbon)

@safesearch77
safesearch77 marked this pull request as ready for review November 26, 2026 15:40
@rgroenewoudt

Copy link
Copy Markdown

Tested on AMD Radeon RX 9070 (RDNA4) at this PR's head 15e88d7: the new test and the GPU rounding tests pass; no new failures.

Tested

Not tested

  • No regression run on a real title (no game data here); this covers only the test suite on AMD

AI use

  • Claude Code (Claude Opus 5.5) ran the commands and wrote this report from the logs.

@saintwolf

Copy link
Copy Markdown
Contributor

merge-check claim
head: 15e88d7

@github-actions github-actions Bot added area:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) 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 labels Nov 30, 2026
@tiagonleal

tiagonleal commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: 15e88d7
merge: clean, alone and together with #1763 (0f257d1, test files only under tests/compile_bench/): both heads merged onto the base in one tree (052f736e) without conflicts
build: cargo build --workspace -> ok on the combined tree (also cargo build --release -p xcl)
tests: cargo test --workspace --no-fail-fast -j 8 -- --test-threads=4 on the combined tree of this head and #1763's head on the base (one suite run for the two PRs, not one per PR) -> 2895 passed, 1 failed, 51 ignored; SKIPPED: 24 lines, the same as on the base; failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, which fails the same way on the base alone (2885 passed, 1 failed, 51 ignored; #3513 fixes it). gpu::dxil::round_tests::direct_f32_round_mode_vintrp_p1_p2_rejected ran and passed. With lower.rs and lower_valu.rs put back to the base, it fails at round_tests.rs:558 ("expected error for S_ROUND_MODE, V_INTERP_P1_F32, ENC_VINTRP"); files restored after.
review: whole diff read (+101/-3). The check f32_rm && f32_round_unsupported(name) moves from Lw::valu to the top of Lw::inst (lower.rs:965), before the encoding match, so ENC_VINTRP, which lower.rs:1086 sends straight to interp_gfx without passing through valu, is now covered too. What is rejected: only the five names in f32_round_unsupported (lower_round.rs:480-481: v_fma_mix_f32, v_dot2_f32_f16, v_dot2c_f32_f16, v_interp_p1_f32, v_interp_p2_f32), and only when f32_round_writes (lower_round.rs:461-473) finds a write of MODE[1:0] anywhere in the program: s_round_mode with low bits set, s_setreg_imm32_b32 with a nonzero round field, or any s_setreg_b32 that covers the round bits (whatever value it writes, so that one is conservative). What happens to a rejected shader: the direct translation returns an error and the shader takes the HLSL path, logged as [SHADER] direct DXIL fallback stage=... reason=... - HLSL path (recomp/pso.rs:1280-1283); no draw is skipped. The direct-DXIL cache key includes a hash of the translator sources (recomp/pso.rs:330, :371), so cached translations from the base are not reused by this build.
performance: scripts/smoke.ps1, 60 s of a retail title, release, two runs of the merge against today's base run (1659 frames, 17322 MB peak commit, after one warm-up). The first merge run was cold for direct DXIL, since the cache key includes the translator sources: 1697 frames, 16857 MB. The second: 1701 frames, 18164 MB. Both ended on the 60 s limit, exit 0x0, no device removal, no crash; 60753 pipelines made, as on the base. No direct DXIL fallback line names the directed f32 rounding reason in either run, so no shader of the title in these menus takes the HLSL path because of this rejection. The second run logs 20 fallback lines with other reasons (wave64 VS / PS in 32-lane waves reading lanes 32 to 63, and wave64 graphics v_writelane spill). Both reasons also appear in the base runs of today (2 such lines in a base smoke log), and 13 of the 20 come in the last two seconds of the run, so I read the count as how far the run got, not as this PR; the lines carry no shader ids.
verdict: safe to merge
hardware / tool and model: RTX 5070 Ti 16 GB (617.42, wave32), Ryzen 7 9800X3D, 32 GB, Windows 11 26300, rustc 1.100.0 / Claude Code (Claude Opus 5.5 ran the build, suite and tests, reviewed the diff against the merged source and wrote this)

  • Tiago

@saintwolf

Copy link
Copy Markdown
Contributor

merge-check
base: 9dfbe3e
head: 15e88d7
merge: clean (trial merge 4da541f552dcb00f0e7ffa220cd02681ccffe960; git diff --check clean; +101/-3 in crates/xcl/src/gpu/dxil/lower.rs, lower_valu.rs, round_tests.rs)
build: cargo build --workspace -> ok (39 pre-existing warnings, none from the PR's files)
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2886 passed, 1 failed, 51 ignored; SKIPPED: 27 (22 "no wave64" — wave32-only GPU, 2 "no heap windows", 1 "cannot disable the driver cache (Developer Mode)", 2 "no xgameruntime.dll"); failing: gpu::dxil::msaa_tests::gpu_direct_image_get_resinfo_d16, pre-existing on this machine (fails identically on base 9dfbe3e, same "2D D16 resinfo clobbered v2/v3" assertion). All 11 round_tests pass, including the new direct_f32_round_mode_vintrp_p1_p2_rejected and the five existing GPU rounding tests on this card.
review: read the whole diff. The bug is real and verified on main: lower.rs:1083 dispatches "ENC_VINTRP" straight to interp_gfx, so V_INTERP_P1/P2_F32 in the 32-bit pixel encoding never reached the f32_rm check that lived in Lw::valu — a pixel shader under directed f32 rounding lowered those with the default rounding mode instead of falling back to the HLSL path. The fix moves the check into Lw::inst before the encoding match, covering every encoding; it is safe because f32_rm is computed upfront over the whole program (kernel.rs:408), so block lowering order cannot matter, and f32_round_unsupported matches only five names (v_fma_mix_f32, v_dot2_f32_f16, v_dot2c_f32_f16, v_interp_p1_f32, v_interp_p2_f32), so no new rejections of other encodings. The new test covers 5 mode setters x 4 interp variants (P1/P2 x ENC_VINTRP/ENC_VOP3) x wave32/wave64 expecting the rejection, with controls that MODE[1:0]==0, 0xC (f16/f64-only), and V_INTERP_MOV_F32 still translate to well-formed DXIL; ettehn reproduced the failure on main with the test copied over (fail->pass). No unsafe, no new dependencies.
performance: none; a name lookup that valu already did, now once per instruction for all of them — negligible.
verdict: safe to merge
hardware / tool and model: RTX 4070 SUPER (driver 32.0.16.2140), Ryzen 7 7800X3D, Windows 11 build 26300, Rust 1.100.0 / OpenCode, Qwen 3.8 27B

@github-actions github-actions Bot added 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) labels Nov 30, 2026
@github-actions github-actions Bot added ready-to-merge Has 2 independent safe merge-checks on current head (#3041) and removed needs-2nd-check Has 1 safe merge-check; needs second independent check (#3041) needs:amd-test Needs a test report or merge-check on an AMD GPU labels Nov 30, 2026
@Foniass

Foniass commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

Triage (#1607) – head 15e88d7

No open or merged PR makes the same change. Moving the f32_round_unsupported check from Lw::valu to Lw::inst makes it cover ENC_VINTRP (which dispatches to interp_gfx and bypassed it); valu has no other caller, so VOP encodings keep the check.
No problems found in the diff; the test covers VINTRP and VOP3 forms under three mode setters plus default-mode and v_interp_mov_f32 controls.
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:recompiler RDNA2 decoder, HLSL/direct-DXIL recompiler, wave64/wave32 area:tests Unit, integration, e2e tests, or testtitle gpu:amd Code is specific to AMD / RDNA / wave64 GPUs (scope tag; see needs:amd-test) ready-to-merge Has 2 independent safe merge-checks on current head (#3041)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants