So I will elaborate on the title
What I am trying to accomplish is do all the computation and rendering in one process and then read the resulting frame (I am going for swapchain backbuffer before present when all computation is done) from another process and show it on display. Basically I want to share video memory (not the whole screen just the app window) between two separate processes.
I am using direct3d11 with DirectXTK. My laptop has NVIDIA gpu along with intel UHD 620 graphics . Opened visual studio with admin access.
Here goes the code where I try to create shared handle to the buffer
auto swapChain = m_deviceResources->GetSwapChain();
/*ComPtr< ID3D11Resource> backbuffer;*/
/*swapChain->GetBuffer(0, __uuidof(ID3D11Resource),
(void **) backbuffer.GetAddressOf());*/
swapChain->GetBuffer(0, __uuidof(ID3D11Texture2D),(void **)tex_shared.GetAddressOf());
D3D11_TEXTURE2D_DESC tex_2d_desc{};
tex_shared->GetDesc(&tex_2d_desc);
tex_2d_desc.MiscFlags = D3D11_RESOURCE_MISC_SHARED_KEYEDMUTEX | D3D11_RESOURCE_MISC_SHARED_NTHANDLE;
tex_2d_desc.CPUAccessFlags = D3D11_CPU_ACCESS_READ | D3D11_CPU_ACCESS_WRITE;
HANDLE sharedhandle=nullptr;
IDXGIResource1* pOtherResource=nullptr;
tex_shared->QueryInterface(__uuidof(IDXGIResource1), (void**)&pOtherResource);
SECURITY_ATTRIBUTES sa{};
sa.bInheritHandle = FALSE;
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = NULL;
pOtherResource->CreateSharedHandle(&sa,GENERIC_ALL,L"SharedTexture" ,&sharedhandle);
From another process I try to retrieve the handle with this code
ComPtr<IDXGIResource1> p_tex_shared;
device->OpenSharedResourceByName(L"SharedTexture",
DXGI_SHARED_RESOURCE_READ ,
__uuidof(IDXGIResource1),
(void**)p_tex_shared.GetAddressOf());
But I get this error
Exception thrown at 0x00007FF84751466C in SimpleTrianglePC.exe: Microsoft C++ exception: _com_error at memory location 0x000000139CEFF248.
D3D11 ERROR: ID3D11Device::OpenSharedResourceByName: Returning E_INVALIDARG, meaning
invalid parameters were passed. [ STATE_CREATION ERROR #381:
DEVICE_OPEN_SHARED_RESOURCE_INVALIDARG_RETURN]
D3D11: **BREAK** enabled for the previous message, which was: [ ERROR STATE_CREATION
Exception thrown at 0x00007FF84751466C (KernelBase.dll) in SimpleTrianglePC.exe:
0x0000087A (parameters: 0x0000000000000001, 0x000000139CEFC500, 0x000000139CEFE2D0).
Unhandled exception at 0x00007FF84751466C (KernelBase.dll) in SimpleTrianglePC.exe:
0x0000087A (parameters: 0x0000000000000001, 0x000000139CEFC500, 0x000000139CEFE2D0).
I tried using OpenSharedResource1 too instead of OpenSharedResourceByName but gives same error.
You can't modify the texture surface owned by the DXGI swapchain to add the share flags like you tried to do above. Your best bet is going to require copying the backbuffer to a sharable texture.
ID3D11DeviceContext::CopyResourceto copy the context from the backbuffer to the sharable texture each frame.See Microsoft Docs