Sign in to follow this  

Why simple D3D app consume 100% CPU?

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

Main loop code as following: if(xGetMainWnd()->IsActive() || !(xGetApp()->GetAppstyles() & xApp::APPS_PAUSEONLOST)) bRet=(PeekMessage(&msg,NULL,0U,0U,PM_REMOVE)!=0); else bRet=(GetMessage(&msg,NULL,0U,0U)!=0); if(bRet){ TranslateMessage(&msg); DispatchMessage(&msg); xGetApp()->RenderProcedure(); } The Render proceudre only clear back buffer to black color and draws nothing. How to reduce it?Any indication is appreciate,thanks in advance!

Share this post


Link to post
Share on other sites
Well, it's just running as fast as possible, it's not actually a CPU-intensive program or anything, if that's what you're worried about.

Try putting Sleep( 17 ); in there at the bottom if to bothers you enough.

Share this post


Link to post
Share on other sites
I don't understand why so many people worry about this; it's not like you're stealing time from other applications. If an application needs a resource, it's the OS responsibility to provide it. You can use Sleep() if you want to be extra nice to other apps, but then again who expects a 3D graphics program, of all applications, to be "nice"?

Share this post


Link to post
Share on other sites
Quote:
Original post by mikeman
I don't understand why so many people worry about this; it's not like you're stealing time from other applications. If an application needs a resource, it's the OS responsibility to provide it. You can use Sleep() if you want to be extra nice to other apps, but then again who expects a 3D graphics program, of all applications, to be "nice"?


Well, its pretty annoying when a 2D game (even a basic 3D game) is chewing through my laptop battery and burning a hole through my pants... Of course, no one expects Doom 3 to give of "extra" resources, since it needs them, but 3D pong doesn't need that much cpu time.

Share this post


Link to post
Share on other sites
Thanks everybody.
My current solution is to limit the 1000+ FPS to 60 to give time back to OS.
Now I use (1000/CurFPS)*(CurFPS-60) to calculate the time should "relax" during one frame in ms,as

RenderEverything();
Sleep( (1000/CurFPS)*(CurFPS-60) );

But it seems not so accurate,is there any good ways to achieve this?

Thanks again.

Share this post


Link to post
Share on other sites
The other way is to force VSYNC, so there is a pause after you've done all your logic and rendering while you wait for the monitor to refresh.

Does VSYNC work on laptops and LCDs?

Share this post


Link to post
Share on other sites
Quote:
Original post by Boder
The other way is to force VSYNC, so there is a pause after you've done all your logic and rendering while you wait for the monitor to refresh.

Does VSYNC work on laptops and LCDs?


Yep. And it definitely cuts down on the medical bills for burned thighs.

Share this post


Link to post
Share on other sites
The problem with vsync is that the refresh rate may be different on different video cards. My LCD is synced to 60 Hz, but my CRT can run over 100 on lower resolutions. Keep that in mind if you plan to base all the frame timing assuming 60 FPS.

Share this post


Link to post
Share on other sites
I was going to mention some of the problems with VSync. Besides what Sr_Guapo said, using VSync can drop a low-end user from 59 frames/sec to 30 frames/sec. If you miss the "deadline" by even a little bit you have to wait for the next round. So it may be useful to allow users to choose, so someone doesn't end up with a lower framerate than they could achieve by drawing immediately.

Share this post


Link to post
Share on other sites

This topic is 4204 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.

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