Jump to content

  • Log In with Google      Sign In   
  • Create Account

Interested in a FREE copy of HTML5 game maker Construct 2?

We'll be giving away three Personal Edition licences in next Tuesday's GDNet Direct email newsletter!

Sign up from the right-hand sidebar on our homepage and read Tuesday's newsletter for details!


We're also offering banner ads on our site from just $5! 1. Details HERE. 2. GDNet+ Subscriptions HERE. 3. Ad upload HERE.


High cpu usage


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 thefatshizms   Members   -  Reputation: 159

Like
0Likes
Like

Posted 05 August 2014 - 07:11 PM

Okay so I'm having a slight problem with cpu usage with my directx 11 application. The cpu usage isn't that high but for the things it's doing (which isn't a lot, rendering 2 cubes with textures and then rotating etc) it shouldn't be that high.

 

4a87a81aa5.png

 

The code is located at: https://github.com/thefatshizms/MEngine/tree/master/src

 

Sorry, at the moment the code is in a bit of a state and I'll clean it up tomorrow.



Sponsor:

#2 MJP   Moderators   -  Reputation: 11569

Like
6Likes
Like

Posted 05 August 2014 - 07:24 PM

Your  app is set up to render as quickly as it can, with no sleeping. For such a simple scene, you're probably updating and rendering 100's of frames per second. This will naturally result in your main thread saturating a core of your CPU. There's 3 easy things you can do to fix this:

 

  1. Use VSYNC. This is done by passing "1" as the first parameter of IDXGISwapChain::Present. Doing this will cause the CPU and GPU to wait for the next sync interval, which will essentially prevent your app from running faster than the refresh rate of your display (typically 60Hz). If you're not doing very much in a frame, then your thread will spend a lot of time just waiting which will keep your CPU usage low. However if you start do a lot of CPU work for each frame, then you will see your CPU usage increase.
  2. Do lots of work on the GPU. If your GPU is take a long time per frame to render, the CPU will have to wait for it which will give it some idle time. 
  3. Call Sleep(). For games this is usually not a good idea, since you want your game to achieve as high a framerate as possible. However if you're not making a game and framerate is not a concern, then it's the best way to guarantee that your thread doesn't saturate a CPU core.

Edited by MJP, 05 August 2014 - 07:25 PM.


#3 thefatshizms   Members   -  Reputation: 159

Like
0Likes
Like

Posted 05 August 2014 - 07:32 PM

Thanks for the insight! VSYNC seems to work great for cpu usage :) (It does slow down the rotating of the cubes but I'm going to leave that to the fact I havent implemented rendering based on time yet).



#4 aregee   Members   -  Reputation: 1026

Like
0Likes
Like

Posted 06 August 2014 - 09:52 AM

Yes, if you haven't based your rotation on time, it would affect your animation too, but that shouldn't be a problem once you fix that. :)






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS