diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76b847b6b5..305d22a826 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -10,6 +10,7 @@ on: env: CARGO_INCREMENTAL: false CARGO_TERM_COLOR: always + WGPU_DX12_COMPILER: dxc RUST_LOG: info RUST_BACKTRACE: full # This is the MSRV used by `wgpu` itself and all surrounding infrastructure. @@ -353,6 +354,10 @@ jobs: . -> target xtask -> xtask/target + - name: (windows) install dxc + if: matrix.os == 'windows-2022' + uses: napokue/setup-dxc@v1.1.0 + - name: (windows) install warp if: matrix.os == 'windows-2022' shell: bash diff --git a/examples/bunnymark/screenshot.png b/examples/bunnymark/screenshot.png index f8b8293cac..d26f5f81c3 100644 Binary files a/examples/bunnymark/screenshot.png and b/examples/bunnymark/screenshot.png differ diff --git a/examples/bunnymark/src/main.rs b/examples/bunnymark/src/main.rs index baebe40fd7..2da396945e 100644 --- a/examples/bunnymark/src/main.rs +++ b/examples/bunnymark/src/main.rs @@ -372,8 +372,8 @@ static TEST: wgpu_example::framework::ExampleTestParams = comparisons: &[ wgpu_test::ComparisonType::Mean(0.05), wgpu_test::ComparisonType::Percentile { - percentile: 0.95, - threshold: 0.05, + percentile: 0.99, + threshold: 0.19, }, ], _phantom: std::marker::PhantomData::, diff --git a/examples/common/src/framework.rs b/examples/common/src/framework.rs index 9e9e949ef4..c4c595384f 100644 --- a/examples/common/src/framework.rs +++ b/examples/common/src/framework.rs @@ -156,7 +156,7 @@ async fn setup(title: &str) -> Setup { log::info!("Initializing the surface..."); - let backends = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all); + let backends = wgpu::util::backend_bits_from_env().unwrap_or_default(); let dx12_shader_compiler = wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(); let gles_minor_version = wgpu::util::gles_minor_version_from_env().unwrap_or_default(); diff --git a/examples/timestamp-queries/src/main.rs b/examples/timestamp-queries/src/main.rs index 915eef8956..b10d54cc70 100644 --- a/examples/timestamp-queries/src/main.rs +++ b/examples/timestamp-queries/src/main.rs @@ -178,7 +178,7 @@ impl Queries { #[cfg_attr(test, allow(unused))] async fn run() { // Instantiates instance of wgpu - let backends = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all); + let backends = wgpu::util::backend_bits_from_env().unwrap_or_default(); let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { backends, flags: wgpu::InstanceFlags::from_build_config().with_env(), diff --git a/tests/tests/multi-instance.rs b/tests/tests/multi-instance.rs index 087fac7137..196d791765 100644 --- a/tests/tests/multi-instance.rs +++ b/tests/tests/multi-instance.rs @@ -3,7 +3,7 @@ async fn get() -> wgpu::Adapter { let adapter = { let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { - backends: wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all), + backends: wgpu::util::backend_bits_from_env().unwrap_or_default(), ..Default::default() }); instance diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 23bd25e6aa..28524858f9 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -1,6 +1,6 @@ use crate::{ auxil::{self, dxgi::result::HResult as _}, - dx12::SurfaceTarget, + dx12::{shader_compilation, SurfaceTarget}, }; use std::{mem, ptr, sync::Arc, thread}; use winapi::{ @@ -50,7 +50,7 @@ impl super::Adapter { adapter: d3d12::DxgiAdapter, library: &Arc, instance_flags: wgt::InstanceFlags, - dx12_shader_compiler: &wgt::Dx12Compiler, + dxc_container: Option>, ) -> Option> { // Create the device so that we can get the capabilities. let device = { @@ -305,7 +305,7 @@ impl super::Adapter { private_caps, presentation_timer, workarounds, - dx12_shader_compiler: dx12_shader_compiler.clone(), + dxc_container, }, info, features, @@ -421,7 +421,7 @@ impl crate::Adapter for super::Adapter { limits, self.private_caps, &self.library, - self.dx12_shader_compiler.clone(), + self.dxc_container.clone(), )?; Ok(crate::OpenDevice { device, diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index 4ad43cc165..84146a006b 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -1,4 +1,7 @@ -use crate::auxil::{self, dxgi::result::HResult as _}; +use crate::{ + auxil::{self, dxgi::result::HResult as _}, + dx12::shader_compilation, +}; use super::{conv, descriptor, view}; use parking_lot::Mutex; @@ -19,7 +22,7 @@ impl super::Device { limits: &wgt::Limits, private_caps: super::PrivateCapabilities, library: &Arc, - dx12_shader_compiler: wgt::Dx12Compiler, + dxc_container: Option>, ) -> Result { let mem_allocator = if private_caps.suballocation_supported { super::suballocation::create_allocator_wrapper(&raw)? @@ -27,14 +30,6 @@ impl super::Device { None }; - let dxc_container = match dx12_shader_compiler { - wgt::Dx12Compiler::Dxc { - dxil_path, - dxc_path, - } => super::shader_compilation::get_dxc_container(dxc_path, dxil_path)?, - wgt::Dx12Compiler::Fxc => None, - }; - let mut idle_fence = d3d12::Fence::null(); let hr = unsafe { profiling::scope!("ID3D12Device::CreateFence"); diff --git a/wgpu-hal/src/dx12/instance.rs b/wgpu-hal/src/dx12/instance.rs index 5476eb1412..ef7a7958fb 100644 --- a/wgpu-hal/src/dx12/instance.rs +++ b/wgpu-hal/src/dx12/instance.rs @@ -72,6 +72,27 @@ impl crate::Instance for super::Instance { } } + // Initialize DXC shader compiler + let dxc_container = match desc.dx12_shader_compiler.clone() { + wgt::Dx12Compiler::Dxc { + dxil_path, + dxc_path, + } => { + let container = super::shader_compilation::get_dxc_container(dxc_path, dxil_path) + .map_err(|e| { + crate::InstanceError::with_source(String::from("Failed to load DXC"), e) + })?; + + container.map(Arc::new) + } + wgt::Dx12Compiler::Fxc => None, + }; + + match dxc_container { + Some(_) => log::debug!("Using DXC for shader compilation"), + None => log::debug!("Using FXC for shader compilation"), + } + Ok(Self { // The call to create_factory will only succeed if we get a factory4, so this is safe. factory, @@ -80,7 +101,7 @@ impl crate::Instance for super::Instance { _lib_dxgi: lib_dxgi, supports_allow_tearing, flags: desc.flags, - dx12_shader_compiler: desc.dx12_shader_compiler.clone(), + dxc_container, }) } @@ -112,7 +133,7 @@ impl crate::Instance for super::Instance { adapters .into_iter() .filter_map(|raw| { - super::Adapter::expose(raw, &self.library, self.flags, &self.dx12_shader_compiler) + super::Adapter::expose(raw, &self.library, self.flags, self.dxc_container.clone()) }) .collect() } diff --git a/wgpu-hal/src/dx12/mod.rs b/wgpu-hal/src/dx12/mod.rs index 6563b22491..39c24bd528 100644 --- a/wgpu-hal/src/dx12/mod.rs +++ b/wgpu-hal/src/dx12/mod.rs @@ -95,7 +95,7 @@ pub struct Instance { supports_allow_tearing: bool, _lib_dxgi: d3d12::DxgiLib, flags: wgt::InstanceFlags, - dx12_shader_compiler: wgt::Dx12Compiler, + dxc_container: Option>, } impl Instance { @@ -211,7 +211,7 @@ pub struct Adapter { //Note: this isn't used right now, but we'll need it later. #[allow(unused)] workarounds: Workarounds, - dx12_shader_compiler: wgt::Dx12Compiler, + dxc_container: Option>, } unsafe impl Send for Adapter {} @@ -253,7 +253,7 @@ pub struct Device { render_doc: crate::auxil::renderdoc::RenderDoc, null_rtv_handle: descriptor::Handle, mem_allocator: Option>, - dxc_container: Option, + dxc_container: Option>, } unsafe impl Send for Device {} diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index 8dd62303f2..430c734267 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -99,7 +99,7 @@ mod dxc { let dxil = match hassle_rs::Dxil::new(dxil_path) { Ok(dxil) => dxil, Err(e) => { - log::warn!("Failed to load dxil.dll. Defaulting to Fxc instead: {}", e); + log::warn!("Failed to load dxil.dll. Defaulting to DXC instead: {}", e); return Ok(None); } }; @@ -111,7 +111,7 @@ mod dxc { Ok(dxc) => dxc, Err(e) => { log::warn!( - "Failed to load dxcompiler.dll. Defaulting to Fxc instead: {}", + "Failed to load dxcompiler.dll. Defaulting to FXC instead: {}", e ); return Ok(None); diff --git a/wgpu-info/src/report.rs b/wgpu-info/src/report.rs index 3b50ebcf0b..5e27fa7c0e 100644 --- a/wgpu-info/src/report.rs +++ b/wgpu-info/src/report.rs @@ -17,7 +17,12 @@ pub struct GpuReport { impl GpuReport { pub fn generate() -> Self { - let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::default()); + let instance = wgpu::Instance::new(wgpu::InstanceDescriptor { + backends: wgpu::util::backend_bits_from_env().unwrap_or_default(), + flags: wgpu::InstanceFlags::debugging().with_env(), + dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(), + gles_minor_version: wgpu::util::gles_minor_version_from_env().unwrap_or_default(), + }); let adapters = instance.enumerate_adapters(wgpu::Backends::all()); let mut devices = Vec::with_capacity(adapters.len()); diff --git a/wgpu-types/src/lib.rs b/wgpu-types/src/lib.rs index 9d5b10f37b..8c39f98392 100644 --- a/wgpu-types/src/lib.rs +++ b/wgpu-types/src/lib.rs @@ -177,6 +177,12 @@ bitflags::bitflags! { } } +impl Default for Backends { + fn default() -> Self { + Self::all() + } +} + impl_bitflags!(Backends); impl From for Backends {