shared texture in dx9 between processes

chenhao li 1 Reputation point
2021-07-14T03:21:17.893+00:00

I want to share texture resource between different processes. My problem is that when I create a shared texture in process A, then I create a texture in process B by using sharedHandle. the createTexture funciton return S_OK, but when I want to show the texture , it shows a black texture.

Here is the process A:

 HANDLE SharedHandle = nullptr;  
       IDirect3DTexture9* d3dTex = nullptr;  
       D3DLOCKED_RECT lockrect;  
       HRESULT res = g_pD3D_DeviceEx->CreateTexture(8, 8, 1,   
       D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &d3dTex, &SharedHandle);  
        res = d3dTex->LockRect(0, &lockrect, 0, 0);  
        pData = (DWORD*)((BYTE*)lockrect.pBits + lockrect.Pitch);  
        for (int y = 0; y < 8; y++)  
        {  
            for (int x = 0; x < 8; x++)  
            pData[x] = Image[y * 8 + x];  
        }  
  
        d3dTex->UnlockRect(0);  
  
         ....  
        g_pD3D_DeviceEx->SetTexture(0, d3dTex);  

the result is
114357-thumbnail-265cfcc604c55243866ede4d351d0451png.png

the process B is just like A but without LockRect, just create it by shared handle

       HANDLE SharedHandle = pSharedHandle;  //get the handle from A process  
       IDirect3DTexture9* d3dTex = nullptr;  
   
       HRESULT res = g_pD3D_DeviceEx->CreateTexture(8, 8, 1, D3DUSAGE_DYNAMIC, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &d3dTex, &SharedHandle);  
         ....  
        g_pD3D_DeviceEx->SetTexture(0, d3dTex);  

while the result is
114368-thumbnail-ec50cda2d907d84d9b052ff4007926e4png.png

the HRESULT res is OK, the result is just like can not find the texture data.

Any suggestions will help, thanks

Universal Windows Platform (UWP)
{count} votes

Your answer

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