DirectX 12 on Windows: the fallback when Vulkan fails, and a setting (#746)

The Windows client builds wgpu's dx12 backend. With graphicsApi:auto (the
default), the renderer opens Vulkan and falls back to DirectX 12 when Vulkan
has no adapter (no Vulkan driver) or its device request fails; vulkan and dx12
pick one (horizon-graphics.txt, Video Settings > Graphics API on Windows, or
HORIZON_GRAPHICS_API; WGPU_BACKEND still overrides). Other systems keep their
one backend.

DirectX 12 keeps wgpu's indirect-draw validation: it is what passes each
draw's first instance to shaders there. Occlusion culling stays Vulkan-only and
flat draws Metal-only, as before; multi-draw and the GPU timer use DirectX 12's
own. gpu-allocator now resolves to the windows crate wgpu-hal's dx12 code
uses (0.62): with cpal's 0.54 it did not compile. A test translates every WGSL
shader to HLSL as the dx12 backend does for FXC.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Ludovic Marie
2026-10-19 07:34:11 +02:00
parent 70de685d2b
commit 8aacf93d8f
6 changed files with 396 additions and 100 deletions
+18 -2
View File
@@ -2,7 +2,7 @@
//! they show, in what groups, with what description and cost, and their
//! input. How they look comes from `graphics_style`.
use crate::{
graphics::{Overlay, Pacing, PresentMode, Preset},
graphics::{GraphicsApi, Overlay, Pacing, PresentMode, Preset},
graphics_style::{Cost, STYLE},
hud::{HudAtlas, HudBatch},
options_ui::Opt,
@@ -38,6 +38,7 @@ pub enum H {
Antialiasing,
BatteryMode,
ShaderPack,
GraphicsApi,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
@@ -99,7 +100,7 @@ pub fn rows(level: Level) -> Vec<Row> {
None,
"Sets the options below together. Changing one makes it Custom.",
);
match level {
let mut rows = match level {
Level::Simple => vec![preset, render, fov, fps, vsync, gui],
Level::Advanced => vec![
Row::Header("Rendering"),
@@ -248,6 +249,11 @@ pub fn rows(level: Level) -> Vec<Row> {
None,
"Threads that generate, light and mesh chunks. Next start.",
),
h(
H::GraphicsApi,
None,
"Vulkan, or DirectX 12 where Vulkan fails. Next start.",
),
h(
H::UploadBudget,
Low,
@@ -260,7 +266,14 @@ pub fn rows(level: Level) -> Vec<Row> {
"Frame rate and frame times over the game, with a graph.",
),
],
};
// Only Windows has more than one graphics API.
if !cfg!(windows) {
rows.retain(
|row| !matches!(row, Row::Setting(s) if s.item == Item::Horizon(H::GraphicsApi)),
);
}
rows
}
const UPLOAD_STEPS: [u32; 8] = [0, 256, 512, 1024, 2048, 4096, 8192, 16384];
@@ -342,6 +355,7 @@ impl H {
H::ResolutionScale => labelled("Resolution Scale", format!("{}%", g.resolution_scale)),
H::Antialiasing => labelled("Anti-aliasing", if g.fxaa { "FXAA" } else { "Off" }),
H::BatteryMode => labelled("Battery Mode", on_off(g.battery)),
H::GraphicsApi => labelled("Graphics API", g.api.label()),
H::ShaderPack => match g.shader_pack.as_str() {
"" => labelled("Shader Pack", "Off"),
id => labelled("Shader Pack", id),
@@ -393,6 +407,7 @@ impl H {
H::PresentMode => g.present_mode = step(&PresentMode::ALL, g.present_mode, back),
H::Antialiasing => g.fxaa = !g.fxaa,
H::BatteryMode => g.battery = !g.battery,
H::GraphicsApi => g.api = step(&GraphicsApi::ALL, g.api, back),
H::ShaderPack => {
// Off, then every pack in shaderpacks/ by folder name.
let dir = std::env::current_dir()
@@ -497,6 +512,7 @@ impl Item {
| H::Workers
| H::BatteryMode
| H::ShaderPack
| H::GraphicsApi
) | Item::Vanilla(
Opt::GuiScale
| Opt::Fullscreen