CaffeineMC / sodium

A Minecraft mod designed to improve frame rates and reduce micro-stutter
Other
4.77k stars 811 forks source link

Cache multi draw batches on regions #2771

Open douira opened 1 month ago

douira commented 1 month ago

I get an improvement of around 7% by caching multi draw batches on each region. The margin is somewhat smaller when in motion, but often the batch can still be reused. The increase in memory use seems to be minimal.

If only one section in the region changed, only re-writing the command buffer starting at that section might bring an improvement of 50% on average for regions with block updates, but the metadata management for such partial buffer writes is somewhat complicated and may not be worth it if we're going to be changing this part of the renderer anyway.

dev dev

dev with this patch dev with patch

douira commented 1 month ago

I've measured the cache hit ratios for some situations. Average over 100 frames (values eyeballed), limited to 150 fps, average world. The hit ratio will be better the higher the fps, but even with 30 fps the hit ratios were generally good.

not weighted by batch size (number of cached batches / total)

weighted by batch size (number of commands from cached batches / total)

douira commented 1 month ago

I hope I found all the places where cache invalidation needs to happen, but that's something to look out for during review.