I'm writing a DirectX application with two threads:
Producer thread grabs desktop frames with DirectX (as in the Desktop Duplication DirectX sample)
IDXGIResource* DesktopResource = nullptr; ID3D11Texture2D *m_AcquiredDesktopImage = nullptr; HRESULT hr = m_DeskDupl->AcquireNextFrame(500, &FrameInfo, &DesktopResource); hr = DesktopResource->QueryInterface(__uuidof(ID3D11Texture2D), reinterpret_cast<void **>(&m_AcquiredDesktopImage)); DesktopResource->Release(); // The texture pointer I'm interested is m_AcquiredDesktopImage
Consumer thread performs image processing operations on the GPU.
To avoid copies I'd like to keep everything on the GPU as much as possible. From ReleaseFrame's documentation I kinda get that I should call ReleaseFrame
on the desktop duplication interface as soon as I'm done processing the frame.
My question: should I copy the m_AcquiredDesktopImage
texture into another one and call ReleaseFrame
as soon as the copy is finished and return that new texture to the producer thread for processing or can I just get away with returning the m_AcquiredDesktopImage
texture pointer to the consumer thread? Is this a copy of the framebuffer texture or is it the framebuffer texture and I might generate a data race by returning it?
Which one is the correct way to handle a producer of grabbed frames and a consumer of GPU textures?