Jump to content

RenderTarget Texture Loading is slow


photo

Recommended Posts

Posted

I'm Blitting one texture into another using RenderTargets, and while everything works as expected I am hitting a performance problem when it comes to the initial texture loading operation.

 

The structure of the problem is this... I want to designate a texture source in the UI and then Blit that texture into a RenderTarget Texture.  In order to designate the source texture in the UI I am using an AssetLink, then converting the AssetLink to a Texture using Texture.Load(), then Blitting the loaded texture into a RenderTarget Texture.  I am doing a number of these texture load/blit operations, and sometimes on high resolution textures.  This works well except the Texture.Load() function is creating a performance bottleneck, probably due to the size of texture (8192x8192).

 

Is there an alternative to designating a Texture in the UI where I can assign a texture directly to Texture, rather than loading a texture through an AssetLink?  

 

This is the code I'm using:

// Public Variables
public AssetLink blitTexturePath;

// Setup Render Texture
Texture renderTexDiffuse = new Texture();
renderTexDiffuse.Create2D(8192, 8192, 3, 1 << 9);

Texture renderTexture = new Texture();
renderTexture.Create2D(8192, 8192, 3, 1 << 9);

// Setup Blit Material
Material mat_Blit;
mat_Blit = Materials.FindManualMaterial("Blit_RGB");

// Load Texture from Path
Texture blitTexture = new Texture();
blitTexture.Load(blitTexturePath.Path, 0);

// RenderTarget Blit
RenderTarget rt = new RenderTarget();
rt.BindColorTexture(0, renderTexture);
rt.Enable();

	mat.SetTexture("src", renderTexDiffuse);
	mat.SetTexture("blit", blitTexture);

	Render.RenderScreenMaterial(mat_Blit.ManualName);

rt.Disable();
rt.UnbindColorTextures();

 

Posted

Hi,

There are currently no API for simple deferred texture loading aside from doing some shenanigans with Materials.
You should be able to create/load textures on another thread, but you can't render anything on a non main thread, so I'd suggest you could try to do this otherway around:

1) Create a simple struct that will contain texture and asset path you want to load and add them into list of tasks for worker thread.
2) Create worker thread and add logic that will wait for new tasks and go through incomplete task queue one by one.
3) When task is completed you can add them to completed list that you could check from a main thread for completed tasks.
4) Blit your texture into a diffrent one as you were previously doing.

This deferred method should hide long loading of such big textures but this depends if it is feasable for this particular case.



p.s. Never use random values like 3 for representing the FORMAT_RGBA8 format and 1 << 9 for FORMAT_USAGE_RENDER.
Those values will change in the future rendering such code incompatable.


Hope this helps!

  • Thanks 1
Posted (edited)

Thank you very much for the reply and advice.  I will try out the deferred method you suggested.

Edited by TanukiDigital
×
×
  • Create New...