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
This is a follow-up from #1580 (comment)
Currently, WGSL spec only describes the clamping behavior. Instead, it should follow WebGPU group decision to allow any of the following behaviors:
discard the whole draw call
behave like RBA, which means reading can return anything within the buffer (not within the array), or zeroes, or other stuff
behave like D3D, which means reading always returns zeroes, and writing is ignored
Having all of these 3 options is hurting portability, and I've been advocating the group to strictly follow D3D behavior. However, we haven't figured out how to efficiently implement out-of-bounds checks for vertex attributes on Vulkan in D3D style. Vertex pulling requires descriptors, and on some GPUs we only have 4 descriptor sets, all of which are exposed to users. RBA can return one of many things, it's not as portable as D3D style. See also - #955
MM: Can we talk about OOB access derailing the whole draw call? (yes, but next week)
MM: If you have shader with array, and index off the end, something happens, spec offers some options. There’s also a different situation where you have a draw call that asks to read off the end of the vertex buffer (e.g. too-large index), and that has options too. This is particularly an issue for indirect draw calls. You can’t stop an OOB indirect draw call, but we can use a compute shader to write vert_count=0 before the draw call.
AB: Can we just say “as if the draw call was discarded”?
MM: Can say “if you OOB off the end of anything, impl can <list of options>”. But there are cases where you can’t actually fully discard the draw call, because you may have already done work.
DM: Maybe we don’t need to mention this in WGSL, but rather the API spec. We would only need the RBAB defined.
GR: What does the API say today?
DM: Clamped I think, but lots of TODOs
Sending this to API group
DM: Worried about OOB being able to return (safe) garbage for OOBs. [Someone] had an idea to enforce stronger D3D behavior with shader preambles.
AB: At a cost though.
DM: We would at least expect desktops to have this for free.
RM: Do we have numbers? 1% very different from 20%
DM: We need to test on mobile
RM: Can we agree to revisit this after investigation?
AB: For storage, does it let us store anywhere in an array? Discarding the store would be control flow. Additionally, would bias performance balancing towards mobile, vs usually overpowered desktops
MM: We think it’s worth seeing if the perf tradeoff is worth it. Portability concern makes it worth considering. DM: Can you look?
DM: We will look
JB: Does hardware have conditional stores? (yes probably)
DM: Can test with shaderplayground, which does tell us e.g. RDNA
Activity
alan-baker commentedon Apr 21, 2021
Is there a reference to where the decision to discard the whole draw call was agreed to? That seems especially non-portable.
kvark commentedon Apr 21, 2021
#311 (comment)
Having all of these 3 options is hurting portability, and I've been advocating the group to strictly follow D3D behavior. However, we haven't figured out how to efficiently implement out-of-bounds checks for vertex attributes on Vulkan in D3D style. Vertex pulling requires descriptors, and on some GPUs we only have 4 descriptor sets, all of which are exposed to users. RBA can return one of many things, it's not as portable as D3D style. See also - #955
dneto0 commentedon Apr 21, 2021
Just to throw in a nit, the current language in the spec is looser than "clamp".
So if you have N=4, then a valid thing to do is bitwise (i & 3). That might be faster than clamp(i,0,3. Who knows.
dneto0 commentedon Apr 21, 2021
For my own reference, the WebGL draft spec section is here: https://www.khronos.org/registry/webgl/specs/latest/1.0/#4.5
kdashg commentedon Apr 27, 2021
WGSL meeting minutes 2021-04-27
kdashg commentedon May 5, 2021
WGSL meeting minutes 2021-05-04
Clarify out of bounds behavior
Clarify out of bounds behavior
Clarify out of bounds behavior
Clarify out of bounds behavior (#1722)
jimblandy commentedon Apr 30, 2022
The current spec language permits both index clamping and read zero / skip write. Is there any more spec work required here?
kdashg commentedon May 2, 2022
I think so, but feel free to interject, anyone!