Skip to content

Commit

Permalink
Add feature for subgroup ballot in fragment and compute shaders
Browse files Browse the repository at this point in the history
  • Loading branch information
exrook committed Sep 30, 2023
1 parent 9a76c48 commit 414f844
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ By @wumpf in [#4147](https://github.com/gfx-rs/wgpu/pull/4147)

- Add `gles_minor_version` field to `wgpu::InstanceDescriptor`. By @PJB3005 in [#3998](https://github.com/gfx-rs/wgpu/pull/3998)
- Re-export Naga. By @exrook in [#4172](https://github.com/gfx-rs/wgpu/pull/4172)
- Subgroup feature. By @exrook in [#4189](https://github.com/gfx-rs/wgpu/pull/4189)

### Changes

Expand Down
26 changes: 25 additions & 1 deletion wgpu-hal/src/vulkan/adapter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -488,6 +488,18 @@ impl PhysicalDeviceFeatures {
);
}

if let Some(ref subgroup) = caps.subgroup {
features.set(
F::SUBGROUP_BALLOT,
subgroup
.supported_operations
.contains(vk::SubgroupFeatureFlags::BALLOT)
&& subgroup
.supported_stages
.contains(vk::ShaderStageFlags::COMPUTE | vk::ShaderStageFlags::FRAGMENT),
);
}

let supports_depth_format = |format| {
supports_format(
instance,
Expand Down Expand Up @@ -545,6 +557,7 @@ 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 Vulkan specification states the following in the documentation for VkPhysicalDeviceProperties:
Expand Down Expand Up @@ -815,6 +828,13 @@ impl super::InstanceShared {
builder = builder.push_next(next);
}

if self.driver_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 @@ -1247,6 +1267,10 @@ impl super::Adapter {
capabilities.push(spv::Capability::Geometry);
}

if features.contains(wgt::Features::SUBGROUP_BALLOT) {
capabilities.push(spv::Capability::GroupNonUniformBallot);
}

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 All @@ -1271,7 +1295,7 @@ impl super::Adapter {
true, // could check `super::Workarounds::SEPARATE_ENTRY_POINTS`
);
spv::Options {
lang_version: (1, 0),
lang_version: (1, 3),
flags,
capabilities: Some(capabilities.iter().cloned().collect()),
bounds_check_policies: naga::proc::BoundsCheckPolicies {
Expand Down
10 changes: 9 additions & 1 deletion wgpu-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,15 @@ bitflags::bitflags! {
/// This is a web and native feature.
const SHADER_F16 = 1 << 8;

// 9..14 available
/// Allows shaders to use the subgroup opteraion built-ins
///
/// Supported Platforms:
/// - Vulkan
///
/// This is a web and native feature.
const SUBGROUP_BALLOT = 1 << 9;

// 10..14 available

// Texture Formats:

Expand Down

0 comments on commit 414f844

Please sign in to comment.