hal/dx12: fix depth formats and pipeline layout

This commit is contained in:
Dzmitry Malyshau 2021-07-29 01:03:18 -04:00 committed by Dzmitry Malyshau
parent b79c910b0f
commit 3a004ecf9a
3 changed files with 29 additions and 2 deletions

View File

@ -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

View File

@ -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,

View File

@ -393,8 +393,20 @@ impl crate::Device<super::Api> 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<super::Api> 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);