Skip to content

Commit 33cab56

Browse files
authored
Merge pull request #902 from unoplatform/dev/jela/jiterpreter
chore: Adjust raytracer performance
2 parents daf3274 + 2a9e663 commit 33cab56

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

src/Uno.Wasm.Sample.RayTracer.Shared/Benchmark.cs

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ struct Vec3
2626
{
2727
public Num X, Y, Z;
2828

29-
public static readonly Vec3 Zero = new Vec3();
30-
3129
public Vec3(Num x, Num y, Num z)
3230
{
3331
X = x;
@@ -115,6 +113,12 @@ public static Vec3 Normalize(Vec3 v)
115113
}
116114
}
117115

116+
static class Vec3Const
117+
{
118+
// Required for AOT with https://github.com/dotnet/runtime/issues/109170
119+
public static readonly Vec3 Zero = new Vec3();
120+
}
121+
118122
struct Ray
119123
{
120124
public Vec3 Org;
@@ -226,7 +230,7 @@ private static Vec3 trace (Ray ray, Scene scene, int depth)
226230
}
227231
}
228232

229-
if (obj == null) return Vec3.Zero;
233+
if (obj == null) return Vec3Const.Zero;
230234

231235
var point_of_hit = ray.Org + (ray.Dir * nearest);
232236
var normal = Sphere.Normal(obj, point_of_hit);
@@ -238,7 +242,7 @@ private static Vec3 trace (Ray ray, Scene scene, int depth)
238242
normal = -normal;
239243
}
240244

241-
Vec3 color = Vec3.Zero;
245+
Vec3 color = Vec3Const.Zero;
242246
var reflection_ratio = obj.Reflection;
243247

244248
foreach(var l in scene.Lights)
@@ -309,7 +313,7 @@ private static Vec3 trace (Ray ray, Scene scene, int depth)
309313

310314
public static byte[] Render(Scene scene, byte[] pixels)
311315
{
312-
var eye = Vec3.Zero;
316+
var eye = Vec3Const.Zero;
313317
Num h = (Num)Math.Tan(((fov / 360) * (2 * PI)) / 2) * 2;
314318
Num w = h * Width / Height;
315319

0 commit comments

Comments
 (0)