Community
cancel
Showing results for 
Search instead for 
Did you mean: 
Andrew_B_2
Beginner
77 Views

Copy contents of DirectX10 Texture

I am trying to encode a series of frames from a D3D10Texture2D using the Intel Media SDK.  I have the pipeline all setup and that works with test data and I am now trying to transfer data from my D3D10Texture2D to my VPP surface to start processing.  I am able to get a DirectX reference to the VPP surface using:

(IDirect3DSurface9 *)_mfxSurfacesVPPIn[nVPPSurfIdx]->Data.MemId

I am now trying to write to this surface from my D3D10Texture2D without using a system copy step and have it all in the GPU.  I am trying to do this by creating a texture from the surface and then open this DirectX 9 Texture as a shared resource from my DirectX 10 device.

           void fun(IDirect3DSurface9 * pSurface)
           {
			D3D10_TEXTURE2D_DESC desc;
			_sharedTexture->GetDesc(&desc);
			
			//	Create D3D9 texture of the surface to copy to
			IDirect3DDevice9 * d3d9;
			pSurface->GetDevice(&d3d9);
			
			int width = desc.Width;
			int height = desc.Height;

			HANDLE SharedHandle = NULL;
			LPDIRECT3DTEXTURE9 pTexture9 = NULL;
			HRESULT hr = d3d9->CreateTexture(width, height, 0, D3DUSAGE_RENDERTARGET, D3DFMT_A8R8G8B8, D3DPOOL_DEFAULT, &pTexture9, &SharedHandle);
			
			if (SUCCEEDED(hr))
			{
				IDirect3DSurface9* dest = NULL; // to be our level0 surface of the texture
				hr = pTexture9->GetSurfaceLevel(0, &dest);

				if (FAILED(hr))
				{
					return;
				}

				hr = d3d9->StretchRect(pSurface, NULL, dest, NULL, D3DTEXF_NONE);

				if (FAILED(hr))
				{
					return;
				}
				// Create a D3D10 reference to our texture
				ID3D10Texture2D* destTexture = NULL;

				hr = _d3dDevice->OpenSharedResource(SharedHandle, __uuidof(ID3D10Texture2D), (LPVOID*)&destTexture);

				if (FAILED(hr))
				{
					return;
				}

				if (destTexture != nullptr)
				{
					// Copy to the shared resource
					_d3dDevice->CopyResource(destTexture, _sharedTexture);
				}
			}
		}

At the moment it is failing at the StretchRect function and I am unsure why.  I want to continue using DirectX 9 support as I would like to support Windows 7.

Is this the way to go with moving data a DirectX 10 resource to a DirectX 9 resource?  Is there some other technique to do this?  Any ideas why the above copy of the surfaces is failing?

 

0 Kudos
0 Replies
Reply