Skip to content

Commit

Permalink
DXC on DX12 in CI (#4571)
Browse files Browse the repository at this point in the history
  • Loading branch information
cwfitzgerald authored Oct 26, 2023
1 parent a4b5316 commit ca7ac86
Show file tree
Hide file tree
Showing 13 changed files with 59 additions and 27 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -353,6 +354,10 @@ jobs:
. -> target
xtask -> xtask/target
- name: (windows) install dxc
if: matrix.os == 'windows-2022'
uses: napokue/[email protected]

- name: (windows) install warp
if: matrix.os == 'windows-2022'
shell: bash
Expand Down
Binary file modified examples/bunnymark/screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions examples/bunnymark/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<Example>,
Expand Down
2 changes: 1 addition & 1 deletion examples/common/src/framework.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async fn setup<E: Example>(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();

Expand Down
2 changes: 1 addition & 1 deletion examples/timestamp-queries/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(),
Expand Down
2 changes: 1 addition & 1 deletion tests/tests/multi-instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
@@ -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::{
Expand Down Expand Up @@ -50,7 +50,7 @@ impl super::Adapter {
adapter: d3d12::DxgiAdapter,
library: &Arc<d3d12::D3D12Lib>,
instance_flags: wgt::InstanceFlags,
dx12_shader_compiler: &wgt::Dx12Compiler,
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
) -> Option<crate::ExposedAdapter<super::Api>> {
// Create the device so that we can get the capabilities.
let device = {
Expand Down Expand Up @@ -305,7 +305,7 @@ impl super::Adapter {
private_caps,
presentation_timer,
workarounds,
dx12_shader_compiler: dx12_shader_compiler.clone(),
dxc_container,
},
info,
features,
Expand Down Expand Up @@ -421,7 +421,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
limits,
self.private_caps,
&self.library,
self.dx12_shader_compiler.clone(),
self.dxc_container.clone(),
)?;
Ok(crate::OpenDevice {
device,
Expand Down
15 changes: 5 additions & 10 deletions wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -19,22 +22,14 @@ impl super::Device {
limits: &wgt::Limits,
private_caps: super::PrivateCapabilities,
library: &Arc<d3d12::D3D12Lib>,
dx12_shader_compiler: wgt::Dx12Compiler,
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
) -> Result<Self, crate::DeviceError> {
let mem_allocator = if private_caps.suballocation_supported {
super::suballocation::create_allocator_wrapper(&raw)?
} else {
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");
Expand Down
25 changes: 23 additions & 2 deletions wgpu-hal/src/dx12/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,27 @@ impl crate::Instance<super::Api> 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,
Expand All @@ -80,7 +101,7 @@ impl crate::Instance<super::Api> for super::Instance {
_lib_dxgi: lib_dxgi,
supports_allow_tearing,
flags: desc.flags,
dx12_shader_compiler: desc.dx12_shader_compiler.clone(),
dxc_container,
})
}

Expand Down Expand Up @@ -112,7 +133,7 @@ impl crate::Instance<super::Api> 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()
}
Expand Down
6 changes: 3 additions & 3 deletions wgpu-hal/src/dx12/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Arc<shader_compilation::DxcContainer>>,
}

impl Instance {
Expand Down Expand Up @@ -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<Arc<shader_compilation::DxcContainer>>,
}

unsafe impl Send for Adapter {}
Expand Down Expand Up @@ -253,7 +253,7 @@ pub struct Device {
render_doc: crate::auxil::renderdoc::RenderDoc,
null_rtv_handle: descriptor::Handle,
mem_allocator: Option<Mutex<suballocation::GpuAllocatorWrapper>>,
dxc_container: Option<shader_compilation::DxcContainer>,
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
}

unsafe impl Send for Device {}
Expand Down
4 changes: 2 additions & 2 deletions wgpu-hal/src/dx12/shader_compilation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
};
Expand All @@ -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);
Expand Down
7 changes: 6 additions & 1 deletion wgpu-info/src/report.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 6 additions & 0 deletions wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ bitflags::bitflags! {
}
}

impl Default for Backends {
fn default() -> Self {
Self::all()
}
}

impl_bitflags!(Backends);

impl From<Backend> for Backends {
Expand Down

0 comments on commit ca7ac86

Please sign in to comment.