diff --git a/Cargo.toml b/Cargo.toml index 7c87436c02..926d3bd53b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 12ad6da619..370b842ade 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -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, diff --git a/wgpu-hal/src/dx12/instance.rs b/wgpu-hal/src/dx12/instance.rs index 3a87e2617a..68d988da37 100644 --- a/wgpu-hal/src/dx12/instance.rs +++ b/wgpu-hal/src/dx12/instance.rs @@ -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) diff --git a/wgpu-hal/src/dx12/shader_compilation.rs b/wgpu-hal/src/dx12/shader_compilation.rs index 81e51b83d1..957bd8c3c4 100644 --- a/wgpu-hal/src/dx12/shader_compilation.rs +++ b/wgpu-hal/src/dx12/shader_compilation.rs @@ -135,6 +135,7 @@ unsafe fn dxc_create_instance( // 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, @@ -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 { 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::()?; Ok(DxcContainer { + max_shader_model, compiler, utils, validator: Some(validator), @@ -198,6 +201,7 @@ pub(super) fn get_static_dxc_container() -> Result Self { Self::DynamicDxc { dxc_path: String::from("dxcompiler.dll"), dxil_path: String::from("dxil.dll"), + max_shader_model: DxcShaderModel::V6_5, } } diff --git a/wgpu/src/lib.rs b/wgpu/src/lib.rs index 427d548cac..7b799a2a39 100644 --- a/wgpu/src/lib.rs +++ b/wgpu/src/lib.rs @@ -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,