Skip to content

Out-of-bounds clamping may require additional draw-call validation #311

Closed

Description

@litherum

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)

struct Foo {
    uint x;
    uint y;
}
compute void computeShader(device Foo[] theBuffer : register(u0)) {
    Foo z = theBuffer[17];
}

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.

Activity

  1. 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
  2. RobinMorisset commented on May 24, 2019

    @RobinMorisset
    Contributor

    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.

  3. kdashg commented on May 24, 2019

    @kdashg
    Contributor

    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.

  4. Kangz commented on May 27, 2019

    @Kangz
    Contributor

    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).

  5. kvark commented on Jun 10, 2019

    @kvark
    Contributor

    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:

    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.

  6. magcius commented on Jun 10, 2019

    @magcius

    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.

  7. kvark commented on Jun 11, 2019

    @kvark
    Contributor

    @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.

  8. kvark commented on Jun 11, 2019

    @kvark
    Contributor

    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.

  9. magcius commented on Jun 11, 2019

    @magcius

    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.

  10. kvark commented on Jun 11, 2019

    @kvark
    Contributor

    @litherum apologies for stealing the thread! This discussion was erroneously placed here, was meant to be in #320 instead.

  11. kenrussell commented on Jun 12, 2019

    @kenrussell
    Member

    @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 .

  12. kainino0x commented on Sep 17, 2019

    @kainino0x
    Contributor

    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).

  13. litherum commented on Sep 27, 2019

    @litherum
    ContributorAuthor

    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.

  14. kdashg commented on Sep 27, 2019

    @kdashg
    Contributor

    @litherum Did you want to leave this open until we add spec text, or can we close this issue?

  15. litherum commented on Sep 27, 2019

    @litherum
    ContributorAuthor

    @jdashg I like to leave issues open until there is spec text. Is this unacceptable?

  16. kdashg commented on Sep 27, 2019

    @kdashg
    Contributor

    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.

  17. kvark commented on Sep 30, 2019

    @kvark
    Contributor

    @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.

  18. Kangz commented on Sep 2, 2021

    @Kangz
    Contributor

    Closing. We added the minBindingSize for 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.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions