From 9e6fdd8b6fb9a5f8d2b295351d9a31492cb4d035 Mon Sep 17 00:00:00 2001 From: Jacob Hughes Date: Sat, 30 Sep 2023 18:33:19 -0400 Subject: [PATCH] Adds feature detection for Vulkan. --- wgpu-hal/src/vulkan/adapter.rs | 46 +++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) diff --git a/wgpu-hal/src/vulkan/adapter.rs b/wgpu-hal/src/vulkan/adapter.rs index 5ad8e40023..a2e6633126 100644 --- a/wgpu-hal/src/vulkan/adapter.rs +++ b/wgpu-hal/src/vulkan/adapter.rs @@ -488,6 +488,24 @@ impl PhysicalDeviceFeatures { ); } + if let Some(ref subgroup) = caps.subgroup { + features.set( + F::SUBGROUP_OPERATIONS, + subgroup.supported_operations.contains( + vk::SubgroupFeatureFlags::BASIC + | vk::SubgroupFeatureFlags::VOTE + | vk::SubgroupFeatureFlags::ARITHMETIC + | vk::SubgroupFeatureFlags::BALLOT + | vk::SubgroupFeatureFlags::SHUFFLE + | vk::SubgroupFeatureFlags::SHUFFLE_RELATIVE + | vk::SubgroupFeatureFlags::CLUSTERED + | vk::SubgroupFeatureFlags::QUAD, + ) && subgroup + .supported_stages + .contains(vk::ShaderStageFlags::COMPUTE | vk::ShaderStageFlags::FRAGMENT), + ); + } + let supports_depth_format = |format| { supports_format( instance, @@ -550,6 +568,8 @@ pub struct PhysicalDeviceCapabilities { maintenance_3: Option, descriptor_indexing: Option, driver: Option, + subgroup: Option, + /// The effective driver api version supported by the physical device. /// The device API version. /// /// Which is the version of Vulkan supported for device-level functionality. @@ -815,6 +835,13 @@ impl super::InstanceShared { builder = builder.push_next(next); } + if capabilities.device_api_version >= vk::API_VERSION_1_1 { + let next = capabilities + .subgroup + .insert(vk::PhysicalDeviceSubgroupProperties::default()); + builder = builder.push_next(next); + } + let mut properties2 = builder.build(); unsafe { get_device_properties.get_physical_device_properties2(phd, &mut properties2); @@ -1251,6 +1278,19 @@ impl super::Adapter { capabilities.push(spv::Capability::Geometry); } + if features.contains(wgt::Features::SUBGROUP_OPERATIONS) { + capabilities.push(spv::Capability::GroupNonUniform); + capabilities.push(spv::Capability::GroupNonUniformVote); + capabilities.push(spv::Capability::GroupNonUniformArithmetic); + capabilities.push(spv::Capability::GroupNonUniformBallot); + capabilities.push(spv::Capability::GroupNonUniformShuffle); + capabilities.push(spv::Capability::GroupNonUniformShuffleRelative); + capabilities.push(spv::Capability::GroupNonUniformClustered); + capabilities.push(spv::Capability::GroupNonUniformQuad); + capabilities.push(spv::Capability::SubgroupBallotKHR); + capabilities.push(spv::Capability::SubgroupVoteKHR); + } + if features.intersects( wgt::Features::SAMPLED_TEXTURE_AND_STORAGE_BUFFER_ARRAY_NON_UNIFORM_INDEXING | wgt::Features::UNIFORM_BUFFER_AND_STORAGE_TEXTURE_ARRAY_NON_UNIFORM_INDEXING, @@ -1278,7 +1318,11 @@ impl super::Adapter { true, // could check `super::Workarounds::SEPARATE_ENTRY_POINTS` ); spv::Options { - lang_version: (1, 0), + lang_version: if features.contains(wgt::Features::SUBGROUP_OPERATIONS) { + (1, 3) + } else { + (1, 0) + }, flags, capabilities: Some(capabilities.iter().cloned().collect()), bounds_check_policies: naga::proc::BoundsCheckPolicies {