Advertisement

Synchronizing D3D11 texture and D3D12 resource data

Started by June 20, 2018 04:25 PM
1 comment, last by SoldierOfLight 6 years, 7 months ago

I have a problem synchronizing data between shared resources. On the input I receive a D3D11 2D texture, which itself is enabled for sharing and has D3D11_RESOURCE_MISC_SHARED_NTHANDLE in its description.

Having a D3D12 device created on the same adapter I open a resource through sharing a handle.

            const CComQIPtr<IDXGIResource1> pDxgiResource1 = pTexture; // <<--- Input texture on 11 device
            HANDLE hTexture;
            pDxgiResource1->CreateSharedHandle(NULL, GENERIC_ALL, NULL, &hTexture);
            CComPtr<ID3D12Resource> pResource; // <<--- Counterparty resource on 12 device
            pDevice->OpenSharedHandle(hTexture, __uuidof(ID3D12Resource), (VOID**) &pResource);

I tend to keep the mapping between the 11 texture and 12 resource further as they are re-filled with data, but in context of the current problem it does not matter if I reuse the mapping or I do OpenSharedHandle on every iteration.

Further on I have a command list on 12 device where I use 12 resource (pResource) as a copy source. It is an argument in further CopyResource or CopyTextureRegion calls. I don't have any resource barriers in the command list (including that my attempts to use any don't change the behavior).

My problem is that I can't have the data synchronized. Sometimes and especially initially the resource has the correct data, however further iterations have issues such as resource having stale/old data.

I tried to flush immediate context on 11 device to make sure that preceding commands are completed.

I tried to insert resource barriers at the beginning of command list to possibly make sure that source resource has time to receive the correct data.

Same time I have other code paths which don't do OpenSharedHandle mapping and instead do additional texture copying and mapping between original 11 device and 11on12 device, and the code including the rest of the logic works well there. This makes me think that I fail to synchronize the data on the step I mentioned above, even though I am lost how do I synchronize exactly outside of command list.

I originally thought that 12 resource has a IDXGIKeyedMutex implementation which is the case with sharing-enabled 11 textures, but I don't have the IDXGIKeyedMutex and I don't see what is the D3D12 equivalent, if any.

Could you please advise where to look at to fix the sync?

You're probably looking for ID3D11Fence. Treat your D3D11 device as if it was another D3D12 command queue.

This topic is closed to new replies.

Advertisement