Mirror of Svelto.ECS because we're a fan of it
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

68 lines
2.5KB

  1. #if UNITY_NATIVE
  2. using System;
  3. using Svelto.ECS.Extensions.Unity;
  4. using Unity.Jobs;
  5. namespace Svelto.ECS
  6. {
  7. #if UNITY_JOBS
  8. public static class UnityJobExtensions
  9. {
  10. public static JobHandle ScheduleParallel
  11. <JOB>(this JOB job, uint iterations, JobHandle inputDeps) where JOB: struct, IJobParallelForBatch
  12. {
  13. if (iterations == 0)
  14. return inputDeps;
  15. var innerloopBatchCount = ProcessorCount.BatchSize((uint) iterations);
  16. return job.ScheduleBatch((int)iterations, innerloopBatchCount, inputDeps);
  17. }
  18. public static JobHandle ScheduleParallel
  19. <JOB>(this JOB job, int iterations, JobHandle inputDeps) where JOB: struct, IJobParallelForBatch
  20. {
  21. if (iterations <= 0)
  22. return inputDeps;
  23. var innerloopBatchCount = ProcessorCount.BatchSize((uint) iterations);
  24. return job.ScheduleBatch((int)iterations, innerloopBatchCount, inputDeps);
  25. }
  26. }
  27. #endif
  28. public static class UnityJobExtensions2
  29. {
  30. public static JobHandle ScheduleDispose
  31. <T1>(this T1 disposable, JobHandle inputDeps) where T1 : struct, IDisposable
  32. {
  33. return new DisposeJob<T1>(disposable).Schedule(inputDeps);
  34. }
  35. public static JobHandle ScheduleDispose
  36. <T1, T2>(this T1 disposable1, T2 disposable2, JobHandle inputDeps)
  37. where T1 : struct, IDisposable where T2 : struct, IDisposable
  38. {
  39. return new DisposeJob<T1, T2>(disposable1, disposable2).Schedule(inputDeps);
  40. }
  41. public static JobHandle ScheduleParallel
  42. <JOB>(this JOB job, int iterations, JobHandle inputDeps) where JOB: struct, IJobParallelFor
  43. {
  44. if (iterations <= 0)
  45. return inputDeps;
  46. var innerloopBatchCount = ProcessorCount.BatchSize((uint) iterations);
  47. return job.Schedule((int)iterations, innerloopBatchCount, inputDeps);
  48. }
  49. public static JobHandle ScheduleParallel
  50. <JOB>(this JOB job, uint iterations, JobHandle inputDeps) where JOB: struct, IJobParallelFor
  51. {
  52. if (iterations == 0)
  53. return inputDeps;
  54. var innerloopBatchCount = ProcessorCount.BatchSize(iterations);
  55. return job.Schedule((int)iterations, innerloopBatchCount, inputDeps);
  56. }
  57. }
  58. }
  59. #endif