Skip to content

In a single shader instance, can one render target or resource alias the storage of another? #287

Closed

Description

@dneto0

For example, if a shader has storage buffers A and B, is any overlap allowed between the two?

How about different usages, e.g. A is a storage buffer, and B is a texel buffer, or B is a texture that we might be sampling.

I'm trying to get at whether data races can occur due to conflicting accesses across different resources. If this is disallowed, then it's a property to be verified at command buffer recording time. It would likely also simplify the memory model within the shader.

Related issues:

Activity

  1. litherum commented on May 13, 2019

    @litherum
    Contributor

    Let's disallow this, for exactly the reasons you stated. Similarly, if the resources can alias, but the shading language types don't match, some compiler optimizations would be invalid, as well as the races you describe.

  2. kvark commented on May 13, 2019

    @kvark
    Contributor

    I'm trying to get at whether data races can occur due to conflicting accesses across different resources.

    Please note that having the same resource accessed for writing as well as anything else would violate our usage rules, so you can safely assume it's impossible.

    Special care should be taken of the same resource accessed with the same usage but potentially different offsets. This is what your first example refers to: "I'm trying to get at whether data races can occur due to conflicting accesses across different resources.". I don't think it contradict our current valid usage rules, but I think we should update/fix them to handle (and prohibit) this explicitly.

  3. dneto0 commented on May 16, 2019

    @dneto0
    ContributorAuthor

    Discussed in F2F meeting 2019-05-16:

    • Usage rules (should) ban any of aliasing a writable resource
      • Update the usage rules to clarify this as needed, e.g. in cases of different ranges in the same buffer
  4. devshgraphicsprogramming commented on Oct 11, 2019

    @devshgraphicsprogramming

    I'm trying to get at whether data races can occur due to conflicting accesses across different resources. If this is disallowed, then it's a property to be verified at command buffer recording time. It would likely also simplify the memory model within the shader.

    You may get vastly different read values because for different types there may be disjoint caches (TBO vs. SSBO), you'd have to flush both (memory barrier in OpenGL, pipeline barrier in Vulkan) before even attempting to alias read-only resources.

  5. devshgraphicsprogramming commented on Oct 28, 2019

    @devshgraphicsprogramming

    You may get vastly different read values because for different types there may be disjoint caches (TBO vs. SSBO), you'd have to flush both (memory barrier in OpenGL, pipeline barrier in Vulkan) before even attempting to alias read-only resources.

    Actually if you declared the SSBO/Storage Image as coherent in GLSL for all its aliases, you wouldn't get this problem (but only between SSBO and Storage Images).

    Also #156 @dneto0 addresses how to make sure the driver doesn't accuse you of "aliasing", i.e. can formally bind different ranges of the same buffer (for efficiency) without imposing huge validation costs before every draw/dispatch.

  6. Kangz commented on Jun 1, 2021

    @Kangz
    Contributor

    In this issue it seems the group settled to disallow aliasing of writable resources in a single shader instance, however the WebGPU specification currently states:

    Note: race condition of multiple writable storage buffer/texture usages in a single usage scope is allowed.

    and as far as I can tell there is no validation rule to prevent aliasing of writable resources for a single instance of a shader. I'd like to revisit this and suggest we allow aliasing of writable resources in a single draw/dispatch. It's true that it can cause data races, but it is barely different from other data races we allow (for example multiple draws accessing the same writable resource in a single render pass). Also adding the validation would require draw/dispatch time validation every time since we need to inspect the state of bindgroups bound to decide of aliasing happens or not (and quid of the buffer range?)

    Internally we discussed this issue in combination with #1788 and think they are orthogonal.

  7. Kangz commented on Jun 15, 2021

    @Kangz
    Contributor

    Closing this issue as it is mostly resolved.

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

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions