Skip to content

Commit 6ea7962

Browse files
authored
[d3d12] remove the need for dxil.dll (#7566)
1 parent c7330a8 commit 6ea7962

File tree

8 files changed

+12
-69
lines changed

8 files changed

+12
-69
lines changed

.github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -547,7 +547,7 @@ jobs:
547547
set -e
548548
549549
curl.exe -L --retry 5 https://github.com/microsoft/DirectXShaderCompiler/releases/download/$DXC_RELEASE/$DXC_FILENAME -o dxc.zip
550-
7z.exe e dxc.zip -odxc bin/x64/{dxc.exe,dxcompiler.dll,dxil.dll}
550+
7z.exe e dxc.zip -odxc bin/x64/{dxc.exe,dxcompiler.dll}
551551
552552
# We need to use cygpath to convert PWD to a windows path as we're using bash.
553553
cygpath --windows "$PWD/dxc" >> "$GITHUB_PATH"

.github/workflows/shaders.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ jobs:
6464
set -e
6565
6666
curl.exe -L --retry 5 https://github.com/microsoft/DirectXShaderCompiler/releases/download/$DXC_RELEASE/$DXC_FILENAME -o dxc.zip
67-
7z.exe e dxc.zip -odxc bin/x64/{dxc.exe,dxcompiler.dll,dxil.dll}
67+
7z.exe e dxc.zip -odxc bin/x64/{dxc.exe,dxcompiler.dll}
6868
6969
# We need to use cygpath to convert PWD to a windows path as we're using bash.
7070
cygpath --windows "$PWD/dxc" >> "$GITHUB_PATH"

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,10 @@ Naga now infers the correct binding layout when a resource appears only in an as
6767

6868
- Mark `readonly_and_readwrite_storage_textures` & `packed_4x8_integer_dot_product` language extensions as implemented. By @teoxoy in [#7543](https://github.com/gfx-rs/wgpu/pull/7543)
6969

70+
#### D3D12
71+
72+
- Remove the need for dxil.dll. By @teoxoy in [#7566](https://github.com/gfx-rs/wgpu/pull/7566)
73+
7074
### Bug Fixes
7175

7276
#### Naga

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,7 @@ All testing and example infrastructure share the same set of environment variabl
168168
- `WGPU_ADAPTER_NAME` with a substring of the name of the adapter you want to use (ex. `1080` will match `NVIDIA GeForce 1080ti`).
169169
- `WGPU_BACKEND` with a comma-separated list of the backends you want to use (`vulkan`, `metal`, `dx12`, or `gl`).
170170
- `WGPU_POWER_PREF` with the power preference to choose when a specific adapter name isn't specified (`high`, `low` or `none`)
171-
- `WGPU_DX12_COMPILER` with the DX12 shader compiler you wish to use (`dxc`, `static-dxc`, or `fxc`). Note that `dxc` requires `dxil.dll` and `dxcompiler.dll` to be in the working directory, and `static-dxc` requires the `static-dxc` crate feature to be enabled. Otherwise, it will fall back to `fxc`.
171+
- `WGPU_DX12_COMPILER` with the DX12 shader compiler you wish to use (`dxc`, `static-dxc`, or `fxc`). Note that `dxc` requires `dxcompiler.dll` (min v1.8.2502) to be in the working directory, and `static-dxc` requires the `static-dxc` crate feature to be enabled. Otherwise, it will fall back to `fxc`.
172172
- `WGPU_GLES_MINOR_VERSION` with the minor OpenGL ES 3 version number to request (`0`, `1`, `2` or `automatic`).
173173
- `WGPU_ALLOW_UNDERLYING_NONCOMPLIANT_ADAPTER` with a boolean whether non-compliant drivers are enumerated (`0` for false, `1` for true).
174174

wgpu-hal/src/dx12/instance.rs

-2
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,11 @@ impl crate::Instance for super::Instance {
6969
// Initialize DXC shader compiler
7070
let dxc_container = match desc.backend_options.dx12.shader_compiler.clone() {
7171
wgt::Dx12Compiler::DynamicDxc {
72-
dxil_path,
7372
dxc_path,
7473
max_shader_model,
7574
} => {
7675
let container = super::shader_compilation::get_dynamic_dxc_container(
7776
dxc_path.into(),
78-
dxil_path.into(),
7977
max_shader_model,
8078
)
8179
.map_err(|e| {

wgpu-hal/src/dx12/shader_compilation.rs

-53
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,6 @@ use windows::{
77
Win32::Graphics::Direct3D::{Dxc, Fxc},
88
};
99

10-
// Currently this will use Dxc if it is chosen as the dx12 compiler at `Instance` creation time, and will
11-
// fallback to FXC if the Dxc libraries (dxil.dll and dxcompiler.dll) are not found, or if Fxc is chosen at'
12-
// `Instance` creation time.
13-
1410
pub(super) fn compile_fxc(
1511
device: &super::Device,
1612
source: &str,
@@ -134,18 +130,12 @@ unsafe fn dxc_create_instance<T: DxcObj>(
134130
result__.ok_or(crate::DeviceError::Unexpected)
135131
}
136132

137-
// Destructor order should be fine since _dxil and _dxc don't rely on each other.
138133
pub(super) struct DxcContainer {
139134
pub(super) max_shader_model: wgt::DxcShaderModel,
140135
compiler: Dxc::IDxcCompiler3,
141-
utils: Dxc::IDxcUtils,
142-
validator: Option<Dxc::IDxcValidator>,
143136
// Has to be held onto for the lifetime of the device otherwise shaders will fail to compile.
144137
// Only needed when using dynamic linking.
145138
_dxc: Option<DxcLib>,
146-
// Also Has to be held onto for the lifetime of the device otherwise shaders will fail to validate.
147-
// Only needed when using dynamic linking.
148-
_dxil: Option<DxcLib>,
149139
}
150140

151141
#[derive(Debug, Error)]
@@ -158,26 +148,17 @@ pub(super) enum GetDynamicDXCContainerError {
158148

159149
pub(super) fn get_dynamic_dxc_container(
160150
dxc_path: PathBuf,
161-
dxil_path: PathBuf,
162151
max_shader_model: wgt::DxcShaderModel,
163152
) -> Result<DxcContainer, GetDynamicDXCContainerError> {
164153
let dxc = DxcLib::new_dynamic(dxc_path)
165154
.map_err(|e| GetDynamicDXCContainerError::FailedToLoad("dxcompiler.dll", e))?;
166155

167-
let dxil = DxcLib::new_dynamic(dxil_path)
168-
.map_err(|e| GetDynamicDXCContainerError::FailedToLoad("dxil.dll", e))?;
169-
170156
let compiler = dxc.create_instance::<Dxc::IDxcCompiler3>()?;
171-
let utils = dxc.create_instance::<Dxc::IDxcUtils>()?;
172-
let validator = dxil.create_instance::<Dxc::IDxcValidator>()?;
173157

174158
Ok(DxcContainer {
175159
max_shader_model,
176160
compiler,
177-
utils,
178-
validator: Some(validator),
179161
_dxc: Some(dxc),
180-
_dxil: Some(dxil),
181162
})
182163
}
183164

@@ -193,21 +174,11 @@ pub(super) fn get_static_dxc_container() -> Result<DxcContainer, crate::DeviceEr
193174
ppv,
194175
))
195176
})?;
196-
let utils = dxc_create_instance::<Dxc::IDxcUtils>(|clsid, iid, ppv| {
197-
windows_core::HRESULT(mach_dxcompiler_rs::DxcCreateInstance(
198-
clsid.cast(),
199-
iid.cast(),
200-
ppv,
201-
))
202-
})?;
203177

204178
Ok(DxcContainer {
205179
max_shader_model: wgt::DxcShaderModel::V6_7,
206180
compiler,
207-
utils,
208-
validator: None,
209181
_dxc: None,
210-
_dxil: None,
211182
})
212183
}
213184
}
@@ -286,10 +257,6 @@ pub(super) fn compile_dxc(
286257
Dxc::DXC_ARG_ENABLE_STRICTNESS,
287258
]);
288259

289-
if dxc_container.validator.is_some() {
290-
compile_args.push(Dxc::DXC_ARG_SKIP_VALIDATION); // Disable implicit validation to work around bugs when dxil.dll isn't in the local directory.)
291-
}
292-
293260
if device
294261
.shared
295262
.private_caps
@@ -335,25 +302,5 @@ pub(super) fn compile_dxc(
335302

336303
let blob = get_output::<Dxc::IDxcBlob>(&compile_res, Dxc::DXC_OUT_OBJECT)?;
337304

338-
if let Some(validator) = &dxc_container.validator {
339-
let err_blob = {
340-
let res = unsafe { validator.Validate(&blob, Dxc::DxcValidatorFlags_InPlaceEdit) }
341-
.into_device_result("Validate")?;
342-
343-
unsafe { res.GetErrorBuffer() }.into_device_result("GetErrorBuffer")?
344-
};
345-
346-
let size = unsafe { err_blob.GetBufferSize() };
347-
if size != 0 {
348-
let err_blob = unsafe { dxc_container.utils.GetBlobAsUtf8(&err_blob) }
349-
.into_device_result("GetBlobAsUtf8")?;
350-
let err = as_err_str(&err_blob)?;
351-
return Err(crate::PipelineError::Linkage(
352-
stage_bit,
353-
format!("DXC validation error: {err}"),
354-
));
355-
}
356-
}
357-
358305
Ok(crate::dx12::CompiledShader::Dxc(blob))
359306
}

wgpu-types/src/instance.rs

+4-10
Original file line numberDiff line numberDiff line change
@@ -394,9 +394,6 @@ pub enum DxcShaderModel {
394394
}
395395

396396
/// Selects which DX12 shader compiler to use.
397-
///
398-
/// If the `DynamicDxc` option is selected, but `dxcompiler.dll` and `dxil.dll` files aren't found,
399-
/// then this will fall back to the Fxc compiler at runtime and log an error.
400397
#[derive(Clone, Debug, Default)]
401398
pub enum Dx12Compiler {
402399
/// The Fxc compiler (default) is old, slow and unmaintained.
@@ -406,17 +403,15 @@ pub enum Dx12Compiler {
406403
Fxc,
407404
/// The Dxc compiler is new, fast and maintained.
408405
///
409-
/// However, it requires both `dxcompiler.dll` and `dxil.dll` to be shipped with the application.
406+
/// However, it requires `dxcompiler.dll` to be shipped with the application.
410407
/// These files can be downloaded from <https://github.com/microsoft/DirectXShaderCompiler/releases>.
411408
///
412-
/// Minimum supported version: [v1.5.2010](https://github.com/microsoft/DirectXShaderCompiler/releases/tag/v1.5.2010)
409+
/// Minimum supported version: [v1.8.2502](https://github.com/microsoft/DirectXShaderCompiler/releases/tag/v1.8.2502)
413410
///
414411
/// It also requires WDDM 2.1 (Windows 10 version 1607).
415412
DynamicDxc {
416413
/// Path to `dxcompiler.dll`.
417414
dxc_path: String,
418-
/// Path to `dxil.dll`.
419-
dxil_path: String,
420415
/// Maximum shader model the given dll supports.
421416
max_shader_model: DxcShaderModel,
422417
},
@@ -430,12 +425,11 @@ pub enum Dx12Compiler {
430425
impl Dx12Compiler {
431426
/// Helper function to construct a `DynamicDxc` variant with default paths.
432427
///
433-
/// The dll must support at least shader model 6.5.
428+
/// The dll must support at least shader model 6.8.
434429
pub fn default_dynamic_dxc() -> Self {
435430
Self::DynamicDxc {
436431
dxc_path: String::from("dxcompiler.dll"),
437-
dxil_path: String::from("dxil.dll"),
438-
max_shader_model: DxcShaderModel::V6_5,
432+
max_shader_model: DxcShaderModel::V6_7, // should be 6.8 but the variant is missing
439433
}
440434
}
441435

wgpu/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ serde = ["wgpu-core?/serde", "wgpu-types/serde"]
121121
## Enables statically linking DXC.
122122
##
123123
## Normally, to use the modern DXC shader compiler with WGPU, the final application
124-
## must be shipped alongside `dxcompiler.dll` and `dxil.dll` (which can be downloaded from [Microsoft's GitHub][dxc]).
124+
## must be shipped alongside `dxcompiler.dll` (min v1.8.2502) (which can be downloaded from [Microsoft's GitHub][dxc]).
125125
## This feature statically links a version of DXC so that no external binaries are required
126126
## to compile DX12 shaders.
127127
##

0 commit comments

Comments
 (0)