CesiumGS / cesium-unreal

Bringing the 3D geospatial ecosystem to Unreal Engine
https://cesium.com/platform/cesium-for-unreal/
Apache License 2.0
921 stars 295 forks source link

Refactor texture creation to avoid the need for a global lock #1527

Open kring opened 5 days ago

kring commented 5 days ago

This is a PR into #1521. Still to do:

Previously, creating textures in Cesium for Unreal was a two stage process:

  1. Do some work in a worker thread to turn the glTF Texture/Sampler/Image/ImageCesium into a LoadedTextureResult and Unreal FTextureResource. This was synchronous.
  2. Do some work in the main thread to turn the above into an Unreal UTexture2D. This was also synchronous.

Now it's a three step process:

  1. Create an FTextureResource from an ImageCesium, which may or may not be shared among multiple models/tiles. This happens in a worker thread but completes asynchronously (a Future resolves when it is done) because only the first worker thread that needs a shared image will process it, while the others wait (via Future) for the first.
  2. Do some work in a worker thread to turn the above FTextureResource plus the glTF Texture/Sampler/Image/ImageCesium into a new FTextureResource (pointing to the same RHI texture) and a LoadedTextureResult. This part is synchronous.
  3. Do some work in the main thread to turn the above into an Unreal UTexture2D. This part is also synchronous.