Skip to content

Commit e7ebc1b

Browse files
committed
[wgpu-hal] separate 2 float16-related vk features
Separates the Vulkan feature sets `VkPhysicalDeviceShaderFloat16Int8Features` and `VkPhysicalDevice16BitStorageFeatures`, which previously were used "together, or not at all". This commit should not change any behavior yet, but I'd like to run full CI tests on it for now. If the CI tests pass, I'll use this separation to enable the `shader_int8` feature separately from the rest of the features to enable optimizations of `[un]pack4x{I,U}8[Clamp]` on SPIR-V.
1 parent 62c32b3 commit e7ebc1b

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 32 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -62,13 +62,11 @@ pub struct PhysicalDeviceFeatures {
6262
/// Features provided by `VK_EXT_texture_compression_astc_hdr`, promoted to Vulkan 1.3.
6363
astc_hdr: Option<vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT<'static>>,
6464

65-
/// Features provided by `VK_KHR_shader_float16_int8` (promoted to Vulkan
66-
/// 1.2) and `VK_KHR_16bit_storage` (promoted to Vulkan 1.1). We use these
67-
/// features together, or not at all.
68-
shader_float16: Option<(
69-
vk::PhysicalDeviceShaderFloat16Int8Features<'static>,
70-
vk::PhysicalDevice16BitStorageFeatures<'static>,
71-
)>,
65+
/// Features provided by `VK_KHR_shader_float16_int8`, promoted to Vulkan 1.2
66+
shader_float16_int8: Option<vk::PhysicalDeviceShaderFloat16Int8Features<'static>>,
67+
68+
/// Features provided by `VK_KHR_16bit_storage`, promoted to Vulkan 1.1
69+
features_16bit_storage: Option<vk::PhysicalDevice16BitStorageFeatures<'static>>,
7270

7371
/// Features provided by `VK_KHR_acceleration_structure`.
7472
acceleration_structure: Option<vk::PhysicalDeviceAccelerationStructureFeaturesKHR<'static>>,
@@ -154,9 +152,11 @@ impl PhysicalDeviceFeatures {
154152
if let Some(ref mut feature) = self.astc_hdr {
155153
info = info.push_next(feature);
156154
}
157-
if let Some((ref mut f16_i8_feature, ref mut _16bit_feature)) = self.shader_float16 {
158-
info = info.push_next(f16_i8_feature);
159-
info = info.push_next(_16bit_feature);
155+
if let Some(ref mut feature) = self.shader_float16_int8 {
156+
info = info.push_next(feature);
157+
}
158+
if let Some(ref mut feature) = self.features_16bit_storage {
159+
info = info.push_next(feature);
160160
}
161161
if let Some(ref mut feature) = self.zero_initialize_workgroup_memory {
162162
info = info.push_next(feature);
@@ -386,14 +386,18 @@ impl PhysicalDeviceFeatures {
386386
} else {
387387
None
388388
},
389-
shader_float16: if requested_features.contains(wgt::Features::SHADER_F16) {
390-
Some((
391-
vk::PhysicalDeviceShaderFloat16Int8Features::default().shader_float16(true),
389+
shader_float16_int8: if requested_features.contains(wgt::Features::SHADER_F16) {
390+
Some(vk::PhysicalDeviceShaderFloat16Int8Features::default().shader_float16(true))
391+
} else {
392+
None
393+
},
394+
features_16bit_storage: if requested_features.contains(wgt::Features::SHADER_F16) {
395+
Some(
392396
vk::PhysicalDevice16BitStorageFeatures::default()
393397
.storage_buffer16_bit_access(true)
394398
.storage_input_output16(true)
395399
.uniform_and_storage_buffer16_bit_access(true),
396-
))
400+
)
397401
} else {
398402
None
399403
},
@@ -724,7 +728,9 @@ impl PhysicalDeviceFeatures {
724728
);
725729
}
726730

727-
if let Some((ref f16_i8, ref bit16)) = self.shader_float16 {
731+
if let (Some(ref f16_i8), Some(ref bit16)) =
732+
(self.shader_float16_int8, self.features_16bit_storage)
733+
{
728734
features.set(
729735
F::SHADER_F16,
730736
f16_i8.shader_float16 != 0
@@ -1474,15 +1480,17 @@ impl super::InstanceShared {
14741480
.insert(vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT::default());
14751481
features2 = features2.push_next(next);
14761482
}
1477-
if capabilities.supports_extension(khr::shader_float16_int8::NAME)
1478-
&& capabilities.supports_extension(khr::_16bit_storage::NAME)
1479-
{
1480-
let next = features.shader_float16.insert((
1481-
vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR::default(),
1482-
vk::PhysicalDevice16BitStorageFeaturesKHR::default(),
1483-
));
1484-
features2 = features2.push_next(&mut next.0);
1485-
features2 = features2.push_next(&mut next.1);
1483+
if capabilities.supports_extension(khr::shader_float16_int8::NAME) {
1484+
let next = features
1485+
.shader_float16_int8
1486+
.insert(vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR::default());
1487+
features2 = features2.push_next(next);
1488+
}
1489+
if capabilities.supports_extension(khr::_16bit_storage::NAME) {
1490+
let next = features
1491+
.features_16bit_storage
1492+
.insert(vk::PhysicalDevice16BitStorageFeaturesKHR::default());
1493+
features2 = features2.push_next(next);
14861494
}
14871495
if capabilities.supports_extension(khr::acceleration_structure::NAME) {
14881496
let next = features

0 commit comments

Comments
 (0)