Copying a GPU resource to a GPU resource?

Hi,

Does UE4 provide a way to copy a GPU resource into another GPU resource directly? That is, GPU → GPU rather than GPU → CPU → GPU.

My project relies on a lot of procedurally generated geometry and my constant enemy is busing sizable vertex data between the CPU and the GPU. This, unsurprisingly, proves to be a major bottleneck. I have solved this issue in my own test d3d11 framework by generating the geometry via a compute shader. The geometry is calculated in this compute shader and then written to a structured append buffer. Once this is complete, I have to copy this data into a vertex buffer for rendering. It is this final step to which my question relates.

Thanks!

1 Like

Anyone as an answer to the GPU to GPU question?

Not sure what do you mean by GPU → GPU.
I believe you can just set up a shared resource buffer and reuse the buffer between multiple shader calls.
The shaders calls are executed synchronously, so if you have one shader that generates data, and an another that wishes to work on that data.

In your scenario one buffer would generate the mesh, and a vertex shader probably should structure that data for the final output.

Not sure what do you mean by GPU → GPU.
I believe you can just set up a shared resource buffer and reuse the buffer between multiple shader calls.
The shaders calls are executed synchronously, so if you have one shader that generates data, and an another that wishes to work on that data.

In your scenario one buffer would generate the mesh, and a vertex shader probably should structure that data for the final output

Yes, UE4 provides that. The functions are defined in RHICommandList.h. Pick the one that suits your purpose most.

So is it possible to copy vertex buffer, index buffer, and normal vector buffer calculated in CUDA to some custom mesh component without copying once to CPU memory?

Yes, you can transition resource to compute pipeline and back. For CUDA, you will likely need to go beyond RHI and work with device pointer. In any case, it is possible.

Thank you for your comment. I haven’t tried in detail yet, but (do you think) it is possible to give a device pointer from CUDA to UE4’s pipeline without custom engine build?
If we can get ID3D11Device* and ID3D11Resource* from RHI, I think I can communicate between CUDA and UE4 directly through some CUDA - DirectX interop functions provided by CUDA.
However, I think we first need to know (on Windows) which DirectX version (11 or 12) has been used in a UE4 project from the code…