diff --git a/wgpu-hal/src/auxil/dxgi/conv.rs b/wgpu-hal/src/auxil/dxgi/conv.rs index 384775c3e..faf42bc98 100644 --- a/wgpu-hal/src/auxil/dxgi/conv.rs +++ b/wgpu-hal/src/auxil/dxgi/conv.rs @@ -1,10 +1,10 @@ use winapi::shared::dxgiformat; -pub fn map_texture_format(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT { +pub fn map_texture_format_failable(format: wgt::TextureFormat) -> Option { use wgt::TextureFormat as Tf; use winapi::shared::dxgiformat::*; - match format { + Some(match format { Tf::R8Unorm => DXGI_FORMAT_R8_UNORM, Tf::R8Snorm => DXGI_FORMAT_R8_SNORM, Tf::R8Uint => DXGI_FORMAT_R8_UINT, @@ -78,7 +78,14 @@ pub fn map_texture_format(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT | Tf::Astc { block: _, channel: _, - } => unreachable!(), + } => return None, + }) +} + +pub fn map_texture_format(format: wgt::TextureFormat) -> dxgiformat::DXGI_FORMAT { + match map_texture_format_failable(format) { + Some(f) => f, + None => unreachable!(), } } diff --git a/wgpu-hal/src/dx12/adapter.rs b/wgpu-hal/src/dx12/adapter.rs index 0bf3423f9..091a87105 100644 --- a/wgpu-hal/src/dx12/adapter.rs +++ b/wgpu-hal/src/dx12/adapter.rs @@ -336,7 +336,10 @@ impl crate::Adapter for super::Adapter { ) -> crate::TextureFormatCapabilities { use crate::TextureFormatCapabilities as Tfc; - let raw_format = auxil::dxgi::conv::map_texture_format(format); + let raw_format = match auxil::dxgi::conv::map_texture_format_failable(format) { + Some(f) => f, + None => return Tfc::empty(), + }; let mut data = d3d12::D3D12_FEATURE_DATA_FORMAT_SUPPORT { Format: raw_format, Support1: mem::zeroed(), diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 4bfe3fd81..735f6ca36 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -1459,8 +1459,11 @@ impl crate::Adapter for super::Adapter { let properties = self .phd_capabilities .formats - .get(vk_format.as_raw() as usize) - .unwrap(); + .get(vk_format.as_raw() as usize); + let properties = match properties { + Some(p) => p, + None => return Tfc::empty(), + }; let features = properties.optimal_tiling_features; let mut flags = Tfc::empty();