Clarify out of bounds behavior - #1722
Conversation
| <td>Select the |i|'<sup>th</sup> component of vector<br> | ||
| The first component is at index |i|=0.<br> | ||
| If |i| is outside the range [0,|N|-1], then an index in the range [0, |N|-1] is used instead. | ||
| If |i| is outside the range [0,|N|-1], then expression evaluates to either: |
There was a problem hiding this comment.
This is not a memory value so I'm not sure that is appropriate. The vector has been loaded already here and this is then extracting an out of bounds index.
There was a problem hiding this comment.
True. So what does Vulkan/SPIR-V say is going to happen in this case?
There was a problem hiding this comment.
It produces an undefined value, but I do think we could opt for more restrictive behaviour that is written here (by using a max/clamp operation).
There was a problem hiding this comment.
We should discuss this with the group. The way I see it is: RBA's returned value is also pretty much undefined for all the purposes of the user (i.e. the only thing that is defined is that it's not coming from outside of the buffer memory). So if both in-memory and on-stack out-of-bounds accesses are pretty much undefined anyway, why would we prioritize bounds checking (in the spec) one over another?
There was a problem hiding this comment.
We talked some more about this internally and it's worth raising here. Most languages distinguish in some way between undefined values and undefined behaviour. This would be an undefined value; however, again generally, undefined values can lead to undefined behaviours. For example, most languages treat branching on an undefined value as producing undefined behaviour. So it might well be worth paying a small cost (the clamp/max operation) to prevent that possibility.
| <td>Select the |i|'<sup>th</sup> component of vector<br> | ||
| The first component is at index |i|=0.<br> | ||
| If |i| is outside the range [0,|N|-1], then an index in the range [0, |N|-1] is used instead. | ||
| If |i| is outside the range [0,|N|-1], then expression evaluates to either: |
There was a problem hiding this comment.
True. So what does Vulkan/SPIR-V say is going to happen in this case?
kvark
left a comment
There was a problem hiding this comment.
When this is ready, please make sure to update the PR description (to reflect the actual logic) before merging as it becomes a part of the commit message/history.
WGSL meeting minutes 2021-05-18
|
| If a reference or pointer access is out of bounds, an <dfn noexport>invalid | ||
| memory reference</dfn> is produced. | ||
| [=Load Rule|Loads=] from an invalid reference return one of: | ||
| * a value from any [=memory locations|memory location=] of the [=originating variable=] |
There was a problem hiding this comment.
Is the use of "originating variable" appropriate here? I.e. if I have a struct Foo {...} used as a uniform buffer, and we are talking about access into this buffer, would the originating variable be that global var<uniform> foo: Foo?
If so, this is still incorrect. Vulkan's RBA allows any value from the buffer (bound from the host side) to show up here, not just Foo contents.
There was a problem hiding this comment.
I made a change to refer to the bound buffer instead of just the originating variable.
| [=Load Rule|Loads=] from an invalid reference return one of: | ||
| * a value from any [=memory locations|memory location=] of the [=originating variable=] | ||
| * the zero value for store type of the reference | ||
| * if the loaded value is a vector, the value (0, 0, 0, x), where x is: |
There was a problem hiding this comment.
may need a bit of clarify (possibly in follow-up) on, like, what if it's vec2. Maybe we should just say here "if the loaded value is vec4?
WGSL meeting minutes 2021-05-25
|
WGSL meeting minutes 2021-06-01
|
Contributes to gpuweb#1649 * Update out of bounds behaviour to allow D3D and Vulkan RBA behaviour * For references, introduce an invalid memory reference * propagates through indirection and address of operators * loads can return any value in the buffer, 0, or (0,0,0,x) * stores can store to any location in the buffer or not be executed * for values, the accessed value is undefined
* The load/store may access any location(s) of the bound buffer, not just the originating variable
|
Sorry I didn't directly respond to this, but I did look it over. The provisions for out of bounds access seem broad enough that they aren't of concern. I share the concern @kvark expressed here https://github.com/gpuweb/gpuweb/pull/1722/files#r639050496, but I suppose that will be address later |
Contributes to #1649
reference that covers those behaviours when used
expression necessarily