Advertisement

What to release and when, while passing shared texture between two D3D11 devices

Started by November 06, 2017 11:11 AM
2 comments, last by aquila_prosperus 7 years, 3 months ago

As part of a video project I'm working on, I have to pass ID3D11Texture2D decoded by CUDA, from one D3D11Device to the other, which handles rendering. I managed to achieve the goal, but it looks like I'm leaking textures. The workflow looks as follows:

Sending side (decoder):


ID3D11Texture2D* pD3D11OutTexture;
	if (!createOutputTexture(pD3D11OutTexture))
		return false;
	
	IDXGIResource1* pRsrc = nullptr;
	pD3D11OutTexture->QueryInterface(__uuidof(IDXGIResource1), reinterpret_cast<void**>(&pRsrc));
	auto hr = pRsrc->CreateSharedHandle(
		nullptr, 
		DXGI_SHARED_RESOURCE_READ | DXGI_SHARED_RESOURCE_WRITE, 
		nullptr, &frameData->shared_handle);
	pRsrc->Release();

Receiving side (renderer):


ID3D11Texture2D* pTex = nullptr;
hres = m_pD3D11Device->OpenSharedResource1(
			frameData->shared_handle,
			__uuidof(ID3D11Texture2D),
			reinterpret_cast<void**>(&pTex));
              
DrawFrame(pTex);
pTex->Release();
CloseHandle(frameData->shared_handle);              

I'm somewhat puzzled by the inner workings of this workflow, namely:

  • what happens when I create a shared handle? Does this allow me to release texture?
  • what happens, when I call OpenSharedResource? Does it create separate texture - that is do I have to release both textures after rendering?

Appreciate your help!

 

The underlying resource will stay alive as long as there is at least one D3D resource or NT shared handle referencing it. In order to destroy it, you must release the original (created) resource, the NT handle, and the opened resource.

Advertisement

Then it's exactly as I thought it is. Thanks SoldierOfLight!

This topic is closed to new replies.

Advertisement