Skip to content

Commit 8594f8f

Browse files
committed
Allow wgpu to use specialized dot4{I,U}8Packed
See #7574, in particular <#7574 (comment)>. Adds `FeaturesWGPU::NATIVE_PACKED_INTEGER_DOT_PRODUCT`, which is available on `Adapter`s that support the specialized implementations for `dot4I8Packed` and `dot4U8Packed` implemented in #7574 (currently, this includes DX12 with Shader Model >= 6.4 and Vulkan with device extension "VK_KHR_shader_integer_dot_product". If this feature is requested during `Device` creation, the device is set up such that `dot4I8Packed` and `dot4U8Packed` will be compiled to their respective specialized instructions. This means that, on a vulkan `Device`, the SPIR-V language version is set to 1.6, and the required SPIR-V capabilities are marked as available (on DX12, requesting the feature doesn't change anything since availability of the feature already guarantees that Shader Model >= 6.4, which is all we need to generate specialized code).
1 parent be9debd commit 8594f8f

File tree

3 files changed

+34
-1
lines changed

3 files changed

+34
-1
lines changed

wgpu-hal/src/dx12/adapter.rs

+6
Original file line numberDiff line numberDiff line change
@@ -495,6 +495,12 @@ impl super::Adapter {
495495
atomic_int64_on_typed_resource_supported,
496496
);
497497

498+
// HLSL functions `dot4add_i8packed` and `dot4add_u8packed` are supported on SM >= 6.4.
499+
features.set(
500+
F::NATIVE_PACKED_INTEGER_DOT_PRODUCT,
501+
shader_model >= naga::back::hlsl::ShaderModel::V6_4,
502+
);
503+
498504
// TODO: Determine if IPresentationManager is supported
499505
let presentation_timer = auxil::dxgi::time::PresentationTimer::new_dxgi();
500506

wgpu-hal/src/vulkan/adapter.rs

+17-1
Original file line numberDiff line numberDiff line change
@@ -841,6 +841,15 @@ impl PhysicalDeviceFeatures {
841841
F::EXPERIMENTAL_MESH_SHADER,
842842
caps.supports_extension(ext::mesh_shader::NAME),
843843
);
844+
845+
// The SPIR-V capabilities `DotProductInput4x8BitPackedKHR` and `DotProductKHR` seem to be
846+
// implemented in the device extension `VK_KHR_shader_integer_dot_product`, see
847+
// <https://registry.khronos.org/vulkan/specs/latest/man/html/VK_KHR_shader_integer_dot_product.html>.
848+
features.set(
849+
F::NATIVE_PACKED_INTEGER_DOT_PRODUCT,
850+
caps.supports_extension(khr::shader_integer_dot_product::NAME),
851+
);
852+
844853
if let Some(ref mesh_shader) = self.mesh_shader {
845854
features.set(
846855
F::EXPERIMENTAL_MESH_SHADER_MULTIVIEW,
@@ -2011,8 +2020,15 @@ impl super::Adapter {
20112020
if features.contains(wgt::Features::EXPERIMENTAL_RAY_HIT_VERTEX_RETURN) {
20122021
capabilities.push(spv::Capability::RayQueryPositionFetchKHR)
20132022
}
2023+
if features.contains(wgt::Features::NATIVE_PACKED_INTEGER_DOT_PRODUCT) {
2024+
capabilities.push(spv::Capability::DotProduct);
2025+
capabilities.push(spv::Capability::DotProductInput4x8BitPacked);
2026+
}
20142027
spv::Options {
2015-
lang_version: if features
2028+
lang_version: if features.contains(wgt::Features::NATIVE_PACKED_INTEGER_DOT_PRODUCT)
2029+
{
2030+
(1, 6)
2031+
} else if features
20162032
.intersects(wgt::Features::SUBGROUP | wgt::Features::SUBGROUP_VERTEX)
20172033
{
20182034
(1, 3)

wgpu-types/src/features.rs

+11
Original file line numberDiff line numberDiff line change
@@ -1193,6 +1193,17 @@ bitflags_array! {
11931193
///
11941194
/// This is a native only feature.
11951195
const EXPERIMENTAL_MESH_SHADER_MULTIVIEW = 1 << 49;
1196+
1197+
/// Ensures that `dot4I8Packed` and `dot4U8Packed` in WGSL are compiled to specialized
1198+
/// intrinsics.
1199+
///
1200+
/// Supported platforms:
1201+
/// - Vulkan (with SPIR-V 1.6+ and [DotProductInput4x8BitPackedKHR](https://registry.khronos.org/vulkan/specs/latest/html/vkspec.html#spirvenv-capabilities-table-DotProductInput4x8BitPacked))
1202+
/// - DX12 (with SM 6.4+)
1203+
///
1204+
/// Potential Platforms:
1205+
/// - WebGPU
1206+
const NATIVE_PACKED_INTEGER_DOT_PRODUCT = 1 << 50;
11961207
}
11971208

11981209
/// Features that are not guaranteed to be supported.

0 commit comments

Comments
 (0)