Add emit_int_div_checks option to skip integer division safety wrappers#9443
Open
kvark wants to merge 2 commits intogfx-rs:trunkfrom
Open
Add emit_int_div_checks option to skip integer division safety wrappers#9443kvark wants to merge 2 commits intogfx-rs:trunkfrom
kvark wants to merge 2 commits intogfx-rs:trunkfrom
Conversation
8642947 to
86836df
Compare
Collaborator
|
Can you add this (and anything else missing) to ShaderRuntimeChecks? |
Member
Author
|
@JMS55 good idea! Done |
Member
Author
|
I'll wait for proper review before rebasing. |
cwfitzgerald
requested changes
Apr 29, 2026
SPIR-V and MSL backends wrap integer division/modulo in helper functions that guard against division by zero (and signed MIN/-1 overflow). This is correct per WGSL spec but adds ~10 extra instructions per division. For compute shaders doing implicit GEMM convolutions, this overhead is significant: 6 divisions per im2col element × thousands of elements per tile load = measurable performance impact. New option on both backends: emit_int_div_checks: bool (default: true, preserving current behavior) When set to false: SPIR-V: emits raw OpSDiv/OpUDiv/OpSRem/OpUMod without wrapper functions MSL: emits raw lhs/rhs and lhs%rhs without naga_div/naga_mod wrappers All 200 naga snapshot tests pass with no changes (default is true). Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Member
Author
|
@cwfitzgerald thanks for reviewing! Everything addressed now |
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.
Connections
Related to #4385
Description
SPIR-V and MSL backends wrap integer division/modulo in helper functions that guard against division by zero (and signed MIN/-1 overflow). This is correct per WGSL spec but adds ~10 extra instructions per division.
For compute shaders doing implicit GEMM convolutions, this overhead is significant: 6 divisions per im2col element × thousands of elements per tile load = measurable performance impact.
New option on both backends:
emit_int_div_checks: bool (default: true, preserving current behavior)
When set to false:
SPIR-V: emits raw OpSDiv/OpUDiv/OpSRem/OpUMod without wrapper functions
MSL: emits raw lhs/rhs and lhs%rhs without naga_div/naga_mod wrappers
Testing
All 200 naga snapshot tests pass with no changes (default is true).
Includes a SPIRV reftest.
Squash or Rebase?
Squash
Checklist
wgpumay be affected behaviorally.CHANGELOG.mdentries for the user-facing effects of this change are present.