Author Topic: Collision detection performance  (Read 7369 times)

0 Members and 1 Guest are viewing this topic.

Offline kgersen

  • 22
Collision detection performance
Hi there,

I noticed in your master sticky post that collision detection has performance issue. Is this still true ?

I managed to download the code and build it. But I don't have much time to actually learn and play the game.

So I was wondering if you have any special mod or special missions (or benchmarks or whatever your call them) to stress test the code and to do profiling because launching the game and doing training mission #1 takes time and yield not much performance data...

Thx

 

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Collision detection performance
Any mission that has a lot of stuff flying around will do. Artemis, Aristeia and Delenda Est (All from Blue Planet 2) for example will show this.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline kgersen

  • 22
Re: Collision detection performance
Artemis, you mean something like Battle of Artemis Station ? (I just Googled to find this).

if so, how can I access this mission directly when launching the game in profiling mode. Any game parameter to directly go there ?

my problem is that I can't and don't have time to play the mod from start to reach that specific mission.

  

Offline The E

  • He's Ebeneezer Goode
  • Moderator
  • 213
  • Nothing personal, just tech support.
    • Steam
    • Twitter
Re: Collision detection performance
Load the game with Blue Planet 2 installed. Select the BP2 campaign in the campaign room. Go to the techroom, mission simulator. Press Ctrl-Shift-S. It will be the first mission.
If I'm just aching this can't go on
I came from chasing dreams to feel alone
There must be changes, miss to feel strong
I really need lifе to touch me
--Evergrey, Where August Mourns

 

Offline Dragon

  • Citation needed
  • 212
  • The sky is the limit.
Re: Collision detection performance
Actually, if you start BP2 campaign, you'll immidiately be taken to Artemis cutscene, since it's the opening.

 

Offline Valathil

  • ...And I would have had a custom title if it wasn't for you meddling kids!
  • 29
  • Custom Title? Wizards need no Custom Title!
Re: Collision detection performance
Besides we already know whats the problem with the collsion detection. Its a probable memory alignement issue in the bsp_data structure or caching issue combined with a massive cache miss issue in destroying collision pairs when there are lot of objects created and destroyed like many missiles. Swifty's working on something i heard
┏┓╋┏┓╋╋╋╋╋╋╋╋╋┏┓
┃┃╋┃┃╋╋╋╋╋╋╋╋╋┃┃
┃┃┏┫┃┏┳━━┓┏━━┓┃┗━┳━━┳━━┳━━┓
┃┃┣┫┗┛┫┃━┫┃┏┓┃┃┏┓┃┏┓┃━━┫━━┫
┃┗┫┃┏┓┫┃━┫┃┏┓┃┃┗┛┃┗┛┣━━┣━━┃
┗━┻┻┛┗┻━━┛┗┛┗┛┗━━┻━━┻━━┻━━┛

 

Offline kgersen

  • 22
Re: Collision detection performance
thx a lot everyone, i'll try that.

@Valathil, I'm more here to study FS2 code rather than actually fix or optimize anything. At least for now since I've just downloaded the code yesterday...anything more so soon would be pretentious. But i'll keep you posted if I find anything.

to say it all, I come from the Free Allegiance development team (my handle is KGJV or TheCount) and I've been coding and modding its C++ engine for 10 years now. I'm currently fishing for ideas or code to improve some parts of Allegiance or eventually "merge" Allegiance within another similar game. FS2 SCP is one candidate for this. Looking at the collision code is just a convenient way to start my study.

 

Offline Iss Mneur

  • 210
  • TODO:
Re: Collision detection performance
to say it all, I come from the Free Allegiance development team (my handle is KGJV or TheCount) and I've been coding and modding its C++ engine for 10 years now. I'm currently fishing for ideas or code to improve some parts of Allegiance or eventually "merge" Allegiance within another similar game. FS2 SCP is one candidate for this. Looking at the collision code is just a convenient way to start my study.
Interesting.  I have never heard of that one before, I will have to check it out when I have more time. Is its source available as well?

Either way, keep in mind what the FSO license is.

"I love deadlines. I like the whooshing sound they make as they fly by." -Douglas Adams
wxLauncher 0.9.4 public beta (now with no config file editing for FRED) | wxLauncher 2.0 Request for Comments

 

Offline kgersen

  • 22
Re: Collision detection performance
to say it all, I come from the Free Allegiance development team (my handle is KGJV or TheCount) and I've been coding and modding its C++ engine for 10 years now. I'm currently fishing for ideas or code to improve some parts of Allegiance or eventually "merge" Allegiance within another similar game. FS2 SCP is one candidate for this. Looking at the collision code is just a convenient way to start my study.
Interesting.  I have never heard of that one before, I will have to check it out when I have more time. Is its source available as well?

Either way, keep in mind what the FSO license is.

yes the source is fully available (VS 2008 or 2010 C++, Windows only, DirectX 9.0 gfx and DirectPlay network code).
Microsoft released the source a few years ago with a special license  (worst than FSO license since everything you do can be reused by M$...).
Check our wiki 1st if you're interested.

 

Offline Sushi

  • Art Critic
  • 211
Re: Collision detection performance
to say it all, I come from the Free Allegiance development team (my handle is KGJV or TheCount) and I've been coding and modding its C++ engine for 10 years now. I'm currently fishing for ideas or code to improve some parts of Allegiance or eventually "merge" Allegiance within another similar game. FS2 SCP is one candidate for this. Looking at the collision code is just a convenient way to start my study.

KGJV! Fun to see a familiar name. :)

 

Offline Swifty

  • 210
  • I reject your fantasy & substitute my own
Re: Collision detection performance
I'm currently working on collision detection performance issues ATM. If you have any questions regarding the collision detection code, feel free to post or PM questions.
« Last Edit: July 26, 2011, 05:49:03 pm by Swifty »

 

Offline Parias

  • 27
Re: Collision detection performance
I'm currently fishing for ideas or code to improve some parts of Allegiance or eventually "merge" Allegiance within another similar game. FS2 SCP is one candidate for this. Looking at the collision code is just a convenient way to start my study.

Wow, I was a huge, hardcore Allegiance fan back in the day - something like this would be awesome. I hope you succeed in your efforts.

 

Offline Sushi

  • Art Critic
  • 211
Re: Collision detection performance
I'm currently fishing for ideas or code to improve some parts of Allegiance or eventually "merge" Allegiance within another similar game. FS2 SCP is one candidate for this. Looking at the collision code is just a convenient way to start my study.

Wow, I was a huge, hardcore Allegiance fan back in the day - something like this would be awesome. I hope you succeed in your efforts.

It would indeed be cool.

TBH, though, I think you'd have better luck writing a completely new game engine instead of trying to merge two fundamentally different decade-old games (the only thing in common, really, is the space setting).

 

Offline karajorma

  • King Louie - Jungle VIP
  • Administrator
  • 214
    • Karajorma's Freespace FAQ
Re: Collision detection performance
Porting the features of Allegiance to FSO until they can run the game on our engine might work though.
Karajorma's Freespace FAQ. It's almost like asking me yourself.

[ Diaspora ] - [ Seeds Of Rebellion ] - [ Mind Games ]

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Collision detection performance
has anyone profiled the engine lately? do we know where exactly the performance hit is? is it in the collision detection proper (collide point with bsp, bsp with bsp, etc) or is it in the pair generation/collision culling section?
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Swifty

  • 210
  • I reject your fantasy & substitute my own
Re: Collision detection performance
I've lately been working on a sort and prune solution using quicksort such that the engine won't have to go through all pairs to brute force collision queries. It's a lot faster than iterating through all n^2 pairs but there are still some bugs with the diff. I'm putting off sharing it until I can clean it up.

We've also seen a significant portion of frametime going into the initial submodel bounding box checks. Submodels redundantly had their orientations and local offsets computed for each collision. A patch I made, which only does it per frame, has been committed into the code base.

Most of the bottleneck is now coming from the actual BSP queries. I guess for smaller models with low poly counts are fine but way bigger models, we end up getting a huge spike. Valathil did some profiling of the BSP queries as did I. Most of the bottleneck from model_collide_sub is not coming from the meat of the process (loading of points, triangle tests, or the bounding box tests) but just from accesses of the p pointer. I also wrote an non-recursive version of model_collide_sub thinking that the performance issues were coming from the function call overhead. I got the same results there.

Valathil's hunch was that it was a memory alignment issue. Based on that, I rewrote model_collide_sub and wrote a parser for bsp_data that would load all the data into well-defined structs to negate that problem. It works and calculates collision 100% correctly. The bad news is that it performs just as badly.

I'm therefore beginning to suspect that it's not a memory alignment issue but a cache issue. I think cache misses that are killing our performance in model_collide_sub, especially if you have models with huge ass triangle counts. It makes sense too. We're always bouncing all around the tree depth first search-style looking for intersecting bounding boxes and triangles.

So I think I might take advantage of the parser I wrote to play around with organizing the chunk data differently to find out which data storage layouts are better cache friendly (while keeping the actual tree structure intact). I might also combine that with different tree traversal strategies. All the while I've been reading some white papers on cache oblivious algorithms and data structures to give me some better understanding on the problem.

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Collision detection performance
well, even if it does not improve performance, you should DEFINITELY include the parsed version of the BSP code, this problem will not get fixed with unreadable gobldygook like the dereferenced pointer dynamic data structure crap. So now you have a nice data structure rather than a massive data buffer, hopefully you have separated the polygons from the sort norms, sortnorms is where most of the movement happens, so if you can condense that, it will help with cache issues. how is the BSP tree constructed now? I'm guessing that you are not using new to allocate new sort norms, but rather allocating a solid block of them and pointing them at each other, I think the best way to organize such a tree would be with a heap like architecture, keep children of the same node together, this would require a breadth first construction, but the depth first reading would end up not moving around as much when it was actually getting run through. do keep in mind the tree depth is log(n) of the poly count, a 50,000 poly model might only have a tree depth of 16, PCS2 (should) be working at keeping this tree balanced so there are the same number of polies on either side of any given branch.

this might be an area where multi-threading could be applied. if you break the list of possible collisions apart into n sublists (where n is the number of CPUs) it might be possible to run each on it's own thread, you might have to completely rewrite the collision code to get this to work properly though.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline kgersen

  • 22
Re: Collision detection performance
I'm still discovering FS architecture & code so I can't comment more on it yet but I can talk about how Allegiance handles collision detection.

Allegiance being a multiplayer only game with a dedicated server, only the server actually computes the collisions. To do this efficiently on 10 years ago hardware and allowing up to 200 players per game, they had to really optimize the collision code. Even more since there is no 'beam' weapon but only 'particle' weapons firing bullets (called projectiles) each been handled as a distinct object in the game logic code (and so in the collision code too).

The 1st thing they did is to not use the 3D models directly but instead use specially computed models made of convex hulls. These convex hulls use variable n-polygons instead of triangles and are convex (orly?) which speed up greatly collision detection.
At compile time, the 3D models are transformed using QHull and a CVH (convex hull) file is generated for each 3D model file.
Also instead of using a classical bounding box, the CVH files include a bounding ellipsoid of each object, optimizing even more the initial computation (that same bounding ellipsoid is also used for energy shields).

Then the code uses and updates a K-D tree to store the objects and compute the collisions more efficiently as illustrated here.
The collision code only uses CVH files and not the more complex 3D model files.

so to sum up , current optimizations are:

- bounding ellipsoids instead of bounding boxes
- special pre-computed 'convex hulls' models instead of the 3D gfx models
- k-d tree structure to store and sort the objects, updated every frame

There are more optimizations beyond that but they are more Allegiance specific (like 'sectoring' and separating moving and non moving objects).

 

Offline Bobboau

  • Just a MODern kinda guy
    Just MODerately cool
    And MODest too
  • 213
Re: Collision detection performance
I considered suggesting the convex hull optimization, but I assumed it would require a major rewrite of the game media, this QHull (library?) intrigues me...

I also started describing something very similar to a k-d tree, but then I realized that addresses pair generation, and that is apparently not currently where most of the slowdown occurs.
Bobboau, bringing you products that work... in theory
learn to use PCS
creator of the ProXimus Procedural Texture and Effect Generator
My latest build of PCS2, get it while it's hot!
PCS 2.0.3


DEUTERONOMY 22:11
Thou shalt not wear a garment of diverse sorts, [as] of woollen and linen together

 

Offline Luis Dias

  • 211
Re: Collision detection performance
Convex hulls wouldn't work in FS ships. Consider the Collossus


EDIT: You could however, without much media rewrite fuss, use the other simplified meshes from the same ships to calculate impacts, instead of the full mesh (I don't know if FSO already does this)
« Last Edit: August 09, 2011, 03:48:24 pm by Luis Dias »