Closed xentripetal closed 4 months ago
I don't know how bevy manages multithreading systems, but i made something working here https://github.com/andreakarasho/TinyEcs/tree/feat/scheduler-multithread The logic should [didn't test so much lol] split all systems which are not using borrowed/already-accessed resources.
In addition, systems are spawned with the ThreadingType.Auto
as default value. You can change that ofc and force the running behaviour.
scheduler.AddSystem(() => Console.WriteLine("Auto"), threadingType: ThreadingMode.Auto);
scheduler.AddSystem(() => Console.WriteLine("Single"), threadingType: ThreadingMode.Single);
scheduler.AddSystem(() => Console.WriteLine("Multi"), threadingType: ThreadingMode.Multi);
Interesting strategy, thanks for the quick solution!
Bevy looks at the tables each system will read or write, run systems in parallel based on it, and automatically inserts sync points/end defers between write-reads.
It would be great to eventually support automatically parallelizing systems in schedules based on their resource access.
I started work on porting Bevy's ECS scheduler to C# but put it on hold for now. I plan to come back to in the future, but if you're interested my draft state is here https://github.com/xentripetal/PolyGame/tree/73b5596a2ecb85016f9edc937b091c7ce05c1117/PolyECS/Scheduling