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
In a single shader instance, can one render target or resource alias the storage of another? #287
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:
Investigation: Render Target Aliasing #63: Render target aliasing. Limited to render targets, and concerned about sharing between render passes, not within a render pass. Also, the resolution is postponed beyond MVP
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.
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.
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.
devshgraphicsprogramming commented on Oct 28, 2019
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.
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.
Storage textures are either readonly or writeonly (and readonly might be removed). Another discussion will be necessary for read-write storage textures when we add them.
Activity
litherum commentedon May 13, 2019
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.
kvark commentedon May 13, 2019
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.
dneto0 commentedon May 16, 2019
Discussed in F2F meeting 2019-05-16:
devshgraphicsprogramming commentedon Oct 11, 2019
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.
devshgraphicsprogramming commentedon Oct 28, 2019
Actually if you declared the SSBO/Storage Image as
coherentin 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.
Kangz commentedon Jun 1, 2021
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:
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.
Kangz commentedon Jun 15, 2021
Closing this issue as it is mostly resolved.
Add validation tests for CopyTextureToTexture - Part II (gpuweb#287)