forked from dotnet/performance
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOneBodyConstraintBenchmarksDeep.cs
More file actions
153 lines (138 loc) · 8.97 KB
/
Copy pathOneBodyConstraintBenchmarksDeep.cs
File metadata and controls
153 lines (138 loc) · 8.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using BenchmarkDotNet.Attributes;
using BepuPhysics;
using BepuPhysics.Constraints;
using BepuPhysics.Constraints.Contact;
using BepuUtilities;
using System.Numerics;
using static DemoBenchmarks.OneBodyConstraintBenchmarks;
namespace DemoBenchmarks;
/// <summary>
/// Evaluates performance of all one body constraints excluded from <see cref="OneBodyConstraintBenchmarks"/>
/// </summary>
/// <remarks>
/// Note that all constraints operate across <see cref="Vector{}.Count"/> lanes simultaneously where T is of type <see cref="float"/>.
/// <para>The number of bundles being executed does not change if <see cref="Vector{}.Count"/> changes; if larger bundles are allowed, then more lanes end up getting solved.</para>
/// </remarks>
public class OneBodyConstraintBenchmarksDeep
{
[Benchmark]
public BodyVelocityWide Contact1OneBody()
{
var prestep = new Contact1OneBodyPrestepData
{
Contact0 = new() { Depth = Vector<float>.Zero, OffsetA = Vector3Wide.Broadcast(new Vector3(1, 0, 0)) },
MaterialProperties = new MaterialPropertiesWide
{
FrictionCoefficient = new Vector<float>(1f),
MaximumRecoveryVelocity = new Vector<float>(2f),
SpringSettings = new() { TwiceDampingRatio = new Vector<float>(2), AngularFrequency = new Vector<float>(20 * MathF.PI) }
},
Normal = Vector3Wide.Broadcast(new Vector3(0, 1, 0))
};
QuaternionWide.Broadcast(Quaternion.Identity, out var orientation);
var inertia = new BodyInertiaWide { InverseInertiaTensor = new Symmetric3x3Wide { XX = Vector<float>.One, YY = Vector<float>.One, ZZ = Vector<float>.One }, InverseMass = Vector<float>.One };
return BenchmarkOneBodyConstraint<Contact1OneBodyFunctions, Contact1OneBodyPrestepData, Contact1AccumulatedImpulses>(new Vector3Wide(), orientation, inertia, prestep);
}
[Benchmark]
public BodyVelocityWide Contact2OneBody()
{
var prestep = new Contact2OneBodyPrestepData
{
Contact0 = new() { Depth = Vector<float>.Zero, OffsetA = Vector3Wide.Broadcast(new Vector3(1, 0, 0)) },
Contact1 = new() { Depth = Vector<float>.Zero, OffsetA = Vector3Wide.Broadcast(new Vector3(1, 0, 0)) },
MaterialProperties = new MaterialPropertiesWide
{
FrictionCoefficient = new Vector<float>(1f),
MaximumRecoveryVelocity = new Vector<float>(2f),
SpringSettings = new() { TwiceDampingRatio = new Vector<float>(2), AngularFrequency = new Vector<float>(20 * MathF.PI) }
},
Normal = Vector3Wide.Broadcast(new Vector3(0, 1, 0))
};
QuaternionWide.Broadcast(Quaternion.Identity, out var orientation);
var inertia = new BodyInertiaWide { InverseInertiaTensor = new Symmetric3x3Wide { XX = Vector<float>.One, YY = Vector<float>.One, ZZ = Vector<float>.One }, InverseMass = Vector<float>.One };
return BenchmarkOneBodyConstraint<Contact2OneBodyFunctions, Contact2OneBodyPrestepData, Contact2AccumulatedImpulses>(new Vector3Wide(), orientation, inertia, prestep);
}
[Benchmark]
public BodyVelocityWide Contact3OneBody()
{
var prestep = new Contact3OneBodyPrestepData
{
Contact0 = new() { Depth = Vector<float>.Zero, OffsetA = Vector3Wide.Broadcast(new Vector3(1, 0, 0)) },
Contact1 = new() { Depth = Vector<float>.Zero, OffsetA = Vector3Wide.Broadcast(new Vector3(1, 0, 0)) },
Contact2 = new() { Depth = Vector<float>.Zero, OffsetA = Vector3Wide.Broadcast(new Vector3(1, 0, 0)) },
MaterialProperties = new MaterialPropertiesWide
{
FrictionCoefficient = new Vector<float>(1f),
MaximumRecoveryVelocity = new Vector<float>(2f),
SpringSettings = new() { TwiceDampingRatio = new Vector<float>(2), AngularFrequency = new Vector<float>(20 * MathF.PI) }
},
Normal = Vector3Wide.Broadcast(new Vector3(0, 1, 0))
};
QuaternionWide.Broadcast(Quaternion.Identity, out var orientationA);
var inertia = new BodyInertiaWide { InverseInertiaTensor = new Symmetric3x3Wide { XX = Vector<float>.One, YY = Vector<float>.One, ZZ = Vector<float>.One }, InverseMass = Vector<float>.One };
return BenchmarkOneBodyConstraint<Contact3OneBodyFunctions, Contact3OneBodyPrestepData, Contact3AccumulatedImpulses>(new Vector3Wide(), orientationA, inertia, prestep);
}
[Benchmark]
public BodyVelocityWide Contact2NonconvexOneBody()
{
var prestep = new Contact2NonconvexOneBodyPrestepData
{
Contact0 = new() { Depth = Vector<float>.Zero, Offset = Vector3Wide.Broadcast(new Vector3(1, 0, 0)), Normal = Vector3Wide.Broadcast(new Vector3(0, 1, 0)) },
Contact1 = new() { Depth = Vector<float>.Zero, Offset = Vector3Wide.Broadcast(new Vector3(1, 0, 0)), Normal = Vector3Wide.Broadcast(new Vector3(0, 1, 0)) },
MaterialProperties = new MaterialPropertiesWide
{
FrictionCoefficient = new Vector<float>(1f),
MaximumRecoveryVelocity = new Vector<float>(2f),
SpringSettings = new() { TwiceDampingRatio = new Vector<float>(2), AngularFrequency = new Vector<float>(20 * MathF.PI) }
},
};
QuaternionWide.Broadcast(Quaternion.Identity, out var orientation);
var inertia = new BodyInertiaWide { InverseInertiaTensor = new Symmetric3x3Wide { XX = Vector<float>.One, YY = Vector<float>.One, ZZ = Vector<float>.One }, InverseMass = Vector<float>.One };
return BenchmarkOneBodyConstraint<ContactNonconvexOneBodyFunctions<Contact2NonconvexOneBodyPrestepData, Contact2NonconvexAccumulatedImpulses>,
Contact2NonconvexOneBodyPrestepData, Contact2NonconvexAccumulatedImpulses>(new Vector3Wide(), orientation, inertia, prestep);
}
[Benchmark]
public BodyVelocityWide Contact3NonconvexOneBody()
{
var prestep = new Contact3NonconvexOneBodyPrestepData
{
Contact0 = new() { Depth = Vector<float>.Zero, Offset = Vector3Wide.Broadcast(new Vector3(1, 0, 0)), Normal = Vector3Wide.Broadcast(new Vector3(0, 1, 0)) },
Contact1 = new() { Depth = Vector<float>.Zero, Offset = Vector3Wide.Broadcast(new Vector3(1, 0, 0)), Normal = Vector3Wide.Broadcast(new Vector3(0, 1, 0)) },
Contact2 = new() { Depth = Vector<float>.Zero, Offset = Vector3Wide.Broadcast(new Vector3(1, 0, 0)), Normal = Vector3Wide.Broadcast(new Vector3(0, 1, 0)) },
MaterialProperties = new MaterialPropertiesWide
{
FrictionCoefficient = new Vector<float>(1f),
MaximumRecoveryVelocity = new Vector<float>(2f),
SpringSettings = new() { TwiceDampingRatio = new Vector<float>(2), AngularFrequency = new Vector<float>(20 * MathF.PI) }
},
};
QuaternionWide.Broadcast(Quaternion.Identity, out var orientation);
var inertia = new BodyInertiaWide { InverseInertiaTensor = new Symmetric3x3Wide { XX = Vector<float>.One, YY = Vector<float>.One, ZZ = Vector<float>.One }, InverseMass = Vector<float>.One };
return BenchmarkOneBodyConstraint<ContactNonconvexOneBodyFunctions<Contact3NonconvexOneBodyPrestepData, Contact3NonconvexAccumulatedImpulses>,
Contact3NonconvexOneBodyPrestepData, Contact3NonconvexAccumulatedImpulses>(new Vector3Wide(), orientation, inertia, prestep);
}
[Benchmark]
public BodyVelocityWide OneBodyAngularMotor()
{
QuaternionWide.Broadcast(Quaternion.Identity, out var orientation);
var prestep = new OneBodyAngularMotorPrestepData
{
Settings = new() { Damping = Vector<float>.One, MaximumForce = Vector<float>.One },
TargetVelocity = default
};
var inertia = new BodyInertiaWide { InverseInertiaTensor = new Symmetric3x3Wide { XX = Vector<float>.One, YY = Vector<float>.One, ZZ = Vector<float>.One }, InverseMass = Vector<float>.One };
return BenchmarkOneBodyConstraint<OneBodyAngularMotorFunctions, OneBodyAngularMotorPrestepData, Vector3Wide>(new Vector3Wide(), orientation, inertia, prestep);
}
[Benchmark]
public BodyVelocityWide OneBodyLinearServo()
{
QuaternionWide.Broadcast(Quaternion.Identity, out var orientation);
var prestep = new OneBodyLinearServoPrestepData
{
ServoSettings = new() { BaseSpeed = Vector<float>.Zero, MaximumForce = new Vector<float>(float.MaxValue), MaximumSpeed = new Vector<float>(float.MaxValue) },
SpringSettings = new() { TwiceDampingRatio = new Vector<float>(2), AngularFrequency = new Vector<float>(20 * MathF.PI) }
};
var inertia = new BodyInertiaWide { InverseInertiaTensor = new Symmetric3x3Wide { XX = Vector<float>.One, YY = Vector<float>.One, ZZ = Vector<float>.One }, InverseMass = Vector<float>.One };
return BenchmarkOneBodyConstraint<OneBodyLinearServoFunctions, OneBodyLinearServoPrestepData, Vector3Wide>(new Vector3Wide(), orientation, inertia, prestep);
}
}