Skip to content

Direct DXIL: size a compute program's LDS block from its LDS_SIZE - #2158

Open
grahamster2 wants to merge 2 commits into
xcl-dev:mainfrom
grahamster2:lds-size-direct-dxil
Open

grahamster2 wants to merge 2 commits into
xcl-dev:mainfrom
grahamster2:lds-size-direct-dxil

Conversation

@grahamster2

Copy link
Copy Markdown
Collaborator

Stacked on #2146; only the last commit (55d06c1) belongs here, please review that one.

The direct DXIL backend (XCL_DIRECT_DXIL) declares its xcl_lds with 8192 words for every program, as the HLSL kernel did before #2146. This sizes it by the same rule: a compute program's COMPUTE_PGM_RSRC2.LDS_SIZE plus the same reserved top words, rounded up to a power of two. The exchange words, XCL_WT and the address mask in lds_index move to the new block's top. LDS_SIZE 0 and the other stages keep 8192 words.

Part of #675.

What is in it

  • Lw::lds_words, set in setup_storage from the entry's lds_bytes (gpu/dxil/lanes.rs, kernel.rs, lower.rs), and used by the mask in lds_index (lower_mem.rs).
  • gpu_compute_lds_ring_in_a_block_of_the_programs_size also runs the direct translation. It covers the kernels direct_or runs (wave32, and wave64 in the split form) and checks that @xcl_lds has the HLSL block's size. With the old 8192-word block, the test fails.
  • bench_compute_lds_block (ignored, next to bench_split_wave64): the 32 KB block against the LDS_SIZE block, in a loop with an LDS store and load and an exchange per iteration.

Tested

  • RTX 3080 10 GB (driver 610.88), Ryzen 5 7600X, Windows 11 Pro 26200, rustc 1.94.0.
  • cargo test --workspace -- --test-threads=4 at 55d06c1: 1156 passed, 0 failed, 47 ignored. The SKIPPED tests are the same as in Recompiler: size a compute program's LDS block from its LDS_SIZE #2146 (no wave64).
  • XCL_DIRECT_DXIL=1 cargo test -p xcl --lib -- --test-threads=4: 1099 passed, 1 failed, 27 ignored. The failure, gpu_image_get_resinfo_1d_array, also fails with XCL_DIRECT_DXIL=1 at 52577f9, so it is not from this change.
  • bench_compute_lds_block, 2^18 threads x 8192 iterations, 64-thread groups, 32 KB block -> LDS_SIZE block:
backend wave32 wave64, split form
HLSL (#2146) 7.8 -> 3.5 ms 39.4 -> 12.4 ms
direct DXIL (this PR) 10.3 -> 2.3 ms 16.5 -> 5.5 ms

256-thread groups: 1.0x to 1.27x.

Regression run
Both runs with XCL_DIRECT_DXIL=1 (the path this changes).

main (cbc296a):

xcl-smoke v1
commit: cbc296ab65a2661a61e3e2da109134bcd5319f60
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1576 (PresentX 1577)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15317 MB

this PR (55d06c1):

xcl-smoke v1
commit: 55d06c1e02831b09a931d383b7f6ea4bb6793b9e
gpu: NVIDIA GeForce RTX 3080
title: 5d6132ca
seconds: 60
exit: 0x0
frames shown: 1623 (PresentX 1623)
presents per 2 s (last 3): 60 60 60
device removals: 0
crashes: 0
peak commit: 15370 MB

Not tested

  • AMD (native wave64).
  • Each backend picks its own exchange slot size: HLSL from what it emits, direct DXIL from a scan of the program. A program with a ds_bpermute, a coherent s_load or a two-word reduction tail can get a different slot size, and then a different block in the two backends. Each layout still fits its own block, and the test covers the one-word slot.
  • Out-of-range LDS addresses wrap within the smaller block, as in Recompiler: size a compute program's LDS block from its LDS_SIZE #2146.

AI use

  • Claude Code with Claude Opus 5.5: the code, the tests and this description. A separate Claude Sonnet review of the diff led to gating the direct half of the test to the kernels direct_or runs, and to matching @xcl_lds exactly.

Every translated program that touches LDS declared `groupshared uint
xcl_lds[8192]`, the D3D12 limit of 32 KB, whatever the console program
allocated. COMPUTE_PGM_RSRC2.LDS_SIZE (bits 15..23, 512-byte units) is in
the FSSM descriptor already: the HLSL block of a compute program is now the
next power of two that holds it and the runtime words kept at the top (the
split-wave64 exchange, the safe barrier's words, the 2-D thread hand-out),
with accesses masked by `XCL_LDS_MASK`. LDS_SIZE 0 and the other stages
keep 32 KB.

32 KB per group lets an NVIDIA Ampere SM hold 3 groups, 6 warps of a
64-thread group, so the split form's meets have nothing to hide behind.
On an RTX 3080, a loop with an LDS store and load and one exchange per
iteration (2^18 threads x 8192 iterations, 64-thread groups) takes
41.9 ms in the split form with the 32 KB block and 14.0 ms with a 1K-word
one; native wave32 10.0 -> 4.2 ms. The retail title's 84 LDS-using split
programs allocate 512 B to 16.9 KB (34 of them 512 B).

Assisted-by: Claude Code (Claude Opus 5.5)
The direct DXIL backend (XCL_DIRECT_DXIL) declared its `xcl_lds` with
8192 words for every program, as the HLSL kernel did. It now sizes it by
the same rule: a compute program's COMPUTE_PGM_RSRC2.LDS_SIZE plus the
same reserved top words, rounded up to a power of two (the exchange slot
size each backend picks can still differ for a program), with the exchange,
`XCL_WT` and the address mask moved to that block's top. LDS_SIZE 0 and
the other stages keep 8192 words.

The LDS ring GPU test runs the direct translation too (the kernels
`direct_or` runs), and checks that its block has the HLSL block's size. `bench_compute_lds_block` (ignored,
next to `bench_split_wave64`) times a loop with an LDS store and load and
an exchange per iteration with both blocks. RTX 3080, 2^18 threads x 8192
iterations, 64-thread groups, 32 KB block -> LDS_SIZE block:
  HLSL:   wave32 7.8 -> 3.5 ms, split wave64 39.4 -> 12.4 ms
  direct: wave32 10.3 -> 2.3 ms, split wave64 16.5 -> 5.5 ms

Assisted-by: Claude Code (Claude Opus 5.5)
@JJAutoCompare

Copy link
Copy Markdown

Tested

PR #2158, stacked on #2146, was open at 55d06c1e02831b09a931d383b7f6ea4bb6793b9e before and after testing. The assigned checkout was clean and detached at that SHA. The initial GitHub API response and final public PR page agreed with the live Git pull ref. The PR describes same-head RTX 3080 coverage. The discussion contained no equivalent Arc A770 coverage.

STOR-WINLAB ran Windows 11 Enterprise Evaluation 26200.9974 on a Ryzen 7 3800X with an Intel Arc A770, driver 32.0.101.9175. Rust and Cargo were 1.100.0 on x86_64-pc-windows-msvc (rustc 0ef1bc386). Both runs loaded DXC and DXIL 1.9.2609.5 from %LOCALAPPDATA%/XclTooling/dxc-1.9.2609/bin/x64.

Cargo used the unoptimized test profile with CARGO_BUILD_JOBS=2, CARGO_INCREMENTAL=0, CARGO_PROFILE_DEV_DEBUG=0, CARGO_PROFILE_TEST_DEBUG=0 and the exclusive target L:/XclTooling/pr1947-1831ec4-t3-97236edf/target. TEMP and TMP both used L:/XclTooling/pr2158/temp. The build finished outside the Arc mutex in 59.47 s. The invocation used -NoProfile -ExecutionPolicy RemoteSigned for that PowerShell process.

cargo test --locked -p xcl --lib -j 2 --no-run --message-format=json
$fixtureExe = 'L:/XclTooling/pr1947-1831ec4-t3-97236edf/target/debug/build/xcl/97fdf2b9ff8e1482/out/xcl-97fdf2b9ff8e1482.exe'
$env:XCL_ADAPTER = 'A770'
$env:XCL_DXC_DIR = Join-Path $env:LOCALAPPDATA 'XclTooling/dxc-1.9.2609/bin/x64'
& 'L:/XclTooling/Invoke-ArcTest.ps1' -Test {
    $env:XCL_DIRECT_DXIL = '1'
    & $fixtureExe --exact gpu::recomp::tests::gpu_compute_lds_ring_in_a_block_of_the_programs_size --nocapture --test-threads=1
    $env:XCL_DIRECT_DXIL = '0'
    & $fixtureExe --exact gpu::recomp::tests::gpu_compute_lds_ring_in_a_block_of_the_programs_size --nocapture --test-threads=1
}
XCL_DIRECT_DXIL Passed Failed Ignored Skipped Filtered out Fixture time Exit
1 1 0 0 0 1126 1.60 s 0
0 1 0 0 0 1126 1.01 s 0

The fixture explicitly compiles HLSL through DXC and translates direct DXIL under both environment settings. The two invocations therefore repeat the same assertions. The existing STOR-WINLAB A770 capability log records a D3D12 wave-lane range of 8 to 32, so the fixture exercised wave32 and split wave64 for 64×1×1, 256×1×1 and 8×8×1 thread groups. For each of the six configurations, the fixture checked the direct DXIL @xcl_lds declaration against the HLSL block size and compared each backend’s per-thread ring and first-lane exchange result to the expected integer arithmetic. This exercises the fixture’s one-word exchange slot.

The executable SHA-256 was 896E8C588C18A5363FF54AD4B25C76842C9B260409AA28D89C9772E0825B74D9 before waiting for the Arc mutex, after acquiring it and after both runs. The Arc mutex and target were released after testing.

Combined: 2 passed, 0 failed, 0 ignored, 0 skipped.

Not tested

Native wave64, other adapters, other exchange layouts, negative cases, runtime backend selection, broader test suites, benchmarks, retail titles and smoke/regression runs.

AI use

T3 Code / Codex (gpt-6.2-sol) ran the checked-in fixture, verified its assertion coverage and prepared this report.

@DavidM1911

Copy link
Copy Markdown
Contributor

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

Thanks!

@DarkPanda69

Copy link
Copy Markdown

Tested: gpu_compute_lds_ring_in_a_block_of_the_programs_size passes on AMD with native 64-lane waves (the case the PR lists as untested), and on an RTX 3060.

Head 55d06c1 applied on main 568e7db, debug, cargo test -p xcl --lib -- gpu:: --test-threads=4 with XCL_ADAPTER set to each card. The HLSL half (#2146) passed the same way on this card earlier.
Not tested: occupancy or speed on AMD (correctness only), a title.
AI use: Claude Code (Claude Opus 5.5) ran the tests on this machine 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.

4 participants