diff options
Diffstat (limited to 'third_party/rust/wgpu-hal/src/dx12')
-rw-r--r-- | third_party/rust/wgpu-hal/src/dx12/adapter.rs | 99 | ||||
-rw-r--r-- | third_party/rust/wgpu-hal/src/dx12/conv.rs | 2 | ||||
-rw-r--r-- | third_party/rust/wgpu-hal/src/dx12/device.rs | 33 | ||||
-rw-r--r-- | third_party/rust/wgpu-hal/src/dx12/mod.rs | 3 | ||||
-rw-r--r-- | third_party/rust/wgpu-hal/src/dx12/types.rs | 22 |
5 files changed, 120 insertions, 39 deletions
diff --git a/third_party/rust/wgpu-hal/src/dx12/adapter.rs b/third_party/rust/wgpu-hal/src/dx12/adapter.rs index b417a88a6f..faf25cc852 100644 --- a/third_party/rust/wgpu-hal/src/dx12/adapter.rs +++ b/third_party/rust/wgpu-hal/src/dx12/adapter.rs @@ -115,18 +115,6 @@ impl super::Adapter { ) }); - let mut shader_model_support: d3d12_ty::D3D12_FEATURE_DATA_SHADER_MODEL = - d3d12_ty::D3D12_FEATURE_DATA_SHADER_MODEL { - HighestShaderModel: d3d12_ty::D3D_SHADER_MODEL_6_0, - }; - assert_eq!(0, unsafe { - device.CheckFeatureSupport( - d3d12_ty::D3D12_FEATURE_SHADER_MODEL, - &mut shader_model_support as *mut _ as *mut _, - mem::size_of::<d3d12_ty::D3D12_FEATURE_DATA_SHADER_MODEL>() as _, - ) - }); - let mut workarounds = super::Workarounds::default(); let info = wgt::AdapterInfo { @@ -181,6 +169,53 @@ impl super::Adapter { hr == 0 && features3.CastingFullyTypedFormatSupported != 0 }; + let shader_model = if dxc_container.is_none() { + naga::back::hlsl::ShaderModel::V5_1 + } else { + let mut versions = [ + crate::dx12::types::D3D_SHADER_MODEL_6_7, + crate::dx12::types::D3D_SHADER_MODEL_6_6, + crate::dx12::types::D3D_SHADER_MODEL_6_5, + crate::dx12::types::D3D_SHADER_MODEL_6_4, + crate::dx12::types::D3D_SHADER_MODEL_6_3, + crate::dx12::types::D3D_SHADER_MODEL_6_2, + crate::dx12::types::D3D_SHADER_MODEL_6_1, + crate::dx12::types::D3D_SHADER_MODEL_6_0, + crate::dx12::types::D3D_SHADER_MODEL_5_1, + ] + .iter(); + match loop { + if let Some(&sm) = versions.next() { + let mut sm = crate::dx12::types::D3D12_FEATURE_DATA_SHADER_MODEL { + HighestShaderModel: sm, + }; + if 0 == unsafe { + device.CheckFeatureSupport( + 7, // D3D12_FEATURE_SHADER_MODEL + &mut sm as *mut _ as *mut _, + mem::size_of::<crate::dx12::types::D3D12_FEATURE_DATA_SHADER_MODEL>() + as _, + ) + } { + break sm.HighestShaderModel; + } + } else { + break crate::dx12::types::D3D_SHADER_MODEL_5_1; + } + } { + crate::dx12::types::D3D_SHADER_MODEL_5_1 => naga::back::hlsl::ShaderModel::V5_1, + crate::dx12::types::D3D_SHADER_MODEL_6_0 => naga::back::hlsl::ShaderModel::V6_0, + crate::dx12::types::D3D_SHADER_MODEL_6_1 => naga::back::hlsl::ShaderModel::V6_1, + crate::dx12::types::D3D_SHADER_MODEL_6_2 => naga::back::hlsl::ShaderModel::V6_2, + crate::dx12::types::D3D_SHADER_MODEL_6_3 => naga::back::hlsl::ShaderModel::V6_3, + crate::dx12::types::D3D_SHADER_MODEL_6_4 => naga::back::hlsl::ShaderModel::V6_4, + crate::dx12::types::D3D_SHADER_MODEL_6_5 => naga::back::hlsl::ShaderModel::V6_5, + crate::dx12::types::D3D_SHADER_MODEL_6_6 => naga::back::hlsl::ShaderModel::V6_6, + crate::dx12::types::D3D_SHADER_MODEL_6_7 => naga::back::hlsl::ShaderModel::V6_7, + _ => unreachable!(), + } + }; + let private_caps = super::PrivateCapabilities { instance_flags, heterogeneous_resource_heaps: options.ResourceHeapTier @@ -196,6 +231,7 @@ impl super::Adapter { casting_fully_typed_format_supported, // See https://github.com/gfx-rs/wgpu/issues/3552 suballocation_supported: !info.name.contains("Iris(R) Xe"), + shader_model, }; // Theoretically vram limited, but in practice 2^20 is the limit @@ -273,7 +309,7 @@ impl super::Adapter { wgt::Features::TEXTURE_BINDING_ARRAY | wgt::Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING | wgt::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING, - shader_model_support.HighestShaderModel >= d3d12_ty::D3D_SHADER_MODEL_5_1, + shader_model >= naga::back::hlsl::ShaderModel::V5_1, ); let bgra8unorm_storage_supported = { @@ -295,21 +331,28 @@ impl super::Adapter { bgra8unorm_storage_supported, ); - // we must be using DXC because uint64_t was added with Shader Model 6 - // and FXC only supports up to 5.1 - let int64_shader_ops_supported = dxc_container.is_some() && { - let mut features1: d3d12_ty::D3D12_FEATURE_DATA_D3D12_OPTIONS1 = - unsafe { mem::zeroed() }; - let hr = unsafe { - device.CheckFeatureSupport( - d3d12_ty::D3D12_FEATURE_D3D12_OPTIONS1, - &mut features1 as *mut _ as *mut _, - mem::size_of::<d3d12_ty::D3D12_FEATURE_DATA_D3D12_OPTIONS1>() as _, - ) - }; - hr == 0 && features1.Int64ShaderOps != 0 + let mut features1: d3d12_ty::D3D12_FEATURE_DATA_D3D12_OPTIONS1 = unsafe { mem::zeroed() }; + let hr = unsafe { + device.CheckFeatureSupport( + d3d12_ty::D3D12_FEATURE_D3D12_OPTIONS1, + &mut features1 as *mut _ as *mut _, + mem::size_of::<d3d12_ty::D3D12_FEATURE_DATA_D3D12_OPTIONS1>() as _, + ) }; - features.set(wgt::Features::SHADER_INT64, int64_shader_ops_supported); + + features.set( + wgt::Features::SHADER_INT64, + shader_model >= naga::back::hlsl::ShaderModel::V6_0 + && hr == 0 + && features1.Int64ShaderOps != 0, + ); + + features.set( + wgt::Features::SUBGROUP, + shader_model >= naga::back::hlsl::ShaderModel::V6_0 + && hr == 0 + && features1.WaveOps != 0, + ); // float32-filterable should always be available on d3d12 features.set(wgt::Features::FLOAT32_FILTERABLE, true); @@ -377,6 +420,8 @@ impl super::Adapter { .min(crate::MAX_VERTEX_BUFFERS as u32), max_vertex_attributes: d3d12_ty::D3D12_IA_VERTEX_INPUT_RESOURCE_SLOT_COUNT, max_vertex_buffer_array_stride: d3d12_ty::D3D12_SO_BUFFER_MAX_STRIDE_IN_BYTES, + min_subgroup_size: 4, // Not using `features1.WaveLaneCountMin` as it is unreliable + max_subgroup_size: 128, // The push constants are part of the root signature which // has a limit of 64 DWORDS (256 bytes), but other resources // also share the root signature: diff --git a/third_party/rust/wgpu-hal/src/dx12/conv.rs b/third_party/rust/wgpu-hal/src/dx12/conv.rs index 2b6c1d959e..b09ea76080 100644 --- a/third_party/rust/wgpu-hal/src/dx12/conv.rs +++ b/third_party/rust/wgpu-hal/src/dx12/conv.rs @@ -224,7 +224,7 @@ pub fn map_polygon_mode(mode: wgt::PolygonMode) -> d3d12_ty::D3D12_FILL_MODE { } /// D3D12 doesn't support passing factors ending in `_COLOR` for alpha blending -/// (see https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_render_target_blend_desc). +/// (see <https://learn.microsoft.com/en-us/windows/win32/api/d3d12/ns-d3d12-d3d12_render_target_blend_desc>). /// Therefore this function takes an additional `is_alpha` argument /// which if set will return an equivalent `_ALPHA` factor. fn map_blend_factor(factor: wgt::BlendFactor, is_alpha: bool) -> d3d12_ty::D3D12_BLEND { diff --git a/third_party/rust/wgpu-hal/src/dx12/device.rs b/third_party/rust/wgpu-hal/src/dx12/device.rs index 23bd409dc4..82075294ee 100644 --- a/third_party/rust/wgpu-hal/src/dx12/device.rs +++ b/third_party/rust/wgpu-hal/src/dx12/device.rs @@ -218,21 +218,39 @@ impl super::Device { use naga::back::hlsl; let stage_bit = crate::auxil::map_naga_stage(naga_stage); - let module = &stage.module.naga.module; + + let (module, info) = naga::back::pipeline_constants::process_overrides( + &stage.module.naga.module, + &stage.module.naga.info, + stage.constants, + ) + .map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("HLSL: {e:?}")))?; + + let needs_temp_options = stage.zero_initialize_workgroup_memory + != layout.naga_options.zero_initialize_workgroup_memory; + let mut temp_options; + let naga_options = if needs_temp_options { + temp_options = layout.naga_options.clone(); + temp_options.zero_initialize_workgroup_memory = stage.zero_initialize_workgroup_memory; + &temp_options + } else { + &layout.naga_options + }; + //TODO: reuse the writer let mut source = String::new(); - let mut writer = hlsl::Writer::new(&mut source, &layout.naga_options); + let mut writer = hlsl::Writer::new(&mut source, naga_options); let reflection_info = { profiling::scope!("naga::back::hlsl::write"); writer - .write(module, &stage.module.naga.info) + .write(&module, &info) .map_err(|e| crate::PipelineError::Linkage(stage_bit, format!("HLSL: {e:?}")))? }; let full_stage = format!( "{}_{}\0", naga_stage.to_hlsl_str(), - layout.naga_options.shader_model.to_str() + naga_options.shader_model.to_str() ); let ep_index = module @@ -1062,12 +1080,7 @@ impl crate::Device for super::Device { }, bind_group_infos, naga_options: hlsl::Options { - shader_model: match self.dxc_container { - // DXC - Some(_) => hlsl::ShaderModel::V6_0, - // FXC doesn't support SM 6.0 - None => hlsl::ShaderModel::V5_1, - }, + shader_model: self.private_caps.shader_model, binding_map, fake_missing_bindings: false, special_constants_binding, diff --git a/third_party/rust/wgpu-hal/src/dx12/mod.rs b/third_party/rust/wgpu-hal/src/dx12/mod.rs index 4f958943ca..9f021bc241 100644 --- a/third_party/rust/wgpu-hal/src/dx12/mod.rs +++ b/third_party/rust/wgpu-hal/src/dx12/mod.rs @@ -195,6 +195,7 @@ struct PrivateCapabilities { heap_create_not_zeroed: bool, casting_fully_typed_format_supported: bool, suballocation_supported: bool, + shader_model: naga::back::hlsl::ShaderModel, } #[derive(Default)] @@ -439,7 +440,7 @@ impl Texture { } } - /// see https://learn.microsoft.com/en-us/windows/win32/direct3d12/subresources#plane-slice + /// see <https://learn.microsoft.com/en-us/windows/win32/direct3d12/subresources#plane-slice> fn calc_subresource(&self, mip_level: u32, array_layer: u32, plane: u32) -> u32 { mip_level + (array_layer + plane * self.array_layer_count()) * self.mip_level_count } diff --git a/third_party/rust/wgpu-hal/src/dx12/types.rs b/third_party/rust/wgpu-hal/src/dx12/types.rs index b4ad38324a..17b608b840 100644 --- a/third_party/rust/wgpu-hal/src/dx12/types.rs +++ b/third_party/rust/wgpu-hal/src/dx12/types.rs @@ -41,3 +41,25 @@ winapi::STRUCT! { BarycentricsSupported: winapi::shared::minwindef::BOOL, } } + +winapi::ENUM! { + enum D3D_SHADER_MODEL { + D3D_SHADER_MODEL_NONE = 0, + D3D_SHADER_MODEL_5_1 = 0x51, + D3D_SHADER_MODEL_6_0 = 0x60, + D3D_SHADER_MODEL_6_1 = 0x61, + D3D_SHADER_MODEL_6_2 = 0x62, + D3D_SHADER_MODEL_6_3 = 0x63, + D3D_SHADER_MODEL_6_4 = 0x64, + D3D_SHADER_MODEL_6_5 = 0x65, + D3D_SHADER_MODEL_6_6 = 0x66, + D3D_SHADER_MODEL_6_7 = 0x67, + D3D_HIGHEST_SHADER_MODEL = 0x67, + } +} + +winapi::STRUCT! { + struct D3D12_FEATURE_DATA_SHADER_MODEL { + HighestShaderModel: D3D_SHADER_MODEL, + } +} |