Skip to content

Direct DXIL: reject invalid stage exports and graphics LDS ops - #2102

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1269-dxil-stage-guards
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-1269-dxil-stage-guards

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

What is in it
Matches the HLSL recompiler's stage guards (recomp/emit.rs) in the direct DXIL translator's Lw::export() and Lw::ds() (crates/xcl/src/gpu/dxil/lower_mem.rs):

  • In Lw::export(): after dispatching Entry::Mesh (self.mesh.is_some()) and Entry::Vertex / Entry::Pixel (self.gfx.is_some()), rejects Entry::Compute (self.res.is_none()) and Entry::Geometry (self.geom.is_some()) with err(d, "export target") before reaching the kernel-mode KERNEL_EXPORTS store path. Previously, ENC_EXP in Entry::Compute panicked on self.res.expect("res") when EN != 0 and silently returned Ok(()) when EN == 0, while ENC_EXP in Entry::Geometry silently wrote kernel-export offsets into the geometry mesh-record UAV (u1).
  • In Lw::ds(): after handling wave-level ds_swizzle_b32 and ds_bpermute_b32 (with ds_nop already skipped in NOOPS), rejects LDS ENC_DS operations in Entry::Vertex and Entry::Pixel (self.gfx.is_some()) with err(d, "LDS outside compute") before GDS / LDS lowering. Previously, direct DXIL emitted invalid addrspace(3) TGSM ops in graphics stages and returned Ok.
  • Adds 4 unit tests in gpu::dxil::lower_mem::stage_guard_tests covering compute EXP (EN = 0xF and EN = 0, wave32 and wave64), geometry EXP (EN = 0xF and EN = 0, ES-only and GS-only, native and split), VS/PS LDS ops (DS_READ_B32, DS_WRITE_B32, and GDS = 1), and positive dxil.dll validation controls for kernel EXP, compute LDS, and VS/PS DS_SWIZZLE_B32 / DS_BPERMUTE_B32 / DS_NOP + valid EXP.

Part of #1269

Tested
Environment: Windows 11 Home 26200, Intel Core i5-11400F, 32 GB RAM, NVIDIA GeForce RTX 4060 8 GB (driver 621.14, wave32), Rust 1.100.0, DXC 1.9.2609.5 (01b62ad4).

  • Failing-first pre-fix check (cargo test -j 4 -p xcl --lib gpu::dxil::lower_mem::stage_guard_tests -- --nocapture): 1 passed, 3 failed (compute_export_rejected panicked at lower_mem.rs:2511:28: res -> "the direct DXIL translator panicked: res"; geometry_export_rejected and graphics_lds_rejected unexpectedly succeeded; valid_stage_ops_still_translate_and_validate passed).
  • Post-fix targeted tests (cargo test --release -p xcl --lib gpu::dxil::lower_mem::stage_guard_tests -- --nocapture): 4 passed, 0 failed (including dxil 1.9.2609.5 validation of positive controls).
  • Full release workspace build & test (cargo build --release --workspace and cargo test --release --workspace -- --test-threads=4 --nocapture): 1,158 passed, 0 failed, 46 ignored across 21 test binaries (1102 in xcl lib, 56 across the remaining 20 binaries), with 27 SKIPPED lines on this RTX 4060:
    • 20 no wave64 (RTX 4060 is wave32-only)
    • 3 per-lane form: refused (wave32 f16 arithmetic, f16 packed, f32 conversions)
    • 2 no d3d12SDKLayers.dll / no D3D12 debug layer
    • 1 cannot disable the driver cache (Windows Developer Mode not enabled)
    • 1 no heap windows

Regression run
Paired 60 s runs via scripts/smoke.ps1 on clean origin/main (cbc296ab) and clean PR head (00b5eef7):

Main (cbc296ab65a2661a61e3e2da109134bcd5319f60):

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1591 (PresentX 1591)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14478 MB

PR (00b5eef722359d70fd2549a12a5f87edb9b154f5):

xcl-smoke v1
commit: 00b5eef722359d70fd2549a12a5f87edb9b154f5
gpu: NVIDIA GeForce RTX 4060
title: 29640639
seconds: 60
exit: 0x0
frames shown: 1589 (PresentX 1589)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 14486 MB

Not tested

  • Native wave64 GPU execution (20 no wave64 skips on RTX 4060), D3D12 debug layer tests (2 skips without d3d12SDKLayers.dll), driver cache disable toggle (1 skip without Windows Developer Mode), and heap-window OOM fallback (1 skip without XCL_HEAP_WINDOWS).
  • Retail titles other than title: 29640639 (and runtime title execution specifically exercising malformed compute/geometry EXP or graphics LDS shaders under XCL_DIRECT_DXIL).

AI use
Google Antigravity (Gemini 4 Neon) wrote the stage guards, unit tests, and this PR description. All pre-fix/post-fix unit tests, full release workspace tests, paired 60 s smoke runs, and scripts/pr_check.py --local validation were run locally on this machine.

Match the HLSL recompiler's stage guards in Lw::export and Lw::ds:
- Reject ENC_EXP in compute (res is None) and geometry (geom is Some)
  entries with "export target" instead of panicking on
  self.res.expect("res") (compute, en != 0), silently returning Ok
  (en == 0), or writing kernel-export offsets into the geometry mesh
  record buffer.
- Reject LDS ENC_DS operations in vertex and pixel entries (gfx is
  Some) with "LDS outside compute" after allowing wave-level
  ds_swizzle_b32 and ds_bpermute_b32 (and ds_nop), instead of emitting
  invalid addrspace(3) TGSM ops in graphics DXIL.

Part of xcl-dev#1269

Assisted-by: Google Antigravity (Gemini 4 Neon)
@futurepro62

futurepro62 commented Nov 25, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 00b5eef (on its base cbc296a).

Tested

  • NVIDIA GeForce RTX 5070 Ti 16 GB (Blackwell, 32-lane waves only, mesh shaders), driver 621.40, Ryzen 7 9800X3D, Windows 11 Home 26300, Rust 1.100.0 MSVC, DXC + dxil.dll 1.9.2602.17 (Windows SDK 10.0.26100), debug, D3D12 debug layer installed.
  • cargo build --workspace, then XCL_REQUIRE_GPU=mesh cargo test --workspace -- --test-threads=4 --skip heap_window_out_of_memory_falls_back_to_the_switch_form --skip gpu::recomp::lower_dxil::tests::f16_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f32_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::integer_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::f64_programs_on_the_gpu --skip gpu::recomp::lower_dxil::tests::const_and_null_mask_operands_agree_with_hlsl_on_the_gpu --skip gpu::recomp::lower_dxil::tests::mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu --skip gpu::dxil::fuzz_tests: 1146 passed, 0 failed, 44 ignored. SKIPPED (no wave64): a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu, a_per_lane_2d_or_3d_group_runs_on_the_gpu, coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu, cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu, gpu_geometry_wave32_prefix_count_over_a_mask, gpu_wave32_program_in_wave64_hardware, the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu.
  • The new tests ran and passed: compute_export_rejected, geometry_export_rejected, graphics_lds_rejected, valid_stage_ops_still_translate_and_validate.
  • Same head on the AMD Radeon integrated GPU (iGPU) of the Ryzen 7 9800X3D (RDNA2, XCL_ADAPTER=radeon), cargo test --workspace -- --test-threads=4 --skip gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1: 1157 passed, 0 failed, 46 ignored. SKIPPED: f16_programs_on_the_gpu (f16 arithmetic, wave32, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 arithmetic, wave64, per-lane form: refused (unsupported V_MUL_F16 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave32, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f16_programs_on_the_gpu (f16 packed, wave64, per-lane form: refused (unsupported V_PK_MUL_F16: VOP3 modifiers (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave32, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), f32_programs_on_the_gpu (f32 conversions, wave64, per-lane form: refused (unsupported V_CVT_F16_F32 (its gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426 semantics differ from the console's))), heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows).
  • --skip leaves out tests that fail on main 6020a33 too, not because of this PR. On NVIDIA: heap_window_out_of_memory_falls_back_to_the_switch_form (Tests: heap_window_out_of_memory_falls_back_to_the_switch_form fails under XCL_REQUIRE_GPU=mesh (opt-in skip counted as missing coverage) #1651), the four gpu::recomp::lower_dxil::tests::*_programs_on_the_gpu tests, const_and_null_mask_operands_agree_with_hlsl_on_the_gpu and mask_ff0_and_flbit_agree_with_hlsl_on_the_gpu (follow-up on #1651) fail because runner::skip_test turns their skips into failures under XCL_REQUIRE_GPU=mesh, and gpu::dxil::fuzz_tests seeds 70, 545, 1019 and 1507 fail CreateComputePipelineState with E_OUTOFMEMORY on this card (drivers 616.64 and 621.40). On AMD: fuzz_validate_and_gpu_1 fails on seed 540 (res[833] 0x7 vs CPU 0x6). The AMD run does not set XCL_REQUIRE_GPU.

Not tested

  • a release build, a game (test run only).

AI use

  • Claude Code (Claude Opus 5.5) ran the tests and wrote this report. I checked it before posting.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

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.

3 participants