Skip to content

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

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
Decodere:fix-1269-dxil-stage-guards
Nov 29, 2026
Merged

raylitebull merged 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!

@upipibi

upipibi commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

Tested head 00b5eef722359d70fd2549a12a5f87edb9b154f5, merge-base cbc296ab65a2661a61e3e2da109134bcd5319f60, RTX 3070 (Ampere) driver 616.56, Windows 11, rustc 1.100.0

  • cargo test -p xcl --lib -- stage_guard_tests --test-threads=1 --nocapture, 3 runs on head: 4 passed, 0 failed (each run).
  • Negative control: the PR's stage_guard_tests module appended alone to the merge-base's lower_mem.rs (compiles, without the two guards): 1 passed, 3 failed (compute_export_rejected, geometry_export_rejected, graphics_lds_rejected; the compute export case panics in the translator on res). valid_stage_ops_still_translate_and_validate passes there.
  • cargo test -p xcl --lib -- --test-threads=4: head 1102 passed, 0 failed, 26 ignored; merge-base (unmodified) 1098 passed, 0 failed, 26 ignored.
  • SKIPPED lines (24, same set on both): 20 "no wave64" (32-lane waves only), 3 refused f16/conversion fixtures (gpu: direct RDNA2 -> DXIL backend (no HLSL / DXC), behind XCL_DIRECT_DXIL #1426), 1 driver-cache test needing Windows Developer Mode.

Not tested: retail title; AMD hardware.

AI-assisted (Claude Code, Claude Sonnet 5.5 ran the tests; Claude Opus 5.5 checked and posted).

@JJAutoCompare

Copy link
Copy Markdown

Tested: Clean 00b5eef722359d70fd2549a12a5f87edb9b154f5, Windows 11 build 26200, Ryzen 7 3800X, Intel Arc A770 driver 32.0.101.9175, Rust 1.100.0 MSVC, DXC/DXIL 1.9.2602.17, debug. Built with cargo test --locked -j 2 -p xcl --lib --no-run and ran the resulting executable with --exact --test-threads=1 --nocapture under the shared Arc lock. With XCL_ADAPTER=A770 and XCL_DIRECT_DXIL=1, 7 passed across graphics linking/branches, pixel survival, geometry records, mesh pass-through, compute LDS, and lane swizzle/bpermute. With XCL_DIRECT_DXIL=0, 3 passed on the same mesh, compute LDS and lane-operation controls. Both runs had 0 failures, ignores or skips. The binary hash matched before and after each run.

Not tested: Native wave64 execution, the full workspace suite, retail smoke, and on-device execution of the exact VS/PS wave-DS validator fixture.

AI use: T3 Code / Codex (gpt-6.2-sol) ran and reran the GPU checks and wrote the report.

@thehollowedone

thehollowedone commented Nov 28, 2026 •

Copy link
Copy Markdown
Contributor

merge-check
base: e429936
head: 00b5eef
merge: clean
build: cargo build --offline --locked -j 4 --workspace -> ok
tests: cargo test --offline --locked -j 4 --workspace --no-fail-fast -- --test-threads=4 -> 2,129 passed, 10 failed, 48 ignored; 25 GPU skip notices. The 10 failures match my earlier untouched-main run at this base: dispatch_chain_oversized_loop_matches_whole, dispatch_chain_wave32_live_loops, dispatch_chain_wave64_live_loops_and_exchange, gpu_heap_flat_reads_match_guarded_and_root_output, console_mesh_caches_hlsl_compute_pass_in_memory_and_on_disk, gpu_compute_mode_dispatch_abi, gpu_float_cas_uses_ieee_equality, and the three test_title_* e2e cases (test_title_runs_and_game_folder_is_untouched, test_title_runs_under_the_debug_layer_with_dred, test_title_draws_with_a_root_signature_under_the_debug_layer). The four new stage_guard_tests passed separately (4 passed, 0 failed, 0 ignored, 0 skipped) with cargo test --offline --locked -j 4 -p xcl --lib gpu::dxil::lower_mem::stage_guard_tests -- --nocapture.
review: none. I read the full diff. The stage checks run before the kernel export path or graphics LDS lowering; existing wave-level DS operations and valid kernel/compute exports remain covered by the positive DXIL validation controls. The PR author also supplied a failing-first check and a clean-commit smoke pair on its head.
performance: reasoned only. These checks run during shader translation and add no work to a successfully translated frame. No frame-time or memory benchmark was run here.
verdict: safe to merge relative to the checked main base; the workspace suite remains red for the same 10 base failures.
hardware / tool and model: Windows 11 build 26300, Ryzen 7 9800X3D, RTX 3080 Ti / 621.35, DXC 1.8.2502.11; Codex (GPT-6.2 Sol) reviewed the diff and ran these checks.

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check claim
head: 00b5eef

@throny

throny commented Nov 28, 2026

Copy link
Copy Markdown
Collaborator

merge-check
base: e429936
head: 00b5eef
merge: clean
build: cargo build --workspace -> ok
tests: cargo test --workspace --no-fail-fast -- --test-threads=4 -> 2130 passed, 9 failed, 48 ignored: the base's 9 only (26 SKIPPED lines). The 9 failures are main's own at e429936 on this GPU (#3093); base alone: 2126 passed, 9 failed, 48 ignored.
review: no blocking finding. On main an export in a compute program panics (no export resources there), and in geometry mode it writes into the kernel export area of the record buffer; the new guard refuses both. The LDS guard applies to vertex and pixel programs only, after the swizzle and permute forms are handled; mesh and compute LDS are unaffected. Behaviour change not mentioned in the description: an export with nothing enabled in a compute or geometry program was a no-op before and now sends the program to the HLSL path (low risk). A negative control in the thread shows three of the four tests fail without the fix.
performance: direct DXIL only (the graphics part only with XCL_DIRECT_DXIL=all); a one-time re-translation there.
verdict: safe to merge
hardware / tool and model: RTX 4080 16 GB (621.40), i9-12900K, Windows 11 26300, Rust 1.100.0, debug. Claude Code; merge, build and suite run by Claude Fable 5.2, diff review by Claude Opus 5.5 (every hunk read; nothing run on the GPU beyond the suite).

@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Test report for merging this together with the other of #2102 / #2419 (both are ready to merge on their own): trial merge of both into main d8bd9a38, cargo build --workspace && cargo test --workspace -- --test-threads=4, RTX 4080 16 GB, 621.40:

So the two do not go in together as they are; whichever is merged second needs a rebase and a look at those two tests. I have not looked into which side is right.

AI use: Claude Code (Claude Fable 5.2) ran the suite and wrote this.

@raylitebull
raylitebull merged commit 848be4c into xcl-dev:main Nov 29, 2026
2 checks passed
@throny

throny commented Nov 29, 2026

Copy link
Copy Markdown
Collaborator

Correction to my report above: #2102 and #2419 do not clash with each other. Since #3203, kernel::translate_geometry refuses the split wave64 form when the program has an ES phase, and the new tests of both PRs call it that way, so they stop at that refusal. #3411 fixes the tests on main. Sorry for the wrong lead.

AI use: Claude Code (Claude Fable 5.2) wrote this; Claude Opus 5.5 found the cause.

raylitebull pushed a commit that referenced this pull request Nov 29, 2026
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 #1269

From #2102 (merge 848be4c). Adapted: the tests' CsInterface / PsInterface take this tree's lds_dwords and
early_depth fields, and geometry_export_rejected also accepts, for a split pass
with an ES phase, this tree's earlier refusal of it (kernel::translate_geometry
with the safe barrier: "split wave64 geometry: the ES phase exchanges at group
barriers"), which comes before the export is lowered. The guards themselves
as upstream.

(cherry picked from commit 848be4c)

Assisted-by: Google Antigravity (Gemini 4 Neon)
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
raylitebull pushed a commit that referenced this pull request Nov 29, 2026
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 #1269

From #2102 (merge 848be4c). Adapted: the tests' CsInterface / PsInterface take this tree's lds_dwords and
early_depth fields, and geometry_export_rejected also accepts, for a split pass
with an ES phase, this tree's earlier refusal of it (kernel::translate_geometry
with the safe barrier: "split wave64 geometry: the ES phase exchanges at group
barriers"), which comes before the export is lowered. The guards themselves
as upstream.

(cherry picked from commit 848be4c)

Assisted-by: Google Antigravity (Gemini 4 Neon)
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