Deterministic fixed-point port, open source

Discuss topics related to BEPUphysics or physics engine development.
RedToasty
Posts: 10
Joined: Tue Sep 18, 2012 1:53 pm

Re: Deterministic fixed-point port, open source

Post by RedToasty » Fri May 04, 2018 1:17 pm

I forked and stuck it in a Unity project (2017.4.1f1), along with a simple test scene to compare with the Unity inbuilt physics. I'll keep adding bindings for all the primitive types, compound objects and expose a load more values. It's definitely interesting and the performance looks fantastic, I'm intrigued to see how it does though IL2CPP.

There's a decent profiler built in to Unity that might be of some use, at a glance the overheads just literally seemed to be the shear amount of function calls to the Fix64 methods, I'm building against an older Mono, so didn't have the aggressive inlining. The jitter also looks to be very minor, I created a dummy Fix64 which used float internally, to confirm this was the issue and obviously everything went back to silky smooth.

My aim is to add some sort of rollback/serialization, to allow me to add GGPO style rollback networking. It's something I've been playing with for a few months, given it sync's using a list of input, it should be able to chuck any game onto my current server setup.

sAm_vdP
Posts: 10
Joined: Fri Feb 09, 2018 1:00 pm

Re: Deterministic fixed-point port, open source

Post by sAm_vdP » Fri May 04, 2018 3:30 pm

Hey, thanks for forking!

Where exactly did you notice jitter? Running the BEPUphysics demo scenes I didn't really notice any jitter, so maybe there's a bug I missed?

RedToasty
Posts: 10
Joined: Tue Sep 18, 2012 1:53 pm

Re: Deterministic fixed-point port, open source

Post by RedToasty » Fri May 04, 2018 4:13 pm

I had balls rolling down a long slope, accelerating (a longer slope than the current scene). They'd occasionally do a little hop that I wouldn't see with floats. It could just be confirmation bias on what I was assuming I'll see, I'll give it a much better investigation tonight, as well as recreating some of the original demo scenes in Unity.

I had a quick peep at porting the V2 library across. Sadly it's very reliant on C# 7, which Unity doesn't support, so almost every line would need changing (no support for ref locals). Almost everything seemed to be refs to structs so I'd lose all the performance with a "find and replace" job :)

I wouldn't advise anyone to pull the Unity fork currently, there's virtually nothing there. It shouldn't take long to add Unity bindings to all the obvious bits though. The way I've serialized Fix64 in the Unity inspector is fairly messy as well, it's half there so I can debug what values it's baking out, from Unity's floats.

RedToasty
Posts: 10
Joined: Tue Sep 18, 2012 1:53 pm

Re: Deterministic fixed-point port, open source

Post by RedToasty » Fri May 04, 2018 4:40 pm

Ugh, as I'd thought the error was indeed in my own code. The code updating the positions of the rendered meshes was being called less than the updates were being run. I'll get back to adding graphical representations of the shapes and start porting some demos across :)

sAm_vdP
Posts: 10
Joined: Fri Feb 09, 2018 1:00 pm

Re: Deterministic fixed-point port, open source

Post by sAm_vdP » Sat May 05, 2018 1:24 pm

From what I hear from Norbo, there's not much hope of getting V2 to be deterministic. Its highly optimized to use SIMD instructions, which don't really translate to integer math at all.

tonic
Posts: 1
Joined: Tue Feb 27, 2018 8:21 pm

Re: Deterministic fixed-point port, open source

Post by tonic » Sat May 05, 2018 3:30 pm

There's a new 32.32 fixed point library for C#:
https://github.com/XMunkki/FixPointCS
There might be point in considering a switch to that one.

Norbo
Site Admin
Posts: 4558
Joined: Tue Jul 04, 2006 4:45 am

Re: Deterministic fixed-point port, open source

Post by Norbo » Sat May 05, 2018 8:21 pm

From what I hear from Norbo, there's not much hope of getting V2 to be deterministic. Its highly optimized to use SIMD instructions, which don't really translate to integer math at all.
Yup- for now. I would like to look into abstracting scalars with a compile time switch, though. If I can find a way to do that with decent codegen (or if later versions of the compiler open up some more doors), it would be possible to build a SIMD accelerated fixed point version with fairly constrained changes. Performance would definitely suffer relative to FP32- particularly if 64 bit wide scalars were stored in the solver- but it would still be vastly faster than a fixed point v1.

(Also, to avoid confusion for future readers, this is referring to cross platform determinism. Determinism across simulations on the same hardware is just a matter of setting Simulation.Deterministic to true.)

RedToasty
Posts: 10
Joined: Tue Sep 18, 2012 1:53 pm

Re: Deterministic fixed-point port, open source

Post by RedToasty » Mon May 07, 2018 9:12 am

Thanks for the feedback Norbo. For a bit of perspective, I work in a mobile studio so I end up targeting a huge mash of CPU types, hence the interest in the fixed point determinism. I'm keen to have a play with networking some games you wouldn't normally associate with deterministic rollback networking. Simple driving games, spaceships, rolling ball, things with a bit of momentum that hides some degree of input latency, with a simple enough simulation that allows me to replay a few frames worth of data in a frame, should I need to.

I've been playing about with networking emulators on mobile for a while, even via 4g the connections can be really impressive. My server setup just bounces input, so should drop straight into other titles.

snoopyuj
Posts: 6
Joined: Fri Jun 22, 2018 9:33 am

Re: Deterministic fixed-point port, open source

Post by snoopyuj » Fri Jun 22, 2018 2:51 pm

Hello guys,

Does anyone have this little bouncing problem?
[youtube]https://youtu.be/Iu2VVoQI1fM[/youtube]

Thanks for sharing the deterministic version, btw. I'm trying to use this engine into Unity.
But now I'm stuck in creating mobile mesh collider because of the bouncing problem.
Does anyone can tell me where should I start tracing the code?

Thank you.

Norbo
Site Admin
Posts: 4558
Joined: Tue Jul 04, 2006 4:45 am

Re: Deterministic fixed-point port, open source

Post by Norbo » Fri Jun 22, 2018 10:21 pm

That behavior reminds me of one of a few things:
1) Incorrect depth calculation.
2) Failing shallow collision detection, followed by deep detection trying to compensate and 'bouncing' the shape out.
3) Broken persistent manifold management.

All the pairs in the video would use the GeneralConvexPairHandler. So, chances are, whatever is going wrong is within the GeneralConvexContactManifold.Update function. Prime suspects are ContactRefresher.ContactRefresh and pairTester.GenerateContactCandidate, and maybe ContactReducer.ReduceContacts. Contact reduction doesn't seem likely because it shouldn't be doing anything until after a full manifold exists, and the problem appears to occur on the first impact frame.

Within GeneralConvexPairTester.GenerateContactCandidate, you'll see there are three states a collision can be in- separated, shallow, and deep. It's possible that they're all subtly broken, but the shallow case is the most likely culprit.

snoopyuj
Posts: 6
Joined: Fri Jun 22, 2018 9:33 am

Re: Deterministic fixed-point port, open source

Post by snoopyuj » Mon Jun 25, 2018 1:59 pm

Thank you, @Norbo

It is really GenerateContactCandidate() problem.
For more detail, it's PairSimplex.TryTetrahedronTriangle() problem.

I check the algorithms are the same, but output "point" are different.
When I revert this method to non-fix64 version, it fixes the bouncing problem.
I think it's much multiplication to make the deviation.
Now I have to find a way to resolve the deviation. :(

dave_sf
Posts: 1
Joined: Wed Nov 21, 2018 11:04 pm

Re: Deterministic fixed-point port, open source

Post by dave_sf » Sat Nov 24, 2018 5:10 am

any update on this?

I'm interested in the results!

If this instability is caused by precision limitations, have you considered using much larger (still fixed) precision for certain calculations?

Post Reply

Who is online

Users browsing this forum: Yandex [Bot] and 1 guest