Skip to content

Commit 9c1a8fa

Browse files
committed
Introduce {PhysicalDeviceFeatures, PrivateCapabilities}::shader_integer_dot_product
1 parent 6b340e5 commit 9c1a8fa

File tree

2 files changed

+40
-4
lines changed

2 files changed

+40
-4
lines changed

wgpu-hal/src/vulkan/adapter.rs

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,10 @@ pub struct PhysicalDeviceFeatures {
123123

124124
/// Features proved by `VK_EXT_mesh_shader`
125125
mesh_shader: Option<vk::PhysicalDeviceMeshShaderFeaturesEXT<'static>>,
126+
127+
/// Features provided by `VK_KHR_shader_integer_dot_product`, promoted to Vulkan 1.3.
128+
shader_integer_dot_product:
129+
Option<vk::PhysicalDeviceShaderIntegerDotProductFeaturesKHR<'static>>,
126130
}
127131

128132
impl PhysicalDeviceFeatures {
@@ -187,6 +191,9 @@ impl PhysicalDeviceFeatures {
187191
if let Some(ref mut feature) = self.mesh_shader {
188192
info = info.push_next(feature);
189193
}
194+
if let Some(ref mut feature) = self.shader_integer_dot_product {
195+
info = info.push_next(feature);
196+
}
190197
info
191198
}
192199

@@ -499,6 +506,16 @@ impl PhysicalDeviceFeatures {
499506
} else {
500507
None
501508
},
509+
shader_integer_dot_product: if device_api_version >= vk::API_VERSION_1_3
510+
|| enabled_extensions.contains(&khr::shader_integer_dot_product::NAME)
511+
{
512+
Some(
513+
vk::PhysicalDeviceShaderIntegerDotProductFeaturesKHR::default()
514+
.shader_integer_dot_product(private_caps.shader_integer_dot_product),
515+
)
516+
} else {
517+
None
518+
},
502519
}
503520
}
504521

@@ -1501,6 +1518,16 @@ impl super::InstanceShared {
15011518
features2 = features2.push_next(next);
15021519
}
15031520

1521+
// `VK_KHR_shader_integer_dot_product` is promoted to 1.3
1522+
if capabilities.device_api_version >= vk::API_VERSION_1_3
1523+
|| capabilities.supports_extension(khr::shader_integer_dot_product::NAME)
1524+
{
1525+
let next = features
1526+
.shader_integer_dot_product
1527+
.insert(vk::PhysicalDeviceShaderIntegerDotProductFeatures::default());
1528+
features2 = features2.push_next(next);
1529+
}
1530+
15041531
unsafe { get_device_properties.get_physical_device_features2(phd, &mut features2) };
15051532
features2.features
15061533
} else {
@@ -1684,6 +1711,9 @@ impl super::Instance {
16841711
.properties
16851712
.limits
16861713
.max_sampler_allocation_count,
1714+
shader_integer_dot_product: phd_features
1715+
.shader_integer_dot_product
1716+
.is_some_and(|ext| ext.shader_integer_dot_product != 0),
16871717
};
16881718
let capabilities = crate::Capabilities {
16891719
limits: phd_capabilities.to_wgpu_limits(),
@@ -1976,10 +2006,8 @@ impl super::Adapter {
19762006
if features.contains(wgt::Features::EXPERIMENTAL_RAY_HIT_VERTEX_RETURN) {
19772007
capabilities.push(spv::Capability::RayQueryPositionFetchKHR)
19782008
}
1979-
if self.phd_capabilities.device_api_version >= vk::API_VERSION_1_3
1980-
|| enabled_extensions.contains(&khr::shader_integer_dot_product::NAME)
1981-
{
1982-
// See <https://registry.khronos.org/vulkan/specs/latest/man/html/VK_KHR_shader_integer_dot_product.html#_new_spir_v_capabilities>.
2009+
if self.private_caps.shader_integer_dot_product {
2010+
// See <https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_shader_integer_dot_product.html#_new_spir_v_capabilities>.
19832011
capabilities.extend(&[
19842012
spv::Capability::DotProductInputAllKHR,
19852013
spv::Capability::DotProductInput4x8BitKHR,

wgpu-hal/src/vulkan/mod.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -528,6 +528,14 @@ struct PrivateCapabilities {
528528
zero_initialize_workgroup_memory: bool,
529529
image_format_list: bool,
530530
maximum_samplers: u32,
531+
532+
/// True if this adapter supports the [`VK_KHR_shader_integer_dot_product`] extension
533+
/// (promoted to Vulkan 1.3).
534+
///
535+
/// This is used to generate optimized code for WGSL's `dot4{I, U}8Packed`.
536+
///
537+
/// [`VK_KHR_shader_integer_dot_product`]: https://registry.khronos.org/vulkan/specs/1.3-extensions/man/html/VK_KHR_shader_integer_dot_product.html
538+
shader_integer_dot_product: bool,
531539
}
532540

533541
bitflags::bitflags!(

0 commit comments

Comments
 (0)