Skip to content

Commit ca7ac86

Browse files
authored
DXC on DX12 in CI (#4571)
1 parent a4b5316 commit ca7ac86

File tree

13 files changed

+59
-27
lines changed

13 files changed

+59
-27
lines changed

.github/workflows/ci.yml

+5
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ on:
1010
env:
1111
CARGO_INCREMENTAL: false
1212
CARGO_TERM_COLOR: always
13+
WGPU_DX12_COMPILER: dxc
1314
RUST_LOG: info
1415
RUST_BACKTRACE: full
1516
# This is the MSRV used by `wgpu` itself and all surrounding infrastructure.
@@ -353,6 +354,10 @@ jobs:
353354
. -> target
354355
xtask -> xtask/target
355356
357+
- name: (windows) install dxc
358+
if: matrix.os == 'windows-2022'
359+
uses: napokue/[email protected]
360+
356361
- name: (windows) install warp
357362
if: matrix.os == 'windows-2022'
358363
shell: bash

examples/bunnymark/screenshot.png

1.07 KB
Loading

examples/bunnymark/src/main.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -372,8 +372,8 @@ static TEST: wgpu_example::framework::ExampleTestParams =
372372
comparisons: &[
373373
wgpu_test::ComparisonType::Mean(0.05),
374374
wgpu_test::ComparisonType::Percentile {
375-
percentile: 0.95,
376-
threshold: 0.05,
375+
percentile: 0.99,
376+
threshold: 0.19,
377377
},
378378
],
379379
_phantom: std::marker::PhantomData::<Example>,

examples/common/src/framework.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,7 @@ async fn setup<E: Example>(title: &str) -> Setup {
156156

157157
log::info!("Initializing the surface...");
158158

159-
let backends = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all);
159+
let backends = wgpu::util::backend_bits_from_env().unwrap_or_default();
160160
let dx12_shader_compiler = wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default();
161161
let gles_minor_version = wgpu::util::gles_minor_version_from_env().unwrap_or_default();
162162

examples/timestamp-queries/src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ impl Queries {
178178
#[cfg_attr(test, allow(unused))]
179179
async fn run() {
180180
// Instantiates instance of wgpu
181-
let backends = wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all);
181+
let backends = wgpu::util::backend_bits_from_env().unwrap_or_default();
182182
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
183183
backends,
184184
flags: wgpu::InstanceFlags::from_build_config().with_env(),

tests/tests/multi-instance.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
async fn get() -> wgpu::Adapter {
44
let adapter = {
55
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
6-
backends: wgpu::util::backend_bits_from_env().unwrap_or_else(wgpu::Backends::all),
6+
backends: wgpu::util::backend_bits_from_env().unwrap_or_default(),
77
..Default::default()
88
});
99
instance

wgpu-hal/src/dx12/adapter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use crate::{
22
auxil::{self, dxgi::result::HResult as _},
3-
dx12::SurfaceTarget,
3+
dx12::{shader_compilation, SurfaceTarget},
44
};
55
use std::{mem, ptr, sync::Arc, thread};
66
use winapi::{
@@ -50,7 +50,7 @@ impl super::Adapter {
5050
adapter: d3d12::DxgiAdapter,
5151
library: &Arc<d3d12::D3D12Lib>,
5252
instance_flags: wgt::InstanceFlags,
53-
dx12_shader_compiler: &wgt::Dx12Compiler,
53+
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
5454
) -> Option<crate::ExposedAdapter<super::Api>> {
5555
// Create the device so that we can get the capabilities.
5656
let device = {
@@ -305,7 +305,7 @@ impl super::Adapter {
305305
private_caps,
306306
presentation_timer,
307307
workarounds,
308-
dx12_shader_compiler: dx12_shader_compiler.clone(),
308+
dxc_container,
309309
},
310310
info,
311311
features,
@@ -421,7 +421,7 @@ impl crate::Adapter<super::Api> for super::Adapter {
421421
limits,
422422
self.private_caps,
423423
&self.library,
424-
self.dx12_shader_compiler.clone(),
424+
self.dxc_container.clone(),
425425
)?;
426426
Ok(crate::OpenDevice {
427427
device,

wgpu-hal/src/dx12/device.rs

+5-10
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
use crate::auxil::{self, dxgi::result::HResult as _};
1+
use crate::{
2+
auxil::{self, dxgi::result::HResult as _},
3+
dx12::shader_compilation,
4+
};
25

36
use super::{conv, descriptor, view};
47
use parking_lot::Mutex;
@@ -19,22 +22,14 @@ impl super::Device {
1922
limits: &wgt::Limits,
2023
private_caps: super::PrivateCapabilities,
2124
library: &Arc<d3d12::D3D12Lib>,
22-
dx12_shader_compiler: wgt::Dx12Compiler,
25+
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
2326
) -> Result<Self, crate::DeviceError> {
2427
let mem_allocator = if private_caps.suballocation_supported {
2528
super::suballocation::create_allocator_wrapper(&raw)?
2629
} else {
2730
None
2831
};
2932

30-
let dxc_container = match dx12_shader_compiler {
31-
wgt::Dx12Compiler::Dxc {
32-
dxil_path,
33-
dxc_path,
34-
} => super::shader_compilation::get_dxc_container(dxc_path, dxil_path)?,
35-
wgt::Dx12Compiler::Fxc => None,
36-
};
37-
3833
let mut idle_fence = d3d12::Fence::null();
3934
let hr = unsafe {
4035
profiling::scope!("ID3D12Device::CreateFence");

wgpu-hal/src/dx12/instance.rs

+23-2
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,27 @@ impl crate::Instance<super::Api> for super::Instance {
7272
}
7373
}
7474

75+
// Initialize DXC shader compiler
76+
let dxc_container = match desc.dx12_shader_compiler.clone() {
77+
wgt::Dx12Compiler::Dxc {
78+
dxil_path,
79+
dxc_path,
80+
} => {
81+
let container = super::shader_compilation::get_dxc_container(dxc_path, dxil_path)
82+
.map_err(|e| {
83+
crate::InstanceError::with_source(String::from("Failed to load DXC"), e)
84+
})?;
85+
86+
container.map(Arc::new)
87+
}
88+
wgt::Dx12Compiler::Fxc => None,
89+
};
90+
91+
match dxc_container {
92+
Some(_) => log::debug!("Using DXC for shader compilation"),
93+
None => log::debug!("Using FXC for shader compilation"),
94+
}
95+
7596
Ok(Self {
7697
// The call to create_factory will only succeed if we get a factory4, so this is safe.
7798
factory,
@@ -80,7 +101,7 @@ impl crate::Instance<super::Api> for super::Instance {
80101
_lib_dxgi: lib_dxgi,
81102
supports_allow_tearing,
82103
flags: desc.flags,
83-
dx12_shader_compiler: desc.dx12_shader_compiler.clone(),
104+
dxc_container,
84105
})
85106
}
86107

@@ -112,7 +133,7 @@ impl crate::Instance<super::Api> for super::Instance {
112133
adapters
113134
.into_iter()
114135
.filter_map(|raw| {
115-
super::Adapter::expose(raw, &self.library, self.flags, &self.dx12_shader_compiler)
136+
super::Adapter::expose(raw, &self.library, self.flags, self.dxc_container.clone())
116137
})
117138
.collect()
118139
}

wgpu-hal/src/dx12/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ pub struct Instance {
9595
supports_allow_tearing: bool,
9696
_lib_dxgi: d3d12::DxgiLib,
9797
flags: wgt::InstanceFlags,
98-
dx12_shader_compiler: wgt::Dx12Compiler,
98+
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
9999
}
100100

101101
impl Instance {
@@ -211,7 +211,7 @@ pub struct Adapter {
211211
//Note: this isn't used right now, but we'll need it later.
212212
#[allow(unused)]
213213
workarounds: Workarounds,
214-
dx12_shader_compiler: wgt::Dx12Compiler,
214+
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
215215
}
216216

217217
unsafe impl Send for Adapter {}
@@ -253,7 +253,7 @@ pub struct Device {
253253
render_doc: crate::auxil::renderdoc::RenderDoc,
254254
null_rtv_handle: descriptor::Handle,
255255
mem_allocator: Option<Mutex<suballocation::GpuAllocatorWrapper>>,
256-
dxc_container: Option<shader_compilation::DxcContainer>,
256+
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
257257
}
258258

259259
unsafe impl Send for Device {}

wgpu-hal/src/dx12/shader_compilation.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ mod dxc {
9999
let dxil = match hassle_rs::Dxil::new(dxil_path) {
100100
Ok(dxil) => dxil,
101101
Err(e) => {
102-
log::warn!("Failed to load dxil.dll. Defaulting to Fxc instead: {}", e);
102+
log::warn!("Failed to load dxil.dll. Defaulting to DXC instead: {}", e);
103103
return Ok(None);
104104
}
105105
};
@@ -111,7 +111,7 @@ mod dxc {
111111
Ok(dxc) => dxc,
112112
Err(e) => {
113113
log::warn!(
114-
"Failed to load dxcompiler.dll. Defaulting to Fxc instead: {}",
114+
"Failed to load dxcompiler.dll. Defaulting to FXC instead: {}",
115115
e
116116
);
117117
return Ok(None);

wgpu-info/src/report.rs

+6-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ pub struct GpuReport {
1717

1818
impl GpuReport {
1919
pub fn generate() -> Self {
20-
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor::default());
20+
let instance = wgpu::Instance::new(wgpu::InstanceDescriptor {
21+
backends: wgpu::util::backend_bits_from_env().unwrap_or_default(),
22+
flags: wgpu::InstanceFlags::debugging().with_env(),
23+
dx12_shader_compiler: wgpu::util::dx12_shader_compiler_from_env().unwrap_or_default(),
24+
gles_minor_version: wgpu::util::gles_minor_version_from_env().unwrap_or_default(),
25+
});
2126
let adapters = instance.enumerate_adapters(wgpu::Backends::all());
2227

2328
let mut devices = Vec::with_capacity(adapters.len());

wgpu-types/src/lib.rs

+6
Original file line numberDiff line numberDiff line change
@@ -177,6 +177,12 @@ bitflags::bitflags! {
177177
}
178178
}
179179

180+
impl Default for Backends {
181+
fn default() -> Self {
182+
Self::all()
183+
}
184+
}
185+
180186
impl_bitflags!(Backends);
181187

182188
impl From<Backend> for Backends {

0 commit comments

Comments
 (0)