Skip to content

GPU: our compute shaders compiled by the build on Windows - #2093

Open
Deilach wants to merge 1 commit into
Marvisak:mainfrom
Deilach:linux-prebuilt-shaders
Open

Deilach wants to merge 1 commit into
Marvisak:mainfrom
Deilach:linux-prebuilt-shaders

Conversation

@Deilach

@Deilach Deilach commented Nov 25, 2026 •

Copy link
Copy Markdown

What

Two of VIctory's own compute shaders run in the game: the indirect-argument clamp (indirect.rs) and the 16-bit depth conversion (twin.rs). Both are compiled at first use with D3DCompile. Under Wine and Proton that call goes to Wine's own HLSL compiler (vkd3d-shader), which compiles neither:

  • clamp, depth: E5005: Method 'Load' is not defined on type 'RWByteAddressBuffer'
  • the [RootSignature] attribute is ignored (W5302), so even a shader it does compile has no root signature for CreateRootSignature

The result on Linux is a silent black world. Indirect execution is dropped ("no argument clamp"), and 16-bit depth written through unordered views never reaches the depth texture. The only workaround is installing Microsoft's d3dcompiler_47 into the prefix.

Change

  • The two shaders' HLSL moves, unchanged, to crates/victory-gpu/src/shaders/{clamp,depth}.hlsl.
  • A new crates/victory-gpu/build.rs compiles every src/shaders/*.hlsl when the build runs on Windows for Windows. It uses the system's d3dcompiler_47.dll through raw-dylib, with no new dependencies, and the same entry point, profile (cs_5_1) and flags as at runtime.
    • The bytecode goes to OUT_DIR and is embedded with include_bytes!. Nothing compiled enters the repository, and cargo xtask policy passes.
    • A shader that doesn't compile now fails cargo build, instead of failing at first use in the game.
  • A new crate::hlsl module makes both pipelines. It uses the embedded bytecode when there is some, and otherwise compiles at first use as before. That covers cross builds, where a build script can't run Microsoft's compiler.
    • Under Wine, a failure now logs what to do: build on Windows, or install d3dcompiler_47.
  • The test-only shaders (bindless, memory, draw, pipeline::library) are untouched.

On Windows the runtime behaviour is unchanged: the same bytecode, made at build time instead of first use.

When the shaders are embedded

  • Embedded: the build script runs on a Windows host with the MSVC toolchain (cfg(all(windows, target_env = "msvc")) in build.rs), and the target OS is Windows. That's the documented build. The bytecode comes from that machine's d3dcompiler_47.dll.
  • Not embedded: any other build, such as a Linux cross build or a windows-gnu host. These compile at first use, as before.
  • Not claimed: running without d3dcompiler_47.dll. The binary still imports D3DCompile for the first-use path. Windows ships that DLL, and Wine and Proton always provide their own, so the import always resolves. What changes is that a non-working compiler (Wine's) no longer costs the two pipelines.

Tests

  • hlsl::tests::our_shaders_make_pipelines: both shaders make a pipeline.
  • hlsl::tests::prebuilt_shaders_are_what_the_system_compiler_makes: the build's bytecode is byte-identical to what D3DCompile makes at runtime. I checked locally that d3dcompiler_47 output is deterministic and doesn't depend on the source name.

I ran these on Linux: Wine 11.22 with vkd3d-proton master on RADV, an RX 9070 XT. A Linux build can't run the Windows build-script path, so I compiled build.rs itself for Windows and ran it under Wine with Microsoft's d3dcompiler_47. It wrote both .dxbc files, 3,096 and 3,656 bytes, the same as a runtime compile. With Wine's compiler swapped in, it fails the build, as intended. Results:

bytecode compiler at runtime our_shaders_make_pipelines prebuilt_…_compiler_makes
prebuilt Microsoft d3dcompiler_47 ok ok (byte-identical)
prebuilt Wine's ok fails: nothing to compare against (CI on Windows always has the system compiler)
at first use (before this PR) Wine's fails skipped

cargo clippy --workspace --all-targets [--all-features] -- -D warnings is clean, and the new files are rustfmt-clean. The victory-gpu and victory-shader tests under Wine match main plus the new tests. CI on windows-latest exercises the build-script path.

🤖 Generated with Claude Code

The argument clamp and the depth conversion were compiled at first use by
the system's HLSL compiler. Under Wine and Proton that is Wine's own,
which compiles neither (no `RWByteAddressBuffer.Load`; `[RootSignature]`
is ignored), so indirect execution was dropped and 16-bit depth written
through unordered views never reached the depth texture, with only a
warning in the log.

Their HLSL moves to `src/shaders/`, and a build script compiles it when
the build runs on Windows for Windows, with the same compiler, profile
and flags as before. The binary then needs no HLSL compiler where it
runs, and a shader that does not compile fails the build. A cross build
compiles them at first use as before; under Wine a failure now says how
to fix it. `crate::hlsl` makes both pipelines.

New tests: each shader makes a pipeline, and the build's programs are
byte for byte what the system's compiler makes at first use.

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

@DenRakEiw DenRakEiw 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.

Verified locally merged onto origin/main (940d32f, Windows 11 x64, NVIDIA GeForce RTX 5090, Rust 1.98.1 MSVC):

  • victory-gpu build.rs compiled shaders/clamp.hlsl and shaders/depth.hlsl cleanly via D3DCompile on Windows
  • cargo test -p victory-gpu --lib indirect:: — 5 passed, 0 failed on RTX 5090
  • cargo clippy -p victory-gpu --all-targets — 0 warnings
  • cargo xtask policy — ok (187 files ok)

Clean build-time compilation of the internal HLSL compute shaders on Windows replacing raw bytecode blobs. Looks great.

AI-assisted (Gemini 4 Neon).

@jeremygold02

Copy link
Copy Markdown
Contributor

Triage verdict — Keep the Windows prebuild, preserve the cross-build fallback work (e4e1af2)

Evidence

Checks and limits

  • Both focused exact-head tests passed. A disposable stricter fixture required WARP and embedded bytecode, created both PSOs, then forced the runtime fallback and confirmed byte-for-byte equality and successful PSO creation. This used Microsoft’s compiler. Wine, a build on a non-MSVC host, and startup without the compiler DLL were outside the check. Shader paths · Submitted tests

Next step

  • Keep both embedded shaders and the strict readiness control. Describe the supported build condition explicitly. If the intended distribution claim includes startup with the compiler DLL absent, inspect a production executable’s imports or test that configuration separately.

This verification was AI-assisted.

@upipibi

upipibi commented Nov 25, 2026

Copy link
Copy Markdown

Ran on Windows 11 with an RTX 3070 (Ampere, driver 616.56), debug build, at e4e1af2. victory-gpu: 143 passed, 2 failed, 2 ignored. The new our_shaders_make_pipelines and prebuilt_shaders_are_what_the_system_compiler_makes pass. The 2 failures are #1744's heap-cap failures on main. Same as main on this hardware.

AI-assisted (Claude Code).

@Dathinel

Copy link
Copy Markdown
Contributor

I checked the production executable requested above at e4e1af2 on Windows x64 MSVC (cargo build --release --frozen -p victory, default features).

  • Both generated shaders are embedded byte-for-byte in victory.exe: clamp 3,096 bytes, depth 3,656 bytes.
  • The executable still imports D3DCompile from d3dcompiler_47.dll in its ordinary PE import table. This can be reproduced with dumpbin /imports target\release\victory.exe. The loader must resolve the symbol even if neither shader is compiled at first use.
  • As a control, I compiled out only the body of the runtime compiler fallback in hlsl.rs for the prebuilt, non-test configuration. That removed the DLL from both the executable's ordinary and delay imports. Both embedded blobs remained identical and the separate build helper still imported the compiler.

If the distribution goal includes removing that direct DLL dependency, the existing victory_hlsl_prebuilt cfg can select the embedded-only path at compile time while retaining compilation for cross builds and the comparison test. This was binary inspection; I did not test startup under Wine with a DLL removed. AI-assisted.

@Deilach

Deilach commented Nov 25, 2026

Copy link
Copy Markdown
Author

Thanks for the triage. On the next steps:

Build condition. The shaders are embedded only when the build script runs on a Windows host with the MSVC toolchain (cfg(all(windows, target_env = "msvc"))) and the target OS is Windows. Every other build compiles them at first use, as before: Linux cross builds, and a windows-gnu host. I've added this to the description.

Compiler DLL at startup. That isn't part of the claim. A built victory.exe still imports D3DCompile from d3dcompiler_47.dll (checked with llvm-readobj --coff-imports), because the first-use path needs it. The claim is that it needs no working HLSL compiler. Windows ships the DLL and Wine and Proton always provide their own, so the import resolves wherever VIctory runs; Wine's compiler just can no longer break the two pipelines. In-game check on Linux: an exe with the embedded bytecode, running on Wine's own d3dcompiler_47, loaded into the world (up to ~4,600 draws a frame) with neither the "no argument clamp" nor the "no depth conversion" warning. A lazily loaded compiler would only matter on a system with no DLL at all. Happy to add it if wanted.

#1279. I agree it's complementary. It makes the clamp's source build with Wine's compiler, which also covers cross builds at first use. This PR embeds the clamp and the depth conversion in Windows-built binaries. Both change indirect.rs::make, so whichever lands second needs a rebase. With #1279 the clamp's root signature is serialized beside the shader, so crate::hlsl would take that instead of reading it from the blob. I can rebase onto #1279 if it goes first.

@catminou4 catminou4 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Static review only: victory-gpu is Windows-only (D3D12/windows_sys) — nothing compiles or runs on macOS; source review of the diff.

Compute shaders compiled by the build on Windows — build-time shader compilation step; check the compile happens once and the blobs are cached, not per-run.

Marvisak commented Nov 25, 2026 •

Copy link
Copy Markdown
Owner

Automated triage for the maintainers.

This pull request no longer merges cleanly into main (conflicts in crates/victory-gpu/src/indirect.rs, crates/victory-gpu/src/twin.rs). It will be reviewed once it is rebased onto the current main. The earlier verdict (needs-work) was for an older state of main.


Generated by Claude Code

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants