Repository navigation
fix(vulkan): integer dot products and demote-to-helper, with the device's SPIR-V capabilities for naga - #390
Merged
Merged
Conversation
…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 Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 needsshaderIntegerDotProduct, which we never enabled, and the validation layer reportedVUID-VkShaderModuleCreateInfo-pCode-08740on Intel and NVIDIA.Opennow builds the capability set per device the way wgpu-hal does (vulkan/adapter.rs,Adapter::open), and enablesVK_KHR_shader_integer_dot_productwherever 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
discardturn the invocation into a helper invocation, so the rest of the quad keeps well-defined derivatives. We lowered it toOpKill, which ends the invocation. Where the device supportsVK_EXT_shader_demote_to_helper_invocation, it is now enabled and naga writesOpDemoteToHelperInvocation, as Dawn does on Vulkan; other devices keepOpKill. 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 ascompileStage. 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 beforediscardlands 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.integers/dot4-packed-rt, with no validation messages. Fullgo test ./...passes, and golangci-lint is clean for windows, linux and darwin.No machine here lacks these features, so the polyfill and
OpKillpaths are covered by the hermetic test rather than on hardware.