Skip to content

Commit ef8d842

Browse files
refactor(vulkan): use array iterator + all for tex. fmt. support queries
1 parent b93bab5 commit ef8d842

1 file changed

Lines changed: 54 additions & 59 deletions

File tree

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 54 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -2797,61 +2797,63 @@ impl crate::Adapter for super::Adapter {
27972797
}
27982798

27992799
fn is_format_16bit_norm_supported(instance: &ash::Instance, phd: vk::PhysicalDevice) -> bool {
2800-
let tiling = vk::ImageTiling::OPTIMAL;
2801-
let features = vk::FormatFeatureFlags::SAMPLED_IMAGE
2802-
| vk::FormatFeatureFlags::STORAGE_IMAGE
2803-
| vk::FormatFeatureFlags::TRANSFER_SRC
2804-
| vk::FormatFeatureFlags::TRANSFER_DST;
2805-
let r16unorm = supports_format(instance, phd, vk::Format::R16_UNORM, tiling, features);
2806-
let r16snorm = supports_format(instance, phd, vk::Format::R16_SNORM, tiling, features);
2807-
let rg16unorm = supports_format(instance, phd, vk::Format::R16G16_UNORM, tiling, features);
2808-
let rg16snorm = supports_format(instance, phd, vk::Format::R16G16_SNORM, tiling, features);
2809-
let rgba16unorm = supports_format(
2810-
instance,
2811-
phd,
2800+
[
2801+
vk::Format::R16_UNORM,
2802+
vk::Format::R16_SNORM,
2803+
vk::Format::R16G16_UNORM,
2804+
vk::Format::R16G16_SNORM,
28122805
vk::Format::R16G16B16A16_UNORM,
2813-
tiling,
2814-
features,
2815-
);
2816-
let rgba16snorm = supports_format(
2817-
instance,
2818-
phd,
28192806
vk::Format::R16G16B16A16_SNORM,
2820-
tiling,
2821-
features,
2822-
);
2823-
2824-
r16unorm && r16snorm && rg16unorm && rg16snorm && rgba16unorm && rgba16snorm
2807+
]
2808+
.into_iter()
2809+
.all(|format| {
2810+
supports_format(
2811+
instance,
2812+
phd,
2813+
format,
2814+
vk::ImageTiling::OPTIMAL,
2815+
vk::FormatFeatureFlags::SAMPLED_IMAGE
2816+
| vk::FormatFeatureFlags::STORAGE_IMAGE
2817+
| vk::FormatFeatureFlags::TRANSFER_SRC
2818+
| vk::FormatFeatureFlags::TRANSFER_DST,
2819+
)
2820+
})
28252821
}
28262822

28272823
fn is_float32_filterable_supported(instance: &ash::Instance, phd: vk::PhysicalDevice) -> bool {
2828-
let tiling = vk::ImageTiling::OPTIMAL;
2829-
let features = vk::FormatFeatureFlags::SAMPLED_IMAGE_FILTER_LINEAR;
2830-
let r_float = supports_format(instance, phd, vk::Format::R32_SFLOAT, tiling, features);
2831-
let rg_float = supports_format(instance, phd, vk::Format::R32G32_SFLOAT, tiling, features);
2832-
let rgba_float = supports_format(
2833-
instance,
2834-
phd,
2824+
[
2825+
vk::Format::R32_SFLOAT,
2826+
vk::Format::R32G32_SFLOAT,
28352827
vk::Format::R32G32B32A32_SFLOAT,
2836-
tiling,
2837-
features,
2838-
);
2839-
r_float && rg_float && rgba_float
2828+
]
2829+
.into_iter()
2830+
.all(|format| {
2831+
supports_format(
2832+
instance,
2833+
phd,
2834+
format,
2835+
vk::ImageTiling::OPTIMAL,
2836+
vk::FormatFeatureFlags::SAMPLED_IMAGE_FILTER_LINEAR,
2837+
)
2838+
})
28402839
}
28412840

28422841
fn is_float32_blendable_supported(instance: &ash::Instance, phd: vk::PhysicalDevice) -> bool {
2843-
let tiling = vk::ImageTiling::OPTIMAL;
2844-
let features = vk::FormatFeatureFlags::COLOR_ATTACHMENT_BLEND;
2845-
let r_float = supports_format(instance, phd, vk::Format::R32_SFLOAT, tiling, features);
2846-
let rg_float = supports_format(instance, phd, vk::Format::R32G32_SFLOAT, tiling, features);
2847-
let rgba_float = supports_format(
2848-
instance,
2849-
phd,
2842+
[
2843+
vk::Format::R32_SFLOAT,
2844+
vk::Format::R32G32_SFLOAT,
28502845
vk::Format::R32G32B32A32_SFLOAT,
2851-
tiling,
2852-
features,
2853-
);
2854-
r_float && rg_float && rgba_float
2846+
]
2847+
.into_iter()
2848+
.all(|format| {
2849+
supports_format(
2850+
instance,
2851+
phd,
2852+
format,
2853+
vk::ImageTiling::OPTIMAL,
2854+
vk::FormatFeatureFlags::COLOR_ATTACHMENT_BLEND,
2855+
)
2856+
})
28552857
}
28562858

28572859
fn supports_format(
@@ -2870,9 +2872,7 @@ fn supports_format(
28702872
}
28712873

28722874
fn supports_astc_3d(instance: &ash::Instance, phd: vk::PhysicalDevice) -> bool {
2873-
let mut supports = true;
2874-
2875-
let astc_formats = [
2875+
[
28762876
vk::Format::ASTC_4X4_UNORM_BLOCK,
28772877
vk::Format::ASTC_4X4_SRGB_BLOCK,
28782878
vk::Format::ASTC_5X4_UNORM_BLOCK,
@@ -2901,10 +2901,10 @@ fn supports_astc_3d(instance: &ash::Instance, phd: vk::PhysicalDevice) -> bool {
29012901
vk::Format::ASTC_12X10_SRGB_BLOCK,
29022902
vk::Format::ASTC_12X12_UNORM_BLOCK,
29032903
vk::Format::ASTC_12X12_SRGB_BLOCK,
2904-
];
2905-
2906-
for &format in &astc_formats {
2907-
let result = unsafe {
2904+
]
2905+
.into_iter()
2906+
.all(|format| {
2907+
unsafe {
29082908
instance.get_physical_device_image_format_properties(
29092909
phd,
29102910
format,
@@ -2913,14 +2913,9 @@ fn supports_astc_3d(instance: &ash::Instance, phd: vk::PhysicalDevice) -> bool {
29132913
vk::ImageUsageFlags::SAMPLED,
29142914
vk::ImageCreateFlags::empty(),
29152915
)
2916-
};
2917-
if result.is_err() {
2918-
supports = false;
2919-
break;
29202916
}
2921-
}
2922-
2923-
supports
2917+
.is_ok()
2918+
})
29242919
}
29252920

29262921
fn supports_bgra8unorm_storage(

0 commit comments

Comments
 (0)