Skip to content

Recompiler: honor pixel shader EXP VM valid-mask bit in HLSL and DXIL - #2008

Merged
raylitebull merged 1 commit into
xcl-dev:mainfrom
Decodere:fix-1488-ps-exp-vm
Nov 25, 2026
Merged

raylitebull merged 1 commit into
xcl-dev:mainfrom
Decodere:fix-1488-ps-exp-vm

Conversation

@Decodere

Copy link
Copy Markdown
Contributor

Fixes pixel-shader EXP VM (Valid Mask) handling in both the HLSL emitter and Direct DXIL graphics lowering (XCL-BT-012).

In RDNA2 pixel shaders, lane survival (discard) is determined by the EXEC mask at the last executed ENC_EXP instruction with VM=1 (each VM=1 export overwrites the valid mask, while VM=0 exports leave it unchanged). Previously both recomp/emit.rs and dxil/lower_gfx.rs ignored VM and OR-accumulated xcl_live / live_var on DONE=1, so a later VM=0, DONE=1 export under a restored EXEC revived discarded pixels and a narrower second VM=1 export failed to kill lanes active during an earlier export.

Part of #1488

What is in it

  • crates/xcl/src/gpu/recomp/emit.rs: add Em::has_ps_vm pre-scanned in configure_round_modes for pixel shaders with any ENC_EXP carrying VM=1; in export_graphics, unify the undeclared SV_Target branch with the main pixel-survival update so VM=1 overwrites xcl_live = ({act}); and VM=0 leaves xcl_live untouched when has_ps_vm is true, while preserving the DONE=1 fallback (if ({act}) xcl_live = true;) when no VM=1 export exists.
  • crates/xcl/src/gpu/dxil/lower_gfx.rs: track ps_vm and live_vm_var alongside ps_done and live_var in GfxCtx; overwrite live_vm_var with sel(act, 1, 0) on VM=1 in export_gfx, and read live_vm_var in finish_gfx whenever ps_vm is true (falling back to live_var when only ps_done is set).
  • crates/xcl/src/gpu/recomp/tests.rs: add ps_exp_vm_hlsl_and_direct_dxil_codegen (CPU HLSL codegen/DXC compile + Direct DXIL container validation) and gpu_ps_exp_vm_controls_pixel_survival (GPU draws on both HLSL and Direct DXIL across four cases: VM=1 DONE=0 + restored EXEC + VM=0 DONE=1, narrower second VM=1 overwriting an earlier VM=1, undeclared MRT VM=1 DONE=0 + declared MRT0 VM=0 DONE=1, and the no-VM DONE=1 fallback).

Tested

  • NVIDIA GeForce RTX 4060 8 GB (driver 621.14), Intel Core i5-11400F, 32 GB RAM, Windows 11 Home 26200, Rust 1.100.0 (stable-x86_64-pc-windows-msvc), DXC 1.9.2609.5; targeted regression checks in debug, full suite and smoke runs in release.
  • Confirmed ps_exp_vm_hlsl_and_direct_dxil_codegen fails pre-fix, and gpu_ps_exp_vm_controls_pixel_survival fails independently pre-fix on both HLSL and Direct DXIL (vm1_done0_then_vm0_done1 pixel (0,0) = [0.0, 0.0, 0.0, 0.0], expected [0.0, 0.0, 1.0, 1.0]).
  • Post-fix: ps_exp_vm_hlsl_and_direct_dxil_codegen, gpu_ps_exp_vm_controls_pixel_survival (all 4 cases on both HLSL and Direct DXIL), and gpu_graphics_vs_ps_draw all pass.
  • cargo build --release --workspace + cargo test --release --workspace -- --test-threads=4 --nocapture: 997 passed, 0 failed, 45 ignored across 20 test runs.
  • SKIPPED lines (26 total):
    • 19 no wave64 (gpu::recomp::lower::tests::{a_2d_or_3d_group_agrees_with_the_hlsl_path_on_the_gpu,cross_lane_reads_agree_with_the_hlsl_path_on_the_gpu,coalesced_guarded_runs_agree_with_the_hlsl_path_on_the_gpu,the_wave64_lowering_agrees_with_the_hlsl_path_on_the_gpu}, gpu::recomp::lower_dxil::tests::{a_per_lane_2d_or_3d_group_runs_on_the_gpu,const_and_null_mask_operands_agree_with_hlsl_on_the_gpu,f16_programs_on_the_gpu (2),f32_programs_on_the_gpu (5),f64_programs_on_the_gpu,integer_programs_on_the_gpu (2)}, gpu::recomp::tests::{gpu_geometry_wave32_prefix_count_over_a_mask,gpu_wave32_program_in_wave64_hardware})
    • 3 wave32 per-lane refusals (gpu::recomp::lower_dxil::tests::{f16_programs_on_the_gpu (2),f32_programs_on_the_gpu (1)})
    • 1 shaders::tests::pso_measurement_compiles_an_exact_synthetic_record (cannot disable driver cache without Windows Developer Mode)
    • 1 heap_window_out_of_memory_falls_back_to_the_switch_form (no heap windows)
    • 2 D3D12 debug layer skips (test_title_draws_with_a_root_signature_under_the_debug_layer: no d3d12SDKLayers.dll, uploads_start_from_each_subresources_state: no D3D12 debug layer (0x887A002D))

Regression run

main:

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

this PR:

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

Not tested

  • AMD and Intel GPUs, native wave64 hardware, and D3D12 debug layer tests (d3d12SDKLayers.dll not installed on this machine).
  • Per-MRT independent color export masking beyond whole-pixel discard (not changed in this PR) and retail pixel shaders exercising multi-export VM overwrite; the smoke run above is a regression check only.

AI use

In RDNA2 pixel shaders, lane survival (discard) is controlled by the
EXEC mask at the last executed ENC_EXP instruction with VM=1 (each
VM=1 export overwrites the valid mask, while VM=0 exports do not modify
it). Both the HLSL emitter (emit.rs) and the Direct DXIL graphics
lowering (dxil/lower_gfx.rs) previously ignored VM and OR-accumulated
survival on DONE=1 instead, allowing later VM=0 DONE=1 exports under a
restored EXEC to revive discarded pixels and preventing a narrower
subsequent VM=1 export from killing lanes.

Track VM=1 exports in both backends so any pixel shader with at least
one VM=1 export overwrites xcl_live / live_vm_var with the current
active-lane mask on VM=1 (including undeclared SV_Target exports) and
leaves it untouched on VM=0, while preserving the existing DONE=1
fallback for synthetic shaders with zero VM=1 exports.

Part of xcl-dev#1488
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 dc0d25f (on its base 8c4a46a).

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::dxil::fuzz_tests: 986 passed, 0 failed, 43 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: ps_exp_vm_hlsl_and_direct_dxil_codegen, gpu_ps_exp_vm_controls_pixel_survival.
  • 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: 996 passed, 0 failed, 45 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 7994cd1 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 and const_and_null_mask_operands_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.

@nnonno91

Copy link
Copy Markdown

Tested

Independent pixel readback on AMD Radeon(TM) Graphics (32.0.21042.62) and GeForce RTX 5090 (32.0.16.1742), at exact head dc0d25fe82eb04bdb5710428d122ff1d25e5279a. Windows 11 25H2 (26200.9974), Ryzen 7 9800X3D, Rust 1.100.0 x64 MSVC, and DXC/DXIL 1.8.2502.11. Unoptimized dev/test profiles with debug info off. GPU checks used XCL_ADAPTER to select each adapter and XCL_REQUIRE_GPU=wave64 to catch a skipped draw.

  • cargo build --workspace --locked passed at the PR head.
  • cargo test --locked -p xcl --lib ps_exp_vm -- --test-threads=1 --nocapture passed on each GPU (2 passed, 0 failed, 0 ignored, 0 skipped). All four cases matched the expected 16×16 pixel grid through HLSL and Direct DXIL, for 2,048 pixel comparisons per GPU.
  • cargo test --locked -p xcl --lib gpu::recomp::tests::gpu_graphics_vs_ps_draw -- --test-threads=1 --nocapture also passed on each GPU (1 passed, 0 failed, 0 ignored, 0 skipped).
  • For a pre-fix control, I applied only the two regression tests and their helper to parent 8c4a46a3c2d50498691cbda79cbbf4fadb45fbe8. The ps_exp_vm command failed both tests as expected on each adapter (0 passed, 2 failed). To reach the second backend before the first assertion stopped the test, I swapped only the test's backend order and ran cargo test --locked -p xcl --lib gpu::recomp::tests::gpu_ps_exp_vm_controls_pixel_survival -- --exact --test-threads=1 --nocapture (0 passed, 1 failed on each adapter). In both backend orders on both GPUs, vm1_done0_then_vm0_done1 gave [0, 0, 0, 0] at pixel (0,0) where the test expects the blue clear value [0, 0, 1, 1].

Not tested

Full workspace suite, real-title smoke runs, and performance in this independent check.

AI use

OpenAI Codex (GPT-6 family, exact variant unavailable) ran and checked the tests and drafted this report.

@oni-swr

oni-swr commented Nov 25, 2026

Copy link
Copy Markdown
Contributor

AMD RDNA3 (RX 7800 XT, native wave64) test report for #2008 at head dc0d25fe merged with main 2e1c9562 (clean merge).

Tested

  • AMD Radeon RX 7800 XT 16 GB (RDNA3, native wave64, driver 32.0.31035.1003), Ryzen 7 5700X3D, 64 GB RAM, Windows 11 Pro 26200, Rust 1.100.0 MSVC, DXC 1.8.2502.11 (Windows Kits\10\bin\10.0.26100.0\x64), debug build, XCL_ADAPTER="RX 7800 XT".
  • Targeted runs (all passed, 0 failed, 0 skipped):
    • cargo test -p xcl --lib ps_exp_vm_hlsl_and_direct_dxil_codegen -- --nocapture: 1 passed, 0 failed (0.10s)
    • cargo test -p xcl --lib gpu_ps_exp_vm_controls_pixel_survival -- --nocapture: 1 passed, 0 failed (0.44s; all 4 cases on both HLSL and Direct DXIL)
    • cargo test -p xcl --lib gpu_graphics_vs_ps_draw -- --nocapture: 1 passed, 0 failed (0.23s)
  • Full workspace (cargo build --workspace && cargo test --workspace --no-fail-fast -- --test-threads=4 --nocapture): 1002 passed, 1 failed, 45 ignored across 20 test binaries.
    • The 1 failure is gpu::dxil::fuzz_tests::fuzz_validate_and_gpu_1 (seed 722: res[30] = 0x1, CPU 0x7fffffff). Verified directly on origin/main 2e1c9562 on the same RX 7800 XT: it fails identically there (pre-existing on main, unrelated to this PR).
    • SKIPPED lines (7): the 6 intentional #1426 per-lane refusals in gpu::recomp::lower_dxil::tests (V_MUL_F16, V_PK_MUL_F16, V_CVT_F16_F32, wave32 and wave64) plus heap_window_out_of_memory_falls_back_to_the_switch_form: no heap windows. Zero no wave64 skips — all native wave64 GPU tests ran and passed.

Not tested

  • Release build, scripts/smoke.ps1 title run, or other AMD generations.

AI use

  • T3 Code (Antigravity), Gemini 4 Neon: checked out the PR in a temporary worktree, ran the targeted and workspace tests on @oni-swr's machine, and wrote this report.

@raylitebull
raylitebull merged commit d63071a into xcl-dev:main Nov 25, 2026
2 checks passed
@JJAutoCompare

Copy link
Copy Markdown

Tested

Intel Arc A770 verification on the clean PR head dc0d25fe82eb04bdb5710428d122ff1d25e5279a. Intel driver 32.0.101.9175, AMD Ryzen 7 3800X, Windows 11 Enterprise Evaluation 25H2 build 26200.9974 x64, Rust/Cargo 1.100.0 (x86_64-pc-windows-msvc), debug test profile. Both runs loaded DXC and DXIL 1.9.2609.5.

$env:CARGO_TARGET_DIR = 'L:/XclTooling/pr2008-dc0d25fe/target'
$env:TEMP = 'L:/XclTooling/pr2008-dc0d25fe/temp'
$env:TMP = $env:TEMP
$env:CARGO_BUILD_JOBS = '2'
$env:CARGO_INCREMENTAL = '0'
$env:XCL_ADAPTER = 'A770'
$env:XCL_DXC_DIR = "$env:LOCALAPPDATA/XclTooling/dxc-1.9.2609/bin/x64"
cargo test --locked -p xcl --lib --no-run
cargo test --locked -p xcl --lib gpu::recomp::tests::ps_exp_vm_hlsl_and_direct_dxil_codegen -- --exact --nocapture --test-threads=1
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
    cargo test --locked -p xcl --lib gpu::recomp::tests::gpu_ps_exp_vm_controls_pixel_survival -- --exact --nocapture --test-threads=1
}
  • Precompile succeeded outside the GPU lock. The CPU test passed in 0.12 s, covering HLSL compilation and Direct DXIL validation.
  • The Arc A770 draw test passed in 4.01 s with the lock held. All four cases matched the expected 16×16 output in both backends, for 2,048 pixel comparisons.
  • Total across the two focused runs was 2 passed, 0 failed, 0 ignored. Explicit SKIPPED results were 0.

Not tested

Full workspace suite, release build, pre-fix control, merge commit, retail-title smoke tests, and other adapters.

AI use

Codex (gpt-6.2-sol) ran the tests, verified the outputs, 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.

6 participants