Skip to content

Direct DXIL: unused raw loads and f16 conversions are dropped - #2212

Open
tibzejoker wants to merge 1 commit into
xcl-dev:mainfrom
tibzejoker:dxil-dead-calls
Open

tibzejoker wants to merge 1 commit into
xcl-dev:mainfrom
tibzejoker:dxil-dead-calls

Conversation

@tibzejoker

Copy link
Copy Markdown

Module::optimize kept unused dx.op.rawBufferLoad and dx.op.legacyF16ToF32 calls: neither is in the list of calls dead-code removal may take. A raw load sets RawAndStructuredBuffers while the module is built, so when every raw load of a program is unused the first one stays and the flags still match the code. Part of #1269 (claimed here).

On 573 sampled programs (xcl shaders shaders.rpf --direct --sample 600 --seed 3 --max-bytes 40000 --validate, XCL_HEAP_WINDOWS=1), all validator-clean before and after:

main 568e7db this PR
direct DXIL 42 189 920 B 41 558 656 B (−1.5 %)
instructions (dxc -dumpbin) 5 704 098 5 660 172 (−0.8 %)

A small gain: about 21 000 unused raw loads and 3 100 unused f16 conversions in that sample.

What is in it

  • crates/xcl/src/gpu/dxil/module/opt.rs: removable takes dx.op.rawBufferLoad.* and dx.op.legacyF16ToF32; after liveness, one raw load is kept when none is live. Test unused_raw_loads_and_f16_conversions_go_but_one_raw_load_stays (fails without the change).

Tested

  • NVIDIA GeForce RTX 4090 (driver 621.01), Windows 11 Pro 26200, rustc 1.100.0, release build for the smoke runs and the sweep.
  • cargo test --workspace -- --test-threads=4 (through scripts/test.ps1): 1155 passed, 0 failed, 46 ignored.
  • SKIPPED GPU tests on this adapter (32-lane waves only, 24 lines): 7 no wave64, 13 wave64 variants of the instruction tests, 1 no heap windows, 3 per-lane f16 refusals (V_CVT_F16_F32, V_PK_MUL_F16, V_MUL_F16).
  • The sweep above with --validate: 573 / 573 translated, 0 validator errors, before and after.

Regression run

main:

xcl-smoke v1
commit: 568e7db7729c8fa6c8f0f4b32d798faaf11462bb
gpu: NVIDIA GeForce RTX 4090
title: 82c27de1
seconds: 60
exit: 0x0
frames shown: 1488 (PresentX 1488)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16522 MB

This PR:

xcl-smoke v1
commit: b09f06d50b793bb538dbddf883b3c736853a867e
gpu: NVIDIA GeForce RTX 4090
title: 82c27de1
seconds: 60
exit: 0x0
frames shown: 1631 (PresentX 1631)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 16065 MB

Not tested

AI use

  • Claude Code (Claude Opus 5.5): found the unused calls by attributing DXIL instructions to console opcodes, wrote the change and the test, ran the suite, the sweep and the smoke pair on this machine.

🤖 Generated with Claude Code

Module::optimize kept unused dx.op.rawBufferLoad and dx.op.legacyF16ToF32
calls: neither is in the list of calls dead-code removal may take. A raw
load sets the RawAndStructuredBuffers flag while the module is built, so
when every raw load is unused the first one stays and the flags still
match the code.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@DarkPanda69

Copy link
Copy Markdown

AMD with native wave64 (listed as untested), plus an RTX 3060, paired against main with the direct translator on for the whole GPU suite, since this changes the direct backend's output for every program.

Head b09f06d applied on main 568e7db, debug, Windows 11 Pro 26200, XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- gpu:: --test-threads=4, on main and on this PR for each card:

main this PR
RX 9070 XT (RDNA4, 32.0.32029.2010, native wave64) 583 passed, 3 failed, 22 ignored, 6 SKIPPED 584 passed, 3 failed, 22 ignored, 6 SKIPPED
RTX 3060 (32.0.16.1088, wave32, split wave64) 585 passed, 1 failed, 22 ignored, 23 SKIPPED 586 passed, 1 failed, 22 ignored, 23 SKIPPED

Per-test comparison: on both cards the only difference is the new unused_raw_loads_and_f16_conversions_go_but_one_raw_load_stays (ok). No existing test changes result or skip state. The failures are the same on main: gpu_image_get_resinfo_1d_array on both cards (the direct-path bug #2046 fixes) and, on the RX 9070 XT only, the fuzz seeds 722 and 1599 tracked in #2115.

Not tested: a title with XCL_DIRECT_DXIL=1, driver compile time.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine and wrote this report.

@tibzejoker

Copy link
Copy Markdown
Author

@DarkPanda69 Thanks for running it on RDNA4 and the 3060 with XCL_DIRECT_DXIL=1. That covers the AMD and native wave64 side I listed as untested.

@raylitebull

Copy link
Copy Markdown
Member

Diff review on b09f06d (crates/xcl/src/gpu/dxil/module/opt.rs) looks clean, CI passed, and both NVIDIA (RTX 4090 / RTX 3060) and AMD (RX 9070 XT) runs passed.

b09f06d now conflicts in opt.rs after #2194 (simplify_cfg) landed on main — please rebase onto main so we can get CI green and merge.

@bielfreedom

Copy link
Copy Markdown

AMD Windows driver timing for #2212: on the RX 9070 XT the DXIL shrinks by 1.9 %, but AMD's CreateComputePipelineState time doesn't move (−0.4 %, within noise). The AMD compiler seems to drop these unused loads itself, so the gain here is in DXIL size and translation, not driver time.

Setup

  • GPU: RX 9070 XT 16 GB (RDNA4, native wave64), AMD driver 32.0.32029.2010.
  • CPU and memory: Ryzen 7 7700 (16 threads), 32 GB RAM, Windows 11, release.
  • Builds:
    • base 568e7db;
    • this PR at b09f06d.
  • Both builds carry a local patch that logs per-program DXIL size, record hash (fnv64) and per-CreateComputePipelineState time.

Method

Results (means of 2 rounds; all 104 builds succeeded, 0 refused)

base #2212 change
direct DXIL, total 8,598,156 B 8,438,560 B −1.86 %
programs changed 19 of 26
driver, sum (r1 / r2) 268.0 / 267.8 s 266.5 / 267.2 s −0.4 %
driver run, process peak private 4.45–4.60 GB 4.52–4.55 GB same
  • Every program's driver time is within ±3 % of base, apart from sub-100 ms ones.
  • The largest cut is 84eee477d68b6fdf: 1,025,520 → 1,003,012 B (−2.2 %), driver 52.7 → 52.6 s.
  • ActivateRays (95cc13288a27a96e, plain here): 3,916,120 → 3,912,160 B. It still reached 24 GB after 153 s and was killed (base: 153 s).

Tests on this card (XCL_REQUIRE_GPU=1, XCL_ADAPTER=9070)

  • unused_raw_loads_and_f16_conversions_go_but_one_raw_load_stays: passed.

Read / inference

  • No regression on AMD, and smaller modules, but no driver compile-time gain on this vendor.

Not tested

  • GPU suite with XCL_DIRECT_DXIL=1.
  • XCL_HEAP_WINDOWS=1.
  • A title run.
  • RDNA2 and RDNA3.

AI use: Claude Code (Claude Opus 5.5) ran the measurements and the test and drafted this. The account owner is away; counts and timings only, no game data.

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.

4 participants