From 3a004ecf9ab0bb2b3860d3ba0167692f107aa478 Mon Sep 17 00:00:00 2001 From: Dzmitry Malyshau Date: Thu, 29 Jul 2021 01:03:18 -0400 Subject: [PATCH] hal/dx12: fix depth formats and pipeline layout --- wgpu-hal/src/dx12/adapter.rs | 3 +++ wgpu-hal/src/dx12/conv.rs | 10 ++++++++++ wgpu-hal/src/dx12/device.rs | 18 ++++++++++++++++-- 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 13b78198b..97be281a0 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -121,6 +121,9 @@ impl super::Adapter { hr == 0 && features2.DepthBoundsTestSupported != 0 }; + //Note: `D3D12_FEATURE_D3D12_OPTIONS3::CastingFullyTypedFormatSupported` can be checked + // to know if we can skip "typeless" formats entirely. + let private_caps = super::PrivateCapabilities { instance_flags, heterogeneous_resource_heaps: options.ResourceHeapTier diff --git a/wgpu-hal/src/dx12/conv.rs b/wgpu-hal/src/dx12/conv.rs index b416ff69e..ea810d9f9 100644 --- a/wgpu-hal/src/dx12/conv.rs +++ b/wgpu-hal/src/dx12/conv.rs @@ -129,6 +129,16 @@ pub fn map_texture_format_nodepth(format: wgt::TextureFormat) -> dxgiformat::DXG } } +pub fn map_texture_format_depth_typeless(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT { + match format { + wgt::TextureFormat::Depth32Float => dxgiformat::DXGI_FORMAT_R32_TYPELESS, + wgt::TextureFormat::Depth24Plus | wgt::TextureFormat::Depth24PlusStencil8 => { + dxgiformat::DXGI_FORMAT_R24G8_TYPELESS + } + _ => unreachable!(), + } +} + pub fn map_index_format(format: wgt::IndexFormat) -> dxgiformat::DXGI_FORMAT { match format { wgt::IndexFormat::Uint16 => dxgiformat::DXGI_FORMAT_R16_UINT, diff --git a/wgpu-hal/src/dx12/device.rs b/wgpu-hal/src/dx12/device.rs index a4c7a65be..994348d17 100644 --- a/wgpu-hal/src/dx12/device.rs +++ b/wgpu-hal/src/dx12/device.rs @@ -393,8 +393,20 @@ impl crate::Device for super::Device { Height: desc.size.height, DepthOrArraySize: desc.size.depth_or_array_layers as u16, MipLevels: desc.mip_level_count as u16, - //TODO: map to surface format to allow view casting - Format: conv::map_texture_format(desc.format), + Format: if crate::FormatAspects::from(desc.format).contains(crate::FormatAspects::COLOR) + || !desc.usage.intersects( + crate::TextureUses::RESOURCE + | crate::TextureUses::STORAGE_READ + | crate::TextureUses::STORAGE_WRITE, + ) { + conv::map_texture_format(desc.format) + } else { + // This branch is needed if it's a depth texture, and it's ever needed to be viewed as SRV or UAV, + // because then we'd create a non-depth format view of it. + // Note: we can skip this branch if + // `D3D12_FEATURE_D3D12_OPTIONS3::CastingFullyTypedFormatSupported` + conv::map_texture_format_depth_typeless(desc.format) + }, SampleDesc: dxgitype::DXGI_SAMPLE_DESC { Count: desc.sample_count, Quality: 0, @@ -912,6 +924,8 @@ impl crate::Device for super::Device { bind_group_infos.push(info); } + //Note: we populated them in reverse + bind_group_infos.reverse(); // Ensure that we didn't reallocate! debug_assert_eq!(ranges.len(), total_non_dynamic_entries);