Jump to content

Streaming back render target


photo

Recommended Posts

Posted

For certain functionality, we need to read back the output of a rendering operation. The rendering itself is done in C++ and in the end we use Texture::getImage() to get the result into an image we can read back in script and process the result. This however is a performance bottleneck as this getImage() function stalls the GPU. For our situation it is not needed to immediately read back the result, it could be delayed one of two frames by cycling through multiple render buffers. However, waiting does not help here, since only when getImage() is called, a request is made to the GPU to retrieve the image, which is then pushed to the back of the command buffer, and then it starts waiting for this command to be executed.

 

I took a look at D3D11Texture.cpp, it seems to stall because it calls CopyResource to copy the render target to the staging texture right before mapping the staging texture. Because this copy is done by the GPU, mapping immediately after CopyResource will stall the CPU. I did a small hack here to test the performance, if I call CopyResource once directly after finishing rendering and then call map with D3D11_MAP_FLAG_DO_NOT_WAIT flag, it will not stall, and when I then request the image two frames later (without repeating CopyResource) I get about 20% higher framerate, so it does seem to be worth having a two stage getImage. Would it be possible to have this, or is there something similar hidden away somewhere already?

Posted

Hi there, Michiel!

 

Glad you patched our engine to make it faster! I'm not sure if we need to set this behaviour by default but at least we could think about how to provide this flag in order to be used by our customers. Also, I'm worrying about OpenGL implementation as well.

 

Could you send us a patch with the changes or you just changed one flag?

×
×
  • Create New...