logoalt Hacker News

Zig Structs of Arrays (2024)

80 pointsby Tomtelast Thursday at 6:28 AM19 commentsview on HN

Comments

smallstepformantoday at 1:19 PM

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 3 replies
Sweepitoday at 11:26 AM

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 1 reply
trymastoday at 12:26 PM

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

binaryturtletoday at 12:56 PM

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

show 1 reply
Thaxlltoday at 12:47 PM

This is what games do with ECS.

nejamtoday at 2:26 PM

Jfpe?

nejamtoday at 2:16 PM

Jdoemhoe