Ejemplo n.º 1
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.InJob);
#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.InJob);
#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
        }
Ejemplo n.º 2
0
        public void Run3SimpleJobsInSerial()
        {
            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.InJob);
#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.InJob);
#endif

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

            jobResult3.Dispose();
        }
Ejemplo n.º 3
0
        public void Run3SimpleJobsInSerial()
        {
            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
            };

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

            handle3.Complete();

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

            jobResult3.Dispose();
        }