Load Texture from GPU

Hello Everyone,

I want to know if it’s possible to load a texture from data stored in GPU and if yes, how to do that.
In my project, I have a server that sends encoded Images and the client (on Unity) decodes this image and display it on an object. I use NvPipe to encode and decode on both sides and it uses the GPU to do that. Currently, I use LoadRawTextureData to load a texture.

I ask this question because there is a transfer GPU → CPU and CPU → GPU and I want to remove this useless and expensive transfer if it’s possible.

Thank you in advance for your answer.

best regards

You can use Texture2D.ReadPixels to download the data from GPU memory. After that, you can use GetPixels() to get the actual color data array. This method is synchronous, and stalls the frame for some time. It’s better to use AsyncGPUReadback.

I tried some method like Texture2d::CreateExternalTexture() to get the texture data in gpu .I created a native Intptr for the CreateExternalTexture() using a native plugin but failed in the first time.
Then I realize maybe I should use the device that Unity is using to create the textrue native pointer.I modified the “Unity native plugin” example, Finally I succeeded. You can create a native plugin to pass the address of a gpu texture (in windows, as a D3D11Texture2D object ) to the Texture2d::CreateExternalTexture() method in unity script, then In Unity you assign this texture to some shader,then you will see the texture without copying it from gpu memory to cpu system memory.
Here is the example code.Use this example code to get the right device (in my project it’s “ID3D11Device”).Use this device to get the gpu texture and pass the texture to Unity. If you create the device in your own way without the Unity interface. Unity will crash when you try to pass the texture to it.