I am using 2 directx devices, one to render in my native C++ plugin and the other belongs to Unity. I do the rendering in my plugin but then I send the render target to the unity graphics pipeline. This works generally, but sometimes there is a flicker in the resulting render. I recorded it and slowed it down and it appears as if the frame is in the process of being rendered, one mesh has missing triangles as if it was in the process of drawing the rest of the triangles, and most of the rest of the meshes are completely missing.
My question is, how do I force the render to finish before it is accessed again in the shared resource from unity rendering pipeline? I am already using a mutex lock but that doesn't seam to work, it seems like I need to synchronize from the graphics card. I used a IDXGIKeyedMutex but that actually stopped everything from rendering for some reason, maybe I used it wrong, I don't know. Any help would be much appreciated.