Skip to content

Storage buffer access: compatibility with the pipeline layout #1837

Closed

Description

@kvark

This is a follow-up to #287, specifically about storage buffers.
In particular, the following questions need to be answered:

  1. given a buffer that's used as read-only storage in WGSL, is it compatible with a GPUBindGroupLayoutEntry that is read-write? I don't think the spec has clear rules for this.
  2. are multiple read-write storage bindings be compatible within the same usage scope? Currently, this is allowed by the spec.
  3. is read-only storage usage compatible with read-write storage usage? Currently the spec says no.

Activity

  1. kvark commented on Jun 14, 2021

    @kvark
    ContributorAuthor

    Personally, I feel rather strongly that (2) and (3) are currently well specified and do not need changes.

    As to (1), it's more subtle. I have a concern about the user-authored code. If I'm writing a shader that has a read-only storage buffer, I don't expect the data to change:

    struct Instance {
      position: vec4<f32>,
    };
    var<storage, read> intances: array<Instance>;
    ...
    const pos = intances[instance_index].position;
    // this may end up producing different positions for different vertices of the same instance

    I believe we should just say that the shader declarations need to match the bindings exactly, at least for MVP, and then consider relaxing it more if it's desired.

  2. Kangz commented on Jun 15, 2021

    @Kangz
    Contributor

    Thank you for the explanation.

    I was definitely very confused in yesterday's call and forgot that readonly storage buffers had to work at the same time as other readonly usages. This means they have to be SRVs in D3D12 and can't be used as read write storage since that would be UAV. Plus like you said, it would be confusing for user-authored code.

    Happy to close this issue as won't fix.

  3. Kangz commented on Jun 15, 2021

    @Kangz
    Contributor

    Actually 1) is interesting. "validate shader binding" asks that a readonly storage buffer in the shader matches with a readonly storage buffer in the layout. However Default pipeline layout automatically promotes a readonly storage buffer to storage buffer if needed. One of these two should be changed to match the other.

    As a side note, Dawn doesn't do "validate shader binding" as specced at the moment, but does layout defaulting as specced.

  4. kvark commented on Jun 15, 2021

    @kvark
    ContributorAuthor

    Interesting. Yeah, I think we should just change the Default pipeline layout to be strict.

  5. added this to the V1.0 milestone on Sep 2, 2021
  6. litherum commented on Oct 28, 2021

    @litherum
    Contributor

    Item 2 means I can do 2 draws in the same render pass, where each draw binds the same buffer as read-write? This seems reasonable to allow.

    This is a different question than whether the same resource should be able to be bound two two different names (where both are used) in a single shader. This is #2065 and has a different (more subtle) answer.

  7. litherum commented on Oct 28, 2021

    @litherum
    Contributor

    Item 3 seems fine to say "no."

    For item 1, your argument in #1837 (comment) seems compelling.

  8. Kangz commented on Nov 10, 2021

    @Kangz
    Contributor

    I think we can resolve this: for 1) and 3) the spec is clear that the layout's binding must match the readonlyness of the WGSL declaration (in validating shader binding):

    If entry.buffer.type is:

    • "uniform": variable is declared with the storage class uniform.
    • "storage": variable is declared with the storage class storage and access mode read_write.
    • "read-only-storage": variable is declared with the storage class storage and access mode read.
    1. is clearly something we want, but Describe resource aliasing rules #2065 is still open.

    So the only thing left is to fix the default layout algorithm.

  9. Kangz commented on Nov 10, 2021

    @Kangz
    Contributor

    Actually the default layout is already fixed. Closing this issue.

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

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions