Skip to content

Direct DXIL: sign-extend i1 to i64 through i32 - #1974

Merged
raylitebull merged 2 commits into
xcl-dev:mainfrom
luckyteagirl:codex/dxil-i1-sext
Nov 25, 2026
Merged

raylitebull merged 2 commits into
xcl-dev:mainfrom
luckyteagirl:codex/dxil-i1-sext

Conversation

@luckyteagirl

@luckyteagirl luckyteagirl commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

On the Radeon RX 6800M with Windows driver 30.0.13002.13003, direct sext i1 to i64 produces 0x00000000ffffffff for a true bit; the expected result is 0xffffffffffffffff. This routes that cast through i32. A review follow-up checks existing type IDs so unrelated sign extensions do not intern unused i1 or i64 types. The direct-DXIL source hash from #1947 keys the translation cache, so no manual translator-version bump is needed. The fault was exposed by direct-DXIL fuzz seed 540 after the separate i64 min/max fix in #1946.

What is in it

  • crates/xcl/src/gpu/dxil/module.rs: sign-extend only i1 to i64 through i32, and avoid creating type IDs merely to check the cast. The follow-up commit was supplied by @ettehn and retains their Git authorship.
  • crates/xcl/src/gpu/dxil/module.rs tests: verify unrelated casts do not intern extra integer types and the affected cast still emits two extensions.
  • crates/xcl/src/gpu/dxil/ops_tests.rs: compare both result words and an arithmetic shift on the GPU.

Tested

  • Exact clean head 248c1cecc27dbcfd0dbc225a8eab9915c755fccb rebased on current main 426a5a745db4d5e4b037449ede0b70cb342f5192. Windows 11 build 26200, Ryzen 9 5980HX, Radeon RX 6800M driver 30.0.13002.13003, Rust 1.99.0 MSVC, DXC/DXIL 1.9.2609.5.

  • XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=wave64, XCL_DIRECT_DXIL=1: cargo test --locked -p xcl --lib -j 2 sign_extension -- --test-threads=1 --show-output 3 passed, 0 failed, 0 ignored, no SKIPPED lines. This includes the GPU fixture.

  • cargo build --locked --workspace -j 2, cargo build --release --locked -p xcl -j 2, and git diff --check upstream/main...HEAD passed. Cargo targets were separate for main and the PR.

  • Paired cargo test --locked --workspace --no-fail-fast -- --test-threads=4 on the same RX 6800M:

    Mode Main passed / failed / ignored PR passed / failed / ignored Explicit SKIPPED
    XCL_DIRECT_DXIL=0 1075 / 168 / 46 1077 / 169 / 46 8 each
    XCL_DIRECT_DXIL=1 1074 / 169 / 46 1076 / 170 / 46 8 each

    All existing failure names are identical on base and PR. The only added failure name is the new GPU fixture when run in the broad suite after the RX 6800M device was suspended (CreateComputePipelineState, 0x887A0005); that fixture passes in isolation. The broad suite is not green on this driver.

  • An earlier isolated seed-540 diagnostic combining Direct DXIL: lower i64 min/max as compare/select #1946 and this fix had zero mismatching GPU results, versus 21 mismatches before the fix. That evidence belongs to the earlier tree, not this head.

Regression run

Same locally owned title, release builds, fresh separate XCL data and DXIL caches, networking off, 12 seconds each. Neither run hit the external memory guard.

Main:

xcl-smoke v1
commit: 426a5a745db4d5e4b037449ede0b70cb342f5192
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 12
exit: 0x0
frames shown: 99 (PresentX 99)
presents per 2 s (last 3): 1 38 60
device removals: 0
crashes: 0
peak commit: 8183 MB

PR head:

xcl-smoke v1
commit: 248c1cecc27dbcfd0dbc225a8eab9915c755fccb
gpu: AMD Radeon RX 6800M
title: 2ef5fd64
seconds: 12
exit: 0x0
frames shown: 101 (PresentX 101)
presents per 2 s (last 3): 1 40 60
device removals: 0
crashes: 0
peak commit: 8217 MB

Not tested

  • NVIDIA on this rebased head. NVIDIA verified the previous head and @ettehn's follow-up before this rebase; independent verification on the combined head remains welcome.
  • The title smoke uses default HLSL routing and does not exercise the direct-DXIL cast; the focused GPU fixture does. Longer title sessions were not run because this machine approaches its commit-memory limit.

AI use

OpenAI Codex (GPT-6; exact variant not exposed) implemented the original fix, reviewed and cherry-picked @ettehn's authored follow-up, rebased the branch, ran the paired checks and smoke comparison, and drafted this description.

@DavidM1911

Copy link
Copy Markdown
Contributor

Verification on RTX 3060 Ti (Windows 11), branch merged with current main:

Thanks!

@fallow64

Copy link
Copy Markdown

Confirmed on AMD RX 6750 XT, driver 32.0.21045.5002, Windows 11 build 26200, exact head 848ac65b.

i1_to_i64_sign_extension_and_shift_match_cpu: 1 passed, 0 failed, no skips.

Base cbc296a reproducibly fails fuzz seed 540 (7, expected 6); this PR clears seed 540.

Not tested: full suite or retail title.

AI use: OpenAI Codex (GPT-5) ran and analyzed the test; I reviewed the result.

Thank you!

@ettehn

ettehn commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Two narrow Windows checks on 848ac65b.

  • Module::cast currently calls the type-creating i1() / i64() accessors to test the signature. A module-only regression confirmed that an unrelated sext i32 → i64 interns an unused i1; sext i1 → i16 has the analogous issue with i64. Checking the already-interned type IDs/width instead passed both checks, while the affected cast still emitted the two-step sequence.
  • WARP (Windows 11 26200.9974, DXC/DXIL 1.8.2502.11), four threads with no fixed wave size: the sign-extension and seed-540 arithmetic matched all 16 output words when the input’s low bit was explicitly masked first. A separate validated module containing only trunc i32 → i1 and zext i1 → i32 returned [0, 1, 1, 1] for [0, 1, 2, 0x80000000]; and i32 ..., 1 before truncation gave the expected [0, 1, 0, 0]. There is no sext anywhere in that second module. This is a separate WARP observation; the AMD hardware results above address the original cast issue.

Eight-input WARP control. The raw trunc i32 → i1 also sends nonzero even inputs down the true arm when consumed by a conditional branch. A separate (x & 1) != 0 in the same validated shader returned the correct low bit for all eight inputs. There is no sext in the module. In main 568e7db, I only found emission of the i1-destination truncation in the fuzz generator; the runtime lowering calls go to i32. This is evidence about the software test backend and does not require a runtime change for #1974.

AI use — OpenAI Codex (GPT-6) wrote the local checks and ran them.

@alexdeliu

Copy link
Copy Markdown
Contributor

Test report for 848ac65, on the RDNA2 GPU this fix is for plus an RDNA4 control. Applied on #2170's head 2fe270d (on main 568e7db); #2170 adds seed 540's reduced shapes to amd_reduced_seeds.

Tested

  • AMD Ryzen 7 7700 iGPU (gfx1036, RDNA2, driver 32.0.21045.29003) and AMD RX 9070 (RDNA4, 32.0.32029.2010). Windows 11 Pro 26200, rustc 1.100.0, debug, Windows SDK DXC 1.7.
  • cargo test -p xcl --lib gpu::dxil::fuzz_tests::amd_reduced_seeds -- --ignored --nocapture:
    • gfx1036: 540 sext i1 -> i64, 540 sext i1 -> i64 -> ashr 63 - (-7) and full seed 540 PASS with this PR. Without it they FAIL (res[64] = 0x0, CPU 0xffffffff). Full seeds 722 and 1599 pass, as without it.
    • RX 9070: the 540 cases pass with and without it. 722 and 1599 still fail there; they are a separate RDNA4 issue that this PR does not touch.
  • cargo test -p xcl --lib sext (this PR's test): 1 passed.

This matches @luckyteagirl's RX 6800M result on #2170, so the cast is wrong on RDNA2 in general, not only on one part or driver.

Not tested: NVIDIA and Intel, the whole suite with this PR, a retail title.

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

@raylitebull

Copy link
Copy Markdown
Member

Diff review on 848ac65 looks good (TypeOf -> i64 via i32 sign-extension in crates/xcl/src/gpu/dxil/module.rs plus i1_to_i64_sign_extension_and_shift_match_cpu in ops_tests.rs), and CI is green.

Two quick items before merge:

  1. Addressing @ettehn's nit: avoid interning an unused i1 type inside type_of(v) when checking whether v is Ty(i1).
  2. Confirming i1_to_i64_sign_extension_and_shift_match_cpu passes on NVIDIA hardware on the current head.

@ettehn

ettehn commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

NVIDIA confirmation for item 2 in the merge checklist. On exact, clean head 848ac65b9a2061c01f4fc7574ab3a156fce5abc6, i1_to_i64_sign_extension_and_shift_match_cpu passed on the RTX 5070 Ti Laptop GPU: 1 passed, 0 failed, 0 ignored, no SKIPPED lines, 0.47 s for the test run. The fixture compares the four output words for all 32 lanes.

Windows 11 26200.9974, NVIDIA driver 621.24, DXC/DXIL 1.8.2502.11, Rust 1.97.1 MSVC, debug. XCL_ADAPTER=0, XCL_REQUIRE_GPU=1.

cargo test --offline --locked -j 2 -p xcl --lib gpu::dxil::ops_tests::i1_to_i64_sign_extension_and_shift_match_cpu -- --exact --test-threads=1 --nocapture

Only the focused test ran on this head. AI use — OpenAI Codex (GPT-6.2 Sol) ran the test and wrote this report.

@ettehn

ettehn commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

For item 1 in the merge checklist, bd22b54 is a cherry-pickable follow-up on 848ac65. It checks the existing types before emitting the cast, so unrelated sign extensions do not intern extra integer types.

Windows CPU-only A/B: cargo test --locked -p xcl --lib gpu::dxil::module::tests::sign_extension -- --test-threads=1. With the same tests and 848ac65’s original cast implementation, 1 passed and 1 failed (extra i1). With the follow-up, 2 passed and 0 failed or ignored, including the check that i1 → i64 still emits two casts through i32.

NVIDIA follow-up on clean bd22b54, RTX 5070 Ti Laptop GPU: cargo test --offline --locked -p xcl --lib gpu::dxil::ops_tests::i1_to_i64_sign_extension_and_shift_match_cpu -- --exact --test-threads=1 --nocapture gave 1 passed, 0 failed, 0 ignored, no skips (0.41 s). WARP skipped the same test because it lacks wave32. This run covered the focused regression only.

AI use: OpenAI Codex (GPT-6.2 Sol) assisted with the follow-up and verification.

luckyteagirl and others added 2 commits November 25, 2026 03:20
Read the existing i1 and destination type instead of creating unrelated integer types. Retain the i32 intermediate for the affected i1-to-i64 sign extension and cover both behaviors with CPU unit tests.

Assisted-by: OpenAI Codex (GPT-6.2 Sol)
@thehollowedone

Copy link
Copy Markdown

Independent NVIDIA check on 248c1ce. Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti (621.35), Rust 1.99.1 MSVC, debug.

cargo build --offline --locked --workspace passed. cargo test --offline --locked --workspace --no-fail-fast -- --test-threads=4 --nocapture reported 1,246 passed, 0 failed, 46 ignored, with 25 runtime skip notices included in Cargo's pass count.

With XCL_ADAPTER=3080 Ti, XCL_DIRECT_DXIL=1 and XCL_REQUIRE_GPU=wave32:

  • cargo test --offline --locked -p xcl --lib sign_extension -- --test-threads=1 --nocapture passed all three tests. The two module tests verified that unrelated casts add no extra types and the affected cast emits two extensions. The GPU test matched all four output words for all 32 lanes.
  • cargo test --offline --locked -p xcl --lib gpu::dxil::fuzz_tests::amd_reduced_seeds -- --ignored --exact --nocapture --test-threads=1 passed the two reduced seed 540 shapes and the full seed with zero mismatching dwords. The seven other diagnostic cases passed too.

Zero skips in both focused runs. This is NVIDIA regression coverage. AI-assisted. Codex (GPT-6, exact variant unavailable) ran the tests and drafted this report.

@jennydeth

Copy link
Copy Markdown

NVIDIA run on the rebased head (listed under Not tested).

Setup: RTX 3060 12 GB (32-lane waves, driver 32.0.16.2101), Ryzen 5 5600X, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0, DXC 1.9.2609.5, debug build. Head 248c1ce.

Result: cargo test --workspace -- --test-threads=4: 1246 passed, 0 failed, 46 ignored. SKIPPED: 18 GPU tests for no wave64 (expected on this card); the per-lane refused cases; heap windows; driver cache; 2 debug-layer tests (no d3d12SDKLayers.dll).

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

1 similar comment
@jennydeth

Copy link
Copy Markdown

NVIDIA run on the rebased head (listed under Not tested).

Setup: RTX 3060 12 GB (32-lane waves, driver 32.0.16.2101), Ryzen 5 5600X, 32 GB RAM, Windows 11 build 26300, Rust 1.100.0, DXC 1.9.2609.5, debug build. Head 248c1ce.

Result: cargo test --workspace -- --test-threads=4: 1246 passed, 0 failed, 46 ignored. SKIPPED: 18 GPU tests for no wave64 (expected on this card); the per-lane refused cases; heap windows; driver cache; 2 debug-layer tests (no d3d12SDKLayers.dll).

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

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.

8 participants