Zig Structs of Arrays (2024)

(andreashohmann.com)

66 points | by Tomte 4 days ago

7 comments

  • smallstepforman 57 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.

    • awesan 38 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.

    • beepbooptheory 36 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?

  • nejam 0 minutes ago
    Jdoemhoe
  • 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...

  • hiccuphippo 1 hour ago
  • trymas 1 hour ago
    Slightly related recent HN post: https://news.ycombinator.com/item?id=48382382
  • binaryturtle 1 hour ago
    I'm just seeing a "410 Gone" error on the linked site (same happens to the parent URL too).
    • ArneCode 1 hour ago
      Works for me
      • binaryturtle 43 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.

  • Thaxll 1 hour ago
    This is what games do with ECS.