Skip to content

Commit

Permalink
Adds feature detection for Vulkan.
Browse files Browse the repository at this point in the history
  • Loading branch information
exrook committed Oct 23, 2023
1 parent e7f4d79 commit 9e6fdd8
Showing 1 changed file with 45 additions and 1 deletion.
46 changes: 45 additions & 1 deletion wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -550,6 +568,8 @@ pub struct PhysicalDeviceCapabilities {
maintenance_3: Option<vk::PhysicalDeviceMaintenance3Properties>,
descriptor_indexing: Option<vk::PhysicalDeviceDescriptorIndexingPropertiesEXT>,
driver: Option<vk::PhysicalDeviceDriverPropertiesKHR>,
subgroup: Option<vk::PhysicalDeviceSubgroupProperties>,
/// 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.
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9e6fdd8

Please sign in to comment.