Skip to content

Load FXC dynamically to remove the dependency on d3dcompiler_47.dll #7588

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: trunk
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions wgpu-hal/src/dx12/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl super::Adapter {
library: &Arc<D3D12Lib>,
instance_flags: wgt::InstanceFlags,
memory_budget_thresholds: wgt::MemoryBudgetThresholds,
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
compiler_container: Arc<shader_compilation::CompilerContainer>,
) -> Option<crate::ExposedAdapter<super::Api>> {
// Create the device so that we can get the capabilities.
let device = {
Expand Down Expand Up @@ -224,8 +224,8 @@ impl super::Adapter {
}
};

let shader_model = if let Some(ref dxc_container) = dxc_container {
let max_shader_model = match dxc_container.max_shader_model {
let shader_model = if let Some(max_shader_model) = compiler_container.max_shader_model() {
let max_shader_model = match max_shader_model {
wgt::DxcShaderModel::V6_0 => Direct3D12::D3D_SHADER_MODEL_6_0,
wgt::DxcShaderModel::V6_1 => Direct3D12::D3D_SHADER_MODEL_6_1,
wgt::DxcShaderModel::V6_2 => Direct3D12::D3D_SHADER_MODEL_6_2,
Expand Down Expand Up @@ -519,7 +519,7 @@ impl super::Adapter {
presentation_timer,
workarounds,
memory_budget_thresholds,
dxc_container,
compiler_container,
},
info,
features,
Expand Down Expand Up @@ -658,7 +658,7 @@ impl crate::Adapter for super::Adapter {
self.private_caps,
&self.library,
self.memory_budget_thresholds,
self.dxc_container.clone(),
self.compiler_container.clone(),
)?;
Ok(crate::OpenDevice {
device,
Expand Down
33 changes: 10 additions & 23 deletions wgpu-hal/src/dx12/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ impl super::Device {
private_caps: super::PrivateCapabilities,
library: &Arc<D3D12Lib>,
memory_budget_thresholds: wgt::MemoryBudgetThresholds,
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
compiler_container: Arc<shader_compilation::CompilerContainer>,
) -> Result<Self, crate::DeviceError> {
if private_caps
.instance_flags
Expand Down Expand Up @@ -202,7 +202,7 @@ impl super::Device {
render_doc: Default::default(),
null_rtv_handle,
mem_allocator,
dxc_container,
compiler_container,
counters: Default::default(),
})
}
Expand Down Expand Up @@ -327,27 +327,14 @@ impl super::Device {

let source_name = stage.module.raw_name.as_deref();

// Compile with DXC if available, otherwise fall back to FXC
let result = if let Some(ref dxc_container) = self.dxc_container {
shader_compilation::compile_dxc(
self,
&source,
source_name,
raw_ep,
stage_bit,
&full_stage,
dxc_container,
)
} else {
shader_compilation::compile_fxc(
self,
&source,
source_name,
raw_ep,
stage_bit,
&full_stage,
)
};
let result = self.compiler_container.compile(
self,
&source,
source_name,
raw_ep,
stage_bit,
&full_stage,
);

let log_level = if result.is_ok() {
log::Level::Info
Expand Down
56 changes: 27 additions & 29 deletions wgpu-hal/src/dx12/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,10 @@ use windows::{
};

use super::SurfaceTarget;
use crate::{auxil, dx12::D3D12Lib};
use crate::{
auxil,
dx12::{shader_compilation::CompilerContainer, D3D12Lib},
};

impl crate::Instance for super::Instance {
type A = super::Api;
Expand Down Expand Up @@ -66,39 +69,34 @@ impl crate::Instance for super::Instance {
}
}

// Initialize DXC shader compiler
let dxc_container = match desc.backend_options.dx12.shader_compiler.clone() {
// Initialize the shader compiler
let compiler_container = match desc.backend_options.dx12.shader_compiler.clone() {
wgt::Dx12Compiler::DynamicDxc {
dxc_path,
max_shader_model,
} => {
let container = super::shader_compilation::get_dynamic_dxc_container(
dxc_path.into(),
max_shader_model,
)
.map_err(|e| {
} => CompilerContainer::new_dynamic_dxc(dxc_path.into(), max_shader_model).map_err(
|e| {
crate::InstanceError::with_source(String::from("Failed to load dynamic DXC"), e)
})?;
},
)?,
wgt::Dx12Compiler::StaticDxc => CompilerContainer::new_static_dxc().map_err(|e| {
crate::InstanceError::with_source(String::from("Failed to load static DXC"), e)
})?,
wgt::Dx12Compiler::Fxc => CompilerContainer::new_fxc().map_err(|e| {
crate::InstanceError::with_source(String::from("Failed to load FXC"), e)
})?,
};

Some(Arc::new(container))
match compiler_container {
CompilerContainer::DynamicDxc(..) => {
log::debug!("Using dynamic DXC for shader compilation")
}
wgt::Dx12Compiler::StaticDxc => {
let container =
super::shader_compilation::get_static_dxc_container().map_err(|e| {
crate::InstanceError::with_source(
String::from("Failed to load static DXC"),
e,
)
})?;

Some(Arc::new(container))
CompilerContainer::StaticDxc(..) => {
log::debug!("Using static DXC for shader compilation")
}
CompilerContainer::Fxc(..) => {
log::debug!("Using FXC for shader compilation")
}
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 {
Expand All @@ -110,7 +108,7 @@ impl crate::Instance for super::Instance {
supports_allow_tearing,
flags: desc.flags,
memory_budget_thresholds: desc.memory_budget_thresholds,
dxc_container,
compiler_container: Arc::new(compiler_container),
})
}

Expand Down Expand Up @@ -148,7 +146,7 @@ impl crate::Instance for super::Instance {
&self.library,
self.flags,
self.memory_budget_thresholds,
self.dxc_container.clone(),
self.compiler_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 @@ -460,7 +460,7 @@ pub struct Instance {
_lib_dxgi: DxgiLib,
flags: wgt::InstanceFlags,
memory_budget_thresholds: wgt::MemoryBudgetThresholds,
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
compiler_container: Arc<shader_compilation::CompilerContainer>,
}

impl Instance {
Expand Down Expand Up @@ -592,7 +592,7 @@ pub struct Adapter {
#[allow(unused)]
workarounds: Workarounds,
memory_budget_thresholds: wgt::MemoryBudgetThresholds,
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
compiler_container: Arc<shader_compilation::CompilerContainer>,
}

unsafe impl Send for Adapter {}
Expand Down Expand Up @@ -655,7 +655,7 @@ pub struct Device {
render_doc: auxil::renderdoc::RenderDoc,
null_rtv_handle: descriptor::Handle,
mem_allocator: Allocator,
dxc_container: Option<Arc<shader_compilation::DxcContainer>>,
compiler_container: Arc<shader_compilation::CompilerContainer>,
counters: Arc<wgt::HalCounters>,
}

Expand Down
Loading
Loading