Skip to content

Optimize polygon sorting on batch renderer

Hanicef requested to merge Hanicef/SRB2:optimize-batch-sorting into next

one final optimization before 2.2.14: the way we currently render polygons is... suboptimal. in order to allow us to render polygons efficiently, we sort them based on variables that change rendering, so polygons with the same shader, texture, polyflags, color and light are all in sequence to be pushed to the GPU simultaneously. the problem is that the CPU doesn't do a good job at handling polygons, since that's the GPU's job after all.

here's the thing, though: the order doesn't strictly matter as long as related polygons are grouped. this allows us to use a hash to sort the polygons, which is much faster than checking all related fields to sort the elements. using FNV-1a as a simple hash algorithm, we can hash the related elements and sort on the hash instead, which lowered the amount of CPU samples in comparePolygons from 12% to 3%, and halved the CPU usage for polygon sorting in perfstats 1.

Merge request reports

Loading