Skip to content

fix(vulkan): integer dot products and demote-to-helper, with the device's SPIR-V capabilities for naga - #390

Merged
kolkov merged 2 commits into
mainfrom
fix/vulkan-shader-features
Nov 9, 2026
Merged

kolkov merged 2 commits into
mainfrom
fix/vulkan-shader-features

Conversation

@kolkov

@kolkov kolkov commented Nov 9, 2026

Copy link
Copy Markdown
Contributor

Two Vulkan shader-feature fixes that touch the same device feature chain.

Integer dot products (P2-VK-014). naga got no SPIR-V capability set from the device, so it treated every capability as available and wrote the native packed dot product for dot4I8Packed/dot4U8Packed. That needs shaderIntegerDotProduct, which we never enabled, and the validation layer reported VUID-VkShaderModuleCreateInfo-pCode-08740 on Intel and NVIDIA. Open now builds the capability set per device the way wgpu-hal does (vulkan/adapter.rs, Adapter::open), and enables VK_KHR_shader_integer_dot_product wherever it is supported. On a device without it, naga falls back to its polyfill. Rust entries for features this backend doesn't have yet (multiview, non-uniform binding-array indexing, 64-bit texture atomics, mesh/RT pipelines, cooperative matrices, Int8) are left out and listed in the comment.

Discard as demote-to-helper (P2-VK-018). WGSL makes discard turn the invocation into a helper invocation, so the rest of the quad keeps well-defined derivatives. We lowered it to OpKill, which ends the invocation. Where the device supports VK_EXT_shader_demote_to_helper_invocation, it is now enabled and naga writes OpDemoteToHelperInvocation, as Dawn does on Vulkan; other devices keep OpKill. Both extensions were promoted in Vulkan 1.3. Our instance is 1.2, so the device enables them by name.

Tests:

  • hal/vulkan/spirv_capabilities_test.go: the capability set per feature, the enable chain at 1.2 and 1.3, and a hermetic check that compiles WGSL through the same path as compileStage. It confirms native dot vs. polyfill, and demote vs. kill, per device. It fails if the capability set is dropped.
  • hal/allbackends/discard_semantics_readback_test.go: a store before discard lands and one after it does not; fine derivatives stay exact in a quad whose bottom-right lane discards. Both pass on Vulkan, DX12 (FXC and DXIL), GLES and the software backend.
  • Locally with the Khronos validation layer: naga's readback corpus on Vulkan is 128/128 on Iris Xe and a GTX 1660-class NVIDIA, including integers/dot4-packed-rt, with no validation messages. Full go test ./... passes, and golangci-lint is clean for windows, linux and darwin.

No machine here lacks these features, so the polyfill and OpKill paths are covered by the hermetic test rather than on hardware.

…aga the device's SPIR-V capabilities

naga's SPIR-V options carried no capability set, so naga treated every
capability as available and emitted the native packed dot product
(dot4I8Packed, dot4U8Packed) on devices that never enabled
shaderIntegerDotProduct: the validation layer reports
VUID-VkShaderModuleCreateInfo-pCode-08740 on Intel and NVIDIA. Open now
builds the set per device as Rust wgpu-hal does (vulkan/adapter.rs,
Adapter::open), so naga polyfills the dot product where the device lacks
the feature, and enables VK_KHR_shader_integer_dot_product wherever it is
supported.

WGSL makes discard a helper-invocation demotion, so derivatives stay defined
for the rest of the quad. Open also enables
VK_EXT_shader_demote_to_helper_invocation wherever it is supported, and
naga then writes OpDemoteToHelperInvocation instead of OpKill, as Dawn does
on Vulkan. Both extensions were promoted in Vulkan 1.3; our instance is 1.2,
so the device enables them by name.
@codecov

codecov Bot commented Nov 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@kolkov
kolkov merged commit 4215e4b into main Nov 9, 2026
19 checks passed
@kolkov
kolkov deleted the fix/vulkan-shader-features branch November 9, 2026 07:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant