You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Out-of-bounds clamping may require additional draw-call validation #311
Clamping is only possible if we can ensure that every array has at least one element in it. This corresponds to a requirement that the buffer has to be at least as big as the size of the inner type of the array type, in the shader.
E.g: (Written with WHLSL's current syntax, which will change to be come compatible with HLSL)
So, in order for clamping to work, the buffer that gets attached to register(u0) needs to be at least 8 bytes big.
However, we don't know which buffers are attached to which shaders until draw call time. Therefore, if we wanted to enforce a requirement that clamping is always possible, the validation must be done at draw call time.
It might be something we just want to accept, but it's worth noting.
changed the title [-]Out-of-bounds clamping may not be possible[/-][+]Out-of-bounds clamping may require additional draw-call validation[/+]on May 24, 2019
Another option is to return a default value (e.g. 0 for integers, 0.0 for floats, null for pointers, etc..) for any out-of bounds read, and just not do any out-of-bounds store.
Note that the same issue will happen for uniform and storage buffers when no hardware robust buffer access is exposed. We could have an even laxer form of robust buffer acces where if the pipeline declares a vertex input / uniform buffer / storage buffer that's too big compared to what's in the bindgroup, then an error can be produced (or one of the other forms of RBA).
To clarify @kenrussell concern about the lack of vertex caching when doing programmable pulling.
We don't need to manually fetch from the index buffer. We can still bind the index buffer naturally (and validate on the API side that the index range is valid - without going through the compute troubles), but we'd not be binding the vertex buffers. So the only unique inputs that the vertex shaders would receive would be the Vertex ID and the instance ID. The code we'd generate as a preamble would fetch the actual vertex data using these indices and do the clamping accordingly.
As long as you do indexed vertex rendering, you will have some chance of using it.
The case of using or not using it would totally depend on the actual indices that user provides. From the point of view of the vertex caching - the suggested pulling mechanism is no different from a regular vertex payload.
Some hardware architectures have vertex attribute prefetch, which you wouldn't be using here. You'd also be signing up to decode all sorts of quirky vertex formats "in software". I don't think it makes sense for the platform API to enforce a vertex fetch strategy.
@magcius I'm looking for any HW references about the prefetch. Somewhat related to a wider topic, found this in Mali GPU:
DO: Keep index buffers as static as possible.
JUST16 - Current Mali hardware needs to know min/max of index data.
Current Mali hardware needs to know the index range, either for allocating memory on the GPU or range of vertices to shade. The index buffer should specify as tight bounds as possible.
Use of frequently changing index buffers, or use of client-side index buffers, will manifest asincreased CPU load due to the need to scan and/or transfer the memory into a driver owned buffer.
I think this article has most juice. Relevant pieces:
On AMD’s GCN, it works with pulling. Always. When you’re doing push, the driver patches the shader so the ISA (Instruction Set Architecture) is converted to pull based on the currently bound vertex format.
Timothy Lottes tells me NVIDIA should support pull much better, and that he recommended pull back when he was working there.
On A11 Bionic SoC, all push is converted to pull, just like with AMD’s GCN.
The overall trend here is pretty clear: industry is steering away from the "push" model of vertex buffers. I know and agree that we (WebGPU working group) shouldn't try to innovate in this space, but our need for vertex pulling is not about innovation but for portability and security.
I don't have any public reference I can give you off the top of my head, but vertex attribute prefetch is still in modern hardware. Just because some guy wrote a blog post, does not mean that "industry is steering away". For instance, Mali used to transform vertex shaders into compute shaders (hence the min/max range tracking), but now there are dedicated units for vertex fetch. Newer performance guides do not have that advice anymore.
This WG is certainly not in a space to meaningfully innovate on top of platform APIs, especially since IHVs are not involved in the process. Users can write pull code if they would like to.
@kvark I second @magcius 's comments. In my opinion, the WebGPU working group should not require all vertex shaders to be transformed into the pull model in order to implement the specification on platforms that don't precisely have robust_buffer_access_behavior. It's too large a behavioral change compared to how native applications behave, and there are other alternatives. I'll comment further on #320 .
Resolved: for now, this behavior is unspecified. A browser MAY no-op a draw call which has resources that are too short, or a browser MAY rewrite the shader to make OOB accesses return 0 / do nothing.
Activity
[-]Out-of-bounds clamping may not be possible[/-][+]Out-of-bounds clamping may require additional draw-call validation[/+]RobinMorisset commentedon May 24, 2019
Another option is to return a default value (e.g. 0 for integers, 0.0 for floats, null for pointers, etc..) for any out-of bounds read, and just not do any out-of-bounds store.
kdashg commentedon May 24, 2019
Robust Buffer Access Behavior from D3D and GL are a laxer form of this, which we tolerate in WebGL today for certain out-of-bounds accesses.
Kangz commentedon May 27, 2019
Note that the same issue will happen for uniform and storage buffers when no hardware robust buffer access is exposed. We could have an even laxer form of robust buffer acces where if the pipeline declares a vertex input / uniform buffer / storage buffer that's too big compared to what's in the bindgroup, then an error can be produced (or one of the other forms of RBA).
kvark commentedon Jun 10, 2019
To clarify @kenrussell concern about the lack of vertex caching when doing programmable pulling.
We don't need to manually fetch from the index buffer. We can still bind the index buffer naturally (and validate on the API side that the index range is valid - without going through the compute troubles), but we'd not be binding the vertex buffers. So the only unique inputs that the vertex shaders would receive would be the Vertex ID and the instance ID. The code we'd generate as a preamble would fetch the actual vertex data using these indices and do the clamping accordingly.
Some basic reading on the vertex caches - https://www.khronos.org/opengl/wiki/Post_Transform_Cache
Relevant quote:
The case of using or not using it would totally depend on the actual indices that user provides. From the point of view of the vertex caching - the suggested pulling mechanism is no different from a regular vertex payload.
magcius commentedon Jun 10, 2019
Some hardware architectures have vertex attribute prefetch, which you wouldn't be using here. You'd also be signing up to decode all sorts of quirky vertex formats "in software". I don't think it makes sense for the platform API to enforce a vertex fetch strategy.
kvark commentedon Jun 11, 2019
@magcius I'm looking for any HW references about the prefetch. Somewhat related to a wider topic, found this in Mali GPU:
kvark commentedon Jun 11, 2019
I think this article has most juice. Relevant pieces:
The overall trend here is pretty clear: industry is steering away from the "push" model of vertex buffers. I know and agree that we (WebGPU working group) shouldn't try to innovate in this space, but our need for vertex pulling is not about innovation but for portability and security.
magcius commentedon Jun 11, 2019
I don't have any public reference I can give you off the top of my head, but vertex attribute prefetch is still in modern hardware. Just because some guy wrote a blog post, does not mean that "industry is steering away". For instance, Mali used to transform vertex shaders into compute shaders (hence the min/max range tracking), but now there are dedicated units for vertex fetch. Newer performance guides do not have that advice anymore.
This WG is certainly not in a space to meaningfully innovate on top of platform APIs, especially since IHVs are not involved in the process. Users can write pull code if they would like to.
kvark commentedon Jun 11, 2019
@litherum apologies for stealing the thread! This discussion was erroneously placed here, was meant to be in #320 instead.
kenrussell commentedon Jun 12, 2019
@kvark I second @magcius 's comments. In my opinion, the WebGPU working group should not require all vertex shaders to be transformed into the pull model in order to implement the specification on platforms that don't precisely have robust_buffer_access_behavior. It's too large a behavioral change compared to how native applications behave, and there are other alternatives. I'll comment further on #320 .
kainino0x commentedon Sep 17, 2019
On the call we resolved to do what Robin suggested unless there are further comments from the people who weren't at the meeting (@litherum).
litherum commentedon Sep 27, 2019
Resolved: for now, this behavior is unspecified. A browser MAY no-op a draw call which has resources that are too short, or a browser MAY rewrite the shader to make OOB accesses return 0 / do nothing.
kdashg commentedon Sep 27, 2019
@litherum Did you want to leave this open until we add spec text, or can we close this issue?
litherum commentedon Sep 27, 2019
@jdashg I like to leave issues open until there is spec text. Is this unacceptable?
kdashg commentedon Sep 27, 2019
No that's fine! I wish we had a status to tag this to reflect the updated status, but leaving it open I think is probably best anyways.
kvark commentedon Sep 30, 2019
@jdashg we do have it under "Needs specification" tab of the project now, which you can see on the right side. It's not a tag, but it's visible.
Kangz commentedon Sep 2, 2021
Closing. We added the
minBindingSizefor uniform / storage bindings and checks for their validity / draw-call time checks when they aren't present.We also added validation and robust access behavior for index and vertex buffers.
Add support for logical assignment operators (&&= ||=) (gpuweb#311)