Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit a6ae47c

Browse files
committed
using struct for VectorPacket and pass-by-ref in PacketTracer benchmark
1 parent fa4c1c4 commit a6ae47c

File tree

8 files changed

+11
-10
lines changed

8 files changed

+11
-10
lines changed

tests/src/JIT/Performance/CodeQuality/HWIntrinsic/X86/PacketTracer/ColorPacket.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ internal static class ColorPacket256Helper
1515

1616
private static readonly Vector256<float> One = SetAllVector256<float>(1.0f);
1717
private static readonly Vector256<float> Max = SetAllVector256<float>(255.0f);
18-
public static Int32RGBPacket256 ConvertToIntRGB(this VectorPacket256 colors)
18+
public static Int32RGBPacket256 ConvertToIntRGB(this in VectorPacket256 colors)
1919
{
2020

2121
var rsMask = Compare(colors.Xs, One, FloatComparisonMode.GreaterThanOrderedNonSignaling);

tests/src/JIT/Performance/CodeQuality/HWIntrinsic/X86/PacketTracer/ObjectPacket.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ internal abstract class ObjectPacket256
99
{
1010
public Surface Surface { get; }
1111
public abstract Vector256<float> Intersect(RayPacket256 rayPacket256);
12-
public abstract VectorPacket256 Normals(VectorPacket256 pos);
12+
public abstract VectorPacket256 Normals(in VectorPacket256 pos);
1313

1414
public ObjectPacket256(Surface surface)
1515
{

tests/src/JIT/Performance/CodeQuality/HWIntrinsic/X86/PacketTracer/PacketTracer.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ private ColorPacket256 TraceRay(RayPacket256 rayPacket256, Scene scene, int dept
6767
{
6868
return ColorPacket256Helper.BackgroundColor;
6969
}
70-
var color = Shade(isect, rayPacket256, scene, depth);
70+
var color = Shade(in isect, rayPacket256, scene, depth);
7171
var isNull = Compare(isect.Distances, Intersections.NullDistance, FloatComparisonMode.EqualOrderedNonSignaling);
7272
var backgroundColor = ColorPacket256Helper.BackgroundColor.Xs;
7373
return new ColorPacket256(BlendVariable(color.Xs, backgroundColor, isNull),
@@ -111,14 +111,14 @@ private Intersections MinIntersections(RayPacket256 rayPacket256, Scene scene)
111111
return mins;
112112
}
113113

114-
private ColorPacket256 Shade(Intersections isect, RayPacket256 rays, Scene scene, int depth)
114+
private ColorPacket256 Shade(in Intersections isect, RayPacket256 rays, Scene scene, int depth)
115115
{
116116

117117
var ds = rays.Dirs;
118118
var pos = isect.Distances * ds + rays.Starts;
119119
var normals = scene.Normals(isect.ThingIndices, pos);
120120
var reflectDirs = ds - (Multiply(VectorPacket256.DotProduct(normals, ds), SetAllVector256<float>(2)) * normals);
121-
var colors = GetNaturalColor(isect.ThingIndices, pos, normals, reflectDirs, scene);
121+
var colors = GetNaturalColor(isect.ThingIndices, in pos, in normals, in reflectDirs, scene);
122122

123123
if (depth >= MaxDepth)
124124
{
@@ -128,7 +128,7 @@ private ColorPacket256 Shade(Intersections isect, RayPacket256 rays, Scene scene
128128
return colors + GetReflectionColor(isect.ThingIndices, pos + (SetAllVector256<float>(0.001f) * reflectDirs), normals, reflectDirs, scene, depth);
129129
}
130130

131-
private ColorPacket256 GetNaturalColor(Vector256<int> things, VectorPacket256 pos, VectorPacket256 norms, VectorPacket256 rds, Scene scene)
131+
private ColorPacket256 GetNaturalColor(Vector256<int> things, in VectorPacket256 pos, in VectorPacket256 norms, in VectorPacket256 rds, Scene scene)
132132
{
133133
var colors = ColorPacket256Helper.DefaultColor;
134134
for (int i = 0; i < scene.Lights.Length; i++)

tests/src/JIT/Performance/CodeQuality/HWIntrinsic/X86/PacketTracer/PacketTracer.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
<PropertyGroup>
2020
<DebugType>pdbonly</DebugType>
2121
<Optimize>true</Optimize>
22+
<LangVersion>latest</LangVersion>
2223
</PropertyGroup>
2324

2425
<ItemGroup>

tests/src/JIT/Performance/CodeQuality/HWIntrinsic/X86/PacketTracer/PlanePacket.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public PlanePacket256(VectorPacket256 norms, Vector256<float> offsets, Surface s
2020
Offsets = offsets;
2121
}
2222

23-
public override VectorPacket256 Normals(VectorPacket256 pos)
23+
public override VectorPacket256 Normals(in VectorPacket256 pos)
2424
{
2525
return Norms;
2626
}

tests/src/JIT/Performance/CodeQuality/HWIntrinsic/X86/PacketTracer/Scene.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public VectorPacket256 Normals(Vector256<int> things, VectorPacket256 pos)
2727
for (int i = 0; i < Things.Length; i++)
2828
{
2929
Vector256<float> mask = StaticCast<int, float>(CompareEqual(things, SetAllVector256<int>(i)));
30-
var n = Things[i].Normals(pos);
30+
var n = Things[i].Normals(in pos);
3131
norms.Xs = BlendVariable(norms.Xs, n.Xs, mask);
3232
norms.Ys = BlendVariable(norms.Ys, n.Ys, mask);
3333
norms.Zs = BlendVariable(norms.Zs, n.Zs, mask);

tests/src/JIT/Performance/CodeQuality/HWIntrinsic/X86/PacketTracer/SpherePacket.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public SpherePacket256(VectorPacket256 centers, Vector256<float> radiuses, Surfa
2020
Radiuses = radiuses;
2121
}
2222

23-
public override VectorPacket256 Normals(VectorPacket256 pos)
23+
public override VectorPacket256 Normals(in VectorPacket256 pos)
2424
{
2525
return (pos - Centers).Normalize();
2626
}

tests/src/JIT/Performance/CodeQuality/HWIntrinsic/X86/PacketTracer/VectorPacket.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
using System.Runtime.CompilerServices;
1111
using System;
1212

13-
internal class VectorPacket256
13+
internal struct VectorPacket256
1414
{
1515
public Vector256<float> Xs;
1616
public Vector256<float> Ys;

0 commit comments

Comments
 (0)