Skip to content

wgsl: storageBarrier memory scope question #2980

Open

Description

@dj2

If an atomic comes from an storage buffer then it has a QueueFamily memory scope. Reading the synchronization section it says: All synchronization functions use the Workgroup [memory scope](https://www.w3.org/TR/WGSL/#memory-scope). Isn't that memory scope different from the one used for atomics in a storage buffer?

Activity

  1. added
    wgsl
    on May 30, 2022
  2. alan-baker commented on May 31, 2022

    @alan-baker
    Contributor

    Yes, but atomics aren't synchronization functions.

    A storage barrier provides the synchronization necessary to make memory operations on storage buffers available and visible to other invocations in the same workgroup instance.

    An atomic operation on an atomic type in a storage buffer will become available/visible to all other invocations in the same draw/dispatch. It does not, however, provide necessary synchronization (because it uses relaxed memory ordering) for availability/visibility to be properly synchronized on other storage buffer memory.

  3. dj2 commented on May 31, 2022

    @dj2
    MemberAuthor

    Let me see if I understand that, you can have an atomic inside a storage buffer. Calling storageBarrier will synchronize access to the contents of the storage buffer except for the atomic.

    The atomic access will all be visible to all the invocations, but there is no way to to synchronize them, you can just change the atomic value.

    Is that right?

  4. alan-baker commented on May 31, 2022

    @alan-baker
    Contributor

    Not exactly. Atomics operations made through the same reference (e.g. variable) are mutually ordered. Additionally, there is a modification order, that is all invocations would witness modifications in the same order. Because WGSL only supports relaxed memory ordering for atomics they cannot be used for synchronization, but they are always coherent and synchronize with other atomic operations to the same location.

    Barriers provide the only synchronization mechanism for non-atomic memory operations in WGSL. As such an author can only rely on a consistent view of non-atomic memory operations within a workgroup because that is the memory scope of barriers.

    So,

    The atomic access will all be visible to all the invocations, but there is no way to to synchronize them, you can just change the atomic value.

    Atomics will never race on the same location given the constraints we have in the language (e.g. no aliased bindings). A barrier is unnecessary to synchronize atomics.

  5. dj2 commented on May 31, 2022

    @dj2
    MemberAuthor

    That makes sense, thanks. Clarifying this in the spec would be useful.

  6. added this to the V1.0 milestone on May 31, 2022
  7. added
    copyediting
    on Jun 7, 2022
  8. modified the milestones: Milestone 1, Milestone 2 on Oct 2, 2025
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

    copyeditingwgslwgsl:types

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions