From ca7ac86ccddfc0e705018a16bd4bfe12371851f2 Mon Sep 17 00:00:00 2001 From: Connor Fitzgerald Date: Thu, 26 Oct 2023 04:01:38 -0400 Subject: [PATCH] DXC on DX12 in CI (#4571) --- .github/workflows/ci.yml | 5 +++++ examples/bunnymark/screenshot.png | Bin 7405 -> 8497 bytes examples/bunnymark/src/main.rs | 4 ++-- examples/common/src/framework.rs | 2 +- examples/timestamp-queries/src/main.rs | 2 +- tests/tests/multi-instance.rs | 2 +- wgpu-hal/src/dx12/adapter.rs | 8 ++++---- wgpu-hal/src/dx12/device.rs | 15 +++++--------- wgpu-hal/src/dx12/instance.rs | 25 ++++++++++++++++++++++-- wgpu-hal/src/dx12/mod.rs | 6 +++--- wgpu-hal/src/dx12/shader_compilation.rs | 4 ++-- wgpu-info/src/report.rs | 7 ++++++- wgpu-types/src/lib.rs | 6 ++++++ 13 files changed, 59 insertions(+), 27 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76b847b6b..305d22a82 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 f8b8293cacbce7edca4d685da23e5747f1820161..d26f5f81c3a480886ed7b5ba488cb50e978725b8 100644 GIT binary patch delta 3872 zcmX9>d0bOx+P$bO4l3=(C@t$ZpA}}tQfz5J7DHPqtwo3qkjR!`DWC)h7Q>PV7q!-@ z3RLNc5(6rVkeCF7B$7Y^Qbl$vB!Pr*QIJSN5?K<+dMEVz>wW*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4*Jxys@bd~~KX!Duj;k1mjTHeCn6+Amx#yX!k`f=!i_#mhFA-}`T}_flF?K?T^&Ve(B^{<+zc@m%sZ7PEs!Mr}7XjI(mi1oP fg;8;v^BOy1X6VPiC}yqBadPND^!~, diff --git a/examples/common/src/framework.rs b/examples/common/src/framework.rs index 9e9e949ef..c4c595384 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 915eef895..b10d54cc7 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 087fac713..196d79176 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 23bd25e6a..28524858f 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 4ad43cc16..84146a006 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 5476eb141..ef7a7958f 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 6563b2249..39c24bd52 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 8dd62303f..430c73426 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 3b50ebcf0..5e27fa7c0 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 9d5b10f37..8c39f9839 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 {