On-demand part and model textures via unity mipmap streaming - #418
Phantomical wants to merge 6 commits into
Conversation
|
@Phantomical Any that have a screen are affected, you can try DE, DE+MAS or ASET. After using it for around a month the only other bug I found is the game rarely crashes while loading during "ModuleManager: Running post-patch callbacks". During this period the memory usage is 97-99% even when successful so I guess it's caused by Kopernicus not being able to allocate memory. The log ends like this in those cases |
That's not too surprising, unfortunately. The way this works is that textures all get loaded up front and once we start loading models then we tell unity it is allowed to stream mipmaps for textures used by those models. This does mean that memory usage will max out right about when MM finishes patching. Not sure there's too much I can do about that. We don't have any way of knowing which textures are safe to make on-demand until they actually get used by a model. The usual advice of bumping up your swap space will probably help you here as well. Once you get beyond that and into part compilation then unity will be able to unload textures as you go so you should be safe after that. |
Mipmap streaming (safety valve): bake m_StreamingMipmaps into eligible bundle textures, enable QualitySettings.streamingMipmaps* sized to a fraction of VRAM, pin every streaming texture full-res on load, then release mesh/part textures at their bind sites (ModelInstructions plus two PartLoader postfixes) so only renderer-owned textures drop mips under real pressure. Eligibility gates on >=4KB mip chain and mip-level block alignment under the deepest reduction.
b3cce6b to
bc5fbea
Compare


This PR uses unity's mipmap streaming feature to stream in part and IVA textures on demand. This means that you get to set a memory budget and unity will take care of automatically streaming mipmaps from disk to vram depending on what parts are currently visible.
Here's how it works behind the scenes:
With a few edits to these two we can:
As it turns out, that's basically all you need to get mipmap streaming working. We can set
QualitySettings.streamingMipmapsAddAllCameras, then toggle whether it is enabled usingQualitySettings.streamingMipmapsActive.I don't have a profile in front of me right now, but the overhead for this looks to be about 0.5ms/frame. On the other hand, for an install with many part mods it looks to be able to save up to ~5GB of VRAM.
A testing build is available here for those who want to try it out
KSPCommunityFixes_1.41.1.zip