CaffeineMC / sodium-fabric

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

Clear the texture atlas of unloaded textures to reduce VRAM usage. #2675

Open djmrFunnyMan opened 1 month ago

djmrFunnyMan commented 1 month ago

Bug Description

This is a vanilla bug which was marked as won't fix (MC-263119) I described it in a duplicate issue MC-274736 which is where I will be getting the reproduction steps from.

Basically even after removing a rsp, minecraft will keep the textures in the atlas and won't shrink the dimensions of the atlas either. This will cause excessive and unnecessary VRAM usage if you're frequently loading and unloading texture packs (particularly high res ones)

Reproduction Steps

You will notice the following:

Before: minecraft_textures_atlas_blocks png_0_before After: minecraft_textures_atlas_blocks png_0_after

Log File

Not relevant

Crash Report

Not relevant

PepperCode1 commented 1 month ago

After looking at the code of TextureAtlas, it seems like this issue is actually a driver bug or optimization, which is why the Mojira report was marked as won't fix. The code always calls glTexImage2D on all mip levels of the atlas texture before populating it with sprites, but since all parameters except the width and height stay the same, the driver may have an optimization to not reallocate the texture if it is already allocated with dimensions that are greater than or equal to the given dimensions.

djmrFunnyMan commented 1 month ago

Well even if this is the case (which it might not be) it would only prevent you from shrinking the atlas dimensions, not from clearing the excess textures.

PepperCode1 commented 1 month ago

The excess textures don't affect performance or memory usage so it doesn't matter if they are cleared or not. The dimensions definitely affect memory usage.