Beispiel #1
0
        public void Run3SimpleJobsInParallel()
        {
            didDispose = 0;
            NativeArray <int> input      = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult1 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult2 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult3 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);

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

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

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

            JobHandle[]             arr   = { handle1, handle2, handle3 };
            NativeArray <JobHandle> group = new NativeArray <JobHandle>(arr, Allocator.TempJob);
            JobHandle handle = JobHandle.CombineDependencies(group);

            handle.Complete();

#if !UNITY_DOTSPLAYER
            // TODO: Understand / fix why the editor tests don't run quite the same code path.
            job1.mDisposable.Dispose();
            job2.mDisposable.Dispose();
            job3.mDisposable.Dispose();
#endif
            Assert.AreEqual(3, didDispose);

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

            input.Dispose();
            jobResult1.Dispose();
            jobResult2.Dispose();
            jobResult3.Dispose();
            group.Dispose();
        }
Beispiel #2
0
        public void Run3SimpleJobsInParallel()
        {
            didDispose = 0;
            NativeArray <int> input      = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult1 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult2 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult3 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);

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

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

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

            JobHandle[]             arr   = { handle1, handle2, handle3 };
            NativeArray <JobHandle> group = new NativeArray <JobHandle>(arr, Allocator.TempJob);
            JobHandle handle = JobHandle.CombineDependencies(group);

            handle.Complete();

#if NET_DOTS
            Assert.AreEqual(3, didDispose);
#endif

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

            input.Dispose();
            jobResult1.Dispose();
            jobResult2.Dispose();
            jobResult3.Dispose();
            group.Dispose();
        }
Beispiel #3
0
        public void Run3SimpleJobsInSerial()
        {
            didDispose = 0;
            NativeArray <int> input      = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult1 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult2 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult3 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);

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

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

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

            handle3.Complete();

#if !UNITY_DOTSPLAYER
            // TODO: Understand / fix why the editor tests don't run quite the same code path.
            job1.mDisposable.Dispose();
            job2.mDisposable.Dispose();
            job3.mDisposable.Dispose();
#endif

            Assert.AreEqual(3, didDispose);

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

            input.Dispose();
            jobResult1.Dispose();
            jobResult2.Dispose();
            jobResult3.Dispose();
        }
Beispiel #4
0
        public void Run3SimpleJobsInSerial()
        {
            didDispose = 0;
            NativeArray <int> input      = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult1 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult2 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);
            NativeArray <int> jobResult3 = new NativeArray <int>(SimpleAdd.N, Allocator.TempJob);

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

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

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

            handle3.Complete();

#if NET_DOTS
            Assert.AreEqual(3, didDispose);
#endif

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

            input.Dispose();
            jobResult1.Dispose();
            jobResult2.Dispose();
            jobResult3.Dispose();
        }