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

Open
github-bot wants to merge 1 commit from github-bot/gh-2093 into main AGit
Owner

@⁠Deilach on GitHub · 2026-11-25 04:41 UTC · original
Deilach:linux-prebuilt-shaders → main · +408 −199 · 7 files · 1 commits · open

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

**@⁠Deilach** on GitHub · 2026-11-25 04:41 UTC · [original](https://github.com/Marvisak/VIctory/pull/2093) `Deilach:linux-prebuilt-shaders` → `main` · +408 −199 · 7 files · 1 commits · open ## 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](https://claude.com/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 <[email protected]>
github-bot locked as GitHub sync and limited conversation to collaborators 2026-11-26 04:54:37 +00:00
Author
Owner

@⁠jeremygold02 on GitHub · 2026-11-25 04:45 UTC · original

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

Evidence

  • @⁠Deilach embeds both the indirect clamp and depth-conversion shaders when the build script runs on a Windows MSVC host for a Windows target. #1279 takes a different approach for the clamp, allowing the Wine runtime compiler to build it. Its mixed-record test and cross-built use case still have value. Build condition · #1279 readback

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.

**@⁠jeremygold02** on GitHub · 2026-11-25 04:45 UTC · [original](https://github.com/Marvisak/VIctory/pull/2093#issuecomment-7153140057) **Triage verdict — Keep the Windows prebuild, preserve the cross-build fallback work** (`e4e1af2`) **Evidence** - @⁠Deilach embeds both the indirect clamp and depth-conversion shaders when the build script runs on a Windows MSVC host for a Windows target. #1279 takes a different approach for the clamp, allowing the Wine runtime compiler to build it. Its mixed-record test and cross-built use case still have value. [Build condition](https://github.com/Marvisak/VIctory/blob/e4e1af2af45cc7baeeae9bbfb56f56810c5bcaba/crates/victory-gpu/build.rs#L7-L31) · [#1279 readback](https://git.gtahub.st/github/Marvisak--VIctory/pulls/1279) **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](https://github.com/Marvisak/VIctory/blob/e4e1af2af45cc7baeeae9bbfb56f56810c5bcaba/crates/victory-gpu/src/hlsl.rs#L45-L93) · [Submitted tests](https://github.com/Marvisak/VIctory/blob/e4e1af2af45cc7baeeae9bbfb56f56810c5bcaba/crates/victory-gpu/src/hlsl.rs#L136-L162) **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.
Author
Owner

@⁠upipibi on GitHub · 2026-11-25 04:48 UTC · original

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).

**@⁠upipibi** on GitHub · 2026-11-25 04:48 UTC · [original](https://github.com/Marvisak/VIctory/pull/2093#issuecomment-7153184131) 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).
Author
Owner

@⁠Dathinel on GitHub · 2026-11-25 04:56 UTC · original

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.

**@⁠Dathinel** on GitHub · 2026-11-25 04:56 UTC · [original](https://github.com/Marvisak/VIctory/pull/2093#issuecomment-7153295109) 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.
Author
Owner

@⁠Deilach on GitHub · 2026-11-25 04:59 UTC · original

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.

**@⁠Deilach** on GitHub · 2026-11-25 04:59 UTC · [original](https://github.com/Marvisak/VIctory/pull/2093#issuecomment-7153343404) 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.
Author
Owner

@⁠Marvisak on GitHub · 2026-11-25 10:34 UTC · original · edited 2026-11-25 15:57 UTC

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

**@⁠Marvisak** on GitHub · 2026-11-25 10:34 UTC · [original](https://github.com/Marvisak/VIctory/pull/2093#issuecomment-7159892805) · edited 2026-11-25 15:57 UTC <!-- victory-triage v1 head=e4e1af2af45cc7baeeae9bbfb56f56810c5bcaba verdict=needs-rebase at=2026-11-25T16:00:30Z --> 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](https://claude.ai/code)_
This pull request has changes conflicting with the target branch.
  • crates/victory-gpu/src/indirect.rs
  • crates/victory-gpu/src/twin.rs
View command line instructions

Manual merge helper

Use this merge commit message when completing the merge manually.

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin '+refs/pull/2093/head:github-bot/gh-2093'
git switch 'github-bot/gh-2093'

Merge

Merge the changes and update on Forgejo.
git switch 'main'
git merge --no-ff 'github-bot/gh-2093'
git switch 'github-bot/gh-2093'
git rebase 'main'
git switch 'main'
git merge --ff-only 'github-bot/gh-2093'
git switch 'github-bot/gh-2093'
git rebase 'main'
git switch 'main'
git merge --no-ff 'github-bot/gh-2093'
git switch 'main'
git merge --squash 'github-bot/gh-2093'
git switch 'main'
git merge --ff-only 'github-bot/gh-2093'
git switch 'main'
git merge 'github-bot/gh-2093'
git push origin 'main'
This discussion has been locked. Commenting is limited to contributors.
No reviewers
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
github/Marvisak--VIctory!2093
No description provided.