Download

Reading Render Targets without blocking game thread

Hey guys, i’m trying to read the data from render targets that i use to simulate water reactiveness like this:
https://youtube.com/watch?v=RWI1CRieWLs
Now, i want to add buoyancy to this generated waves, for this i have to re-read the render target info.

The problem is that the only info i have found at the moment is this one:

https://wiki.unrealengine.com/Render_Target_Lookup

With some adjustments, mainly getting the render target like this:
FRenderTarget *RenderTarget = Heightfields[CurrentHeightfieldIndex]->GameThread_GetRenderTargetResource();

I have been able to recover the render target info without any kind of crashes… but is veeeery slow, from 120 fps to 30fps (even limiting the updates to 30 fps TOP).
This line:

RHICmdList.ReadSurfaceData(
Context.SrcRenderTarget->GetRenderTargetTexture(),
Context.Rect,
*Context.OutData,
Context.Flags
);

is really slow, and i need to know if there’s a way to get the pixel data quickly… does anybody have an idea on how i can achieve something like that? or is it imposible right now?

I’m doing other things with RenderTarget like FFT/IFFT calculus, and is pretty mandatory to be able to queue data to be read from the render target at some point, even for basic buoyancy.

Cheers!

Even if you create a separate thread to do this, the action of reading pixels will probably lock the render thread until finished, so I’m not sure if there’s a workaround other than reduce resolution of the captured texture.

The problem is the “copying” of the data itself? would it be better if i read specific pixels instead ?

I have found that disabling HDR does an idiotic performance boost, for this we should use RTF_RGBA8

There’s an issue though, if we use any other value than RTF_RGBA_SOMETHING, the Render thread will crash, most probably because it assumes the 4 channels to always be allocated.
Does anyone knows why such a massive improvement from not using HDR?