Jump to content
  • Advertisement
aquila_prosperus

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

This topic is 377 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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!

 

Share this post


Link to post
Share on other sites
Advertisement

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.

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!