Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/benchmarks/micro/MicroBenchmarks.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
<DebugType>pdbonly</DebugType>
<DebugSymbols>true</DebugSymbols>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>

<IsARM Condition="'$([System.Runtime.InteropServices.RuntimeInformation]::OSArchitecture.ToString().StartsWith(`arm`, System.StringComparison.OrdinalIgnoreCase))'">true</IsARM>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -68,5 +70,9 @@
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp2.0'">
<Compile Remove="corefx\System.Drawing\Perf_Graphics*.cs" />
</ItemGroup>

</Project>

<ItemGroup Condition="'$(TargetFramework)' != 'netcoreapp3.0' OR '$(IsARM)' == 'true'">
<Compile Remove="coreclr\PacketTracer\**" />
</ItemGroup>

</Project>
38 changes: 38 additions & 0 deletions src/benchmarks/micro/coreclr/PacketTracer/Camera.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Intrinsics.X86;
using static System.Runtime.Intrinsics.X86.Avx;
using System.Runtime.Intrinsics;

namespace HardwareIntrinsics.RayTracer
{
internal class Camera
{
public Camera(VectorPacket256 pos, VectorPacket256 forward, VectorPacket256 up, VectorPacket256 right)
{
Pos = pos;
Forward = forward;
Up = up;
Right = right;
}

public VectorPacket256 Pos;
public VectorPacket256 Forward;
public VectorPacket256 Up;
public VectorPacket256 Right;

public static Camera Create(VectorPacket256 pos, VectorPacket256 lookAt)
{
VectorPacket256 forward = (lookAt - pos).Normalize();
VectorPacket256 down =
new VectorPacket256(Vector256<float>.Zero, Vector256.Create(-1.0f), Vector256<float>.Zero);
Comment thread
adamsitnik marked this conversation as resolved.
Vector256<float> OnePointFive = Vector256.Create(1.5f);
VectorPacket256 right = OnePointFive * VectorPacket256.CrossProduct(forward, down).Normalize();
VectorPacket256 up = OnePointFive * VectorPacket256.CrossProduct(forward, right).Normalize();

return new Camera(pos, forward, up, right);
}
}
}
22 changes: 22 additions & 0 deletions src/benchmarks/micro/coreclr/PacketTracer/Color.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

namespace HardwareIntrinsics.RayTracer
{
internal struct Color
{
public float R { get; }
public float G { get; }
public float B { get; }

public static readonly Color Background = new Color(0, 0, 0);

public Color(float _r, float _g, float _b)
{
R = _r;
G = _g;
B = _b;
}
}
}
60 changes: 60 additions & 0 deletions src/benchmarks/micro/coreclr/PacketTracer/ColorPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using static System.Runtime.Intrinsics.X86.Avx;
using System.Runtime.Intrinsics.X86;
using System.Runtime.Intrinsics;
using System.Runtime.CompilerServices;

using ColorPacket256 = HardwareIntrinsics.RayTracer.VectorPacket256;

namespace HardwareIntrinsics.RayTracer
{
internal static class ColorPacket256Helper
{
private static readonly Vector256<float> One = Vector256.Create(1.0f);
private static readonly Vector256<float> Max = Vector256.Create(255.0f);

public static Int32RGBPacket256 ConvertToIntRGB(this VectorPacket256 colors)
{
var rsMask = Compare(colors.Xs, One, FloatComparisonMode.GreaterThanOrderedNonSignaling);
var gsMask = Compare(colors.Ys, One, FloatComparisonMode.GreaterThanOrderedNonSignaling);
var bsMask = Compare(colors.Zs, One, FloatComparisonMode.GreaterThanOrderedNonSignaling);

var rs = BlendVariable(colors.Xs, One, rsMask);
var gs = BlendVariable(colors.Ys, One, gsMask);
var bs = BlendVariable(colors.Zs, One, bsMask);

var rsInt = ConvertToVector256Int32(Multiply(rs, Max));
var gsInt = ConvertToVector256Int32(Multiply(gs, Max));
var bsInt = ConvertToVector256Int32(Multiply(bs, Max));

return new Int32RGBPacket256(rsInt, gsInt, bsInt);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static ColorPacket256 Times(ColorPacket256 left, ColorPacket256 right)
{
return new VectorPacket256(Multiply(left.Xs, right.Xs), Multiply(left.Ys, right.Ys),
Multiply(left.Zs, right.Zs));
}

public static readonly ColorPacket256 BackgroundColor = new ColorPacket256(Vector256<float>.Zero);
public static readonly ColorPacket256 DefaultColor = new ColorPacket256(Vector256<float>.Zero);
}

internal struct Int32RGBPacket256
{
public Vector256<int> Rs;
public Vector256<int> Gs;
public Vector256<int> Bs;

public Int32RGBPacket256(Vector256<int> rs, Vector256<int> gs, Vector256<int> bs)
{
Rs = rs;
Gs = gs;
Bs = bs;
}
}
}
44 changes: 44 additions & 0 deletions src/benchmarks/micro/coreclr/PacketTracer/Intersections.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.
//

using static System.Runtime.Intrinsics.X86.Avx;
using static System.Runtime.Intrinsics.X86.Avx2;
using System.Runtime.Intrinsics.X86;
using System.Runtime.Intrinsics;
using System.Runtime.CompilerServices;

namespace HardwareIntrinsics.RayTracer
{
internal struct Intersections
{
public Vector256<float> Distances;
public Vector256<int> ThingIndices;

public static readonly Vector256<float> NullDistance = Vector256.Create(float.MaxValue);
public static readonly Vector256<int> NullIndex = Vector256.Create(-1);

public Intersections(Vector256<float> dis, Vector256<int> things)
{
Distances = dis;
ThingIndices = things;
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public bool AllNullIntersections()
{
return AllNullIntersections(Distances);
}

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static bool AllNullIntersections(Vector256<float> dis)
{
var cmp = Compare(dis, NullDistance, FloatComparisonMode.EqualOrderedNonSignaling);
var zero = Vector256<int>.Zero;
// efficiently generate an all-one mask vector by lower latency AVX2 ComapreEqual
var mask = Avx2.CompareEqual(zero, zero);
return TestC(cmp, mask.AsSingle());
}
}
}
22 changes: 22 additions & 0 deletions src/benchmarks/micro/coreclr/PacketTracer/LightPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.CompilerServices;
using ColorPacket256 = HardwareIntrinsics.RayTracer.VectorPacket256;

namespace HardwareIntrinsics.RayTracer
{
internal class LightPacket256
{
public VectorPacket256 Positions;
public ColorPacket256 Colors;

[MethodImpl(MethodImplOptions.AggressiveInlining)]
public LightPacket256(Vector pos, Color col)
{
Positions = new VectorPacket256(pos.X, pos.Y, pos.Z);
Colors = new ColorPacket256(col.R, col.G, col.B);
}
}
}
20 changes: 20 additions & 0 deletions src/benchmarks/micro/coreclr/PacketTracer/ObjectPacket.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

using System.Runtime.Intrinsics;

namespace HardwareIntrinsics.RayTracer
{
internal abstract class ObjectPacket256
{
public Surface Surface { get; }
public abstract Vector256<float> Intersect(RayPacket256 rayPacket256);
public abstract VectorPacket256 Normals(VectorPacket256 pos);

public ObjectPacket256(Surface surface)
{
Surface = surface;
}
}
}
Loading