Share via

D3D11 texture sharing between two devices

slice3984 0 Reputation points
2023-12-18T18:24:29.2366667+00:00

Hello,

i attempt to share D3D11Texture2D textures between two D3D11Device devices but I'm unable to make it work.

This is my function to generate my shared textures: https://pastebin.com/8WVRaHfA (Too long for a code block)

This is what the struct looks like keeping a reference to my textures: https://pastebin.com/avcNV814

First I tried to modify my shared texture and checked the result in renderdoc. My shared texture got updated but the main texture my shared texture points to is still empty:

sharedTextures = createSharedTextures(1920, 1080, pD3d11DeviceUnity, pD3d11DeviceFFmpeg, 3);
pD3d11DeviceCtxFFmpeg->CopyResource(sharedTextures.bufferTextures[0].pFFmpegTex, testTex);
pD3d11DeviceCtxFFmpeg->CopyResource(sharedTextures.bufferTextures[0].pFFmpegTex, testTex); // testTex is owned by pD3d11DeviceFFmpeg


=> sharedTextures.bufferTextures[0].pUnityTex is still blank

Then I attempted to use synchronization:

sharedTextures = createSharedTextures(1920, 1080, pD3d11DeviceUnity, pD3d11DeviceFFmpeg, 3);
DWORD result = sharedTextures.bufferTextures[0].pFFmpegMutex->AcquireSync(1, 5000);

    if (result == WAIT_OBJECT_0) {
        std::cout << "Mutex Acquired" << std::endl;
        pD3d11DeviceCtxFFmpeg->CopyResource(sharedTextures.bufferTextures[0].pFFmpegTex, testTex);
        sharedTextures.bufferTextures[0].pFFmpegMutex->ReleaseSync(0);
        std::cout << "Mutex Released" << std::endl;
    } else if (result == E_FAIL) {
        std::cerr << "E_FAIL" << std::endl;
    } else if (result == WAIT_ABANDONED) {
        std::cerr << "WAIT_ABANDONED" << std::endl;
    } else if (result == WAIT_TIMEOUT) {
        std::cerr << "WAIT_TIMEOUT" << std::endl;
    } else {
        std::cerr << "Unable to acquire shared surface error" << std::endl;
    }

Which just ended in a thread lock until the timeout expired and printed WAIT_TIMEOUT.

I'm not experienced with DirectX at all and hope someone in here is able to help me with my issue.

Windows development | Windows API - Win32
Developer technologies | C++
Developer technologies | C++

A high-level, general-purpose programming language, created as an extension of the C programming language, that has object-oriented, generic, and functional features in addition to facilities for low-level memory manipulation.


1 answer

Sort by: Most helpful
  1. Deleted

    This answer has been deleted due to a violation of our Code of Conduct. The answer was manually reported or identified through automated detection before action was taken. Please refer to our Code of Conduct for more information.


    Comments have been turned off. Learn more

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.