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

Commit

Permalink
using struct for VectorPacket and pass-by-ref in PacketTracer benchmark
Browse files Browse the repository at this point in the history
  • Loading branch information
FeiPengIntel committed Aug 28, 2018
1 parent fa4c1c4 commit a6ae47c
Show file tree
Hide file tree
Showing 8 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ internal static class ColorPacket256Helper

private static readonly Vector256<float> One = SetAllVector256<float>(1.0f);
private static readonly Vector256<float> Max = SetAllVector256<float>(255.0f);
public static Int32RGBPacket256 ConvertToIntRGB(this VectorPacket256 colors)
public static Int32RGBPacket256 ConvertToIntRGB(this in VectorPacket256 colors)
{

var rsMask = Compare(colors.Xs, One, FloatComparisonMode.GreaterThanOrderedNonSignaling);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ internal abstract class ObjectPacket256
{
public Surface Surface { get; }
public abstract Vector256<float> Intersect(RayPacket256 rayPacket256);
public abstract VectorPacket256 Normals(VectorPacket256 pos);
public abstract VectorPacket256 Normals(in VectorPacket256 pos);

public ObjectPacket256(Surface surface)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ private ColorPacket256 TraceRay(RayPacket256 rayPacket256, Scene scene, int dept
{
return ColorPacket256Helper.BackgroundColor;
}
var color = Shade(isect, rayPacket256, scene, depth);
var color = Shade(in isect, rayPacket256, scene, depth);
var isNull = Compare(isect.Distances, Intersections.NullDistance, FloatComparisonMode.EqualOrderedNonSignaling);
var backgroundColor = ColorPacket256Helper.BackgroundColor.Xs;
return new ColorPacket256(BlendVariable(color.Xs, backgroundColor, isNull),
Expand Down Expand Up @@ -111,14 +111,14 @@ private Intersections MinIntersections(RayPacket256 rayPacket256, Scene scene)
return mins;
}

private ColorPacket256 Shade(Intersections isect, RayPacket256 rays, Scene scene, int depth)
private ColorPacket256 Shade(in Intersections isect, RayPacket256 rays, Scene scene, int depth)
{

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

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

private ColorPacket256 GetNaturalColor(Vector256<int> things, VectorPacket256 pos, VectorPacket256 norms, VectorPacket256 rds, Scene scene)
private ColorPacket256 GetNaturalColor(Vector256<int> things, in VectorPacket256 pos, in VectorPacket256 norms, in VectorPacket256 rds, Scene scene)
{
var colors = ColorPacket256Helper.DefaultColor;
for (int i = 0; i < scene.Lights.Length; i++)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
<PropertyGroup>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public PlanePacket256(VectorPacket256 norms, Vector256<float> offsets, Surface s
Offsets = offsets;
}

public override VectorPacket256 Normals(VectorPacket256 pos)
public override VectorPacket256 Normals(in VectorPacket256 pos)
{
return Norms;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public VectorPacket256 Normals(Vector256<int> things, VectorPacket256 pos)
for (int i = 0; i < Things.Length; i++)
{
Vector256<float> mask = StaticCast<int, float>(CompareEqual(things, SetAllVector256<int>(i)));
var n = Things[i].Normals(pos);
var n = Things[i].Normals(in pos);
norms.Xs = BlendVariable(norms.Xs, n.Xs, mask);
norms.Ys = BlendVariable(norms.Ys, n.Ys, mask);
norms.Zs = BlendVariable(norms.Zs, n.Zs, mask);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public SpherePacket256(VectorPacket256 centers, Vector256<float> radiuses, Surfa
Radiuses = radiuses;
}

public override VectorPacket256 Normals(VectorPacket256 pos)
public override VectorPacket256 Normals(in VectorPacket256 pos)
{
return (pos - Centers).Normalize();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
using System.Runtime.CompilerServices;
using System;

internal class VectorPacket256
internal struct VectorPacket256
{
public Vector256<float> Xs;
public Vector256<float> Ys;
Expand Down

0 comments on commit a6ae47c

Please sign in to comment.