Skip to content

Optimize and rewrite texture loading#369

Draft
Phantomical wants to merge 19 commits into
KSPModdingLibs:masterfrom
Phantomical:faster-dds-loading
Draft

Optimize and rewrite texture loading#369
Phantomical wants to merge 19 commits into
KSPModdingLibs:masterfrom
Phantomical:faster-dds-loading

Conversation

@Phantomical

@Phantomical Phantomical commented Apr 30, 2026

Copy link
Copy Markdown
Collaborator

KSPCF's texture loader is pretty fast so normally I wouldn't really bother to optimize it, but I would like to do some additional work here and refactoring texture loading to go through asset bundles will help later on.

Here's what's changed:

  • Texture loading has been refactored pretty significantly. Each texture load now gets its own coroutine.
  • We now build an asset bundle on a background thread and use that to load all dds and cached png textures. This points the streaming data to the actual texture files on disk so unity takes care of reading the textures and uploading them to the gpu entirely off the main thread.
  • For other textures DDS loading is now more async:
    • Create a texture
    • Wait a frame for unity to finish its first upload
    • Use AsyncReadManager to read directly into the array returned by GetRawTextureData()
    • Apply (and make it unreadable if needed)
  • PNG/JPG textures are still loaded through UnityWebRequest, normal swizzling is now offloaded to a background thread. Cached png textures have their assets loaded via the asset bundle path above.
  • TGA/MBM/etc. remains mostly the same, though normal swizzling is offloaded.

This still needs a proper performance evaluation but my unscientific tests show performance to be similar to what was there before.

@Phantomical Phantomical marked this pull request as draft May 6, 2026 03:45
@Phantomical

Copy link
Copy Markdown
Collaborator Author

The performance comparisons above are inaccurate. Marking this as draft until I can come up with better ones (and those better ones actually show an improvement)

@Phantomical Phantomical changed the base branch from dev to master July 14, 2026 06:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant