-
Notifications
You must be signed in to change notification settings - Fork 300
Port PacketTracer benchmarks #382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
939209d
copy PacketTracer benchmarks from CoreCLR
adamsitnik f7c1a58
put everything into namespace
adamsitnik 5b2daef
don't try to compile it for non .NET Core 3.0 (unavailable HW API)
adamsitnik 8bcf41f
port to BenchmarkDotNet
adamsitnik f87e2a7
disable this test for ARM using some MSBuild magic
adamsitnik 5a05141
Use OrdinalIgnoreCase instead of InvariantCultureIgnoreCase
adamsitnik b38a952
I completely forgot to remove the old project file
adamsitnik f09e3e3
code review: naming
adamsitnik 1b9c937
code review: use Array instead
adamsitnik File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| 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); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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
44
src/benchmarks/micro/coreclr/PacketTracer/Intersections.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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()); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
| } | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.