Zig Structs of Arrays (2024)
66 points
4 days ago
| 6 comments
| andreashohmann.com
| HN
smallstepforman
52 minutes ago
[-]
The GPU loves arrays of structures AoS, since all vertex data fits in its triangle assembly cache. Once given to the GPU, the software side doesnt really care for all vertex parameters so this optimisation is pointless. Only relavent when you have instance rendering (leaves, grass) but then you only need an array of vec3’s, not the other parameters so back to normal arrays.

Meanwhile, game engines need operator overloading for adding/multiplying vectors (spatial transforms, lighting, physics) and core zig design philosophy prevents operator overloading.

Blind leading the blind. Disclaimer - I do professional rendering engines.

reply
awesan
33 minutes ago
[-]
Zig is adding native vectors including operator support, there are some recent issues/prs about this topic.

The general technique of SoA is pretty useful both in games and other applications, but of course I cannot speak to the specific use-case you are describing.

reply
beepbooptheory
31 minutes ago
[-]
So is the argument that any SoA is pointless? Or just for GPU stuff? Because this isn't really talking about all that one way or another.

Also does one really need operator overloading? That feels a little strong. I've gotten by with functions just fine.. Does that make the GPU not like me Mr. wise engineer?

reply
Sweepi
2 hours ago
[-]
OT: I just spend a few minutes searching for the source of the "Not all CPU operations are created equal" slide of the linked presentation (Andrew Kelley - Practical DOD), its here:

https://6it.dev/blog/infographics-operation-costs-in-cpu-clo...

reply
skywal_l
1 hour ago
[-]
You URL seems KO, an alternative I found: https://x.com/chessMan786/status/1879092981892067383/photo/1
reply
hiccuphippo
1 hour ago
[-]
reply
binaryturtle
1 hour ago
[-]
I'm just seeing a "410 Gone" error on the linked site (same happens to the parent URL too).
reply
ArneCode
1 hour ago
[-]
Works for me
reply
binaryturtle
39 minutes ago
[-]
Still the same. I guess it's some sort of wild anti-bot stuff basing on the user agent?

/edit

Yes, as confirmed with cURL, using my browser's "User Agent": 410 blocked. Using some other "User Agent" and it passes along the data. Pretty silly, IMHO.

reply
trymas
1 hour ago
[-]
Slightly related recent HN post: https://news.ycombinator.com/item?id=48382382
reply
Thaxll
1 hour ago
[-]
This is what games do with ECS.
reply