Tuesday, 30 September 2014

CPU Profiling Totally Rocks

Having a great time profiling the FPSC Reloaded Engine with VTune at the moment. I started by switching off every component and running the profiler on a completely empty scene, no terrain, objects, sky, physics, anything. I then had a look at what might be hogging things.  Turns out quite a few things.


Seems the engine would be monitoring ALL the objects, even if they where invisible for things like animation potential, mesh vertex update potential and other large loops. Completely redundant of course and hogged my CPU cycles. By changing them to use shortlists, I would only do a loop that consisted of the objects of interest, and the bottleneck completely disappeared.

At first I also thought the huge amount of time spent in NVD3DUM.DLL was something I could optimize but I think a good engine spends most of it's time in here as that is where the CPU is constantly giving things to the GPU to process, which means more frames and faster games. My current guideline is to ensure that the engine always spends more time in this module than it does in the remaining modules, thus ensuring a fast throughput of polygons to the card and zero CPU stalling.

I still have an outstanding issue which is causing a DirectX Error crash due to skipping the texture sort each frame (a MASSIVE hog) but once I track down the specific object(s) responsible I can fix it properly and massage the texture sort system so I am not breaking something elsewhere.


As you can see, by ensuring the texture sort only happened when the overall number of objects in the engine changes (i.e. something got added or removed) I went from 143 to 208 by adding two extra lines of code and a new variable!

After I've solved the texture sort crash bug, I need to spend some time playing the game and using the editor and features of the engine to ensure I have not broken anything major. Best to fix those now when I know what code I changed than a week from now when I won't have a clue.

I won't tease you with my current frame rate gains as they are very subjective but I am happy to report that for every bottleneck I find, and eliminate, the bottom line FPS jumps up.  There is still the unavoidable issue that the engine drops back down to the 40 range when I try to draw a thousand shaded objects, but that is something I plan to tackle separately as it relates back to visuals and how the rendering order and quantity is handled.

Pretty happy with the performance work so far, and my hope is to bring you some solid news of the gains before the week is out.  Until then, watch this space and keep your fingers crossed.

16 comments:

  1. Great news. Quick question. What does the 12HR mean? I've always wondered what that was and it never seems to change.

    ReplyDelete
    Replies
    1. Time of day, maybe? I'm not sure either :s

      Delete
  2. Well done Lee, awesome work :D
    No offence intended, but I think everyone can agree performance has always been FPSCR's worst enemy - with these speed gains, hopefully it'll become it's best friend!

    ReplyDelete
  3. All sounds good lee,nice job.

    ReplyDelete
  4. sounds like a nice start to the week :) lets hope for a strong finish later on and see some more of those jumps up :)

    ReplyDelete
  5. Good job Lee, looking forward to the new update.

    ReplyDelete
  6. Hi Lee

    I think you might be being too hard on yourself in terms of performance.

    Starting off with the task of rendering a massive terrain (750k polygons) loads of objects, grass, shaders, post effects, AI and physics is a ridiculous ask considering Reloaded is still fundamentally built on top of the old FPSC classic engine.

    There is acres of wasted space on the escape demo level so why not start off trying to get a constant 60 frames per second on a smaller map with your new performance profiling tools and build up rather than going for months at a time with performance still being a major problem.

    I understand we are still in BETA but I think it would give a much greater sense of progress if people could start building useful projects now that might still be usable later on and make the most of the features as they become available. At the moment it feels like each release is just the next chapter of Lee versus Reloaded and how many frames did we manage to claw back this time!

    I have no idea how much work is involved in making a game engine but having published a commercial game I have an understanding of what it takes to see a project through to completion and keeping the scope under control and taking small but important steps really helped. I just get the feeling you are trying to bite off more than you can chew at the moment.

    The great John Carmack said he 1st experienced the limits of his own capability during development of Quake 1 and it was simply not possible to complete the project on time despite his best efforts and he factored this into all subsequent projects.

    Don't try and be a hero Lee. You are doing a great job but we don't need Reloaded to be Unreal Engine 5 from day 1. We just need some good tools to work with and a good foundation to start building games with. The extra bells and whistles can come along later but if you try and do everything now it will be a very long road before we can start using Reloaded to make anything resembling an actual game.

    ReplyDelete
  7. Thanks for the encouragement! Having been developing game creation tools for well over 20 years, very little phases me these days, and Reloaded is well within my comfort zone and I would say just the right size of project for me and my team :) It might seem like one step forward, two steps back sometimes but that's just the short definition of R&D development, and sometimes you have to make a few mistakes to invent the light bulb. As for right now, my goal is to be the hero of performance, and not much else. The only way I let go of this bone now is if someone takes it from me.

    ReplyDelete
  8. Well said, both of you! I agree with Nomad but I also agree with Lee. No, Reloaded doesn't have to be Unreal Engine 5, but it needs to run well.

    Lee, you are using LOD on the terrain, right? A terrain shouldn't be causing much slowdown (it's just one giant blob of polys to render in one go).

    Either way, excellent work! Definitely gotta find those nasty little hidden sloths and profiling is the way to do it :)

    ReplyDelete
  9. @lee, can we please have a map size changer option at some point? say 1/4 1/2 3/4 ect as a custom option or some sort of % slider that takes the edges and boarders of the map away grid by grid? so we dont have to use the whole map all the time for things its not needed for. this would be fantastic

    ReplyDelete
    Replies
    1. Fantastic indeed. Totally agree :)

      Delete
  10. Will it be possible to have larger maps than what we have today?

    ReplyDelete
  11. So the community want both smaller terrains and larger terrains. Sounds about right ;) There is a slider called Terrain Size in the latest build which can control the terrain size if you want to give that a try. No plans to make the terrain bigger for the Steam release. We will be looking at 'infinite streamed terrain' in 2015 however for massive open worlds and high-speed motion capabilities for things like jets, fast cars and insanely large catapults.

    ReplyDelete
    Replies
    1. Typical. It's like we're TRYING to make your job harder :P

      In all seriousness that sounds like an excellent plan. Plan big but plan long-term. Me likes :)

      Delete
    2. i have used and do use the terrain size slider lee m8, thing is with it you can go beyond those boarders even when its set to smallest... the terrain is still there just hidden, i like the random terrain generator alot for my outdoor maps, but sometimes like for my competition game it was way more than i needed lol.. so please can we have it ;p lol

      +1 for larger terrains overall aswell.&/or the ability sometime to scale players right down also to give the illusion of bigger terrains for giant city crushing monsters :D and catapults

      Delete
  12. 'infinite streamed terrain' sounds great i have seen it getting put into other engines so will be nice if reloaded offered this also another +1 for this.

    ReplyDelete