public void CompleteAllJobsAndInvalidateArrays()
        {
            if (m_DependencyHandlesCount != 0)
            {
#if NET_DOTS
                if (JobsUtility.IsExecutingJob())
#else
                if (JobsUtility.IsExecutingJob)
#endif
                {
                    throw new InvalidOperationException(
                              "Jobs accessing the entity manager must issue a complete sync point");
                }

                m_Marker.Begin();
                for (int t = 0; t < m_DependencyHandlesCount; ++t)
                {
                    m_DependencyHandles[t].WriteFence.Complete();

                    var readFencesCount = m_DependencyHandles[t].NumReadFences;
                    var readFences      = m_ReadJobFences + t * kMaxReadJobHandles;
                    for (var r = 0; r != readFencesCount; r++)
                    {
                        readFences[r].Complete();
                    }
                    m_DependencyHandles[t].NumReadFences = 0;
                }
                ClearDependencies();
                m_Marker.End();
            }

#if ENABLE_UNITY_COLLECTIONS_CHECKS
            Safety.CompleteAllJobsAndInvalidateArrays();
#endif
        }
Esempio n. 2
0
        public void Run3SimpleJobsInSerial()
        {
#if UNITY_SINGLETHREADED_JOBS && UNITY_DOTSPLAYER
            // Note the safety handles use Persistent, so only track TempJob
            long heapMem = UnsafeUtility.GetHeapSize(Allocator.TempJob);
#endif
            NativeArray <int> input      = new NativeArray <int>(SimpleAddSerial.N, Allocator.TempJob);
            NativeArray <int> jobResult1 = new NativeArray <int>(SimpleAddSerial.N, Allocator.TempJob);
            NativeArray <int> jobResult2 = new NativeArray <int>(SimpleAddSerial.N, Allocator.TempJob);
            NativeArray <int> jobResult3 = new NativeArray <int>(SimpleAddSerial.N, Allocator.TempJob);

            for (int i = 0; i < SimpleAddSerial.N; ++i)
            {
                input[i] = i;
            }

            SimpleAddSerial job1 = new SimpleAddSerial()
            {
                a = 1, input = input, result = jobResult1
            };
            SimpleAddSerial job2 = new SimpleAddSerial()
            {
                a = 2, input = jobResult1, result = jobResult2
            };
            SimpleAddSerial job3 = new SimpleAddSerial()
            {
                a = 3, input = jobResult2, result = jobResult3
            };

#if UNITY_SINGLETHREADED_JOBS && UNITY_DOTSPLAYER
            Assert.IsFalse(JobsUtility.IsExecutingJob());
#endif

            JobHandle handle1 = job1.Schedule();
            JobHandle handle2 = job2.Schedule(handle1);
            JobHandle handle3 = job3.Schedule(handle2);
            handle3.Complete();

#if UNITY_SINGLETHREADED_JOBS && UNITY_DOTSPLAYER
            Assert.IsFalse(JobsUtility.IsExecutingJob());
#endif

            for (int i = 0; i < SimpleAddSerial.N; ++i)
            {
                Assert.AreEqual(i + 1 + 2 + 3, jobResult3[i]);
            }

            jobResult3.Dispose();

#if UNITY_SINGLETHREADED_JOBS && UNITY_DOTSPLAYER
            long postWork = UnsafeUtility.GetHeapSize(Allocator.TempJob);
            Assert.IsTrue(heapMem == postWork);    // make sure cleanup happened, including DeallocateOnJobCompletion
#endif
        }
Esempio n. 3
0
            public void Execute()
            {
#if UNITY_DOTSPLAYER    // Don't have the C# version in the editor.
                AssertOnThread(!input.m_Safety.IsAllowedToWrite());
                AssertOnThread(input.m_Safety.IsAllowedToRead());
                AssertOnThread(result.m_Safety.IsAllowedToWrite());
                AssertOnThread(!result.m_Safety.IsAllowedToRead());

#if UNITY_SINGLETHREADED_JOBS
                AssertOnThread(JobsUtility.IsExecutingJob());
#endif
#endif
                for (int i = 0; i < N; ++i)
                {
                    result[i] = a + input[i];
                }
            }