Skip to content

Relax the out-of-bounds specification #1649

Closed

Description

@kvark

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

Activity

  1. added
    wgsl
    on Apr 21, 2021
  2. added this to the MVP milestone on Apr 21, 2021
  3. alan-baker commented on Apr 21, 2021

    @alan-baker
    Contributor

    Is there a reference to where the decision to discard the whole draw call was agreed to? That seems especially non-portable.

  4. kvark commented on Apr 21, 2021

    @kvark
    ContributorAuthor

    #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

  5. dneto0 commented on Apr 21, 2021

    @dneto0
    Contributor

    Just to throw in a nit, the current language in the spec is looser than "clamp".

    If i is outside the range [0,N-1], then an index in the range [0, N-1] is used instead.

    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.

  6. dneto0 commented on Apr 21, 2021

    @dneto0
    Contributor
  7. kdashg commented on Apr 27, 2021

    @kdashg
    Contributor
    WGSL meeting minutes 2021-04-27
    • This should be needs-spec
    • MM: Can we talk about OOB access derailing the whole draw call? (yes, but next week)
  8. kdashg commented on May 5, 2021

    @kdashg
    Contributor
    WGSL meeting minutes 2021-05-04
    • 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
    • TR: Don’t they need this? (yes)
  9. added a commit that references this issue on May 11, 2021
  10. added a commit that references this issue on May 20, 2021
  11. added a commit that references this issue on Jun 9, 2021
  12. added a commit that references this issue on Jun 10, 2021
  13. added
    wgsl resolved
    on Apr 26, 2022
  14. jimblandy commented on Apr 30, 2022

    @jimblandy
    Contributor

    The current spec language permits both index clamping and read zero / skip write. Is there any more spec work required here?

  15. kdashg commented on May 2, 2022

    @kdashg
    Contributor

    I think so, but feel free to interject, anyone!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugwgslwgsl resolved

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions