Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Burst*Batch job optimisations
#1
Hello,
I think I found a 2nd potential perf boost for the Burst backend, mearused using a profiler sample BurstConstraintsImpl.Project() call like so:
Code:
        public JobHandle Project(JobHandle inputDeps, float deltaTime)
        {
            UnityEngine.Profiling.Profiler.BeginSample("Project");

            var parameters = m_Solver.abstraction.GetConstraintParameters(m_ConstraintType);

            switch(parameters.evaluationOrder)
            {
                case Oni.ConstraintParameters.EvaluationOrder.Sequential:
                    inputDeps = EvaluateSequential(inputDeps, deltaTime);
                break;

                case Oni.ConstraintParameters.EvaluationOrder.Parallel:
                    inputDeps = EvaluateParallel(inputDeps, deltaTime);
                break;
            }

            UnityEngine.Profiling.Profiler.EndSample();
           
            return inputDeps;
        }
I've replaced BurstDistanceConstraintsBatch's job generation code to:
Code:
        public void SetDistanceConstraints(ObiNativeIntList particleIndices, ObiNativeFloatList restLengths, ObiNativeVector2List stiffnesses, ObiNativeFloatList lambdas, int count)
        {
            this.particleIndices = particleIndices.AsNativeArray<int>();
            this.restLengths = restLengths.AsNativeArray<float>();
            this.stiffnesses = stiffnesses.AsNativeArray<float2>();
            this.lambdas = lambdas.AsNativeArray<float>();

            projectConstraints.particleIndices = this.particleIndices;
            projectConstraints.restLengths = this.restLengths;
            projectConstraints.stiffnesses = this.stiffnesses;
            projectConstraints.lambdas = this.lambdas;

            applyConstraints.particleIndices = this.particleIndices;

        }

        DistanceConstraintsBatchJob projectConstraints = new DistanceConstraintsBatchJob();

        public override JobHandle Evaluate(JobHandle inputDeps, float deltaTime)
        {
            projectConstraints.positions = solverImplementation.positions;
            projectConstraints.invMasses = solverImplementation.invMasses;
            projectConstraints.deltas = solverImplementation.positionDeltas;
            projectConstraints.counts = solverImplementation.positionConstraintCounts;
            projectConstraints.deltaTime = deltaTime;
           
            return projectConstraints.Schedule(m_ActiveConstraintCount, 32, inputDeps);
        }

        ApplyDistanceConstraintsBatchJob applyConstraints = new ApplyDistanceConstraintsBatchJob();

        public override JobHandle Apply(JobHandle inputDeps, float deltaTime)
        {
            var parameters = solverAbstraction.GetConstraintParameters(m_ConstraintType);

            applyConstraints.positions = solverImplementation.positions;
            applyConstraints.deltas = solverImplementation.positionDeltas;
            applyConstraints.counts = solverImplementation.positionConstraintCounts;
            applyConstraints.sorFactor = parameters.SORFactor;
           
            return applyConstraints.Schedule(m_ActiveConstraintCount, 64, inputDeps);
        }
which returned the following result (Ignore total time, the number of simulations in each case is randomised in my test scene, simulation type is one of 2 types in each case, the 0.05ms/cloth is consistent across multiple tests)
[Image: project-cost.png]
EDIT:
I assume this can be applied across all batch job types to improve the performance further
Reply


Messages In This Thread
Burst*Batch job optimisations - by ThoughtMango - 04-06-2021, 04:09 PM
RE: Burst*Batch job optimisations - by josemendez - 07-06-2021, 07:56 AM
RE: Burst*Batch job optimisations - by josemendez - 07-06-2021, 08:04 AM