Is there a way to make sure the texture was loaded before using it?

Hello,

I’m unable to ensure a texture is loaded and has the correct render resource before rendering. I need this in two places

  • uniform buffer that references few texture used with a compute shader.
  • texture baking

Naturally, I followed the example texture baker built in Unreal. However, the code there doesn’t work. Basically, it’s:

  • Texture->SetForceMipLevelsToBeResident()
  • Texture->StreamIn(FStreamableRenderResourceState::MAX_LOD_COUNT, true)
  • IStreamingManager::Get().StreamAllResources(1) until all resources are loaded

After looking at more places in the UE sources, I threw in the mix:

  • IStreamingManager::Get().GetRenderAssetStreamingManager().FastForceFullyResident(Texture);
  • UTexture::ForceUpdateTextureStreaming();
  • Texture->WaitForPendingInitOrStreaming();
  • Texture->bIgnoreStreamingMipBias = true

The streaming API is really rich, maybe too rich for me, since I failed to do the job with all of them.

I also tried to disable streaming for these textures, but this didn’t help either. Basically, randomly, I get the default checkers texture. I’m probably still missing something key here.

Thanks,

Ivo

Hello,

Thank you for reaching out.

I’ve been assigned this issue, and we will be looking into texture readiness for you.

Hello,

Please check these following tickets, as they discuss the same type of request, and mention other functions that might be helpful for your use-case:

[Content removed]

[Content removed]

[Content removed]

[Content removed]

Please let us know if this helps.

Nope, sadly these do not work.

Hello,

Thank you for checking the other tickets.

Can you please send us a minimal test project that demonstrates the streaming miss, and include screenshots of the visual result?

The guide for test projects:

[Content removed]

Hi,

The problem is that this is part of a big project, I must try to create something from scratch, which isn’t trivial.

The problem which is 100% reproducible happens with compute shader and volumetric textures that I can’t send. Unreal has 3 different behaviour depending on how it’s started:

  • in the editor - only some textures are loaded the first time. Starting the game for a second time, all textures are loaded
  • shipping - all textures are loaded correctly right away
  • editor with -game command line (i.e. standalone)- none of the textures are loaded. Starting the game for a second time will not fix this

If I can reproduce the issue with 2d textures, this will be much easier for minimap project.

Our other issue - with the runtime texture baking is too random, it happens in shipping. But it also depends on many textures I can’t send.

Hello,

The grey checkerboard appearing likely means that a Material is not ready, rather than a texture. You can use the following two functions on the Materials to force them to be loaded as well:

UMaterial->CacheShaders(EMaterialShaderPrecompileMode::Synchronous);
UMaterial->EnsureIsComplete();

If you are using PSO Precaching and the CVar “r.PSOPrecache.ProxyCreationDelayStrategy” is set to 1, it could also mean that the PSO was not ready. Run the project with the command-line arguments “-logpso -clearPSODriverCache” to get log messages related to PSO Precaching misses.

Keep in mind “FRenderAssetStreamingManager::FastForceFullyResident(…)” does not block - it only enqueues the streaming request.

Please let us know if this helps.

Hello,

We had another crash related to the texture streaming issue. On the positive side, it gave me easy to reproduce test case. I’m attaching uproject.

The code is very simple:

  • load a texture asset
  • try to stream it in
  • create a second texture with the same size and try to do a copy

This code will crash because the render thread will check the size of the first image and detect it’s 32x32 since it’s still not loaded

Thanks,

Ivo

Hello,

Can you please try adding this line before the rest of the force loading code? It will update the texture on the GPU, so that the texture has somewhere to stream the MIPs into.

FTextureCompilingManager::Get().FinishAllCompilation(); // add this line
TexSrc->bIgnoreStreamingMipBias = true;
...

Please let us know if this helps.

Thanks, that seems to be what I was missing.

Hello,

Thank you for the reply.

Can we close your case? You can always re-open it if you need additional assistance for the same issue.

Sure