Certainly possible to render to offscreen texture and display it in another process. To display, you can call CopyResource
or CopyTextureRegion
to copy shared resource into the Swapchain
's backbuffer and then present it.
I'm not sure what you mean by your named shared memory approach
, but to get interprocess memory sharing working you have to:
In process A:
In process B:
Sample sketched quickly (creates a buffer, but that shouldn't be any different for textures):
Microsoft::WRL::ComPtr<ID3D12Resource> ptr{};
if (isProcessA) {
HANDLE handle{};
throwIfFailed(device->CreateCommittedResource(
&CD3DX12_HEAP_PROPERTIES{D3D12_HEAP_TYPE_DEFAULT},
D3D12_HEAP_FLAG_SHARED,
&CD3DX12_RESOURCE_DESC::Buffer(1024),
D3D12_RESOURCE_STATE_COMMON,
nullptr,
IID_PPV_ARGS(&ptr)));
throwIfFailed(device->CreateSharedHandle(ptr.Get(), nullptr, GENERIC_ALL, L"Name", &handle));
} else {
HANDLE handle{};
throwIfFailed(device->OpenSharedHandleByName(L"Name", GENERIC_ALL, &handle));
throwIfFailed(device->OpenSharedHandle(handle, IID_PPV_ARGS(&ptr)));
}
Note, that you have to avoid collisions of Name
values passed to the ID3D12Device::CreateCommittedResource.
For further reference, see MSDN.