Skip to content

DXIL: lower v_bfe_u32 and v_bfe_i32 to Ubfe and Ibfe - #2171

Open
O5-7 wants to merge 1 commit into
xcl-dev:mainfrom
O5-7:dxil/bfe-intrinsic
Open

O5-7 wants to merge 1 commit into
xcl-dev:mainfrom
O5-7:dxil/bfe-intrinsic

Conversation

@O5-7

@O5-7 O5-7 commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

Lower RDNA2 v_bfe_u32 and v_bfe_i32 in the direct DXIL translator directly to dx.op.tertiary (Tertiary::Ubfe, op 52, and Tertiary::Ibfe, op 51) instead of emitting an 10–11 op shift/mask/select expansion.

s_bfe_u32 and s_bfe_i32 (Lw::sbfe_u / Lw::sbfe_i) are left unchanged because scalar BFE masks width to 7 bits (0x7F) where width >= 32 extracts all remaining bits, whereas DXIL Ubfe/Ibfe masks width and offset to 5 bits (0..=31).

Part of #1269

What is in it

  • crates/xcl/src/gpu/dxil/lower.rs: replace Lw::bfe_u and Lw::bfe_i bodies with self.s.tertiary(Tertiary::Ubfe, w, o, v) and self.s.tertiary(Tertiary::Ibfe, w, o, v) (+2/-21 lines).
  • crates/xcl/src/gpu/dxil/core_tests.rs: add bfe_lowers_to_dxil_intrinsics checking DXIL validation and disassembly for dx.op.tertiary.i32 opcodes 52 (Ubfe) and 51 (Ibfe).
  • crates/xcl/src/gpu/recomp/tests.rs: add gpu_v_bfe_edge_cases testing 24 edge cases (w = 0, w = 1, w = 31, unmasked w = 32 / w = 0x104 / o = 32 / o = 0x104, o + w == 32, o + w > 32, sign-extension boundaries) against an exact CPU reference.
  • Synthetic compute shader measurement (1 and 64 (V_BFE_U32, V_BFE_I32) pairs, wave32): n = 1 changes 2332 → 2352 bytes (first dx.op.tertiary.i32 declaration); n = 64 drops 5940 → 5548 bytes (-392 bytes).

Tested

  • Hardware & toolchain: NVIDIA GeForce RTX 5080 (driver 32.0.15.9579, wave32), AMD Ryzen 7 9700X, Windows 11 Pro 10.0.26100, rustc 1.100.0, DXC 1.8.2502.11 (XCL_DXC_DIR=D:\Windows Kits\10\bin\10.0.26100.0\x64), debug & release builds.
  • cargo test --workspace -- --test-threads=4: 1156 passed, 0 failed, 46 ignored (24 SKIPPED hardware-capability / policy checks: native wave64 unavailable on RTX 5080 and rejected direct-path f16 arithmetic), including bfe_lowers_to_dxil_intrinsics and gpu_v_bfe_edge_cases.
  • XCL_DIRECT_DXIL=1 targeted GPU parity runs on RTX 5080 (gpu_v_bfe_edge_cases, gpu_signed_bfe_arithmetic_shift, gpu_valu_float_and_int): all 3 passed; confirms NVIDIA's D3D12 compiler masks DXIL Ubfe/Ibfe width and offset to 5 bits cleanly even for unmasked 32 and 0x104.

Regression run
main:

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1686 (PresentX 1686)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14083 MB

PR:

xcl-smoke v1
commit: cd6764952e46276a8ff65d2a95c91ec81a0c76a2
gpu: NVIDIA GeForce RTX 5080
title: 9cc6a39e
seconds: 60
exit: 0x0
frames shown: 1686 (PresentX 1686)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14072 MB

Not tested

  • Native wave64 GPU execution (skipped automatically on wave32-only RTX 5080 hardware).
  • Running the title with XCL_DIRECT_DXIL=1 in the smoke.ps1 launch (because on unmerged main without PR VFS: exempt xcl.exe and host tool dirs from console drive mounts #2101, D:\Windows Kits\... in XCL_DXC_DIR is intercepted by the {game} D-drive VFS mount inside the host process; XCL_DIRECT_DXIL=1 was verified in unit/GPU tests).

AI use

  • Antigravity (Gemini 4 Neon): lowered Lw::bfe_u and Lw::bfe_i to Tertiary::Ubfe/Tertiary::Ibfe, wrote the disassembly and GPU edge-case tests, and ran the test suite and scripts/smoke.ps1 regression checks.

@luckyteagirl

Copy link
Copy Markdown
Contributor

Independent native Windows AMD check of exact PR head cd6764952e46276a8ff65d2a95c91ec81a0c76a2. The PR description lists native wave64 as untested.

Tested

  • 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; debug tests.
  • XCL_ADAPTER=6800M, XCL_REQUIRE_GPU=wave64, XCL_DIRECT_DXIL=1; cargo test --locked -p xcl --lib -j 2 gpu_v_bfe_edge_cases -- --test-threads=1 --show-output: 1 passed, 0 failed, 0 ignored, 0 SKIPPED. The fixture runs both wave64 and wave32 and compares 24 signed/unsigned BFE edge cases against its CPU reference per lane.
  • The same GPU command with XCL_DIRECT_DXIL=0: 1 passed, 0 failed, 0 ignored, 0 SKIPPED.
  • bfe_lowers_to_dxil_intrinsics on this head: 1 passed, 0 failed, 0 ignored (DXIL intrinsic validation/disassembly unit test).

This checks the focused GPU and DXIL tests. I did not run the full workspace suite or a paired title smoke on this PR. No claim about speed or title shader use follows from these tests.

AI-assisted checkout, testing, log verification, and report drafting with OpenAI Codex (GPT-6). No game data was used.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@SzczepanGrela

Copy link
Copy Markdown

Linux/RADV + Wine GPU test report on PR #2171 head cd67649 (cd6764952e46276a8ff65d2a95c91ec81a0c76a2, local merge 75aee93dd43dc8a8fd5afbe283dcbd2b6407a957 onto origin/main 568e7db7729c8fa6c8f0f4b32d798faaf11462bb).

Setup

  • OS/kernel: CachyOS Linux (7.3.0-5-cachyos)
  • GPU/driver: AMD Radeon RX 9070 (RADV GFX1201, native wave64) (device 0x7550, Vulkan 1.4.354, Mesa RADV 26.2.5-arch3.1)
  • Wine/DX: GE-Proton11-12 (wine-11.0 (Staging)), vkd3d-proton v3.1, DXVK dxgi.dll, DXC 1.9.2602.17 (21d28f72)
  • Build/env: rustc 1.97.1, cargo test --target x86_64-pc-windows-gnu --release --workspace --no-run (43.96s, exit 0, zero compiler warnings), XCL_REQUIRE_GPU=wave64 XCL_NETWORK=0

Results
New tests (cargo test --target x86_64-pc-windows-gnu --release -p xcl --lib ... -- --exact --nocapture):

  • gpu::dxil::core_tests::bfe_lowers_to_dxil_intrinsics: 1 passed, 0 failed, 0 ignored in both default env (0.01s, exit 0) and XCL_DIRECT_DXIL=1 (0.01s, exit 0).
  • gpu::recomp::tests::gpu_v_bfe_edge_cases: 1 passed, 0 failed, 0 ignored (exit 0) across all 5 tested modes: default (0.11s), XCL_DIRECT_DXIL=1 (0.09s), XCL_DIRECT_DXIL=all (0.09s), XCL_SPLIT_WAVE64=1 (0.11s), and XCL_DIRECT_DXIL=1 XCL_SPLIT_WAVE64=1 (0.09s).

Affected suites (cargo test --target x86_64-pc-windows-gnu --release -p xcl --lib ...):

  • gpu::dxil::core_tests: 16 passed, 0 failed, 1 ignored in default env (0.16s, exit 0) and XCL_DIRECT_DXIL=1 (0.13s, exit 0; dump_dxc_lowering ignored), vs baseline 568e7db 15 passed, 0 failed, 1 ignored (0.12s each, exit 0; +1 passed, 0 regressions).
  • gpu::dxil -- --skip ops_tests::integer_ops_match_cpu --skip ops_tests::uaddc_and_usubb_match_cpu:
    • Default env: 120 passed, 1 failed, 3 ignored (1.16s, exit 101), vs baseline 568e7db 119 passed, 1 failed, 3 ignored (1.11s, exit 101).
    • XCL_DIRECT_DXIL=1: 120 passed, 1 failed, 3 ignored (0.96s, exit 101), vs baseline 568e7db 119 passed, 1 failed, 3 ignored (0.88s, exit 101).
    • All 4 runs failed identically on gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_2 (crates/xcl/src/gpu/dxil/fuzz_tests.rs:1171:21, seed 1003: res[713] = 0x1, CPU 0x0).
  • gpu::recomp::tests::gpu_ -- --skip gpu_sparse_vram_descriptors_buffers_and_xmem --skip gpu_uma_import_check_at_init --skip gpu_unified_memory_arena:
    • Default env: 100 passed, 1 failed, 1 ignored (1.06s, exit 101), vs baseline 568e7db 99 passed, 1 failed, 1 ignored (0.89s, exit 101; identical failure gpu_nonfused_mad_and_mac_prevent_fma_contraction, ignored gpu_arena_partial_commit_probe).
    • XCL_DIRECT_DXIL=1: 97 passed, 4 failed, 1 ignored (0.69s, exit 101), vs baseline 568e7db 96 passed, 4 failed, 1 ignored (0.65s, exit 101; identical 4 failures: gpu_f64_math_random, gpu_f64_roots, gpu_image_get_resinfo_1d_array, gpu_nonfused_mad_and_mac_prevent_fma_contraction).
    • XCL_DIRECT_DXIL=all: 97 passed, 4 failed, 1 ignored (0.61s, exit 101), vs baseline 568e7db 96 passed, 4 failed, 1 ignored (0.60s, exit 101; identical 4 failures).
    • XCL_SPLIT_WAVE64=1: 90 passed, 11 failed, 1 ignored (1.54s, exit 101), vs baseline 568e7db 89 passed, 11 failed, 1 ignored (1.49s, exit 101; identical 11 failures).

Not tested

  • No retail game workload, no scripts/smoke.ps1, no integration test binaries, and no --lib modules outside gpu::dxil and gpu::recomp::tests::gpu_.
  • gpu::dxil::ops_tests::integer_ops_match_cpu and ops_tests::uaddc_and_usubb_match_cpu (excluded via --skip in both baseline 568e7db and PR #2171 runs due to known vkd3d-proton v3.1 / libvulkan_radeon.so exit 3 crash).
  • gpu_sparse_vram_descriptors_buffers_and_xmem, gpu_uma_import_check_at_init, and gpu_unified_memory_arena (excluded via --skip in the mode sweeps; baseline 568e7db unskipped gpu::recomp::tests::gpu_ -- --test-threads=1 passed 83, failed 20, ignored 1, with 19 HRESULT(0x80070057) failures after gpu_sparse_vram_descriptors_buffers_and_xmem while gpu_uma_import_check_at_init and gpu_unified_memory_arena passed in isolation).

AI use

  • Diff audit, test execution, and comment drafting used Antigravity (Gemini 4 Neon) multi-agent verification, reviewed by me before posting.

Replace the 10-11 op shift/mask/select expansion in Lw::bfe_u and
Lw::bfe_i with direct dx.op.tertiary Ubfe (op 52) and Ibfe (op 51)
intrinsics. Leave s_bfe_u32 / s_bfe_i32 (sbfe_u / sbfe_i) untouched
because they use 7-bit widths where width >= 32 keeps all remaining
bits rather than masking width to 5 bits.

Part of xcl-dev#1269

Assisted-by: Antigravity (Gemini 4 Neon)
@O5-7
O5-7 force-pushed the dxil/bfe-intrinsic branch from cd67649 to 457db25 Compare November 25, 2026 11:58
@Toons29

Toons29 commented Nov 25, 2026

Copy link
Copy Markdown

Regression run of 457db25d on the retail title, for this PR's Regression run section. Both blocks are from scripts/smoke.ps1 as printed, not edited: main on 568e7db7, this PR on its head commit with no uncommitted changes, same title and time.

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1566 (PresentX 1566)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14592 MB
xcl-smoke v1
commit: 457db25d580ca459a8a0ad2f723bd7a021375d9c
gpu: AMD Radeon RX 9070
title: 34df7c50
seconds: 60
exit: 0x0
frames shown: 1630 (PresentX 1630)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14559 MB

Against the limits in CONTRIBUTING.md: 104 % of main's frames, 100 % of its peak commit, no crash, no device removal.

AMD Radeon RX 9070 (RDNA4, driver 32.0.32029.2010), Ryzen 7 7800X3D, 32 GB, Windows 11 build 26300, Rust 1.100.0, cargo build --release -p xcl, 60 s, XCL_NETWORK=0. This is a regression check only: it does not show whether the run reaches the code this PR changes.

AI use: Claude Code (Claude Opus 5.5) built both trees and ran scripts/smoke.ps1; a script posted this right after the run, with both blocks exactly as printed.

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