Game is consuming 100% of resources

Oct 28, 2010 at 9:58 PM

I have a board game with simple-ish graphics, which runs on XNA native devices at around 1-5% CPU usage. However, when I run the project through SilverSprite, it consumes 100% of the processor. I am not generating any errors in the debugger, though Chrome and other browsers are reporting a bazillion page faults when running the program. Visually, the program appears to run fine (it is not choppy).

 

Am I doing something wrong? Is there a way to profile the issues causing this 100% CPU usage without using the Visual Studio profiler? I have professional edition and do not have access to the profiler feature. Anyone have any ideas?

Oct 31, 2010 at 10:03 PM

Anyone have any ideas on how to decrease my CPU usage? :D

Oct 31, 2010 at 10:39 PM

Hi,

Not sure if I can help but I will try.

If you are getting page errors you need to fix those. Using lots of cpu usually means there is a loop of some sort. Try and find out if the loop is in your game code or in Silverlight. Do you have more than one spritebatch? This will really eat up resources in silverlight. What I tend to do in these situations is to comment out draws and see if things change. Also check that you are  not initializing anything over and over again in the game loop.

If you could be more specific I might be able to be of more help.

Regards.

Nov 1, 2010 at 1:47 PM

Lionel,

Thank you for the reply! I do appreciate the help :) Sorry I was not being specific - basically, I'm finding that if I draw pretty much *any* Texture2D, the CPU usage goes up exponentially.

I have a series of game board pieces which are PNG Texture2D's. They are put into the sprite batch at varying sizes/transparencies according to an associated object of a simple data class.

 

Taking a look at my code, if I have the following things rendering on screen in my Draw method:

1) A background PNG file, 800 x 480

2) A game "board" PNG file, 460 x 460

3) A game piece PNG file, 50 x 50 (scaled)

4 & 5) Borders for the game pieces - PNG files, 54 x 54 and 470 x 470. They are mostly transparent.

 

 

So that's only 5 PNG files being rendered to the screen - nothing else is happening in my game, no loops or anything. It's just rendering those 5 PNGs into the spritebatch. This uses about 50% of CPU. If i just render the background PNG and nothing else, it's at about 20%.

 

Is there some sort of problem with PNG files, or with transparent textures? Maybe I'm missing hardware GPU caching or something? Or is this just the way SilverSprite is?

Thank you again in advance for any help - I really do appreciate it :D

Nov 1, 2010 at 3:02 PM

Hi,

png files may well be a problem. I am using .xnb versions that can be found in the bin of your xna game version.

I used option1 of the instructions:

Textures -

  • Option 1: Add the .xnb file built by the Windows XNA Debug project, only uncompressed xnb files right now. The texture itself can be compressed, in XNA this is a property you can set, and it can make the texture file 4 to 8 times smaller. Make sure the build action is set to "Content".
  • Option 2: Add the PNG, JPG or BMP file using a file name that matches the asset name, making sure the build action is "Content". This can make for a smaller XAP file.

Let me know if that helps. Don't know much about how SilverSprite works but am slowly learning. The silverlight game loop is different to xna.

Regards.

Nov 2, 2010 at 2:26 AM

I did change the textures around significantly and found that nothing really fixed the issue. I don't believe it's an issue with XNB vs PNG or compressed/uncompressed.

 

After some investigation, I find that the CPU consumption goes up when the game isn't doing anything - it hits the draw method faster and therefore consumes more CPU.

As a stopgap measure I've put in a "renderme" variable that determines whether or not something on screen has changed. Every time I alter an on-screen object, I turn this variable to "true". If nothing has changed, I make the draw thread sleep for 25ms. Ideally I'd like to let the screen go without redrawing at all (i.e. no pause at all, just don't redraw a blank canvas) - unfortunately this is a known issue currently in the tracker - if you don't redraw your spritebatch, it will blank out the screen instead of leaving it as-is like XNA does by default.

This measure has served to drop my CPU usage by around 50%, which is good, but it's not really acceptable in terms of performance from something as simple as a board game :(

So a few questions - does anyone else have any tips/tricks to further reduce CPU usage when I've tracked it down to just the Spritebatch as the main issue? Also, does anyone know if it's now possible to render the screen without clearing it to cornflower blue each time?

Jan 13, 2011 at 5:28 PM

Hi! did you know then ExEn Project? I posted a thread here http://silversprite.codeplex.com/Thread/View.aspx?ThreadId=241319 to explain why if you Help ExEn Project (xna for iphone, android and silverlight), you'll be helping SilverSprite to solve bugs

Please read it!!