mirror of
https://github.com/gfx-rs/wgpu.git
synced 2025-04-16 05:56:37 +00:00
add max_shader_model
to Dx12Compiler
(#7167)
This commit is contained in:
parent
e590555a8c
commit
b5e32cec58
@ -159,7 +159,7 @@ gpu-descriptor = "0.3"
|
||||
# DX12 dependencies
|
||||
gpu-allocator = { version = "0.27", default-features = false }
|
||||
range-alloc = "0.1"
|
||||
mach-dxcompiler-rs = { version = "0.1.4", default-features = false }
|
||||
mach-dxcompiler-rs = { version = "0.1.4", default-features = false } # remember to increase max_shader_model if applicable
|
||||
windows-core = { version = "0.58", default-features = false }
|
||||
|
||||
# Gles dependencies
|
||||
|
@ -226,9 +226,18 @@ impl super::Adapter {
|
||||
}
|
||||
};
|
||||
|
||||
let shader_model = if dxc_container.is_none() {
|
||||
naga::back::hlsl::ShaderModel::V5_1
|
||||
} else {
|
||||
let shader_model = if let Some(ref dxc_container) = dxc_container {
|
||||
let max_shader_model = match dxc_container.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,
|
||||
wgt::DxcShaderModel::V6_3 => Direct3D12::D3D_SHADER_MODEL_6_3,
|
||||
wgt::DxcShaderModel::V6_4 => Direct3D12::D3D_SHADER_MODEL_6_4,
|
||||
wgt::DxcShaderModel::V6_5 => Direct3D12::D3D_SHADER_MODEL_6_5,
|
||||
wgt::DxcShaderModel::V6_6 => Direct3D12::D3D_SHADER_MODEL_6_6,
|
||||
wgt::DxcShaderModel::V6_7 => Direct3D12::D3D_SHADER_MODEL_6_7,
|
||||
};
|
||||
|
||||
let mut versions = [
|
||||
Direct3D12::D3D_SHADER_MODEL_6_7,
|
||||
Direct3D12::D3D_SHADER_MODEL_6_6,
|
||||
@ -239,7 +248,8 @@ impl super::Adapter {
|
||||
Direct3D12::D3D_SHADER_MODEL_6_1,
|
||||
Direct3D12::D3D_SHADER_MODEL_6_0,
|
||||
]
|
||||
.iter();
|
||||
.iter()
|
||||
.filter(|shader_model| shader_model.0 <= max_shader_model.0);
|
||||
|
||||
let highest_shader_model = loop {
|
||||
if let Some(&sm) = versions.next() {
|
||||
@ -274,6 +284,8 @@ impl super::Adapter {
|
||||
Direct3D12::D3D_SHADER_MODEL_6_7 => naga::back::hlsl::ShaderModel::V6_7,
|
||||
_ => unreachable!(),
|
||||
}
|
||||
} else {
|
||||
naga::back::hlsl::ShaderModel::V5_1
|
||||
};
|
||||
let private_caps = super::PrivateCapabilities {
|
||||
instance_flags,
|
||||
|
@ -71,10 +71,12 @@ impl crate::Instance for super::Instance {
|
||||
wgt::Dx12Compiler::DynamicDxc {
|
||||
dxil_path,
|
||||
dxc_path,
|
||||
max_shader_model,
|
||||
} => {
|
||||
let container = super::shader_compilation::get_dynamic_dxc_container(
|
||||
dxc_path.into(),
|
||||
dxil_path.into(),
|
||||
max_shader_model,
|
||||
)
|
||||
.map_err(|e| {
|
||||
crate::InstanceError::with_source(String::from("Failed to load dynamic DXC"), e)
|
||||
|
@ -135,6 +135,7 @@ unsafe fn dxc_create_instance<T: DxcObj>(
|
||||
|
||||
// Destructor order should be fine since _dxil and _dxc don't rely on each other.
|
||||
pub(super) struct DxcContainer {
|
||||
pub(super) max_shader_model: wgt::DxcShaderModel,
|
||||
compiler: Dxc::IDxcCompiler3,
|
||||
utils: Dxc::IDxcUtils,
|
||||
validator: Option<Dxc::IDxcValidator>,
|
||||
@ -157,6 +158,7 @@ pub(super) enum GetDynamicDXCContainerError {
|
||||
pub(super) fn get_dynamic_dxc_container(
|
||||
dxc_path: PathBuf,
|
||||
dxil_path: PathBuf,
|
||||
max_shader_model: wgt::DxcShaderModel,
|
||||
) -> Result<DxcContainer, GetDynamicDXCContainerError> {
|
||||
let dxc = DxcLib::new_dynamic(dxc_path)
|
||||
.map_err(|e| GetDynamicDXCContainerError::FailedToLoad("dxcompiler.dll", e))?;
|
||||
@ -169,6 +171,7 @@ pub(super) fn get_dynamic_dxc_container(
|
||||
let validator = dxil.create_instance::<Dxc::IDxcValidator>()?;
|
||||
|
||||
Ok(DxcContainer {
|
||||
max_shader_model,
|
||||
compiler,
|
||||
utils,
|
||||
validator: Some(validator),
|
||||
@ -198,6 +201,7 @@ pub(super) fn get_static_dxc_container() -> Result<DxcContainer, crate::DeviceEr
|
||||
})?;
|
||||
|
||||
Ok(DxcContainer {
|
||||
max_shader_model: wgt::DxcShaderModel::V6_7,
|
||||
compiler,
|
||||
utils,
|
||||
validator: None,
|
||||
|
@ -337,6 +337,20 @@ impl NoopBackendOptions {
|
||||
}
|
||||
}
|
||||
|
||||
/// DXC shader model.
|
||||
#[derive(Clone, Debug)]
|
||||
#[allow(missing_docs)]
|
||||
pub enum DxcShaderModel {
|
||||
V6_0,
|
||||
V6_1,
|
||||
V6_2,
|
||||
V6_3,
|
||||
V6_4,
|
||||
V6_5,
|
||||
V6_6,
|
||||
V6_7,
|
||||
}
|
||||
|
||||
/// Selects which DX12 shader compiler to use.
|
||||
///
|
||||
/// If the `DynamicDxc` option is selected, but `dxcompiler.dll` and `dxil.dll` files aren't found,
|
||||
@ -361,6 +375,8 @@ pub enum Dx12Compiler {
|
||||
dxc_path: String,
|
||||
/// Path to `dxil.dll`.
|
||||
dxil_path: String,
|
||||
/// Maximum shader model the given dll supports.
|
||||
max_shader_model: DxcShaderModel,
|
||||
},
|
||||
/// The statically-linked variant of Dxc.
|
||||
///
|
||||
@ -371,10 +387,13 @@ pub enum Dx12Compiler {
|
||||
|
||||
impl Dx12Compiler {
|
||||
/// Helper function to construct a `DynamicDxc` variant with default paths.
|
||||
///
|
||||
/// The dll must support at least shader model 6.5.
|
||||
pub fn default_dynamic_dxc() -> Self {
|
||||
Self::DynamicDxc {
|
||||
dxc_path: String::from("dxcompiler.dll"),
|
||||
dxil_path: String::from("dxil.dll"),
|
||||
max_shader_model: DxcShaderModel::V6_5,
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,16 +64,16 @@ pub use wgt::{
|
||||
Color, ColorTargetState, ColorWrites, CommandBufferDescriptor, CompareFunction,
|
||||
CompositeAlphaMode, CopyExternalImageDestInfo, CoreCounters, DepthBiasState, DepthStencilState,
|
||||
DeviceLostReason, DeviceType, DownlevelCapabilities, DownlevelFlags, DownlevelLimits,
|
||||
Dx12BackendOptions, Dx12Compiler, DynamicOffset, Extent3d, Face, Features, FeaturesWGPU,
|
||||
FeaturesWebGPU, FilterMode, FrontFace, GlBackendOptions, GlFenceBehavior, Gles3MinorVersion,
|
||||
HalCounters, ImageSubresourceRange, IndexFormat, InstanceDescriptor, InstanceFlags,
|
||||
InternalCounters, Limits, MemoryHints, MultisampleState, NoopBackendOptions, Origin2d,
|
||||
Origin3d, PipelineStatisticsTypes, PollError, PollStatus, PolygonMode, PowerPreference,
|
||||
PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState, PrimitiveTopology,
|
||||
PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBindingType, SamplerBorderColor,
|
||||
ShaderLocation, ShaderModel, ShaderRuntimeChecks, ShaderStages, StencilFaceState,
|
||||
StencilOperation, StencilState, StorageTextureAccess, SurfaceCapabilities, SurfaceStatus,
|
||||
TexelCopyBufferLayout, TextureAspect, TextureDimension, TextureFormat,
|
||||
Dx12BackendOptions, Dx12Compiler, DxcShaderModel, DynamicOffset, Extent3d, Face, Features,
|
||||
FeaturesWGPU, FeaturesWebGPU, FilterMode, FrontFace, GlBackendOptions, GlFenceBehavior,
|
||||
Gles3MinorVersion, HalCounters, ImageSubresourceRange, IndexFormat, InstanceDescriptor,
|
||||
InstanceFlags, InternalCounters, Limits, MemoryHints, MultisampleState, NoopBackendOptions,
|
||||
Origin2d, Origin3d, PipelineStatisticsTypes, PollError, PollStatus, PolygonMode,
|
||||
PowerPreference, PredefinedColorSpace, PresentMode, PresentationTimestamp, PrimitiveState,
|
||||
PrimitiveTopology, PushConstantRange, QueryType, RenderBundleDepthStencil, SamplerBindingType,
|
||||
SamplerBorderColor, ShaderLocation, ShaderModel, ShaderRuntimeChecks, ShaderStages,
|
||||
StencilFaceState, StencilOperation, StencilState, StorageTextureAccess, SurfaceCapabilities,
|
||||
SurfaceStatus, TexelCopyBufferLayout, TextureAspect, TextureDimension, TextureFormat,
|
||||
TextureFormatFeatureFlags, TextureFormatFeatures, TextureSampleType, TextureTransition,
|
||||
TextureUsages, TextureUses, TextureViewDimension, VertexAttribute, VertexFormat,
|
||||
VertexStepMode, WasmNotSend, WasmNotSendSync, WasmNotSync, COPY_BUFFER_ALIGNMENT,
|
||||
|
Loading…
Reference in New Issue
Block a user