Implement scheduling system with parallel execution support and dummy job systems

This commit is contained in:
max
2026-08-07 12:14:02 +02:00
parent a0f2713fdc
commit 0132c1326d
14 changed files with 844 additions and 5 deletions
+52 -4
View File
@@ -2,7 +2,9 @@
using Nerfed.Editor.Systems;
using Nerfed.Runtime;
using Nerfed.Runtime.Components;
using Nerfed.Runtime.Scheduling;
using Nerfed.Runtime.Systems;
using Nerfed.Runtime.Systems.Synthetic;
using Nerfed.Runtime.Util;
using System.Numerics;
@@ -12,10 +14,22 @@ internal class Program
{
private static readonly World world = new World();
private static List<MoonTools.ECS.System> systems = new List<MoonTools.ECS.System>();
private static SystemScheduler scheduler;
public static List<MoonTools.ECS.System> editorSystems = new List<MoonTools.ECS.System>();
private static bool enableDummySchedulerHarness;
private static bool enableParallelSystemExecution;
private static void Main(string[] args)
{
enableDummySchedulerHarness = args.Contains("--dummy-scheduler-test", StringComparer.OrdinalIgnoreCase);
enableParallelSystemExecution = args.Contains("--parallel-systems", StringComparer.OrdinalIgnoreCase);
scheduler = new SystemScheduler(new SystemSchedulerOptions
{
EnableParallelSystemExecution = enableParallelSystemExecution,
StrictDependencyValidation = true,
});
Engine.OnInitialize += HandleOnInitialize;
Engine.OnUpdate += HandleOnUpdate;
Engine.OnRender += HandleOnRender;
@@ -27,7 +41,42 @@ internal class Program
private static void HandleOnInitialize()
{
//systems.Add(new ParentSystem(world));
systems.Add(new LocalToWorldSystem(world));
LocalToWorldSystem localToWorldSystem = new LocalToWorldSystem(world);
systems.Add(localToWorldSystem);
scheduler.Register(localToWorldSystem, SystemSchedulePhase.Simulation);
if (enableDummySchedulerHarness)
{
DummyLongJobSharedState sharedState = new DummyLongJobSharedState();
// Producer starts long work, middle system burns time on main thread, consumer acts as a barrier.
DummyLongJobProducerSystem producer = new DummyLongJobProducerSystem(
world,
sharedState,
JobSystem.Default,
TimeSpan.FromMilliseconds(6),
DummyWorkloadMode.Compute,
JobDeadlineMode.FrameCritical);
systems.Add(producer);
scheduler.Register(producer, SystemSchedulePhase.Simulation);
DummyMainThreadWorkSystem mainThreadWork = new DummyMainThreadWorkSystem(
world,
TimeSpan.FromMilliseconds(2),
DummyWorkloadMode.Compute,
nameof(DummyMainThreadWorkSystem));
systems.Add(mainThreadWork);
scheduler.Register(mainThreadWork, SystemSchedulePhase.Simulation);
DummyLongJobConsumerSystem consumer = new DummyLongJobConsumerSystem(
world,
sharedState,
JobSystem.Default,
requireCompletion: true);
systems.Add(consumer);
scheduler.Register(consumer, SystemSchedulePhase.LateSimulation, nameof(DummyLongJobProducerSystem));
}
editorSystems.Add(new EditorProfilerWindow(world));
editorSystems.Add(new EditorHierarchyWindow(world));
#if DEBUG
@@ -72,10 +121,9 @@ internal class Program
private static void HandleOnUpdate()
{
foreach (MoonTools.ECS.System system in systems)
using (new ProfilerScope("SystemScheduler.Execute"))
{
using ProfilerScope scope = new(system.GetType().Name);
system.Update(Engine.Timestep);
scheduler.Execute(Engine.Timestep);
}
using (new ProfilerScope("EditorGui.Update"))