From 16b77b825c439624223c998c80d3fe1d7b2be0f6 Mon Sep 17 00:00:00 2001 From: Ross Nordby Date: Fri, 8 Dec 2023 15:46:27 -0600 Subject: [PATCH] Some tuning. --- .../CollidableOverlapFinder.cs | 1 - BepuPhysics/Trees/Tree_IntertreeQueriesMT.cs | 2 +- BepuPhysics/Trees/Tree_SelfQueriesMT.cs | 2 +- Demos/SpecializedTests/SimpleTestDemo.cs | 69 ------------------- .../SpecializedTests/StaggeredDropTestDemo.cs | 69 +++++++++++++++++++ 5 files changed, 71 insertions(+), 72 deletions(-) delete mode 100644 Demos/SpecializedTests/SimpleTestDemo.cs create mode 100644 Demos/SpecializedTests/StaggeredDropTestDemo.cs diff --git a/BepuPhysics/CollisionDetection/CollidableOverlapFinder.cs b/BepuPhysics/CollisionDetection/CollidableOverlapFinder.cs index bed536c4..b1d158c0 100644 --- a/BepuPhysics/CollisionDetection/CollidableOverlapFinder.cs +++ b/BepuPhysics/CollisionDetection/CollidableOverlapFinder.cs @@ -822,7 +822,6 @@ public void DispatchOverlaps3(float dt, IThreadDispatcher threadDispatcher = nul narrowStack = &narrowTaskStack; const int targetJobsPerThread = 1; int maximumTaskSize = int.Max(1, previousPairCount3 / (threadDispatcher.ThreadCount * targetJobsPerThread)); - //Console.WriteLine($"maixmum taskese: {maximumTaskSize}"); var estimatedMaximumTaskCountPerThread = targetJobsPerThread * 2; for (int i = 0; i < threadDispatcher.ThreadCount; ++i) { diff --git a/BepuPhysics/Trees/Tree_IntertreeQueriesMT.cs b/BepuPhysics/Trees/Tree_IntertreeQueriesMT.cs index 561229ae..432fbefd 100644 --- a/BepuPhysics/Trees/Tree_IntertreeQueriesMT.cs +++ b/BepuPhysics/Trees/Tree_IntertreeQueriesMT.cs @@ -46,7 +46,7 @@ public void PrepareJobs(ref Tree treeA, ref Tree treeB, TOverlapHandler[] overla return; } Debug.Assert(overlapHandlers.Length >= threadCount); - const float jobMultiplier = 8f; + const float jobMultiplier = 4f; var targetJobCount = Math.Max(1, jobMultiplier * threadCount); //TODO: Not a lot of thought was put into this leaf threshold for intertree. Probably better options. leafThreshold = (int)((treeA.LeafCount + treeB.LeafCount) / targetJobCount); diff --git a/BepuPhysics/Trees/Tree_SelfQueriesMT.cs b/BepuPhysics/Trees/Tree_SelfQueriesMT.cs index 4e0f7c48..a4443486 100644 --- a/BepuPhysics/Trees/Tree_SelfQueriesMT.cs +++ b/BepuPhysics/Trees/Tree_SelfQueriesMT.cs @@ -76,7 +76,7 @@ public void PrepareJobs(ref Tree tree, TOverlapHandler[] overlapHandlers, int th return; } Debug.Assert(overlapHandlers.Length >= threadCount); - const float jobMultiplier = 8f; + const float jobMultiplier = 4f; var targetJobCount = Math.Max(1, jobMultiplier * threadCount); leafThreshold = (int)(tree.LeafCount / targetJobCount); jobs = new QuickList((int)(targetJobCount * 2), Pool); diff --git a/Demos/SpecializedTests/SimpleTestDemo.cs b/Demos/SpecializedTests/SimpleTestDemo.cs deleted file mode 100644 index 1332ed29..00000000 --- a/Demos/SpecializedTests/SimpleTestDemo.cs +++ /dev/null @@ -1,69 +0,0 @@ -using BepuUtilities; -using DemoRenderer; -using BepuPhysics; -using BepuPhysics.Collidables; -using System; -using System.Numerics; -using BepuUtilities.Collections; -using DemoContentLoader; -using BepuPhysics.Constraints; -using DemoUtilities; - -namespace Demos.SpecializedTests -{ - public class SimpleTestDemo : Demo - { - public override void Initialize(ContentArchive content, Camera camera) - { - camera.Position = new Vector3(-30, 10, -30); - //camera.Yaw = MathHelper.Pi ; - camera.Yaw = MathHelper.Pi * 3f / 4; - //camera.Pitch = MathHelper.PiOver2 * 0.999f; - Simulation = Simulation.Create(BufferPool, new DemoNarrowPhaseCallbacks(new SpringSettings(30, 1)), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)), new SolveDescription(4, 1)); - - var box = new Box(1f, 3f, 2f); - - var boxInertia = box.ComputeInertia(1); - var boxIndex = Simulation.Shapes.Add(box); - const int width = 256; - const int height = 1; - const int length = 256; - var shapeCount = 0; - for (int i = 0; i < width; ++i) - { - for (int j = 0; j < height; ++j) - { - for (int k = 0; k < length; ++k) - { - var location = new Vector3(6, 3, 6) * new Vector3(i, j, k) + new Vector3(-width * 3, 5.5f, -length * 3); - var bodyDescription = BodyDescription.CreateDynamic(location, boxInertia, boxIndex, -0.01f); - var index = shapeCount++; - Simulation.Bodies.Add(bodyDescription); - } - } - } - - Simulation.Statics.Add(new StaticDescription(new Vector3(), Simulation.Shapes.Add(new Box(5000, 1, 5000)))); - //var mesh = DemoMeshHelper.CreateDeformedPlane(128, 128, (x, y) => new Vector3(x - 64, 2f * (float)(Math.Sin(x * 0.5f) * Math.Sin(y * 0.5f)), y - 64), new Vector3(4, 1, 4), BufferPool); - //Simulation.Statics.Add(new StaticDescription(new Vector3(), Simulation.Shapes.Add(mesh))); - } - - double time = 0; - long frameCount = 0; - public override void Update(Window window, Camera camera, Input input, float dt) - { - base.Update(window, camera, input, dt); - const long minimumFrameToMeasure = 256; - frameCount++; - if (frameCount >= minimumFrameToMeasure) - { - var frameTime = Simulation.Profiler[Simulation.BroadPhaseOverlapFinder]; - time += frameTime; - Console.WriteLine($"coldet time (ms): {1e3 * frameTime}, average (ms): {1e3 * time / (frameCount - minimumFrameToMeasure)}"); - } - - } - } -} - - diff --git a/Demos/SpecializedTests/StaggeredDropTestDemo.cs b/Demos/SpecializedTests/StaggeredDropTestDemo.cs new file mode 100644 index 00000000..3fd7a5bb --- /dev/null +++ b/Demos/SpecializedTests/StaggeredDropTestDemo.cs @@ -0,0 +1,69 @@ +using BepuUtilities; +using DemoRenderer; +using BepuPhysics; +using BepuPhysics.Collidables; +using System; +using System.Numerics; +using BepuUtilities.Collections; +using DemoContentLoader; +using BepuPhysics.Constraints; +using DemoUtilities; + +namespace Demos.SpecializedTests; + +public class StaggeredDropTestDemo : Demo +{ + public override void Initialize(ContentArchive content, Camera camera) + { + camera.Position = new Vector3(-30, 10, -30); + //camera.Yaw = MathHelper.Pi ; + camera.Yaw = MathHelper.Pi * 3f / 4; + //camera.Pitch = MathHelper.PiOver2 * 0.999f; + Simulation = Simulation.Create(BufferPool, new DemoNarrowPhaseCallbacks(new SpringSettings(30, 1)), new DemoPoseIntegratorCallbacks(new Vector3(0, -10, 0)), new SolveDescription(4, 1)); + + var box = new Box(1f, 3f, 2f); + + var boxInertia = box.ComputeInertia(1); + var boxIndex = Simulation.Shapes.Add(box); + const int width = 256; + const int height = 1; + const int length = 256; + var shapeCount = 0; + var random = new Random(5); + for (int i = 0; i < width; ++i) + { + for (int j = 0; j < height; ++j) + { + for (int k = 0; k < length; ++k) + { + var location = new Vector3(6, 3, 6) * new Vector3(i, j, k) + new Vector3(-width * 3, 5.5f + random.NextSingle() * 5, -length * 3); + var bodyDescription = BodyDescription.CreateDynamic(location, boxInertia, boxIndex, -0.01f); + var index = shapeCount++; + Simulation.Bodies.Add(bodyDescription); + } + } + } + + Simulation.Statics.Add(new StaticDescription(new Vector3(), Simulation.Shapes.Add(new Box(5000, 1, 5000)))); + //var mesh = DemoMeshHelper.CreateDeformedPlane(128, 128, (x, y) => new Vector3(x - 64, 2f * (float)(Math.Sin(x * 0.5f) * Math.Sin(y * 0.5f)), y - 64), new Vector3(4, 1, 4), BufferPool); + //Simulation.Statics.Add(new StaticDescription(new Vector3(), Simulation.Shapes.Add(mesh))); + } + + double time = 0; + long frameCount = 0; + public override void Update(Window window, Camera camera, Input input, float dt) + { + base.Update(window, camera, input, dt); + const long minimumFrameToMeasure = 512; + frameCount++; + if (frameCount >= minimumFrameToMeasure) + { + var frameTime = Simulation.Profiler[Simulation.BroadPhaseOverlapFinder]; + time += frameTime; + Console.WriteLine($"coldet time (ms): {1e3 * frameTime}, average (ms): {1e3 * time / (frameCount - minimumFrameToMeasure)}"); + } + + } +} + +