December 20 2022

Early vs. Late Z-Kill (+ Hiring AI Dev)

For your GPU, rendering fragments (or “pixels”) is the main performance bottleneck nowadays.

Just think of the amount of potential fragments we have with these stupidly high screen resolutions (reason why DLSS are FSR are so popular). Personally, I wish devs would sometimes lock games to Full HD rather than targeting 4k… you’d get much better visuals most of the time.

But nope, marketing primes, so why not 8k @1 FPS?

Anyway, I always try to get away with not rendering unnecessary fragments. Like, not rendering fragments that are behind other opaque fragments, or fragments that fail the stencil test, etc..

But you know what?

You can easily mess up these GPU fragment tests by mistake (I quickly detect this when I do Unity consulting). Mistakes that tank your FPS dramatically.

Let me quickly explain this.

Your GPU has optimizations to kill the rendering of certain fragments BEFORE it even happens. For example, early z-test.

But… if you do certain operations in your fragment shaders, these early optimizations don’t work. Bad-boys like fragment clipping and discarding fragments. If you do those, you transform your fast “early z-tests” to SLOW “late z-tests”.

And worst of all, you will not know what’s going on. You’ll only see that your FPS (and monthly active users) s(t)inks.

Those problems won’t happen if you learn some low-level details of the fragment shading pipeline (topic I teach in the Unity Performance Taskforce this month). So becoming aware of the early vs. late GPU tests is a good step to build your optimization skills portfolio.

Unrelated: I’m looking for a developer with extensive experience in AI for games. Behavior trees, GOAP, FSM and such have to be your best buddies. If you are interested in applying, apply here and we’ll talk.

Ruben (The GameDev Guru)

The Gamedev Guru Logo

Ruben Torres Bonet (VReality Labs)
Breitenbachstraße 23, 13509 Berlin, Germany

This website is not sponsored by or affiliated with Facebook, Unity Technologies, or Gamasutra.

The content you find here is based on my own opinions. Use this information at your own risk.
Some icons provided by Icons8