Sign in to follow this  
anglee

Switch from DDraw to D3D make frame rate drop

Recommended Posts

anglee    122
I am writing a function that brings the content of a offscreen surface to the screen. The function is called after a frame finished rendering to the offscreen surface. Using Direct3D, the frame rate is much lower than using DirectDraw and the result animation jitters, which is very annoying. I'm wondering if there is a way to achieve same frame rate. Here is how I did it: In DirectDraw, I use the Blt functiton to copy the offscreen surface directly to the onscreen surface:
directDrawObj->GetVerticalBlankStatus(&s);
if (s == FALSE)
	directDrawObj->WaitForVerticalBlank( DDWAITVB_BLOCKBEGIN, NULL );
HRESULT hr = screenSurface->Blt(&dstR, offscreenSurface, &srcR, DDBLT_WAIT, NULL );

In Direct3D, the surface is copied to the backbuffer and than present. I am Using D3DPRESENT_INTERVAL_ONE, D3DSWAPEFFECT_DISCARD:
LPDIRECT3DSURFACE9 offscreenPlainSurface;
LPDIRECT3DSURFACE9 backSurface;

d3dDevice->GetBackBuffer(0, 0, D3DBACKBUFFER_TYPE_MONO, &backSurface);
d3dDevice->StretchRect(offscreenPlainSurface, srcR, backSurface, dstR);
d3dDevice->Present(dstR, dstR, NULL, NULL);

Comparing Direct3D method to DirectDraw method, the frame rate drop about 50% which kinda can be expected. I've also tried D3DSWAPEFFECT_FLIP, and it didn't help much there. Is there a way to solve this problem? Thanks in advance.

Share this post


Link to post
Share on other sites
jollyjeffers    1570
Directly accessing the frame buffers in D3D is generally a bad idea - it's quite common for people who use Direct3D in a DirectDraw style to get very bad performance. Where possible you want to use the ::Draw**() commands to get images on to the screen - directly modifying or accessing resources is more a last resort...

Without more details on what you're trying to achieve its difficult to suggest a solution, but you could look into "screen aligned quad" rendering. That and render target textures may get you what you need.


hth
Jack

Share this post


Link to post
Share on other sites
anglee    122
Quote:
Original post by Adam_42
Have you tried IDirect3DDevice9::UpdateSurface()?


Thank you for the suggestion.
I have tried it. However, to use UpdateSurface(), the surface must be D3DPOOL_SYSTEMMEM . But the other two functions I am using, StretchRect and ColorFill, require D3DPOOL_DEFAULT on the other hand.

Share this post


Link to post
Share on other sites
anglee    122
Quote:
Original post by jollyjeffers
...
Without more details on what you're trying to achieve its difficult to suggest a solution, but you could look into "screen aligned quad" rendering. That and render target textures may get you what you need.


hth
Jack


Thank you very much Jack. I will definitely look into screen aligned quad rendering.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this