Skip to content

Commit ae3159e

Browse files
committed
Sanitize vulkan API version
1 parent d8f1ff7 commit ae3159e

File tree

2 files changed

+15
-4
lines changed

2 files changed

+15
-4
lines changed

wgpu-hal/src/vulkan/adapter.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{borrow::ToOwned as _, collections::BTreeMap, ffi::CStr, sync::Arc, vec
33
use ash::{amd, ext, google, khr, vk};
44
use parking_lot::Mutex;
55

6-
use super::conv;
6+
use super::{conv, remove_variant};
77

88
fn depth_stencil_required_flags() -> vk::FormatFeatureFlags {
99
vk::FormatFeatureFlags::SAMPLED_IMAGE | vk::FormatFeatureFlags::DEPTH_STENCIL_ATTACHMENT
@@ -1021,7 +1021,7 @@ impl PhysicalDeviceProperties {
10211021
//extensions.push(ext::sampler_filter_minmax::NAME);
10221022
}
10231023

1024-
if self.device_api_version < vk::API_VERSION_1_3 {
1024+
if remove_variant(self.device_api_version) < vk::API_VERSION_1_3 {
10251025
// Optional `VK_EXT_image_robustness`
10261026
if self.supports_extension(ext::image_robustness::NAME) {
10271027
extensions.push(ext::image_robustness::NAME);
@@ -2016,7 +2016,7 @@ impl super::Adapter {
20162016
if features.contains(wgt::Features::EXPERIMENTAL_RAY_HIT_VERTEX_RETURN) {
20172017
capabilities.push(spv::Capability::RayQueryPositionFetchKHR)
20182018
}
2019-
if self.phd_capabilities.device_api_version >= vk::API_VERSION_1_3
2019+
if remove_variant(self.phd_capabilities.device_api_version) >= vk::API_VERSION_1_3
20202020
|| enabled_extensions.contains(&khr::shader_integer_dot_product::NAME)
20212021
{
20222022
// See <https://registry.khronos.org/vulkan/specs/latest/man/html/VK_KHR_shader_integer_dot_product.html#_new_spir_v_capabilities>.
@@ -2028,7 +2028,7 @@ impl super::Adapter {
20282028
]);
20292029
}
20302030
spv::Options {
2031-
lang_version: match self.phd_capabilities.device_api_version {
2031+
lang_version: match remove_variant(self.phd_capabilities.device_api_version) {
20322032
// Use maximum supported SPIR-V version according to
20332033
// <https://github.com/KhronosGroup/Vulkan-Docs/blob/19b7651/appendices/spirvenv.adoc?plain=1#L21-L40>.
20342034
vk::API_VERSION_1_0..vk::API_VERSION_1_1 => (1, 0),

wgpu-hal/src/vulkan/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1490,6 +1490,17 @@ fn get_lost_err() -> crate::DeviceError {
14901490
crate::DeviceError::Lost
14911491
}
14921492

1493+
/// Removes the variant bits from the API version number.
1494+
///
1495+
/// Returns `api_version` with the variant bits set to zero. The return value can be compared against
1496+
/// predefined constants like [`vk::API_VERSION_1_0`] (comparing to these constants without removing
1497+
/// the variant bits would make any API versions with nonzero variant appear to be very high).
1498+
///
1499+
/// See <https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#extendingvulkan-coreversions>.
1500+
fn remove_variant(api_version: u32) -> u32 {
1501+
api_version & 0x1fff_ffff // The variant bits are the top 3 bits of the version number.
1502+
}
1503+
14931504
#[derive(Clone, Copy, Pod, Zeroable)]
14941505
#[repr(C)]
14951506
struct RawTlasInstance {

0 commit comments

Comments
 (0)