4

I am trying to create two applications. One application will render a texture off-screen and the second application will read it from graphic memory and render/present it on window.

My doubt is is it possible to share graphic memory in directx 12.

My named shared memory approach is causing comptr addref error...

I am using a comptr for ID3D12Resource for texture data...

So how can we go on with such approach...

Maciej Dziuban
  • 474
  • 3
  • 21
JackCarver
  • 61
  • 7

1 Answers1

5

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.

Maciej Dziuban
  • 474
  • 3
  • 21