Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Still performance problems modifying an offscreen renderd surface

This topic is 5126 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

Hi, trying to modify an offscreen rendered surface, is there any other (faster) way than copying it to a D3DPOOL_SYSTEMMEM surface using GetRenderTargetData(m_defaultpoolSurface, m_systemmemSurface)? What I do to render my scene offscreen usig the D3DXCreateRenderToSurface method is to create first a dynamic texture with D3DXCreateTexture which needs D3DPOOL_DEFAULT to work properly:
hr = D3DXCreateTexture( m_pD3DDevice, 256, 256, 1, 
			D3DUSAGE_RENDERTARGET, 
			D3DFMT_A8R8G8B8, 
			D3DPOOL_DEFAULT, 
			&m_pDynamicTexture);

if( FAILED(hr) )
{
	MessageBox(NULL,TEXT("Failed to create a texture with the D3DUSAGE_RENDERTARGET usage flag set!"),
		   TEXT("ERROR"),MB_OK|MB_ICONEXCLAMATION);
	exit(-1);
}

D3DSURFACE_DESC desc;
m_pDynamicTexture->GetSurfaceLevel( 0, &m_pTextureSurface );
m_pTextureSurface->GetDesc( &desc );

hr = D3DXCreateRenderToSurface( m_pD3DDevice, 
                            	desc.Width, desc.Height, desc.Format, 
                                TRUE, 
				D3DFMT_D16, 
                                &m_pRenderToSurface );
And then render the scene between m_pRenderToSurface->BeginScene( m_pTextureSurface, NULL ) and m_pRenderToSurface->EndScene( 0 ). After that I use the m_pD3DDevice->GetRenderTargetData(m_pTextureSurface, m_pD3DSurface) to copy the surface to system memory so I''m able to modify it as usual: m_pD3DSurface->LockRect(&d3dlr, 0, D3DLOCK_DONOTWAIT); //modify algorithm m_pD3DSurface->UnlockRect(); I need to apply an algorithm to modify the rendered scene, so I need it to be copied to system memory. Now I just use memcpy for test reasons to see I''m able to modify the surface.. so at this point the algorithm isn''t responsible for my performance problems. Is this the only way to do this? I''ve been reading Performance Optimizations Tips but I don''t find any clue. Thanks!

Share this post


Link to post
Share on other sites
Advertisement
Any copying from video memory will be slow, actually with modern video cards its not that bad - but still if you really have to do some manual modifications of rendered image - then use pixel shaders, maybe write what kind of algorithm is it?

Share this post


Link to post
Share on other sites
I pretend to create a chroma algorithm to set all pixels in a green range color to transparent, using alpha channel. Not only one color key, but a range.

I''m thinking of using MMX assambler to improve performance (not sure if is called like this in english, sorry), but just for test I tried using memcpy to see how fast I can lock/modify/unlock a surface and it doesn''t seem to be very fast, since I have to copy from default memory (video card one) to system memory to do that.

In fact, I''m creating different video streams from the surfaces I render, so I''ve to lock/modify/unlock at least 5times per second each surface... to update any scenes changes (translations, rotations of objects, etc).

Thanks again

Share this post


Link to post
Share on other sites
Iam not sure if I understand corectly what chroma algorithm do but if all your computations are per pixel only then using pixel shader can really speed things up. I understand that for any pixel in a given color range you want to set its alpha. All you have to do then is render quad of the same size as the video frame texture and use this texture in pixel shader to output to render target surface. This way all the computations takes place inside the video card so there is no transfer from video memory to system memory.

Iam also doing computations on GPU, but I need the results so I have to copy rendered textures to system memory - small textures
of size 128x128 takes aproximately 16ms - on ati 9800 PRO so it can be executed at most few times per second.

martin

Share this post


Link to post
Share on other sites
quote:

I understand that for any pixel in a given color range you want to set its alpha.



That''s exactly what I want to do, but I also have to copy the texture to my video sample buffer to provide a video stream.

So, if I''ve understand you.. the chroma stuff can be made using a pixel shader (I''ll have to work around this, never done it before hehe).. but to copy the result surface with the correct alpha value to my video sample buffer, I''ll have to do it as normal (lock/memcpy/unlock). Did I understand right?

Thanks again

Share this post


Link to post
Share on other sites
hey, if you want to send it over the network or store it to file on the disk - then I think you will have to copy it to system memory first. You might also look at ati "video shaders" - there is a demo on ati.com : "Video Shader Demo".

Share this post


Link to post
Share on other sites
quote:

if you want to send it over the network or store it to file on the disk - then I think you will have to copy it to system memory first.



I'm just going to do realtime processing of the videos to the screen, so.. I was wondering if there was a way to get do processing directly to the surface in video memory.

The IVMRMixerBitmap9 interface does something similar with very good performance, but I don't know how it internally works
(I'm not using this interface because it's limited to one surface over all other videos, and I want to have several surfaces which can be over or under the other videos)

Thanks





[edited by - crypting on May 9, 2004 10:16:55 AM]

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!