// Schedule() implementation for ITriggerEventsJob when Havok Physics is available public static unsafe JobHandle Schedule <T>(this T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, ITriggerEventsJob { switch (simulation.Type) { case SimulationType.UnityPhysics: // Call the scheduling method for Unity.Physics return(ITriggerEventJobExtensions.ScheduleUnityPhysicsTriggerEventsJob(jobData, simulation, ref world, inputDeps)); case SimulationType.HavokPhysics: { var data = new TriggerEventJobData <T> { UserJobData = jobData, EventReader = ((Havok.Physics.HavokSimulation)simulation).TriggerEvents }; // Ensure the input dependencies include the end-of-simulation job, so events will have been generated inputDeps = JobHandle.CombineDependencies(inputDeps, simulation.FinalSimulationJobHandle); var parameters = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref data), TriggerEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); } default: return(inputDeps); } }
static unsafe JobHandle Schedule(void *fullData, NativeArray <byte> prefilterData, int unfilteredLength, int innerloopBatchCount, bool isParallelFor, bool isFiltered, ref JobForEachCache cache, void *deferredCountData, JobHandle dependsOn, ScheduleMode mode) { #if ENABLE_UNITY_COLLECTIONS_CHECKS try { #endif if (isParallelFor) { var scheduleParams = new JobsUtility.JobScheduleParameters(fullData, cache.JobReflectionDataParallelFor, dependsOn, mode); if (isFiltered) { return(JobsUtility.ScheduleParallelForDeferArraySize(ref scheduleParams, innerloopBatchCount, deferredCountData, null)); } else { return(JobsUtility.ScheduleParallelFor(ref scheduleParams, unfilteredLength, innerloopBatchCount)); } } else { var scheduleParams = new JobsUtility.JobScheduleParameters(fullData, cache.JobReflectionData, dependsOn, mode); return(JobsUtility.Schedule(ref scheduleParams)); } #if ENABLE_UNITY_COLLECTIONS_CHECKS } catch (InvalidOperationException e) { prefilterData.Dispose(); throw e; } #endif }
/// <summary> Schedule a <see cref="IJobEventReader{T}"/> job. </summary> /// <param name="jobData"> The job. </param> /// <param name="eventSystem"> The event system. </param> /// <param name="dependsOn"> The job handle dependency. </param> /// <typeparam name="TJob"> The type of the job. </typeparam> /// <typeparam name="T"> The type of the key in the hash map. </typeparam> /// <returns> The handle to job. </returns> public static unsafe JobHandle Schedule <TJob, T>( this TJob jobData, EventSystemBase eventSystem, JobHandle dependsOn = default) where TJob : struct, IJobEventReader <T> where T : struct { dependsOn = eventSystem.GetEventReaders <T>(dependsOn, out var events); for (var i = 0; i < events.Count; i++) { var fullData = new EventJobReaderStruct <TJob, T> { Reader = events[i], JobData = jobData, Index = i, }; #if UNITY_2020_2_OR_NEWER const ScheduleMode scheduleMode = ScheduleMode.Parallel; #else const ScheduleMode scheduleMode = ScheduleMode.Batched; #endif var scheduleParams = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref fullData), EventJobReaderStruct <TJob, T> .Initialize(), dependsOn, scheduleMode); dependsOn = JobsUtility.Schedule(ref scheduleParams); } eventSystem.AddJobHandleForConsumer <T>(dependsOn); return(dependsOn); }
// Schedule() implementation for IContactsJob when Havok Physics is available public static unsafe JobHandle Schedule <T>(this T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, IContactsJobBase { switch (simulation.Type) { case SimulationType.UnityPhysics: // Call the scheduling method for Unity.Physics return(IContactsJobExtensions.ScheduleUnityPhysicsContactsJob(jobData, simulation, ref world, inputDeps)); case SimulationType.HavokPhysics: { var data = new ContactsJobData <T> { UserJobData = jobData, ManifoldStream = ((Havok.Physics.HavokSimulation)simulation).ManifoldStream, PluginIndexToLocal = ((Havok.Physics.HavokSimulation)simulation).PluginIndexToLocal, Bodies = world.Bodies }; var parameters = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref data), ContactsJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); } default: return(inputDeps); } }
public static unsafe JobHandle Schedule <T>(this T jobData, ref CustomWorld world, JobHandle dependsOn) where T : struct, ICustomJob { var data = new CustomJobData <T> { UserJobData = jobData, abData = world.abData, testArray = new NativeArray <int>(10, Allocator.TempJob) }; var parameters = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref data), CustomJobProcess <T> .Initialize(), dependsOn, ScheduleMode.Batched #if JOBS_CODEGEN_SAMPLE , UnsafeUtility.SizeOf <CustomJobData <T> >() // A size for memory allocation , data.UserJobData.PrepareJobAtScheduleTimeFn_Gen() // The return parameter does nothing except debug checks. // Just a reasonable place to find and insert the // call to PrepareJobAtScheduleTimeFn_Gen #endif ); return(JobsUtility.Schedule(ref parameters)); }
unsafe internal static void Run <T>(this T jobData) where T : struct, IJobBurstSchedulable { var reflectionData = JobStruct <T> .jobReflectionData.Data; CheckReflectionDataCorrect(reflectionData); var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), reflectionData, new JobHandle(), ScheduleMode.Run); JobsUtility.Schedule(ref scheduleParams); }
unsafe static public JobHandle ScheduleFilter <T>(this T jobData, NativeList <int> indices, int innerloopBatchCount, JobHandle dependsOn = new JobHandle()) where T : struct, IJobParallelForFilter { JobStructProduce <T> .JobDataWithFiltering fullData; fullData.data = jobData; fullData.outputIndices = indices; fullData.appendCount = -1; var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref fullData), JobStructProduce <T> .Initialize(), dependsOn, ScheduleMode.Batched); return(JobsUtility.Schedule(ref scheduleParams)); }
private static unsafe JobHandle FinalizeScheduleNoExceptions(bool isParallel, int batchCount, ref JobsUtility.JobScheduleParameters scheduleParams) { if (!isParallel) { return(JobsUtility.Schedule(ref scheduleParams)); } else { return(JobsUtility.ScheduleParallelFor(ref scheduleParams, batchCount, 1)); } }
public unsafe static JobHandle ScheduleWithInt <T>(this T jobData, int value, JobHandle dependsOn = new JobHandle()) where T : struct, IJobWithInt { JobDataWithInt <T> jobDataWithInt = new JobDataWithInt <T> { value = value, jobData = jobData }; var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobDataWithInt), JobWithIntStruct <T> .Initialize(), dependsOn, ScheduleMode.Batched); return(JobsUtility.Schedule(ref scheduleParams)); }
public unsafe static void RunWithInt <T>(this T jobData, int value) where T : struct, IJobWithInt { JobDataWithInt <T> jobDataWithInt = new JobDataWithInt <T> { value = value, jobData = jobData }; var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobDataWithInt), JobWithIntStruct <T> .Initialize(), new JobHandle(), ScheduleMode.Run); JobsUtility.Schedule(ref scheduleParams); }
unsafe internal static JobHandle Schedule <T>(this T jobData, JobHandle dependsOn = new JobHandle()) where T : struct, IJobBurstSchedulable { var reflectionData = JobStruct <T> .jobReflectionData.Data; CheckReflectionDataCorrect(reflectionData); #if UNITY_2020_2_OR_NEWER || UNITY_DOTSRUNTIME var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), reflectionData, dependsOn, ScheduleMode.Parallel); #else var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), reflectionData, dependsOn, ScheduleMode.Batched); #endif return(JobsUtility.Schedule(ref scheduleParams)); }
internal static unsafe JobHandle ScheduleInternal <T>( ref T jobData, EntityQuery query, JobHandle dependsOn, ScheduleMode mode, int batchesPerChunk, bool isParallel = true) where T : struct, IJobEntityBatch { var queryImpl = query._GetImpl(); var queryData = queryImpl->_QueryData; var cachedChunks = queryData->GetMatchingChunkCache(); // Don't schedule the job if there are no chunks to work on var chunkCount = cachedChunks.Length; JobEntityBatchWrapper <T> jobEntityBatchWrapper = new JobEntityBatchWrapper <T> { #if ENABLE_UNITY_COLLECTIONS_CHECKS // All IJobEntityBatch jobs have a EntityManager safety handle to ensure that BeforeStructuralChange throws an error if // jobs without any other safety handles are still running (haven't been synced). safety = new EntitySafetyHandle { m_Safety = queryImpl->SafetyHandles->GetEntityManagerSafetyHandle() }, #endif MatchingArchetypes = queryData->MatchingArchetypes, CachedChunks = cachedChunks, Filter = queryImpl->_Filter, JobData = jobData, JobsPerChunk = batchesPerChunk, IsParallel = isParallel ? 1 : 0 }; var scheduleParams = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref jobEntityBatchWrapper), isParallel ? JobEntityBatchProducer <T> .InitializeParallel() : JobEntityBatchProducer <T> .InitializeSingle(), dependsOn, mode); if (!isParallel) { return(JobsUtility.Schedule(ref scheduleParams)); } else { return(JobsUtility.ScheduleParallelFor(ref scheduleParams, chunkCount * batchesPerChunk, 1)); } }
public static unsafe JobHandle ScheduleFilter <T>(this T jobData, NativeList <int> indices, int innerloopBatchCount, JobHandle dependsOn = new JobHandle()) where T : struct, IJobParallelForFilter { JobParallelForFilterProducer <T> .JobWrapper jobWrapper = new JobParallelForFilterProducer <T> .JobWrapper() { JobData = jobData, outputIndices = indices, appendCount = -1 }; var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobWrapper), JobParallelForFilterProducer <T> .Initialize(), dependsOn, ScheduleMode.Batched); return(JobsUtility.Schedule(ref scheduleParams)); }
unsafe public static void Run <T>(this T jobData) where T : struct, IJobBurstScheduable { var reflectionData = JobStruct2 <T> .jobReflectionData.Data; if (reflectionData == IntPtr.Zero) { throw new InvalidOperationException("This should have been initialized by code gen"); } var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref jobData), reflectionData, new JobHandle(), ScheduleMode.Run); JobsUtility.Schedule(ref scheduleParams); }
public static unsafe JobHandle Schedule <T>(this T jobData, JobHandle dependsOn = default(JobHandle)) where T : struct, IJob { var jobProducer = new JobProducer <T>() { JobData = jobData }; var scheduleParams = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref jobProducer), JobProducer <T> .Initialize(), dependsOn, ScheduleMode.Batched); return(JobsUtility.Schedule(ref scheduleParams)); }
internal static unsafe JobHandle ScheduleUnityPhysicsBodyPairsJob <T>(T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, IBodyPairsJobBase { SafetyChecks.CheckAreEqualAndThrow(SimulationType.UnityPhysics, simulation.Type); var data = new BodyPairsJobData <T> { UserJobData = jobData, PhasedDispatchPairs = ((Simulation)simulation).StepContext.PhasedDispatchPairs.AsDeferredJobArray(), Bodies = world.Bodies }; var parameters = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref data), BodyPairsJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); }
private static unsafe JobHandle Schedule(void *fullData, int length, int innerloopBatchCount, bool isParallelFor, ref JobProcessComponentDataCache cache, JobHandle dependsOn, ScheduleMode mode) { if (isParallelFor) { var scheduleParams = new JobsUtility.JobScheduleParameters(fullData, cache.JobReflectionDataParallelFor, dependsOn, mode); return(JobsUtility.ScheduleParallelFor(ref scheduleParams, length, innerloopBatchCount)); } else { var scheduleParams = new JobsUtility.JobScheduleParameters(fullData, cache.JobReflectionData, dependsOn, mode); return(JobsUtility.Schedule(ref scheduleParams)); } }
unsafe static public JobHandle ScheduleAppend <T>(this T jobData, NativeList <int> indices, int arrayLength, int innerloopBatchCount, JobHandle dependsOn = new JobHandle()) where T : struct, IJobParallelForFilter { JobStructProduce <T> .JobDataWithFiltering fullData; fullData.data = jobData; fullData.outputIndices = indices; fullData.appendCount = arrayLength; #if UNITY_AVOID_REFLECTION JobStructProduce <T> job; job.FilteringData = fullData; return(job.Schedule(dependsOn)); #else var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref fullData), JobStructProduce <T> .Initialize(), dependsOn, ScheduleMode.Batched); return(JobsUtility.Schedule(ref scheduleParams)); #endif }
public static unsafe JobHandle Schedule <T>(this T jobData, JobHandle dependsOn = default) where T : struct, ICustomJobV2 { var parameters = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref jobData), CustomJobProcessV2 <T> .Initialize(), dependsOn, ScheduleMode.Batched #if JOBS_CODEGEN_SAMPLE , UnsafeUtility.SizeOf <CustomJobData <T> >() // A size for memory allocation , data.UserJobData.PrepareJobAtScheduleTimeFn_Gen() // The return parameter does nothing except debug checks. // Just a reasonable place to find and insert the // call to PrepareJobAtScheduleTimeFn_Gen #endif ); return(JobsUtility.Schedule(ref parameters)); }
// Schedules a trigger events job only for UnityPhysics simulation internal static unsafe JobHandle ScheduleUnityPhysicsTriggerEventsJob <T>(T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, ITriggerEventsJobBase { SafetyChecks.CheckAreEqualAndThrow(SimulationType.UnityPhysics, simulation.Type); var data = new TriggerEventJobData <T> { UserJobData = jobData, EventReader = ((Simulation)simulation).TriggerEvents }; // Ensure the input dependencies include the end-of-simulation job, so events will have been generated inputDeps = JobHandle.CombineDependencies(inputDeps, simulation.FinalSimulationJobHandle); var parameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref data), TriggerEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); }
internal static unsafe JobHandle ScheduleImpl<T>(this T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, IBodyPairsJob { if (simulation.Type == SimulationType.UnityPhysics) { var data = new BodyPairsJobData<T> { UserJobData = jobData, PhasedDispatchPairs = ((Simulation)simulation).m_Context.PhasedDispatchPairs.AsDeferredJobArray(), Bodies = world.Bodies }; var parameters = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref data), BodyPairsJobProcess<T>.Initialize(), inputDeps, ScheduleMode.Batched); return JobsUtility.Schedule(ref parameters); } return inputDeps; }
private static unsafe JobHandle ScheduleInternal <TJob, T>( this TJob jobData, EventSystemBase eventSystem, JobHandle dependsOn, bool isParallel) where TJob : struct, IJobEvent <T> where T : struct { dependsOn = eventSystem.GetEventReaders <T>(dependsOn, out var events); for (var i = 0; i < events.Count; i++) { var reader = events[i]; var fullData = new JobEventProducer <TJob, T> { Reader = reader, JobData = jobData, IsParallel = isParallel, }; #if UNITY_2020_2_OR_NEWER const ScheduleMode scheduleMode = ScheduleMode.Parallel; #else const ScheduleMode scheduleMode = ScheduleMode.Batched; #endif var scheduleParams = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref fullData), isParallel ? JobEventProducer <TJob, T> .InitializeParallel() : JobEventProducer <TJob, T> .InitializeSingle(), dependsOn, scheduleMode); dependsOn = isParallel ? JobsUtility.ScheduleParallelFor(ref scheduleParams, reader.ForEachCount, 1) : JobsUtility.Schedule(ref scheduleParams); } eventSystem.AddJobHandleForConsumer <T>(dependsOn); return(dependsOn); }
internal static unsafe JobHandle ScheduleUnityPhysicsBodyPairsJob <T>(T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, IBodyPairsJobBase { if (simulation.Type != SimulationType.UnityPhysics) { throw new ArgumentException($"Simulation type {simulation.Type} is not supported! Should be called only for SimulationType.UnityPhysics."); } var data = new BodyPairsJobData <T> { UserJobData = jobData, PhasedDispatchPairs = ((Simulation)simulation).StepContext.PhasedDispatchPairs.AsDeferredJobArray(), Bodies = world.Bodies }; var parameters = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref data), BodyPairsJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); }
// Schedules a collision events job only for UnityPhysics simulation internal static unsafe JobHandle ScheduleUnityPhysicsCollisionEventsJob <T>(T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, ICollisionEventsJobBase { if (simulation.Type != SimulationType.UnityPhysics) { throw new ArgumentException($"Simulation type {simulation.Type} is not supported! Should be called only for SimulationType.UnityPhysics."); } var data = new CollisionEventJobData <T> { UserJobData = jobData, EventReader = ((Simulation)simulation).CollisionEvents }; // Ensure the input dependencies include the end-of-simulation job, so events will have been generated inputDeps = JobHandle.CombineDependencies(inputDeps, simulation.FinalSimulationJobHandle); var parameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref data), CollisionEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); }
internal static unsafe JobHandle Schedule <T>( this T job, VisualScriptingEventSystem eventSystem, JobHandle inputDeps = default) where T : struct, IVisualScriptingEventPtrReceiverJob { var data = new EventPtrReceiverJobData <T> { UserJob = job, EventData = eventSystem.Events }; var handle = eventSystem.AddJobHandleForProducer(inputDeps); var parameters = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref data), ExecuteUserEventPtrReceiverJobs <T> .Initialize(), handle, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); }
public static unsafe JobHandle ScheduleTest <T>(this T jobData, NativeArray <byte> dataForProducer, JobHandle dependsOn = new JobHandle()) where T : struct, IJobTest { JobTestWrapper <T> jobTestWrapper = new JobTestWrapper <T> { JobData = jobData, ProducerResourceToClean = dataForProducer }; var scheduleParams = new JobsUtility.JobScheduleParameters( UnsafeUtility.AddressOf(ref jobTestWrapper), JobTestProducer <T> .Initialize(), dependsOn, #if UNITY_2020_2_OR_NEWER ScheduleMode.Parallel #else ScheduleMode.Batched #endif ); return(JobsUtility.Schedule(ref scheduleParams)); }
internal static unsafe JobHandle ScheduleImpl <T>(this T jobData, ISimulation simulation, ref PhysicsWorld world, JobHandle inputDeps) where T : struct, ICollisionEventsJob { if (simulation.Type == SimulationType.UnityPhysics) { var data = new CollisionEventJobData <T> { UserJobData = jobData, EventReader = ((Simulation)simulation).CollisionEvents, Bodies = world.Bodies, TimeStep = ((Simulation)simulation).m_Context.TimeStep, InputVelocities = ((Simulation)simulation).m_Context.InputVelocities }; // Ensure the input dependencies include the end-of-simulation job, so events will have been generated inputDeps = JobHandle.CombineDependencies(inputDeps, simulation.FinalSimulationJobHandle); var parameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref data), CollisionEventJobProcess <T> .Initialize(), inputDeps, ScheduleMode.Batched); return(JobsUtility.Schedule(ref parameters)); } return(inputDeps); }
internal unsafe static JobHandle ScheduleInternal_3 <T>(ref T jobData, ComponentSystemBase system, int innerloopBatchCount, JobHandle dependsOn, ScheduleMode mode) where T : struct { JobStruct_ProcessInfer_3 <T> fullData; fullData.Data = jobData; bool isParallelFor = innerloopBatchCount != -1; IJobProcessComponentDataUtility.Initialize(system, typeof(T), typeof(JobStruct_Process3 <, , ,>), isParallelFor, ref JobStruct_ProcessInfer_3 <T> .Cache, out fullData.Iterator); if (isParallelFor) { var length = fullData.Iterator.m_Length; var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref fullData), JobStruct_ProcessInfer_3 <T> .Cache.JobReflectionDataParallelFor, dependsOn, mode); return(JobsUtility.ScheduleParallelFor(ref scheduleParams, length, innerloopBatchCount)); } else { var scheduleParams = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf(ref fullData), JobStruct_ProcessInfer_3 <T> .Cache.JobReflectionData, dependsOn, mode); return(JobsUtility.Schedule(ref scheduleParams)); } }
public static void Run <T>(T jobData) where T : struct, IJob { JobsUtility.JobScheduleParameters jobScheduleParameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf <T>(ref jobData), IJobExtensions.JobStruct <T> .Initialize(), default(JobHandle), ScheduleMode.Run); JobsUtility.Schedule(ref jobScheduleParameters); }
public static JobHandle Schedule <T>(T jobData, JobHandle dependsOn = default(JobHandle)) where T : struct, IJob { JobsUtility.JobScheduleParameters jobScheduleParameters = new JobsUtility.JobScheduleParameters(UnsafeUtility.AddressOf <T>(ref jobData), IJobExtensions.JobStruct <T> .Initialize(), dependsOn, ScheduleMode.Batched); return(JobsUtility.Schedule(ref jobScheduleParameters)); }