Archived

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

jat299

Improving framerates in D3D8

Recommended Posts

Hello Im currently doing a project at uni creating a 3d game which is going alright. Ive created a basic engine that loads in a self designed map format and creates a buffer of vertices and sends these to be rendered in one go. There are currently less than 200 polygons in the scene but the frame rate varies between 60 to 40fps depending on where you look. Hardware acceleration is on, and as ive said i only make one call to a vertex buffer per frame. Does anyone know how i can improve speed so i can expand my map without it crawling along? Would it help if i posted code? James

Share this post


Link to post
Share on other sites
What hardware are you running on? 50fps would be great on a Voodoo3 but dreadful for a geforce.

I''ll assume your using D3D8.

Are you updating the vertex buffer every frame? If so you might need to investigate dynamic vertex buffers.

Do you need to update it each frame?

What are your Present parameters? Its possible that your being locked to the refresh rate. For debugging purposes I tend to use:
d3dpp.SwapEffect = D3DSWAPEFFECT_DISCARD
d3dpp.FullScreen_PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE

More details about what you''re doing would be useful.

Benedict

Share this post


Link to post
Share on other sites
50fps wouldn't be great for a voodoo3 when he's only pushing 200 polygons :o

but benedict is right, we need to know what your device creation paramaters are and what hardware you're running on.



[edited by - sorrow on March 22, 2002 10:23:19 AM]

Share this post


Link to post
Share on other sites
Im running it on a 1.4GHz Athlon, and a geforce using d3d8.

Yes, im updating the vertex buffer each time, but no i dont need to. I tried to save the buffer i created but it kept falling over when i did that as i didnt release it.

Here is the code that i use to initialise the device, is this what you were after? If it doesnt become nicely formatted when i post it, ill try again.

James

**********************************************

// Initializes the Direct3D device
int InitDirect3DDevice( HWND hWndTarget, int Width, int Height, BOOL bWindowed,
D3DFORMAT FullScreenFormat, LPDIRECT3D8 pD3D,
LPDIRECT3DDEVICE8* ppDevice ){
// Structure to hold information about the rendering method
D3DPRESENT_PARAMETERS d3dpp;
// Structure to hold information about the current display mode
D3DDISPLAYMODE d3ddm;

HRESULT r = 0;

if( *ppDevice )
(*ppDevice)->Release();

// Initialize the structure to 0
ZeroMemory( &d3dpp, sizeof( D3DPRESENT_PARAMETERS ) );

// Get the settings for the current display mode
r = pD3D->GetAdapterDisplayMode( D3DADAPTER_DEFAULT, &d3ddm );
if( FAILED( r ) ){
SetError( "Could not get display adapter information" );
return E_FAIL;
}

// The width of the back buffer in pixels
d3dpp.BackBufferWidth = Width;
// The height of the buffer in pixels
d3dpp.BackBufferHeight = Height;
// The format of the back buffer
d3dpp.BackBufferFormat = bWindowed ? d3ddm.Format : FullScreenFormat;

// The number of back buffers
d3dpp.BackBufferCount = 1;

// The type of multisampling
d3dpp.MultiSampleType = D3DMULTISAMPLE_NONE;
// The swap effect
d3dpp.SwapEffect = D3DSWAPEFFECT_COPY_VSYNC;

// The handle to the window that we want to render to
d3dpp.hDeviceWindow = hWndTarget;
// Windowed or fullscreen
d3dpp.Windowed = bWindowed;

// Let Direct3D manage the depth buffer
d3dpp.EnableAutoDepthStencil = TRUE;
// Set the depth buffer format to 16 bits
d3dpp.AutoDepthStencilFormat = D3DFMT_D16;

// Use the default refresh rate available
d3dpp.FullScreen_RefreshRateInHz = D3DPRESENT_RATE_DEFAULT;

// Present the information as fast as possible
d3dpp.FullScreen_PresentationInterval = bWindowed ? 0 : D3DPRESENT_INTERVAL_ONE;
// Allow the back buffer to be accessed for 2D work
d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

// Acquire a pointer to IDirect3DDevice8
//attempt to set up hardware accleration
r = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWndTarget,
D3DCREATE_HARDWARE_VERTEXPROCESSING,
&d3dpp, ppDevice );
//if that fails try software acceleration
if( FAILED( r ) ){
r = pD3D->CreateDevice( D3DADAPTER_DEFAULT, D3DDEVTYPE_HAL, hWndTarget,
D3DCREATE_SOFTWARE_VERTEXPROCESSING,
&d3dpp, ppDevice );
//else fail
if( FAILED( r ) ){
SetError( "Could not create the render device" );
return E_FAIL;
}
}

// Save global copies of the device dimensions
g_DeviceHeight = Height;
g_DeviceWidth = Width;

// Save a coy of the pres params for use in device validation later
g_SavedPresParams = d3dpp;

return S_OK;
}

Share this post


Link to post
Share on other sites
I bet it''s becuase you update the vertex buffer each time. I think there is no need to do that sonce the map certainly is static. Locking a vertexbuffer to copy data to it is expensive.

Try to just move that part out of the gameloop.

2 cents from a newbie.

zilch_

Share this post


Link to post
Share on other sites
Apart from what zilch pointed out:

d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

DONT DO THAT! The driver will hate you forever! You really dont want to be thinking about reading from the backbuffer. If you want to draw individual pixels then use DrawPrimitive with points or something but dont lock the backbuffer and DONT copy from the backbuffer.

make it

d3dpp.Flags = 0;


As for the vertexbuffer - just create that during your initialisation and fill it at the same time (mark it WRITEONLY and MANAGED). If its still giving you gyp post your code for creating\filling the VB and we''ll take a look at it.

HTH

Benedict

Share this post


Link to post
Share on other sites
quote:

1.4GHz Athlon, and a geforce using d3d8


you should be runnign at closer to 500 fps, not 50 :p Locking the vertex buffer once per frame is going to be a negligable impact. If it''s a dynamic buffer and you use the discard flag I think it''s as dirt cheap as it gets.

quote:

Locking a vertexbuffer to copy data to it is expensive


locking vertex buffers 1000 times per frame might be expensive zilch... but once per frame won''t matter.


quote:

Apart from what zilch pointed out:

d3dpp.Flags = D3DPRESENTFLAG_LOCKABLE_BACKBUFFER;

DONT DO THAT! The driver will hate you forever! You really dont want to be thinking about reading from the backbuffer. If you want to draw individual pixels then use DrawPrimitive with points or something but dont lock the backbuffer and DONT copy from the backbuffer.

make it

d3dpp.Flags = 0;



sounds like good advice to me.


What''s your frame rate if you don''t draw the polygons jat? If you just clear the screen each frame? Do you have the z buffer running? Are these small polygons or big ones, if they''re screen sized and there''s no z buffering that would be a lot of wasted fill rate...

Share this post


Link to post
Share on other sites