Hacker News new | past | comments | ask | show | jobs | submit

Zig Structs of Arrays (2024)

https://andreashohmann.com/zig-struct-of-arrays/
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.

loading story #48448054
loading story #48447643
Genuine question: why do you think game engines need operator overloading? I mean, what's wrong with generic functions like add, multiply, dot etc.
loading story #48446254
loading story #48446161
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.

Zig vectors force data into SIMD registers even if that would make the code slower. They're a specialty type. You should only reach for vectors if you would have used SIMD intrinsics in C for example.
Zig vectors do not necessarily force data into SIMD registers; a scalar implementation would work equally well. This is not just a theoretical argument, because Zig code that uses `@Vector` also has to compile for architectures that do not have SIMD instructions.

That being said, the parent commenter is actually referring to other recent proposals as opposed to existing `@Vector` functionality:

https://codeberg.org/ziglang/zig/issues/32032

https://codeberg.org/ziglang/zig/issues/35376

Interesting, so zig might have both "vectors" and "vecs"? I guess naming is another thing to fix before 1.0 <g>
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?

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

I'm just seeing a "410 Gone" error on the linked site (same happens to the parent URL too).
Works for me
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.

This is what games do with ECS.