-
Notifications
You must be signed in to change notification settings - Fork 321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
wgsl: support atomics on f32 (in workgroup and storage buffer) #4894
Comments
As discussed this can likely be worked around via bitcast and a uint32 CAS with possible exception of NaNs |
Starting off with a description in English, then I'll move to pseudocode and actual code. Consider a mesh of vertices and faces. Each face has computed a normal vector (this is called the "facet normal"). We wish to compute a normal vector for each vertex, which is the average of all of the normal vectors of the neighboring faces. The straightforward data-parallel way to compute this is via scatter at cost O(V+E):
|
Something like this. This uses a u32 cell in workgroup memory.
|
If we don't have an atomic add, we can recast this as gather, but it requires cost O(VE):
We could probably build a data structure that mapped vertices to faces (key: vertex, value: list of faces) and that would significantly reduce complexity. Note it's a variable-length list of faces per vertex (a vertex's valence might potentially be a rather high number). |
Here's the code I wrote to do this:
I agree that compare-and-swap is a viable way to do this and I will implement it. |
You can probably avoid parallel for each vertex in mesh: If you just normalize in the CAS. I wonder if the is a ABA problem with this? |
Not sure I understand? I have to wait for all adds to complete before I can normalize (I can't normalize halfway through). My mental picture is that I would need a global barrier to make sure all adds into a vertex normal are complete before I can normalize the resulting normal. |
You are correct. You would need to store additional information (a magnitude) if you wanted to avoid this secondary pass |
I teach the ABA problem but have never encountered it in the wild so this will be fun for me to learn about! |
@jowens has a use case.
The text was updated successfully, but these errors were encountered: