Skip to content

DXC: keep LINK_GATE open on OOM and forward opt/extra args to IDxcLinker::Link - #2585

Open
Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-dxc-linked-oom-and-opt-args
Open

Decodere wants to merge 1 commit into
xcl-dev:mainfrom
Decodere:fix-dxc-linked-oom-and-opt-args

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

Part of #174
Part of #1566
Part of #1269
Part of #1833

What is in it

Fixes two linked-compilation bugs in crates/xcl/src/gpu/recomp/dxc.rs introduced alongside accessor-library linking (#174; touches only compile_here, LinkGate helpers, compile_linked, and accessor_library_tests):

  • Keep LINK_GATE open and avoid monolithic fallback on transient E_OUTOFMEMORY: Previously, compile_here treated every compile_linked error as a permanent toolchain failure — closing LINK_GATE for the entire process and immediately falling back to the heavier monolithic compile_whole path even on transient E_OUTOFMEMORY (0x8007000E). Added is_oom_error (case-insensitive check for 0x8007000e / e_outofmemory) and compile_linked_or_fallback(gate, linked, whole): transient OOM propagates Err(e) directly without closing gate or invoking whole (preserving non-"dxc: " prefixes so compile_cached_in_observed never negatively caches OOM), while deterministic non-OOM failures still close LINK_GATE once and fall back to compile_whole.
  • Forward optimization tier & caller extra arguments to IDxcLinker::Link and guard CreateBlob length: Previously, compile_linked always passed None to IDxcLinker::Link, discarding the shader's auto-selected optimization tier (-O1 above 1 MiB, -O0 -opt-disable debug-nops above UNOPTIMISED_ABOVE) and caller extra flags (such as -Gis) at link time, and truncated dxil.len() as u32 in CreateBlob. Added link_opt_args(src_len, extra) (using the HLSL program.len() captured before library compilation, suppressed when extra already passes -O* / -Od), guarded CreateBlob with u32::try_from(dxil.len()), and passed the wide-string argument slice to IDxcLinker::Link.
  • Tests (gpu::recomp::dxc::accessor_library_tests):
    • compile_linked_or_fallback_keeps_gate_open_on_oom (pure CPU, 0 skips): verifies 0x8007000E / E_OUTOFMEMORY keep LinkGate open and skip whole, while deterministic failures close LinkGate and fall back to whole.
    • link_opt_args_selects_tier_and_preserves_extra (pure CPU, 0 skips): verifies <= 1 MiB, > 1 MiB, > UNOPTIMISED_ABOVE, explicit -O2/-Od suppression, and -Gis preservation.
    • compile_linked_forwards_opt_and_extra_args_to_dxc_linker (live DXC, skips only if dxc::location().is_err()): compiles, validates, and disassembles linked compute shaders on DXC with [], ["-O1"], ["-O0", "-opt-disable", "debug-nops"], ["-Gis"], and a > 1 MiB program.

Tested

  • Observed pre-fix behavior on origin/main (08db8020d323bf478964fcc586152cce54959cfc): compile_here unconditionally closed LINK_GATE and ran compile_whole on E_OUTOFMEMORY, and compile_linked passed None to IDxcLinker::Link.
  • Verified real local DXC 1.9.2609.5 IDxcLinker::Link accepts [], ["-O1"], ["-O0", "-opt-disable", "debug-nops"], and ["-Gis"] with valid DXIL output and expected IR differences (-O0 preserves fadd fast float/mul i32 with 0 dx.op.nop, -Gis preserves strict fadd float without fast).
  • Post-fix targeted release tests on NVIDIA GeForce RTX 4060 (0 compiler warnings in dxc.rs):
    • cargo test --release -p xcl --lib gpu::recomp::dxc:: -- --test-threads=1 --nocapture: 23 passed; 0 failed; 0 ignored (0 skipped).
    • cargo test --release -p xcl --lib gpu::recomp::link_tests:: -- --test-threads=1 --nocapture: 2 passed; 0 failed; 1 ignored (bench_memory_window_accessors), 0 skipped.
  • Post-fix targeted release tests on WARP (XCL_ADAPTER=warp, XCL_WARP=1):
    • cargo test --release -p xcl --lib gpu::recomp::dxc:: -- --test-threads=1 --nocapture: 23 passed; 0 failed; 0 ignored (0 skipped).
    • cargo test --release -p xcl --lib gpu::recomp::link_tests:: -- --test-threads=1 --nocapture: 2 passed; 0 failed; 1 ignored (linked_programs_keep_their_declarations 0 skips; gpu_linked_memory_accessors cleanly reported SKIPPED: no wave64).
  • Full release workspace (cargo test --release --workspace --no-fail-fast -- --test-threads=4 --nocapture):
    • 37 test binaries: 1432 passed; 0 failed; 47 ignored.
    • 29 pre-existing runtime SKIPPED messages (21 no wave64 on wave32-only RTX 4060, 3 per-lane form: refused, 3 no D3D12 debug layer / no d3d12SDKLayers.dll, 1 cannot disable the driver cache, 1 no heap windows).

Regression run

Before (origin/main 08db8020d323bf478964fcc586152cce54959cfc):

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

After (fix-dxc-linked-oom-and-opt-args 2066b32e5d12dd9da29bf66ee4921407723ca54e):

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

Both 60 s runs reach steady 60 presents per 2 s (60 61 60 vs 60 60 60) with 0 device removals, 0 crashes, 1570 vs 1440 frames shown (109.0%), and 14011 MB vs 14013 MB peak commit.

Not tested

  • Real OS-level E_OUTOFMEMORY injection inside IDxcLinker::Link or a > 4 GiB DXIL library blob (OOM gate preservation is covered directly by compile_linked_or_fallback_keeps_gate_open_on_oom).
  • D3D12 debug-layer tests (d3d12SDKLayers.dll is not installed on this machine) and native wave64 GPU tests (RTX 4060 is wave32-only).

AI use

Written and verified with Google Antigravity (Gemini 4 Neon). All code changes, live DXC 1.9 IDxcLinker::Link argument checks, targeted RTX 4060 and WARP test runs, the full release workspace suite, and both paired 60 s GPU smoke runs were executed and checked locally.

…ker::Link

Fix two linked-compilation bugs in dxc.rs introduced alongside accessor-library
linking (xcl-dev#174):

1. Keep LINK_GATE open and propagate transient E_OUTOFMEMORY errors directly
   from compile_linked_or_fallback instead of permanently disabling linked
   compilation and falling back to the heavier monolithic compile_whole path
   under memory pressure (preserving non-"dxc: " error prefixes so transient
   OOM is never negatively cached). Deterministic non-OOM failures still close
   LINK_GATE once and fall back to compile_whole.
2. Forward the shader's auto-selected optimization tier (-O1 above 1 MiB,
   -O0 -opt-disable debug-nops above UNOPTIMISED_ABOVE, suppressed when extra
   already specifies -O*/-Od) and caller extra arguments (e.g. -Gis) to
   IDxcLinker::Link via link_opt_args(program_src_len, extra) instead of
   passing None, and guard CreateBlob length with u32::try_from.

Add unit tests in dxc::accessor_library_tests covering OOM gate retention,
link_opt_args tier boundaries, and live DXC IDxcLinker::Link argument
forwarding.

Part of xcl-dev#174
Part of xcl-dev#1566
Part of xcl-dev#1269
Part of xcl-dev#1833

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

futurepro62 commented Nov 26, 2026 •

Copy link
Copy Markdown

Full-suite run, since this PR has no test report yet. Tested exact head 2066b32e (on its base 08db802).

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: 1420 passed, 0 failed, 45 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, dispatch_chain_native_wave64_builds_whole, 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: compile_linked_or_fallback_keeps_gate_open_on_oom, link_opt_args_selects_tier_and_preserves_extra, compile_linked_forwards_opt_and_extra_args_to_dxc_linker.
  • 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: 1431 passed, 0 failed, 47 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 08db8020 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:

  • cargo test -p xcl --lib: all passed, 0 failed, 26 ignored.

Thanks!

— Devin

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