Zig Structs of Arrays (2024)

105 points35 comments4 days ago
smallstepforman

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.

show comments
Sweepi

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...

show comments
trymas

Slightly related recent HN post: https://news.ycombinator.com/item?id=48382382

binaryturtle

I'm just seeing a "410 Gone" error on the linked site (same happens to the parent URL too).

show comments
Thaxll

This is what games do with ECS.

nejam

Jfpe?

nejam

Jdoemhoe