-
Notifications
You must be signed in to change notification settings - Fork 979
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SPIR-V back end skips bounds checks for AccessIndex
when applied to runtime-sized arrays
#4441
Labels
area: naga back-end
Outputs of naga shader conversion
lang: SPIR-V
Vulkan's Shading Language
naga
Shader Translator
type: bug
Something isn't working
Milestone
Comments
jimblandy
added
kind: bug
lang: SPIR-V
Vulkan's Shading Language
area: naga back-end
Outputs of naga shader conversion
labels
Nov 11, 2021
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
This comment was marked as resolved.
cwfitzgerald
added
naga
Shader Translator
type: bug
Something isn't working
and removed
kind: bug
labels
Oct 25, 2023
jimblandy
added a commit
to jimblandy/wgpu
that referenced
this issue
Oct 1, 2024
Do not neglect to apply bounds checks to indexing operations on runtime-sized arrays, even when they are accessed via an `AccessIndex` instruction. Before this commit, `BlockContext::write_expression_pointer` would not apply bounds checks to `OpAccessChain` indices provided by an `AccessIndex` instruction, apparently with the rationale that any out-of-bounds accesses should all have been reported by constant evaluation. While it is true that the `index` operand of an `AccessIndex` expression is known at compile time, and that the WGSL constant evaluation rules require accesses that can be statically determined to be out-of-bounds to be shader creation or pipeline creation time errors, accesses to runtime-sized arrays don't follow this pattern: even if the index is known, the length with which it must be compared is not. Fixes gfx-rs#4441.
jimblandy
added a commit
to jimblandy/wgpu
that referenced
this issue
Oct 1, 2024
Do not neglect to apply bounds checks to indexing operations on runtime-sized arrays, even when they are accessed via an `AccessIndex` instruction. Before this commit, `BlockContext::write_expression_pointer` would not apply bounds checks to `OpAccessChain` indices provided by an `AccessIndex` instruction, apparently with the rationale that any out-of-bounds accesses should have been reported by constant evaluation. While it is true that the `index` operand of an `AccessIndex` expression is known at compile time, and that the WGSL constant evaluation rules require accesses that can be statically determined to be out-of-bounds to be shader creation or pipeline creation time errors, accesses to runtime-sized arrays don't follow this pattern: even if the index is known, the length with which it must be compared is not. Fixes gfx-rs#4441.
jimblandy
added a commit
to jimblandy/wgpu
that referenced
this issue
Oct 8, 2024
Do not neglect to apply bounds checks to indexing operations on runtime-sized arrays, even when they are accessed via an `AccessIndex` instruction. Before this commit, `BlockContext::write_expression_pointer` would not apply bounds checks to `OpAccessChain` indices provided by an `AccessIndex` instruction, apparently with the rationale that any out-of-bounds accesses should have been reported by constant evaluation. While it is true that the `index` operand of an `AccessIndex` expression is known at compile time, and that the WGSL constant evaluation rules require accesses that can be statically determined to be out-of-bounds to be shader creation or pipeline creation time errors, accesses to runtime-sized arrays don't follow this pattern: even if the index is known, the length with which it must be compared is not. Fixes gfx-rs#4441.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
area: naga back-end
Outputs of naga shader conversion
lang: SPIR-V
Vulkan's Shading Language
naga
Shader Translator
type: bug
Something isn't working
Naga's SPIR-V back end fails to generate a bounds check for an
AccessIndex
expression that is indexing into a runtime-sized array.For example:
When the
ReadZeroSkipWrite
policy is applied to buffers, Naga generates the following SPIR-V for the body:Note that the the
unsized.arr[3]
access has no bounds check, while theunsized.arr[i]
access does. Since it is not known until run time whether3
is a valid index, both accesses should be checked.Two factors limit the impact of this bug:
AccessIndex
expressions applied to any type whose length is statically known.storage
storage class, which is the only storage class that can hold dynamically sized arrays.However, Naga is expected to be used in situations where that kind of robust buffer access is not supported, so this is still important to fix.
The text was updated successfully, but these errors were encountered: