Jump to content
  • Advertisement
Sign in to follow this  
Synthesizer

[XNA] Strange framerate drop + Performance advices

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

Hello guys,
After adding functionality to my project I started working on performance. That's when I noticed a problem I'm having:

Randomly, after 2 or 3 seconds or so, the framerate terribly drops (only in one frame). After it, evrth normal again. 2, 3 seconds more... & again one terrible frame! It seems like a pattern, but I cannot find a logic...

Test Scenario:
I only draw a few object (5, 10, 15, no more, really low poly cones), I stare still at the models & the problem shows. I even draw nothing & the framerate drops from 60 to 53 or so showing the same pattern.
I don't know much about PIX, but i'm able to find the problematic frames in there:
Pix
here nProf result:
NProf
any idea of what it may be?


Well, apart from that:
I noticed drawing my models reeeeally decrease the speed: What's an acceptable polycount for a model? Let's say: for a man? & a house? Is it better if I split it in many models?
Max texture size I'm using is 2048x2048. Is it ok? (the heaviest: 1mb aprox, jpg).
Biggest X file: 63mb. I should split it I guess.

So well, I hope u can give me a tip!!
Thank you for your time & help!

Synth

Share this post


Link to post
Share on other sites
Advertisement
Try disabling VSync when drawing nothing, and see how the pattern looks then. If you really have the same problem when drawing nothing, then it's probably something else than your program causing it.

What graphics card do you have and how much memory does it have?
Do you create any resources after initial setup?
It may be that resources don't fit completely in video memory and must periodically be uploaded from RAM.

Storing a 2048x2048 texture will take up 16 MB on the graphics card.
It all depends on your graphics card. Several thousand polygons should be OK if you don't have too many models, but a hundred thousand might be a problem. Then again if you have a really good graphics card you could draw a few million without a problem.

Share this post


Link to post
Share on other sites
Hi guys, thanks for your quick replies.

My computer is:
-AMD Athlon 3000+ 64 bits (1.81Ghz)
-1Gb RAM
-GForce 6200 256 Mb
-Windows XP (32 bits)

I can run games like Swat 4, Ghost Recon Advanced Warfighter 1 / 2, Obscure 1 in an acceptable way. But of course I cannot compare my program to these great games.

2048x2048 texture takes 16mb?? Wow... that means that with 16 texture I fill the whole memory of my video card!

Many resources are loaded at startup. I don't think I'm creating a lot of objects during update, though I'll double check. I think I only have one ArrayList (I know it's bad, I replaced all by normal arrays to avoid unboxing, but I had to leave this one because of the design I chosed at first, containing both Models & AnimatedModels). Anyway it only contains a few objects(less than let's say 30). It's the ArrayList containing the Models.

I read about GC as u suggested. It seems it's continually collecting trash... (i tested the way it's explained in the link you feeded me with).
I disabled VSync & drawed nothing, & framerate increased a lot, but still found the drops. I also used CRL Profiler & took some screenshots (although they don't tell a lot to me, they may give some hints to u!)
here:
vSync off
Clr Profiler1
In "Update" I have a case statement (because at first a menu is displayed & then during gameplay u can return it). After the initial menu, "loadModels" is executed for the only one time. Then "updateGameplay" as long as you are not in the menu.
Clr Profiler1

Any clue?
Thanks!!

Share this post


Link to post
Share on other sites
I reduced the textures to 512 the most, some 1024 & just 1 or 2 2048 (not to lose so much quality).
But it's still dropping :(
I'm not performing any memory allocation during the Update cycle (just instancing BoundingSpheres & struct stuff).
I wonder why the GC is still collecting...

Share this post


Link to post
Share on other sites
Sorry, I didn't realize there are two threads, I will stick to this as most other ppl do

Quote:
Original post by Synthesizer
I didn't know 2k x 2k was so big! I've already resized most of my textures, turning them into 512 or 1024 max (except 1 or 2 that i left in 2k for quality sake).
it's not just about the size of the whole texture, but also about the pixel size (it eats up bandwidth). Try to use dxt compression (there is a texture utility in the directX sdk, (probably also in XNA).
that will reduce memory usage/bandwidth to 1/8

Quote:

I'm not performing any memory allocation ("new...") during the Update cycle (just instancing BoundingSpheres & struct stuff).
on android the most evil function was some print of the FPS to the debug console, as it concatinated strings and all strings have allocations.
so it's not just bout thew "new" you use, but also bout the implicit allocations. in j2me I had a tool that allowed me to set a breakpoint whenever an allocation happens, try that.
also try to explicitly call the garbage collector every frame, that would split the load across all frames and might prevent those peaks.

Quote:

I'm not sure if performance improved a bit or not, but the glitch is still there...
Is it possible that the map size influences a lot? I'm using a 500x500 heightmap to generate it.
not sure what you mean, but check if there are some implicit allocations.


keep also in mind that GC usually is aimed to run on some unused cores, so you shouldn't notice it peaking in if you don't utilize the cpu fully. (I think on xbox one core is reserved for that). you single core is kind of the worst case and might not reflect the common case (most people's desktop PCs have dual cores so they might not suffer those peaks like you do).


Share this post


Link to post
Share on other sites
This probably isn't a problem with your code, it is an issue with XNA fixed time step. It has been covered in a ton of threads:

http://forums.create.msdn.com/forums/p/9934/53561.aspx#53561
http://forums.create.msdn.com/forums/t/30500.aspx
http://forums.create.msdn.com/forums/t/9934.aspx

Basically the only way to make your game animate smoothly in XNA is:

- Game.IsFixedTimeStep = false
- Game.SynchronizeWithVerticalRetrace = true
- do your own delta time computation between frames

Share this post


Link to post
Share on other sites
Hello,
well, first of all, thank you very much for all your tips.

I performed several tests:
-reduced polygon count in large amounts.
-removed string allocations & operations.
-removed enumerations (during game loop).
-reduced texture's size.
-disabled vSync.

Speed improved. There's something about fixed step and vSync, that's true, as you said. But I couldn't succeed in getting it right. I realized that by disabling vSync, the drop is not so noticeable; I may say it almost disappear. But it sometimes works & it sometimes doesn't. I don't know if it has anything to do with the amount of free memory at the moment of running the project or not.
I think that switching fixed step was giving bad results, related to out of sync in animations.

I may say that I'm using Deferred Rendering (based on Catalin Zima project). After all my tests, I decided to run his project, and I found out that the results were exactly the same. So I think that the causes may be related to:

-my hardware: It may be not enought to run this kind of XNA's project flawlessly.
-something in Catalin Zima's example that may not be 100% performant.
-something that's not 100% compatible between Catalin Zima's code and my hardware.

So I may try it with another hardware in a future and bring the results!
For the moment, I'm happy with all the improvements and everything that I learnt thanks to you!

It's always nice to get expert's tips!
Thank you guys!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!