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

Open
Deilach wants to merge 1 commit from upstream-pr/2093 into main
Deilach commented 2026-11-25 04:41:14 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Deilach on 2026-11-25T04:41:14Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:issue:6597358874 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2093). Originally posted by [Deilach](https://github.com/Deilach) on 2026-11-25T04:41:14Z. --- ## 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)
DenRakEiw commented 2026-11-25 05:06:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by DenRakEiw on 2026-11-25T04:44:41Z.

Review: APPROVED


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

<!-- greyfinch-sync:Marvisak/VIctory:review:6051979904 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2093#pullrequestreview-6051979904). Originally posted by [DenRakEiw](https://github.com/DenRakEiw) on 2026-11-25T04:44:41Z. **Review:** APPROVED --- 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).
catminou4 commented 2026-11-25 05:06:08 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by catminou4 on 2026-11-25T05:02:20Z.

Review: COMMENTED


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.

<!-- greyfinch-sync:Marvisak/VIctory:review:6052104973 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2093#pullrequestreview-6052104973). Originally posted by [catminou4](https://github.com/catminou4) on 2026-11-25T05:02:20Z. **Review:** COMMENTED --- 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.
jeremygold02 commented 2026-11-25 05:06:24 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by jeremygold02 on 2026-11-25T04:45:43Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7153140057 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2093#issuecomment-7153140057). Originally posted by [jeremygold02](https://github.com/jeremygold02) on 2026-11-25T04:45:43Z. --- **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://github.com/Marvisak/VIctory/pull/1279#issuecomment-7138794781) **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.
upipibi commented 2026-11-25 05:06:25 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by upipibi on 2026-11-25T04:48:37Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7153184131 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2093#issuecomment-7153184131). Originally posted by [upipibi](https://github.com/upipibi) on 2026-11-25T04:48:37Z. --- 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 commented 2026-11-25 05:06:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Dathinel on 2026-11-25T04:56:01Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7153295109 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2093#issuecomment-7153295109). Originally posted by [Dathinel](https://github.com/Dathinel) on 2026-11-25T04:56:01Z. --- 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 commented 2026-11-25 05:06:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Deilach on 2026-11-25T04:59:13Z.


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.

<!-- greyfinch-sync:Marvisak/VIctory:comment:7153343404 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2093#issuecomment-7153343404). Originally posted by [Deilach](https://github.com/Deilach) on 2026-11-25T04:59:13Z. --- 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.
Marvisak commented 2026-11-25 11:05:26 +00:00 (Migrated from github.com)

Imported from Marvisak/VIctory. Originally posted by Marvisak on 2026-11-25T10:34:59Z.


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

<!-- greyfinch-sync:Marvisak/VIctory:comment:7159892805 --> Imported from [Marvisak/VIctory](https://github.com/Marvisak/VIctory/pull/2093#issuecomment-7159892805). Originally posted by [Marvisak](https://github.com/Marvisak) on 2026-11-25T10:34:59Z. --- <!-- 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 cannot be merged automatically due to conflicts.
Merge manually to resolve the conflicts.
View command line instructions

Checkout

From your project repository, check out a new branch and test the changes.
git fetch -u origin 'upstream-pr/2093:upstream-pr/2093'
git switch 'upstream-pr/2093'

Merge

Merge the changes and update on Forgejo.

Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.

git switch 'main'
git merge --no-ff 'upstream-pr/2093'
git switch 'upstream-pr/2093'
git rebase 'main'
git switch 'main'
git merge --ff-only 'upstream-pr/2093'
git switch 'upstream-pr/2093'
git rebase 'main'
git switch 'main'
git merge --no-ff 'upstream-pr/2093'
git switch 'main'
git merge --squash 'upstream-pr/2093'
git switch 'main'
git merge --ff-only 'upstream-pr/2093'
git switch 'main'
git merge 'upstream-pr/2093'
git push origin 'main'
Sign in to join this conversation.
No reviewers
No labels
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.

Reference
Marvisak/VIctory!2091
No description provided.