-
Notifications
You must be signed in to change notification settings - Fork 275
/
Copy pathRender.cs
46 lines (39 loc) · 1.62 KB
/
Render.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
// 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;
using System.Runtime.InteropServices;
using System.Runtime.Intrinsics;
using System.Runtime.Intrinsics.X86;
using BenchmarkDotNet.Attributes;
using MicroBenchmarks;
namespace HardwareIntrinsics.RayTracer
{
[BenchmarkCategory(Categories.Runtime)]
[OperatingSystemsArchitectureFilter(allowed: true, Architecture.X64, Architecture.X86)]
public class SoA
{
private const int RunningTime = 1000;
private const int Width = 248;
private const int Height = 248;
private int[] rgbBuffer = new int[Width * 3 * Height]; // Each pixel has 3 fields (RGB)
[Benchmark]
public unsafe void Render()
{
if (!Avx2.IsSupported)
return;
// Create a ray tracer, and create a reference to "sphere2" that we are going to bounce
var packetTracer = new Packet256Tracer(Width, Height);
var scene = packetTracer.DefaultScene;
var sphere2 = (SpherePacket256)scene.Things[0]; // The first item is assumed to be our sphere
var baseY = sphere2.Radiuses;
sphere2.Centers.Ys = sphere2.Radiuses;
float dy2 = 0.8f * MathF.Abs(MathF.Sin((float) (1 * Math.PI / 3000)));
sphere2.Centers.Ys = Avx.Add(baseY, Vector256.Create(dy2));
fixed (int* ptr = rgbBuffer)
{
packetTracer.RenderVectorized(scene, ptr);
}
}
}
}