Skip to content

Figure out whether indirectBuffer OOB is a validation error #1834

Closed

Description

@kainino0x

In #955 (scenario 5), it was recorded that we decided not to generate validation errors when draw calls go out of bounds on indirect buffers.

However, in #980 we (accidentally, I think) ended up speccing that it does. Editors should revisit to resolve this.

As an analogy to index-buffer-OOB behavior, it makes sense that no validation error would be raised here:

  • drawIndexed could produce a validation error on index-buffer-OOB, but would be inconsistent with drawIndexedIndirect. Consistency also allows implementations to upgrade drawIndexed to drawIndexedIndirect if they want to.
  • drawIndirect/drawIndexedIndirect could produce a validation error on indirect-buffer-OOB, but would (probably) be inconsistent with drawIndirectCount/drawIndexedIndirectCount (which we don't have, but exist in Vulkan). Consistency also allows implementations to upgrade to the drawIndirectCount versions.

Note, looking into vkCmdDrawIndirectCount/vkCmdDrawIndexedIndirectCount, I noticed that Vulkan's maxDrawCount behavior is (somewhat peculiarly) actually safe, which would make it possible to check for indirect-buffer-OOB at validation time even for these calls. However, I don't know if this extends to Metal indirect command buffers, for example.

maxDrawCount specifies the maximum number of draws that will be executed. The actual number of executed draw calls is the minimum of the count specified in countBuffer and maxDrawCount.

Note there is no equivalent dispatchIndirectCount. (I guess you would need indirect command buffers (VK_NV_device_generated_commands?) to achieve that.)

Activity

  1. added this to the MVP milestone on Jun 11, 2021
  2. Kangz commented on Jun 11, 2021

    @Kangz
    Contributor

    I'm not sure I understand the discussion about implementation internally upgrading drawIndirect to drawIndirectCount: we still know at the place where drawIndirect is called which buffer is used for the indirect call, at what offset, etc so we can easily validate that we are in bounds of the indirect buffer. Likewise for drawIndexed we have all the data to validate OOB on the index buffer in the call, so we might as well validate at that point. We can't do the same for drawIndexedIndirect because the parameters of the call are on the GPU.

    It is better developer experience for them to have errors specced for index buffer or indirect buffer OOB as it's more convenient to surround them with push/popErrorScope, break on error (in the devtools when that's a thing), etc. Consistency between the direct and indirect call seems fairly minor in comparison.

  3. kainino0x commented on Jun 14, 2021

    @kainino0x
    ContributorAuthor

    Editors: raise to group

    Strawman options, the two ends of the spectrum:

    • Always generate validation errors when we can do so on the CPU from the current state and draw args. The benefit of this is developers get validation errors instead of warnings (does it matter?), and they are protected from loosely-defined behavior (like vertex access clamping vs wrapping vs zeroing).
      • draw: Must be within range of all bound vertex buffers
      • drawIndexed: Must be within range of bound index buffer
      • drawIndirect: Must be within range of indirectBuffer
      • drawIndexedIndirect: Must be within range of indirectBuffer
    • Never validate (which I think was the previous agreement, in Summary of current robust buffer access opinions #955).
      The benefit of this is just saving some potentially-redundant checks on the CPU, i.e. if an implementation already uses some kind of robustness for vertex access, then the CPU checks are extra overhead (but if implementations are issuing warnings in this case anyway then it doesn't save them anything). Also more consistent because validation error cases will be the same between e.g. draw and drawIndirect.

    Or we can pick something in between.

  4. kainino0x commented on Jun 21, 2021

    @kainino0x
    ContributorAuthor

    Resolution

    • Always generate validation errors when we can do so on the CPU from the current state and draw args.

    We can remove validation errors later on, as we consider that to be a non-breaking change.

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

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions