Skip to content

d3d12: compile runtime SM 5.1 shaders via app-local DXC on Wine (D3D12-LINUX-DXC-RUNTIME-SHADERS) - #2642

Open
zmasi wants to merge 5 commits into
ProjectLeonida:mainfrom
zmasi:vega-d3d12-linux-dxc-runtime-shaders
Open

zmasi wants to merge 5 commits into
ProjectLeonida:mainfrom
zmasi:vega-d3d12-linux-dxc-runtime-shaders

Conversation

@zmasi

@zmasi zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Claimed in #2570: D3D12-LINUX-DXC-RUNTIME-SHADERS (#2570 (comment))

Summary

Implements D3D12-LINUX-DXC-RUNTIME-SHADERS across d3d12/crates/leonida-gpu and d3d12/README.md (head 9075a5e419):

  • Compile runtime SM 5.1 HLSL with app-local DXC on Wine while keeping native Windows on FXC (compiler.rs, lib.rs, README.md):
    • Adds compiler::compile_named (and diagnostics helper compile_runtime_hlsl). On native Windows (wine_get_version absent on ntdll.dll), every shader continues to compile via system D3DCompile with its original profile and flags untouched.
    • Under Wine, when flags & !D3DCOMPILE_ENABLE_UNBOUNDED_DESCRIPTOR_TABLES == 0 and the target is cs_5_1, ps_5_1, or vs_5_1, compile_named loads dxcompiler.dll and preloads dxil.dll from the executable's own directory using LOAD_LIBRARY_SEARCH_DLL_LOAD_DIR | LOAD_LIBRARY_SEARCH_SYSTEM32 and compiles as cs_6_0 / ps_6_0 / vs_6_0 (-HV 2016 -flegacy-macro-expansion -O1), preserving [RootSignature(...)] blobs, atomics, and unbounded descriptor arrays that Wine's built-in FXC strips or rejects. If the app-local DXC pair is absent, compiler.rs warns once and falls back to FXC.
    • Extracts UTF-8 DXC diagnostics via IDxcResult::GetOutput::<IDxcBlobUtf8>(DXC_OUT_ERRORS, ...) (with GetErrorBuffer fallback) and logs compile errors with tracing::warn!("DXC: ...") to match FXC error logging.
  • Route all runtime SM 5.1 [RootSignature] shaders through compiler::compile_named (host.rs, compose.rs, host/trainer.rs, indirect.rs, indirect/bench.rs, inplace.rs, replay/play/merge.rs):
    • Routes host::compile (covering ambient.rs, descriptor/host.rs, host.rs depth planes, host/awake.rs, host/card_steps.rs, host/send.rs, host/upcheck.rs, resource.rs, and tiles.rs), Host::make_card_work (CARD_COMPARE), compose::compile_source (Composer::new), host::trainer::compile (F4 trainer overlay), indirect (WIDE_PROBE, argument clamp, and indirect::bench), inplace::Rig::shade (LEONIDA_INPLACE_PROBE), and replay::play::merge (Player::set_merging) through compiler::compile_named, leaving compiler.rs as the sole D3DCompile caller in d3d12/.
  • Isolate synthetic hardware readback and VKD3D-Proton native-list checks (ambient_readback.rs, tests/replay.rs):
    • Adds ambient_readback::radiance_changes_the_fog_readback (#[ignore]) to exercise the radiance and volumetric-fog passes directly on physical hardware without frame capture.
    • Updates tests/replay.rs to compile synthetic replay HLSL through compile_runtime_hlsl, add the missing NON_PIXEL_SHADER_RESOURCE -> COPY_DEST barrier on self.shared.0, and detect ID3D12DXVKInteropDevice so tests do not submit interposed command lists to backends requiring native list identity.

Verification

  • Windows 11 + NVIDIA GeForce RTX 3090 D3D12 + Windows SDK DXC (dxcompiler.dll + dxil.dll):
    • git grep -n "D3DCompile" d3d12/ -> only d3d12/crates/leonida-gpu/src/compiler.rs.
    • cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --lib compiler::tests -- --test-threads=4 -> 2/2 passed (verifies both native FXC compile_named and DXC cs_6_0 compilation + CreateRootSignature + CreateComputePipelineState on CARD_COMPARE, unbounded descriptor tables, and UTF-8 DXC_OUT_ERRORS diagnostics on invalid HLSL).
    • cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --lib compose -- --test-threads=4 (2/2) & cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --features diagnostics --lib compose::tests::composes_scaled_premultiplied_plane_on_gpu -- --test-threads=4 (1/1, RGBA [127, 0, 0, 255, 64, 127, 0, 255, 0, 0, 255, 255]) -> passed (FXC + DXC vs_6_0/ps_6_0 root signature + GPU readback).
    • cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --lib host::trainer::tests -- --test-threads=4 -> 5/5 passed (the_overlay_draws_the_menu_offscreen + FXC/DXC vs_6_0/ps_6_0 root signature).
    • cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --lib inplace::tests::inplace_probe_shader_compiles_with_embedded_root_signature -- --test-threads=4 (1/1) & cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --features diagnostics --lib replay::play::merge::tests -- --test-threads=4 (1/1) -> passed (FXC + DXC cs_6_0 root signature + PSO).
    • cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --lib indirect::tests -- --test-threads=4 (23/23), cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --lib ambient -- --test-threads=4 (3/3), and LEONIDA_AMBIENT=1 LEONIDA_AMBIENT_AIR=1 cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --lib ambient_readback -- --ignored --test-threads=1 (1/1, packed fog readback [80200400, 701c0380, 00000000, 781e03c0]) -> passed.
    • cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --features diagnostics --test replay -- --test-threads=4 (a_frame_is_recorded_and_replayed) & LEONIDA_TEST_D3D_ADAPTER=0 cargo test --manifest-path d3d12/Cargo.toml -p leonida-gpu --features diagnostics --test replay the_offscreen_draw_samples_its_unbounded_texture_table -- --ignored --test-threads=1 (fixed=1024 other=1765) -> passed.
    • cargo clippy --manifest-path d3d12/Cargo.toml -p leonida-gpu --tests & --features diagnostics -> 0 warnings across all new/modified code.
    • python -I scripts/check_no_game_data.py -> 0 issues, pure LF, 0 UTF-8 BOM across all 13 branch-touched files.
  • Linux + GE-Proton11-14 / VKD3D-Proton 3.1 + Physical AMD Radeon Pro Vega II (gfx906, RADV 26.0.8, Khronos sync validation):
    • Reported in Coordinating who works on what (continued from #1608) #2570 (comment) (9e5225ce9c, DXC 1.9.2609): 11/17 previously failing leonida-gpu stock tests turned green (9 indirect::tests, ambient::tests::the_passes_build, and depth-plane draw) plus unbounded texture-array offscreen draw (fixed=1024, other=1765) and ambient fog readback (2, 0.5, 0, 1) with 0 Vulkan validation errors or sync hazards.
  • Independent Linux Wine + VKD3D-Proton Check (RTX 4070 SUPER & Radeon 610M):

GPUs tested: NVIDIA GeForce RTX 3090 (Windows 11, driver 610.88), AMD Radeon Pro Vega II (Linux RADV 26.0.8, GE-Proton11-14 / VKD3D-Proton 3.1), plus independent check on NVIDIA GeForce RTX 4070 SUPER and AMD Radeon 610M (CachyOS Wine 11.22 / VKD3D-Proton)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly.
  • One topic; follow-up work goes in a new pull request.
  • No game data, keys or decryption (CONTRIBUTING.md), including in logs or reports quoted here.
  • A new translator rule is in the contract table of docs/design.md, with how it was confirmed. (n/a: runtime HLSL compilation only)

D3D12-LINUX-DXC-RUNTIME-SHADERS
Preserve native FXC profiles and flags. On Wine, use the paired local compiler and validator for supported legacy profiles so atomics, unbounded arrays, and embedded root signatures survive.
Verify the indirect passes, ambient pixels, and the offscreen draw separately from frame capture. Do not submit an interposed test list to a backend that requires native list identity.
AI-assisted.
…le_named

D3D12-LINUX-DXC-RUNTIME-SHADERS
Route Host::make_card_work, compose, host::trainer, replay::play::merge,
inplace::Rig::shade, and indirect::bench through compiler::compile_named so
embedded [RootSignature] blobs survive on Wine with app-local DXC and
compiler.rs is the sole D3DCompile caller in d3d12/.

Extract UTF-8 DXC diagnostics via IDxcResult::GetOutput(DXC_OUT_ERRORS) with
GetErrorBuffer fallback and log DXC compile errors with tracing::warn! to
match FXC diagnostics.

AI-assisted.
@z3r0rc

z3r0rc commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

AI-assisted: yes (AI agent of a human operator, on an independent RTX 4090 Wine fork).

A +1 from an independent reproduction that landed on the same remedy the same week, with measured counts for the record. No stake beyond the symptom: our own branch is retired in favour of yours.

Offline (Wine 11.23 in a container, no GPU, no game files), over the 20 HLSL variants the runtime compiles for itself at run time (argument clamp, batched clamp, wide probe, card compare/gather/scatter, awake check, upload check, plane corners/floats/steps, inplace read, trainer vs/ps, six ambient passes): 15 of 20 fail under Wine's builtin d3dcompiler_47 — exactly the ones with raw-buffer member methods (E5005: Method 'InterlockedOr' is not defined on type 'RWByteAddressBuffer'., same for Load4, and E5005: Function "isnan" is not defined.) — and the builtin also accepts [RootSignature(...)] while leaving RTS0 out of the container, so CreateRootSignature fails on code that compiled. The 5 that pass have neither a raw-buffer member nor a declared root signature — a split that lines up exactly with the sources your wine_get_version + *_5_1 + flags-mask gate routes to DXC.

Live (RTX 4090, driver 620.73.04, Wine 11.23, app-local dxcompiler.dll+dxil.dll): with the fallback in, the five compile-failure WARN families disappear, the argument clamp comes alive and DROPPED indirect goes from 2,400–3,700 per frame to 0, and the world renders lit where every earlier window showed a black world with perfect menus — menus and cinematics are drawn direct, which is why they looked fine all along. In one normal play window the fallback fires 12 times: 8 × compiled code holding no root signature the source declares, 2 × isnan, 1 × Load4, 1 × InterlockedOr.

One small design note from our tree: report "no app-local DXC found" apart from "DXC refused this source" — one combined message that always blamed the file sent us hunting for a DLL that was already loaded.

@zmasi

zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @z3r0rc for the independent Wine 11.23 + RTX 4090 reproduction (15/20 runtime HLSL variants, 2,400–3,700 -> 0 dropped indirects per frame) and for retiring the duplicate branch in favour of this PR!

Confirmed on your diagnostic note as well: compiler.rs (9075a5e419, lines 66–77 and compile_dxc) separates those two failure modes — missing/unloadable dxcompiler.dll + dxil.dll logs "app-local DXC unavailable; using FXC on Wine (embedded root signatures may be missing)" once in the LazyLock initializer and falls back to D3DCompile, whereas a loaded DXC rejecting HLSL extracts IDxcBlobUtf8 (DXC_OUT_ERRORS) and logs "DXC: ..." directly without falling back or blaming DLL discovery.

AI-assisted.

@merzleckeier

Copy link
Copy Markdown
Contributor

Follow-up covering the graphics and diagnostic paths of 9075a5e41 merged onto 7bbc1d22 (34fc022c). CachyOS, Wine 11.22, VKD3D-Proton 71cae091, RTX 4070 SUPER (620.73.04) and Radeon Raphael (RADV 26.3.1). Microsoft DXC 1.9.2609

MEASURED. With the matching pair beside the unchanged test executable, five cases per GPU switched from failing to passing. They cover CARD_COMPARE and the unbounded root signature, display-plane composition, the trainer overlay, fog readback, and the offscreen unbounded texture table. The table test read fixed=1024 other=1765 on both GPUs. On RADV, a compiler-only directory and a pair in the working directory alone both reproduced the representative FXC fallback failure. The full recorder/replay test stopped at the native command-list identity check in both arms.

MEASURED, diagnostic unit test. The existing test that checks Error::message() failed 3/3 per GPU even with the pair loaded. A local probe printed leonida.hlsl:1:12: error: expected parameter declarator from dxc_errors before Error::new, followed by the generic Call failed. from Error::message().

I put a small follow-up on my fork. The test checks the failed DXC status and the diagnostic text directly from IDxcResult. The runtime still logs the detailed text and returns the same Windows result as before. This passed 3/3 per GPU, and the five working cases above stayed green on both GPUs. Test fix e32fa8b49

Synthetic fixtures only. AI-assisted with OpenAI Codex.

Check IDxcResult::GetStatus and dxc_errors before Windows Error::new wrapping (which Wine may not preserve in Error::message()), and probe load_dxc() beside the test binary in test_dxc_factory. Credit: @merzleckeier (e32fa8b).
@zmasi

zmasi commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Thank you @merzleckeier for testing the graphics, trainer, composition, fog readback, and unbounded-table paths across RTX 4070 SUPER and Radeon Raphael under Wine 11.22, and for isolating the Wine Error::message() behavior in dxc_compiles_card_compare_with_embedded_root_signature_and_utf8_errors!

Folded in your invoke_dxc / test_dxc_factory check (also probing load_dxc() beside the test executable before Windows Kits, and keeping an is_err() check on compile_dxc) and verified compiler::tests (2/2) on Windows 11 + RTX 3090 + Windows SDK DXC.

AI-assisted.

@merzleckeier

Copy link
Copy Markdown
Contributor

Thanks for folding in the diagnostic check. I retested 603845afabf and 9075a5e419 on the same base (a84c41909b) with Wine 11.22 and VKD3D-Proton 3.2 (71cae091). I used the x64 DXC 1.9.2609 pair and selected one Vulkan ICD per process. The adapters were RTX 4070 SUPER (NVIDIA 620.73.04) and Radeon Raphael (RADV 26.3.1).

  • MEASURED, app-local pair. With both DLLs beside the EXE, no Windows Kits in the prefix, and LEONIDA_TEST_DXC_DIR unset, 9075a5e419 printed the DXC skip marker on both adapters (1 run each). 603845afabf executed and passed the DXC root-signature/invalid-HLSL diagnostic test 3/3 times per adapter, with no skip marker.
  • MEASURED, smoke tests. The combined compiler check, composition, trainer, fog readback, and unbounded descriptor-table replay each passed once per adapter at 603845afabf. Both readbacks ran on the selected device.
  • MEASURED, RADV controls (1 run per case). Removing the app-local pair with the override unset restored the explicit diagnostic skip. Supplying the pair only through LEONIDA_TEST_DXC_DIR ran the diagnostic test successfully. In a separate process with the same placement, the runtime-facing compiler test still hit the existing Wine FXC fallback error (0x80004005), consistent with the override's test-only scope.

Offline, synthetic fixtures only. AI-assisted with OpenAI Codex.

@MoonEyes

Copy link
Copy Markdown
Collaborator

Tested 603845afa merged (no commit) with main 060c47160: Windows 11, Rust toolchain from d3d12/rust-toolchain.toml, CPU only, no game run.

  • cargo test -p leonida-gpu --locked: main 549 passed, 47 ignored; with this PR 553 passed, 48 ignored, 0 failed.
  • cargo clippy -p leonida-gpu --locked -- -D warnings: 10 findings on main and the same 10 with the PR (all in leonida-lua and leonida-shader); this PR adds none.
  • Merges cleanly with main and does not force a rebase of [integration] PageMirror, GPU detile, async queue & RDNA2->SPIR-V performance stack (INTEGRATION-PERF-CPU-GPU-R6) #2566.
  • Not covered: an in-game run. It touches the render path, so before merge it should also run in game for 300 s with no device loss, as this project now asks of render-path changes.

AI-assisted (Claude Code).

z3r0rc added a commit to z3r0rc/leonida that referenced this pull request Nov 30, 2026
Wine's builtin d3dcompiler (the vendored vkd3d-shader) refuses our runtime
HLSL helpers: RWByteAddressBuffer member methods fail E5005 and the
[RootSignature] attribute is dropped, so every world-fill pass dies silently
and the composite samples never-written planes - black world, UI fine.
Compile through DXC (*_6_0) on refusal or a missing RTS0 chunk, and build the
composer/trainer root signatures programmatically through
D3D12SerializeVersionedRootSignature v1.1 instead of the HLSL chunk. Same
direction as open upstream PRs ProjectLeonida#2642 and ProjectLeonida#2577; carried here so play windows
work while they sit unmerged.
z3r0rc added a commit to z3r0rc/leonida that referenced this pull request Dec 1, 2026
Wine's builtin d3dcompiler (the vendored vkd3d-shader) refuses our runtime
HLSL helpers: RWByteAddressBuffer member methods fail E5005 and the
[RootSignature] attribute is dropped, so every world-fill pass dies silently
and the composite samples never-written planes - black world, UI fine.
Compile through DXC (*_6_0) on refusal or a missing RTS0 chunk, and build the
composer/trainer root signatures programmatically through
D3D12SerializeVersionedRootSignature v1.1 instead of the HLSL chunk. Same
direction as open upstream PRs ProjectLeonida#2642 and ProjectLeonida#2577; carried here so play windows
work while they sit unmerged.
@z3r0rc

z3r0rc commented Dec 1, 2026

Copy link
Copy Markdown
Contributor

A Linux/NVIDIA data point from a machine that went through this exact wall: on Wine the builtin d3dcompiler_47 (vendored vkd3d-shader 2.1) refuses every runtime HLSL helper this tree compiles — no RWByteAddressBuffer member methods (E5005), [RootSignature]/RTS0 dropped. Five WARN families sit in every log, and the consequence is a black world with fine menus: 2,400-3,700 indirect draws dropped per frame means the world-fill passes never run. Our interim fallback (system D3DCompile *_5_1 first, app-local DXC *_6_0 on refusal or missing RTS0, sources byte-identical) turns it into a lit, drivable world: 20/20 runtime helpers compile with an app-local dxcompiler.dll (DXC 1.9.2609), DROPPED indirect goes to zero, and the same exe and env swing between the black world and 28-30 fps. Your app-local DXC shape is right — please land it; we will delete our local fallback the day it does.

The full measured env baseline for Linux play is posted on #2577. AI-assisted comment; measured logs (RTX 4090, NVIDIA 620.73.04, Wine 11.23, VKD3D-Proton master).

@KelboLive KelboLive left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not superseded: git grep on current main finds no compile_named/compile_runtime_hlsl, and the SM 5.1 call sites still use D3DCompile. Merged into today's main it applies cleanly, builds, and the affected suites pass (compiler::tests 2/2 with the DXC test genuinely executing on the Windows SDK pair, compose 1, trainer 5, inplace_probe 1, merge::tests 1). The native-Windows gate is right (on_wine() via wine_get_version, compiler.rs:98, with the FXC call keeping name/entry/target/flags), and the DXC diagnostic path is mutation-covered (forcing dxc_errors to None fails compiler.rs:339).

Two things before merge:

  1. The "only compiler.rs calls D3DCompile" invariant no longer holds after merge. Main gained texture.rs:4301 (test-only alias_cast_tests) since your base. Please rebase and either route it through the new helper or restate the invariant as "runtime, non-test".
  2. #2577 fixes the same Wine [RootSignature] failure differently — it ships native d3dcompiler_47.dll and serialises root signatures in compose.rs/trainer.rs. The two approaches overlap on these exact files, so one should land first, or the DXC path should be documented as the replacement. This is worth settling before either merges, since both claim the same symptom.

Also: mutating the gate at compiler.rs:56 to if true leaves every test green — the Wine-vs-native routing is covered only by manual runs (here on_wine() is false, load_dxc() looks beside the test exe, and the tests call compile_dxc directly). A sentence saying that is intentional would save the next bisector.

The branch is 1,463 commits behind but the merged tree is green; a rebase is for the invariant and CI, not for correctness.

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.

5 participants