Sign in to follow this  
Quaid Tseng

How to make it run faster?

Recommended Posts

I have built an implicit cloth sim(Baraff's Large Steps in Cloth Simulation) in dx9. 8x8 = 64 particles results in 65 FPS 16x16 = 256 particles results in 25 FPS Many papers mentioned they can do thousands of particles in a decent rate. I don't know if my dx9 loop has some problem, thus slow down the performance.
INT WINAPI WinMain( HINSTANCE hInst, HINSTANCE, LPSTR, INT )
{
    // Register the window class
    WNDCLASSEX wc = { sizeof(WNDCLASSEX), CS_CLASSDC, MsgProc, 0L, 0L, 
                      GetModuleHandle(NULL), NULL, NULL, NULL, NULL,
                      "D3DEngine", NULL };
    RegisterClassEx( &wc );
    // Create the application's window
    HWND hWnd = CreateWindow( "D3DEngine", "D3D GameEngine", 
                              WS_OVERLAPPEDWINDOW, 0, 0, 1000, 1000,
                              GetDesktopWindow(), NULL, wc.hInstance, NULL );
    // Initialize Direct3D
    if( SUCCEEDED( GAMEENGINE->InitD3D( hWnd ) ) )
    {
		if( SUCCEEDED( GAMEENGINE->InitGraphics() ) )
		{
			ShowWindow( hWnd, SW_SHOWDEFAULT );
			UpdateWindow( hWnd );
			// Enter the message loop
			MSG msg; 
			ZeroMemory( &msg, sizeof(msg) );
			while( msg.message!=WM_QUIT )
			{
				if( PeekMessage( &msg, NULL, 0U, 0U, PM_REMOVE ) )
				{
					TranslateMessage( &msg );
					DispatchMessage( &msg );
				}
				else
					GAMEENGINE->Render();
			}
		}
    }

    UnregisterClass( "D3DEngine", wc.hInstance );
    return 0;
}

Even if I put nothing in the Render(), that is, an empty loop, I can only get a max rate, about 70 FPS. Maybe there's another way, let it run faster? Any reply could be appreciated!

Share this post


Link to post
Share on other sites
You're seeing the effects of VSYNC ("Vertical SYNCronization") which is an artificial limit imposed by the API and/or drivers.

Change D3DPRESENT_PARAMETERS::PresentationInterval = D3DPRESENT_INTERVAL_IMMEDIATE and ensure that the driver isn't set to override the application setting.

hth
Jack

Share this post


Link to post
Share on other sites
Amazing! Thanks to Jack!

It seems D3DPRESENT_INTERVAL_IMMEDIATE make the app
always occupies 50% CPU usage.

Now I get 970 FPS in 4x4 = 16 particles
166 FPS in 8x8 = 64
65 FPS in 12x12 = 144
28 FPS in 16x16 = 256

The rate is still slow compared to those papers,
however that's the problem of programming.

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