D3DUSAGE_DYNAMIC to D3DUSAGE_RENDERTARGET

Started by
2 comments, last by Sc4Freak 16 years, 1 month ago
m_pShadowMapSurf is the surface attached to RenderTarget texture. I copy the pSmTile->m_pShadowMapSurf to m_pShadowMapSurf_For_CPU(m_pShadowMapTex) successfully. But I have a problem hr=m_pEffect_QVSM_ADAPTIVE->SetTexture("TestBaseTexture", m_pShadowMapTex_For_CPU); When I SetTexture of m_pShadowMapTex_For_CPU for an effect, it return S_OK. But I cannot see the Texture I want. If I save the Texture of m_pShadowMapTex_For_CPU to a png file. The png file is what I want. If effect SetTexure of RenderTarget texture, it return OK and the texture display in the screen. So shader code and relative source code have no problems Is the parameters of D3DUSAGE_DYNAMIC and D3DPOOL_MANAGED incompatible with Effect->SetTexture?

HRESULT CSmTile::CopySmTileFrom_GPU_To_CPU(CSmTile* pSmTile)
{
	HRESULT hr;

	D3DSURFACE_DESC Desc;
	pSmTile->m_pShadowMapSurf->GetDesc(&Desc);

	// setup shadow map objects
	hr=m_pd3dDevice->CreateTexture(
		Desc.Width,
		Desc.Height,
		1, 
		D3DUSAGE_DYNAMIC,
		Desc.Format, 
		D3DPOOL_MANAGED,
		&m_pShadowMapTex_For_CPU,
		NULL
		);

	hr=m_pShadowMapTex_For_CPU->GetSurfaceLevel(0,&m_pShadowMapSurf_For_CPU);

	//V_RETURN(m_pd3dDevice->CreateOffscreenPlainSurface(Desc.Width,Desc.Height,Desc.Format,D3DPOOL_SYSTEMMEM,&m_pShadowMapSurf_For_CPU,NULL));//Must be D3DPOOL_SYSTEMMEM for MSDN
	V_RETURN(m_pd3dDevice->GetRenderTargetData(pSmTile->m_pShadowMapSurf,m_pShadowMapSurf_For_CPU));

	//hr=D3DXSaveTextureToFile(L"t1.png",D3DXIFF_PNG ,m_pShadowMapTex_For_CPU,NULL);

	return S_OK;
}


akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
Advertisement
GetRenderTargetData needs to work with a system memory surface. That surface won't get rendered.

Why do you copy to the CPU and back, instead of using the render target as is?
Quote:Original post by ET3D
GetRenderTargetData needs to work with a system memory surface. That surface won't get rendered.

Why do you copy to the CPU and back, instead of using the render target as is?


Even I set the pool of texture as system memory, I still can not see the object.
The texture created by using the pool of system memory always cannot be rendered?

The reason of "copy to CPU and back" is that I want to copy the pSmTile->m_pShadowMapSurf to certain texture (I called it as tmpTexture) from video memory to system memory, and then I want to clear the memory of pSmTile->m_pShadowMapSurf. After previous copy operation and some operation, I will render the ceratin texture (tmpTexture). I think this way is very strange. I just set the pointer of tmpTexture to be the pointer of texture of pSmTile->m_pShadowMapSurf. But I afraid that the video memory is not enough for creating many textures. So I choice the method of "copy to CPU and back".

	hr=m_pd3dDevice->CreateTexture(		Desc.Width,		Desc.Height,		1, 		0,		Desc.Format, 		D3DPOOL_SYSTEMMEM,		&m_pShadowMapTex_For_CPU,		NULL		);
akira32 編程之家 Yahoohttp://tw.myblog.yahoo.com/akira32-akira32
From the DXSDK docs:
Quote:D3DPOOL_SYSTEMMEM
Resources are placed in memory that is not typically accessible by the Direct3D device. This memory allocation consumes system RAM but does not reduce pageable RAM. These resources do not need to be recreated when a device is lost. Resources in this pool can be locked and can be used as the source for a IDirect3DDevice9::UpdateSurface or IDirect3DDevice9::UpdateTexture operation to a memory resource created with D3DPOOL_DEFAULT.

In other words, you cannot use a D3DPOOL_SYSTEMMEM surface with the device - aka you can't render with it.

Copying data from GPU->CPU and back again is a very, very slow operation. You want to avoid this at all costs. If all you want to do is clear the surface, you can use the IDirect3DDevice9::Clear() function to clear the currently set render target. If you want to do other operations on it (such as drawing, etc.) you're much better off just using it as a render target and using the GPU to do your rendering.
NextWar: The Quest for Earth available now for Windows Phone 7.

This topic is closed to new replies.

Advertisement