[PR #979] [MERGED] DirectX 12 on Windows: fallback when Vulkan fails, and a Graphics API setting #2959

Closed
opened 2026-11-02 16:00:25 +07:00 by bsakaguchi · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/horizon-rust/horizon/pull/979
Author: @ludovic111
Created: 10/19/2026
Status: ✅ Merged
Merged: 10/19/2026
Merged by: @ludovic111

Base: main ← Head: feat/dx12-fallback


📝 Commits (2)

  • 8aacf93 DirectX 12 on Windows: the fallback when Vulkan fails, and a setting (#746)
  • 272414c Merge remote-tracking branch 'origin/main' into feat/dx12-fallback

📊 Changes

6 files changed (+396 additions, -100 deletions)

View changed files

📝 Cargo.lock (+11 -0)
📝 crates/horizon-client/Cargo.toml (+10 -0)
📝 crates/horizon-client/src/game.rs (+20 -2)
📝 crates/horizon-client/src/gfx.rs (+288 -95)
📝 crates/horizon-client/src/graphics.rs (+49 -1)
📝 crates/horizon-client/src/graphics_ui.rs (+18 -2)

📄 Description

🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself.

What

The Windows client now includes wgpu's DirectX 12 backend:

  • Auto (default): the renderer opens Vulkan as before. When Vulkan has no adapter (no Vulkan driver, vulkan-1.dll missing) or its device request fails, it tries DirectX 12. The log says why:
    Horizon renderer: trying DirectX 12 (Vulkan device: …).
  • A setting: graphicsApi: auto | vulkan | dx12 in horizon-graphics.txt. It shows on Windows as Video Settings > Performance > Graphics API (Auto / Vulkan / DirectX 12, next start). HORIZON_GRAPHICS_API=dx12 overrides it for one run, and WGPU_BACKEND still overrides everything as before.
  • Other systems: Linux and macOS have one backend each and behave exactly as before. The row is hidden there, and the setting is ignored.

A native access violation inside the driver (#746) can't be caught in-process. #980 lets the launcher notice one at the renderer's start and switch this setting to dx12.

The renderer's features on DirectX 12

Feature DirectX 12
Multi-draw (multi_draw_indexed_indirect) Native (ExecuteIndirect), as on Vulkan
Indirect-draw validation Kept on, unlike Vulkan/Metal release builds. On DX12, wgpu-core's validation pass is also what feeds each draw's first instance to shaders that read instance_index (prepare_draw(0, 0) otherwise). Only cull.wgsl reads it today, and that shader is Vulkan-only. The fallback should work first and be fast second; documented on instance_descriptor.
Occlusion culling (#939) Off: Cull::supported already requires Vulkan
Flat draws Off: Metal-only, as before
GPU timer TIMESTAMP_QUERY(_INSIDE_ENCODERS), which DX12 has
Shader packs WGSL → HLSL like every other shader

Shaders compile with FXC (d3dcompiler_47.dll, part of Windows), or with DXC when dxcompiler.dll is on the PATH (wgpu's Auto). Linking DXC statically (static-dxc, +~20 MB) is left out.

A build fix that came with it

With the dx12 backend on, wgpu-hal did not compile for Windows. gpu-allocator 0.28 takes windows >=0.53,<=0.62, and Cargo had unified it with cpal's windows 0.54, while wgpu-hal's dx12 code needs 0.62 (expected ID3D12Device, found a different ID3D12Device). cargo update -p gpu-allocator moves it to 0.62.2. That is the one Cargo.lock line besides the new dx12 dependencies (range-alloc, bit-set, once_cell, windows-core).

How tested

  • cargo fmt --all -- --check and cargo clippy --workspace --all-targets -- -D warnings: clean.
  • cargo test -p horizon-client: all pass (lib 900, including the new tests below).
    • windows_tries_vulkan_then_directx_12: the backend order for each setting, WGPU_BACKEND, and other systems.
    • shaders_translate_to_hlsl_for_directx_12: every .wgsl in the client, entry point by entry point, through naga's HLSL writer at shader model 5.1 (what wgpu writes for FXC). All of them translate.
    • indirect_draws_are_validated_only_in_debug_builds_and_on_directx_12.
    • graphics::round_trips now covers graphicsApi.
  • Windows, cross-checked on the Mac mini (x86_64-pc-windows-msvc, stub libc headers for ring/wasmtime's C files, no MSVC SDK, so --no-default-features):
    • cargo check -p horizon-client --no-default-features --lib --bins --tests: clean.
    • cargo clippy … -- -D warnings: clean.
    • Before the gpu-allocator fix, this check is what failed.
  • Mac (Metal) start through the new open_device: see the comment below.
  • Not tested: a real DirectX 12 frame. No Windows machine is reachable from here (the desktop is Linux), so FXC compiling the HLSL, the swapchain and the first frame on DX12 still need a Windows player. gh workflow run release --ref feat/dx12-fallback builds the Windows zip; results in a comment below.

Part of #746. Stacked on #977.

Needs Ludovic

Whether to ship DXC (dxcompiler.dll + dxil.dll in the Windows zip, or static-dxc) if FXC turns out slow or fails on a shader for DX12 players.

🤖 Generated with Claude Code


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/horizon-rust/horizon/pull/979 **Author:** [@ludovic111](https://github.com/ludovic111) **Created:** 10/19/2026 **Status:** ✅ Merged **Merged:** 10/19/2026 **Merged by:** [@ludovic111](https://github.com/ludovic111) **Base:** `main` ← **Head:** `feat/dx12-fallback` --- ### 📝 Commits (2) - [`8aacf93`](https://github.com/horizon-rust/horizon/commit/8aacf93d8fc523fc80f71d36bc92be54bd2dbba7) DirectX 12 on Windows: the fallback when Vulkan fails, and a setting (#746) - [`272414c`](https://github.com/horizon-rust/horizon/commit/272414cc05c1e7e18477d6f9463e1943e8a2d42e) Merge remote-tracking branch 'origin/main' into feat/dx12-fallback ### 📊 Changes **6 files changed** (+396 additions, -100 deletions) <details> <summary>View changed files</summary> 📝 `Cargo.lock` (+11 -0) 📝 `crates/horizon-client/Cargo.toml` (+10 -0) 📝 `crates/horizon-client/src/game.rs` (+20 -2) 📝 `crates/horizon-client/src/gfx.rs` (+288 -95) 📝 `crates/horizon-client/src/graphics.rs` (+49 -1) 📝 `crates/horizon-client/src/graphics_ui.rs` (+18 -2) </details> ### 📄 Description > 🤖 Opened by Ludovic's AI agent (Claude), not by Ludovic himself. ## What The Windows client now includes wgpu's DirectX 12 backend: - **Auto (default):** the renderer opens Vulkan as before. When Vulkan has **no adapter** (no Vulkan driver, `vulkan-1.dll` missing) or its **device request fails**, it tries DirectX 12. The log says why: `Horizon renderer: trying DirectX 12 (Vulkan device: …)`. - **A setting:** `graphicsApi: auto | vulkan | dx12` in `horizon-graphics.txt`. It shows on Windows as *Video Settings > Performance > Graphics API* (Auto / Vulkan / DirectX 12, next start). `HORIZON_GRAPHICS_API=dx12` overrides it for one run, and `WGPU_BACKEND` still overrides everything as before. - **Other systems:** Linux and macOS have one backend each and behave exactly as before. The row is hidden there, and the setting is ignored. A native access violation inside the driver (#746) can't be caught in-process. #980 lets the launcher notice one at the renderer's start and switch this setting to `dx12`. ## The renderer's features on DirectX 12 | Feature | DirectX 12 | | --- | --- | | Multi-draw (`multi_draw_indexed_indirect`) | Native (`ExecuteIndirect`), as on Vulkan | | Indirect-draw validation | **Kept on**, unlike Vulkan/Metal release builds. On DX12, wgpu-core's validation pass is also what feeds each draw's first instance to shaders that read `instance_index` (`prepare_draw(0, 0)` otherwise). Only `cull.wgsl` reads it today, and that shader is Vulkan-only. The fallback should work first and be fast second; documented on `instance_descriptor`. | | Occlusion culling (#939) | Off: `Cull::supported` already requires Vulkan | | Flat draws | Off: Metal-only, as before | | GPU timer | `TIMESTAMP_QUERY(_INSIDE_ENCODERS)`, which DX12 has | | Shader packs | WGSL → HLSL like every other shader | Shaders compile with FXC (`d3dcompiler_47.dll`, part of Windows), or with DXC when `dxcompiler.dll` is on the PATH (wgpu's `Auto`). Linking DXC statically (`static-dxc`, +~20 MB) is left out. ## A build fix that came with it With the dx12 backend on, wgpu-hal **did not compile for Windows**. `gpu-allocator 0.28` takes `windows >=0.53,<=0.62`, and Cargo had unified it with cpal's `windows 0.54`, while wgpu-hal's dx12 code needs 0.62 (`expected ID3D12Device, found a different ID3D12Device`). `cargo update -p gpu-allocator` moves it to 0.62.2. That is the one `Cargo.lock` line besides the new dx12 dependencies (range-alloc, bit-set, once_cell, windows-core). ## How tested - `cargo fmt --all -- --check` and `cargo clippy --workspace --all-targets -- -D warnings`: clean. - `cargo test -p horizon-client`: all pass (lib 900, including the new tests below). - `windows_tries_vulkan_then_directx_12`: the backend order for each setting, `WGPU_BACKEND`, and other systems. - `shaders_translate_to_hlsl_for_directx_12`: every `.wgsl` in the client, entry point by entry point, through naga's HLSL writer at shader model 5.1 (what wgpu writes for FXC). All of them translate. - `indirect_draws_are_validated_only_in_debug_builds_and_on_directx_12`. - `graphics::round_trips` now covers `graphicsApi`. - Windows, cross-checked on the Mac mini (`x86_64-pc-windows-msvc`, stub libc headers for ring/wasmtime's C files, no MSVC SDK, so `--no-default-features`): - `cargo check -p horizon-client --no-default-features --lib --bins --tests`: clean. - `cargo clippy … -- -D warnings`: clean. - Before the gpu-allocator fix, this check is what failed. - Mac (Metal) start through the new `open_device`: see the comment below. - **Not tested:** a real DirectX 12 frame. No Windows machine is reachable from here (the desktop is Linux), so FXC compiling the HLSL, the swapchain and the first frame on DX12 still need a Windows player. `gh workflow run release --ref feat/dx12-fallback` builds the Windows zip; results in a comment below. Part of #746. Stacked on #977. ## Needs Ludovic Whether to ship DXC (`dxcompiler.dll` + `dxil.dll` in the Windows zip, or `static-dxc`) if FXC turns out slow or fails on a shader for DX12 players. 🤖 Generated with [Claude Code](https://claude.com/claude-code) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
bsakaguchi 2026-11-02 16:00:25 +07:00
Sign in to join this conversation.
No milestone
No project
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
horizon-rust/horizon#2959
No description provided.