Render Anything Engine: tell your AI what to make. Videos, motion graphics, 3D and games as React and TypeScript, rendered on your own GPU. Rust + Bevy, macOS, Linux and Windows.
TypeScript 3dagent-skillsai-agentsai-videobevyclaude-codegame-enginegpulinuxmacosmotion-designmotion-graphicsreactrusttypescriptvideo-editingvideo-renderingwgpuwindows
gpu/device: an Intel GPU on Windows runs on DX12, never meeting its Vulkan driver
shinyobjectz6ee9a06f6727
diff --git a/gpu/device/src/lib.rs b/gpu/device/src/lib.rsindex 9cad9430..ace4eee2 100644--- a/gpu/device/src/lib.rs+++ b/gpu/device/src/lib.rs@@ -31,21 +31,56 @@ pub fn device() -> Result<Handles, String> {SHARED.get_or_init(make).clone()}+/// Intel's PCI vendor id, as DXGI and Vulkan report it.+const INTEL: u32 = 0x8086;++/// Whether the shared device runs on DX12 alone: on Windows, when WGPU_BACKEND isn't set and the GPU DX12 picks+/// (`dx12`: its vendor and kind) is Intel's own hardware (WARP, Windows' software DirectX, is a Cpu). raea 0.1.7 crashed+/// on an Intel integrated GPU under Vulkan on a Windows 10 PC, and ran with WGPU_BACKEND=dx12; asked for every backend,+/// wgpu takes Vulkan's adapter for the same GPU. NVIDIA and AMD, a PC with no GPU, a Mac or Linux, and a WGPU_BACKEND+/// someone set (Windows' check sets vulkan, for lavapipe) keep wgpu's own pick.+pub fn dx12_first(windows: bool, env: Option<wgpu::Backends>, dx12: Option<(u32, wgpu::DeviceType)>) -> bool {+ windows && env.is_none() && matches!(dx12, Some((INTEL, kind)) if kind != wgpu::DeviceType::Cpu)+}+fn make() -> Result<Handles, String> {// wgpu's indirect-draw validation off in release (it stays in debug builds; RAEA_WGPU_INDIRECT_VALIDATION=1 puts it// back): it checks each indirect draw's arguments in compute passes before drawing, and the indirect draws are// Bevy's own, written by its mesh preprocessing on this device. On arena3d it was ~7 extra passes and their blits a// frame, ~0.07 ms of GPU (lightspeed F2); pixels are the same.- // wgpu's own variables are read (WGPU_BACKEND, WGPU_DX12_COMPILER, WGPU_VALIDATION, ...; nothing changes when unset):+ // wgpu's own variables are read (WGPU_BACKEND, WGPU_DX12_COMPILER, WGPU_VALIDATION, ...; nothing changes when unset,+ // but for an Intel GPU on Windows, which goes on DX12: dx12_first):// Windows' check renders on Mesa's lavapipe with WGPU_BACKEND=vulkan, because WARP crashes compiling one of Bevy's// compute shaders on GitHub's GPU-less runner (d3d10warp ComputeShaderTransformer, PT20)- let mut desc = wgpu::InstanceDescriptor::new_without_display_handle_from_env();- if !cfg!(debug_assertions) && std::env::var("RAEA_WGPU_INDIRECT_VALIDATION").as_deref() != Ok("1") {- desc.flags.remove(wgpu::InstanceFlags::VALIDATION_INDIRECT_CALL);- }- let instance = wgpu::Instance::new(desc);- let adapter = pollster::block_on(instance.request_adapter(&wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::HighPerformance, ..Default::default() }))- .map_err(|e| format!("no GPU adapter: {e}"))?;+ let instance_on = |backends: Option<wgpu::Backends>| {+ let mut desc = wgpu::InstanceDescriptor::new_without_display_handle_from_env();+ if let Some(b) = backends {+ desc.backends = b;+ }+ if !cfg!(debug_assertions) && std::env::var("RAEA_WGPU_INDIRECT_VALIDATION").as_deref() != Ok("1") {+ desc.flags.remove(wgpu::InstanceFlags::VALIDATION_INDIRECT_CALL);+ }+ wgpu::Instance::new(desc)+ };+ let options = wgpu::RequestAdapterOptions { power_preference: wgpu::PowerPreference::HighPerformance, ..Default::default() };+ // on Windows with no WGPU_BACKEND, DX12's pick is asked first, so an Intel GPU never meets its Vulkan driver+ // (dx12_first); any other pick is dropped and every backend asked as before+ let env = wgpu::Backends::from_env();+ let dx12 = if cfg!(windows) && env.is_none() {+ let i = instance_on(Some(wgpu::Backends::DX12));+ let a = pollster::block_on(i.request_adapter(&options)).ok();+ a.map(|a| (i, a))+ } else {+ None+ };+ let (instance, adapter) = match dx12 {+ Some((i, a)) if dx12_first(cfg!(windows), env, Some((a.get_info().vendor, a.get_info().device_type))) => (i, a),+ _ => {+ let i = instance_on(None);+ let a = pollster::block_on(i.request_adapter(&options)).map_err(|e| format!("no GPU adapter: {e}"))?;+ (i, a)+ }+ };let mut features = adapter.features();if adapter.get_info().device_type == wgpu::DeviceType::DiscreteGpu {features.remove(wgpu::Features::MAPPABLE_PRIMARY_BUFFERS);@@ -71,3 +106,23 @@ fn make() -> Result<Handles, String> {telemetry::watch(&device, "quads");Ok((instance, adapter, device, queue))}++#[cfg(test)]+mod tests {+ use super::*;+ use wgpu::{Backends, DeviceType};++ // an Intel GPU on Windows goes on DX12 unless WGPU_BACKEND says otherwise; every other GPU and system keeps wgpu's pick+ #[test]+ fn intel_on_windows_runs_on_dx12() {+ assert!(dx12_first(true, None, Some((INTEL, DeviceType::IntegratedGpu))), "Intel's integrated GPU");+ assert!(dx12_first(true, None, Some((INTEL, DeviceType::DiscreteGpu))), "Intel Arc");+ assert!(!dx12_first(true, Some(Backends::VULKAN), Some((INTEL, DeviceType::IntegratedGpu))), "WGPU_BACKEND=vulkan is kept");+ assert!(!dx12_first(true, Some(Backends::DX12), Some((INTEL, DeviceType::IntegratedGpu))), "WGPU_BACKEND set: wgpu's own read of it");+ assert!(!dx12_first(true, None, Some((0x10de, DeviceType::DiscreteGpu))), "NVIDIA keeps wgpu's pick");+ assert!(!dx12_first(true, None, Some((0x1002, DeviceType::IntegratedGpu))), "AMD keeps wgpu's pick");+ assert!(!dx12_first(true, None, Some((0x1414, DeviceType::Cpu))), "WARP alone: wgpu's pick (lavapipe, when it's there)");+ assert!(!dx12_first(true, None, None), "no DX12 adapter");+ assert!(!dx12_first(false, None, Some((INTEL, DeviceType::IntegratedGpu))), "an Intel Mac or Linux");+ }+}