Mirror of Svelto.ECS because we're a fan of it
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

74 lines
2.7KB

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