You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Storage buffer access: compatibility with the pipeline layout #1837
This is a follow-up to #287, specifically about storage buffers.
In particular, the following questions need to be answered:
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.
are multiple read-write storage bindings be compatible within the same usage scope? Currently, this is allowed by the spec.
is read-only storage usage compatible with read-write storage usage? Currently the spec says no.
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:
structInstance{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.
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.
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.
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.
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.
Activity
kvark commentedon Jun 14, 2021
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:
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.
Kangz commentedon Jun 15, 2021
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.
Kangz commentedon Jun 15, 2021
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.
kvark commentedon Jun 15, 2021
Interesting. Yeah, I think we should just change the Default pipeline layout to be strict.
litherum commentedon Oct 28, 2021
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.
litherum commentedon Oct 28, 2021
Item 3 seems fine to say "no."
For item 1, your argument in #1837 (comment) seems compelling.
Kangz commentedon Nov 10, 2021
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):
So the only thing left is to fix the default layout algorithm.
Kangz commentedon Nov 10, 2021
Actually the default layout is already fixed. Closing this issue.