public void BuildLayerPerformanceTests(int count, uint seed, CollisionLayerSettings settings)
        {
            Random random = new Random(seed);

            random.InitState(seed);

            World world  = new World("Test World");
            var   system = world.CreateSystem <FixedSimulationSystemGroup>();

            var eq        = world.EntityManager.CreateEntityQuery(typeof(Translation), typeof(Rotation), typeof(Collider), typeof(LocalToWorld));
            var archetype = world.EntityManager.CreateArchetype(typeof(Translation), typeof(Rotation), typeof(Collider), typeof(LocalToWorld));

            world.EntityManager.CreateEntity(archetype, count, Allocator.Temp);
            new GenerateJob {
                random = new Random(seed), aabb = settings.worldAABB
            }.Run(eq);

            var typeGroup    = BuildCollisionLayerP4.BuildLayerChunkTypeGroup(system);
            var layer        = new TestCollisionLayer(count, settings, Allocator.TempJob);
            var layerIndices = new NativeArray <int>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var aabbs        = new NativeArray <Aabb>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);
            var transforms   = new NativeArray <RigidTransform>(count, Allocator.TempJob, NativeArrayOptions.UninitializedMemory);

            SampleUnit unit = count > 9999 ? SampleUnit.Millisecond : SampleUnit.Microsecond;

            Measure.Method(() => { new BuildCollisionLayerP4.Part1FromQueryJob
                                   {
                                       layer           = layer,
                                       aabbs           = aabbs,
                                       typeGroup       = typeGroup,
                                       layerIndices    = layerIndices,
                                       rigidTransforms = transforms
                                   }.Run(eq); })
            .SampleGroup("Part1")
            .WarmupCount(0)
            .MeasurementCount(1)
            .Run();

            Measure.Method(() => { new BuildCollisionLayerP4.Part2Job
                                   {
                                       layer        = layer,
                                       layerIndices = layerIndices
                                   }.Run(); })
            .SampleGroup("Part2")
            .WarmupCount(0)
            .MeasurementCount(1)
            .Run();

            Measure.Method(() => { new BuildCollisionLayerP4.Part3FromQueryJob
                                   {
                                       layer          = layer,
                                       aabbs          = aabbs,
                                       layerIndices   = layerIndices,
                                       rigidTranforms = transforms,
                                       typeGroup      = typeGroup
                                   }.Run(eq); })
            .SampleGroup("Part3")
            .WarmupCount(0)
            .MeasurementCount(1)
            .Run();

            var layerBetter = new TestCollisionLayer(layer, Allocator.TempJob);
            var layerNew    = new TestCollisionLayer(layer, Allocator.TempJob);

            Measure.Method(() =>
            {
                new BuildCollisionLayerP4.Part4Job
                {
                    layer = layer
                }.Run(layer.BucketCount);
                //}.Schedule(layer.BucketCount, 1).Complete();
            })
            .SampleGroup("Part4Original")
            .WarmupCount(0)
            .MeasurementCount(1)
            .Run();

            Measure.Method(() => {
                new BuildCollisionLayerP4.Part4JobBetter
                {
                    layer = layerBetter
                }.Run(layerBetter.BucketCount);
                //}.Schedule(layer.BucketCount, 1).Complete();
            })
            .SampleGroup("Part4Better")
            .WarmupCount(0)
            .MeasurementCount(1)
            .Run();

            Measure.Method(() => {
                new BuildCollisionLayerP4.Part4JobNew
                {
                    layer = layerBetter
                }.Run(layerBetter.BucketCount);
                //}.Schedule(layer.BucketCount, 1).Complete();
            })
            .SampleGroup("Part4New")
            .WarmupCount(0)
            .MeasurementCount(1)
            .Run();

            layerNew.Dispose();
            layerBetter.Dispose();
            layer.Dispose();
            world.Dispose();
        }
コード例 #2
0
        public void BuildLayerPerformanceTests(int count, uint seed, CollisionLayerSettings settings)
        {
            Random random = new Random(seed);

            random.InitState(seed);

            World world  = new World("Test World");
            var   system = world.CreateSystem <FixedSimulationSystemGroup>();

            var eq        = world.EntityManager.CreateEntityQuery(typeof(Translation), typeof(Rotation), typeof(Collider), typeof(LocalToWorld));
            var archetype = world.EntityManager.CreateArchetype(typeof(Translation), typeof(Rotation), typeof(Collider), typeof(LocalToWorld));
            var e         = world.EntityManager.CreateEntity(archetype, count, Allocator.Persistent);

            e.Dispose();
            new GenerateJob {
                random = new Random(seed), aabb = settings.worldAABB
            }.Run(eq);

            {
                var typeGroup    = BuildCollisionLayerP4.BuildLayerChunkTypeGroup(system);
                var layer        = new TestCollisionLayer(count, settings, Allocator.Persistent);
                var layerIndices = new NativeArray <int>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                var aabbs        = new NativeArray <Aabb>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                var transforms   = new NativeArray <RigidTransform>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

                SampleUnit unit = count > 9999 ? SampleUnit.Millisecond : SampleUnit.Microsecond;

                Measure.Method(() =>
                {
                    new BuildCollisionLayerP4.Part1FromQueryJob
                    {
                        layer           = layer,
                        aabbs           = aabbs,
                        typeGroup       = typeGroup,
                        layerIndices    = layerIndices,
                        rigidTransforms = transforms
                    }.Run(eq);

                    new BuildCollisionLayerP4.Part2Job
                    {
                        layer        = layer,
                        layerIndices = layerIndices
                    }.Run();

                    new BuildCollisionLayerP4.Part3FromQueryJob
                    {
                        layer          = layer,
                        aabbs          = aabbs,
                        layerIndices   = layerIndices,
                        rigidTranforms = transforms,
                        typeGroup      = typeGroup
                    }.Run(eq);

                    new BuildCollisionLayerP4.Part4Job
                    {
                        layer = layer
                    }.Run(layer.BucketCount);
                })
                .SampleGroup("OldVersion")
                .WarmupCount(0)
                .MeasurementCount(1)
                .Run();

                layer.Dispose();
            }

            {
                var typeGroup    = BuildCollisionLayerP4.BuildLayerChunkTypeGroup(system);
                var layer        = new TestCollisionLayer(count, settings, Allocator.Persistent);
                var layerIndices = new NativeArray <int>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                var aabbs        = new NativeArray <Aabb>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                var transforms   = new NativeArray <RigidTransform>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

                SampleUnit unit = count > 9999 ? SampleUnit.Millisecond : SampleUnit.Microsecond;

                Measure.Method(() =>
                {
                    new BuildCollisionLayerP4.Part1FromQueryJob
                    {
                        layer           = layer,
                        aabbs           = aabbs,
                        typeGroup       = typeGroup,
                        layerIndices    = layerIndices,
                        rigidTransforms = transforms
                    }.Run(eq);

                    new BuildCollisionLayerP4.Part2Job
                    {
                        layer        = layer,
                        layerIndices = layerIndices
                    }.Run();

                    new BuildCollisionLayerP4.Part3FromQueryJob
                    {
                        layer          = layer,
                        aabbs          = aabbs,
                        layerIndices   = layerIndices,
                        rigidTranforms = transforms,
                        typeGroup      = typeGroup
                    }.Run(eq);

                    new BuildCollisionLayerP4.Part4JobBetter
                    {
                        layer = layer
                    }.Run(layer.BucketCount);
                })
                .SampleGroup("OldVersionBetter")
                .WarmupCount(0)
                .MeasurementCount(1)
                .Run();

                layer.Dispose();
            }

            //NewVersion
            {
                var typeGroup     = BuildCollisionLayerOldVsNew.BuildLayerChunkTypeGroup(system);
                var layer         = new TestCollisionLayer(count, settings, Allocator.Persistent);
                var layerIndices  = new NativeArray <int>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                var remapSrcArray = new NativeArray <int>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                var xmins         = new NativeArray <float>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                var aos           = new NativeArray <BuildCollisionLayerOldVsNew.ColliderAoSData>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

                SampleUnit unit = count > 9999 ? SampleUnit.Millisecond : SampleUnit.Microsecond;

                Measure.Method(() =>
                {
                    new BuildCollisionLayerOldVsNew.Part1FromQueryJob
                    {
                        layer        = layer,
                        typeGroup    = typeGroup,
                        layerIndices = layerIndices,
                        xmins        = xmins,
                        colliderAoS  = aos
                    }.Run(eq);

                    new BuildCollisionLayerOldVsNew.Part2Job
                    {
                        layer        = layer,
                        layerIndices = layerIndices
                    }.Run();

                    new BuildCollisionLayerOldVsNew.Part3Job
                    {
                        layerIndices       = layerIndices,
                        unsortedSrcIndices = remapSrcArray
                    }.Run(count);

                    new BuildCollisionLayerOldVsNew.Part4Job
                    {
                        unsortedSrcIndices = remapSrcArray,
                        xmins = xmins,
                        bucketStartAndCounts = layer.bucketStartsAndCounts
                    }.Run(layer.BucketCount);

                    new BuildCollisionLayerOldVsNew.Part5Job
                    {
                        layer           = layer,
                        colliderAoS     = aos,
                        remapSrcIndices = remapSrcArray
                    }.Run(count);
                })
                .SampleGroup("NewVersion")
                .WarmupCount(0)
                .MeasurementCount(1)
                .Run();

                remapSrcArray.Dispose();
                layer.Dispose();
            }

            {
                var typeGroup     = BuildCollisionLayerOldVsNew.BuildLayerChunkTypeGroup(system);
                var layer         = new TestCollisionLayer(count, settings, Allocator.Persistent);
                var layerIndices  = new NativeArray <int>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                var remapSrcArray = new NativeArray <int>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                var xmins         = new NativeArray <float>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);
                var aos           = new NativeArray <BuildCollisionLayerOldVsNew.ColliderAoSData>(count, Allocator.Persistent, NativeArrayOptions.UninitializedMemory);

                SampleUnit unit = count > 9999 ? SampleUnit.Millisecond : SampleUnit.Microsecond;

                Measure.Method(() =>
                {
                    new BuildCollisionLayerOldVsNew.Part1FromQueryJob
                    {
                        layer        = layer,
                        typeGroup    = typeGroup,
                        layerIndices = layerIndices,
                        xmins        = xmins,
                        colliderAoS  = aos
                    }.Run(eq);

                    new BuildCollisionLayerOldVsNew.Part2Job
                    {
                        layer        = layer,
                        layerIndices = layerIndices
                    }.Run();

                    new BuildCollisionLayerOldVsNew.Part3Job
                    {
                        layerIndices       = layerIndices,
                        unsortedSrcIndices = remapSrcArray
                    }.Run(count);

                    new BuildCollisionLayerOldVsNew.Part4JobUnity
                    {
                        unsortedSrcIndices = remapSrcArray,
                        xmins = xmins,
                        bucketStartAndCounts = layer.bucketStartsAndCounts
                    }.Run(layer.BucketCount);

                    new BuildCollisionLayerOldVsNew.Part5Job
                    {
                        layer           = layer,
                        colliderAoS     = aos,
                        remapSrcIndices = remapSrcArray
                    }.Run(count);
                })
                .SampleGroup("NewVersionUnity")
                .WarmupCount(0)
                .MeasurementCount(1)
                .Run();

                remapSrcArray.Dispose();
                layer.Dispose();
            }

            world.Dispose();
        }