Skip to content

Commit fcb58b3

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 ac120e9 commit fcb58b3

File tree

1 file changed

+32
-24
lines changed

1 file changed

+32
-24
lines changed

wgpu-hal/src/vulkan/adapter.rs

+32-24
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
},
@@ -717,7 +721,9 @@ impl PhysicalDeviceFeatures {
717721
);
718722
}
719723

720-
if let Some((ref f16_i8, ref bit16)) = self.shader_float16 {
724+
if let (Some(ref f16_i8), Some(ref bit16)) =
725+
(self.shader_float16_int8, self.features_16bit_storage)
726+
{
721727
features.set(
722728
F::SHADER_F16,
723729
f16_i8.shader_float16 != 0
@@ -1467,15 +1473,17 @@ impl super::InstanceShared {
14671473
.insert(vk::PhysicalDeviceTextureCompressionASTCHDRFeaturesEXT::default());
14681474
features2 = features2.push_next(next);
14691475
}
1470-
if capabilities.supports_extension(khr::shader_float16_int8::NAME)
1471-
&& capabilities.supports_extension(khr::_16bit_storage::NAME)
1472-
{
1473-
let next = features.shader_float16.insert((
1474-
vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR::default(),
1475-
vk::PhysicalDevice16BitStorageFeaturesKHR::default(),
1476-
));
1477-
features2 = features2.push_next(&mut next.0);
1478-
features2 = features2.push_next(&mut next.1);
1476+
if capabilities.supports_extension(khr::shader_float16_int8::NAME) {
1477+
let next = features
1478+
.shader_float16_int8
1479+
.insert(vk::PhysicalDeviceShaderFloat16Int8FeaturesKHR::default());
1480+
features2 = features2.push_next(next);
1481+
}
1482+
if capabilities.supports_extension(khr::_16bit_storage::NAME) {
1483+
let next = features
1484+
.features_16bit_storage
1485+
.insert(vk::PhysicalDevice16BitStorageFeaturesKHR::default());
1486+
features2 = features2.push_next(next);
14791487
}
14801488
if capabilities.supports_extension(khr::acceleration_structure::NAME) {
14811489
let next = features

0 commit comments

Comments
 (0)