CesiumGS / CesiumGS/cesium-unity

Improve texture creation performance

Open
#206 8 comments 0 reactions 0 assignees View on GitHub
performance
Dominant language
C#
Stars
535
Forks
132
Avg merge
6h 45m
Merged PRs (30d)
1

Description

Unity is unfortunately lacking an API that allows us to create textures from a worker thread. So for models with large textures, the texture upload happening on the main thread causes significant frame rate drops.

@mwilsnd noticed in profiling that the Texture2D _constructor_ is actually a significant hotspot, even before we upload data. Presumably it is synchronizing with the render thread and causing a stall. So simply pooling textures, rather than creating and destroying them, may be a big win.

He also pointed out that this Unity-provided example:
https://github.com/Unity-Technologies/NativeRenderingPlugin
shows how to register for a callback on Unity's renderer thread, and create a render API specific texture there. Then, in the main thread, we use Unity's [Texture2D.CreateExternalTexture](https://docs.unity3d.com/ScriptReference/Texture2D.CreateExternalTexture.html) to create Unity texture from the RHI texture without stalling the main thread.

Contributor guide

Open the contributing guide

Research direction

Start by reviewing the Unity NativeRenderingPlugin example and the Texture2D constructor and Texture2D.CreateExternalTexture documentation linked in the issue. Compare the current texture upload path with renderer-thread callbacks, then define completion through reduced main-thread stalls and frame-rate impact for models with large textures.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp, unity
Domain
computer-graphics, game-dev, performance
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.