From b4535eff0001b93f9bb3e7c11435d955d17996a3 Mon Sep 17 00:00:00 2001 From: Misaki Date: Wed, 29 Apr 2026 01:35:12 +0900 Subject: [PATCH] Refactor GGXMipGenerationJobSPMD for SPMD support Replaced struct with generic SPMD version for SIMD, added type aliases (commented), optimized RadicalInverse_VdC, and adjusted SampleEquirectangularMap for better performance and code separation. --- .../Benchmark/GGXMipGenerationBenchmark.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Misaki.HighPerformance.Test/Benchmark/GGXMipGenerationBenchmark.cs b/Misaki.HighPerformance.Test/Benchmark/GGXMipGenerationBenchmark.cs index bb64ab6..0ad6dcd 100644 --- a/Misaki.HighPerformance.Test/Benchmark/GGXMipGenerationBenchmark.cs +++ b/Misaki.HighPerformance.Test/Benchmark/GGXMipGenerationBenchmark.cs @@ -10,6 +10,9 @@ using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using static Misaki.HighPerformance.Mathematics.math; +//using TFloat = Misaki.HighPerformance.Mathematics.SPMD.WideLane; +//using TInt = Misaki.HighPerformance.Mathematics.SPMD.WideLane; + namespace Misaki.HighPerformance.Test.Benchmark; internal unsafe struct MipLevel @@ -21,6 +24,7 @@ internal unsafe struct MipLevel public float roughness; } +//internal unsafe struct GGXMipGenerationJobSPMD : IJobParallelFor internal unsafe struct GGXMipGenerationJobSPMD : IJobParallelFor where TFloat : unmanaged, ISPMDLane where TInt : unmanaged, ISPMDLane @@ -32,7 +36,7 @@ internal unsafe struct GGXMipGenerationJobSPMD : IJobParallelFor public float* radicalInverse_VdCLut; public int numMipLevels; - [MethodImpl(MethodImplOptions.AggressiveInlining)] + [MethodImpl(MethodImplOptions.AggressiveInlining | MethodImplOptions.AggressiveOptimization)] public static float RadicalInverse_VdC(uint bits) { bits = (bits << 16) | (bits >> 16); @@ -96,6 +100,7 @@ internal unsafe struct GGXMipGenerationJobSPMD : IJobParallelFor } // Samples the source HDR image using bilinear interpolation (simplified to nearest neighbor for brevity here) + // Do not inline this function to avoid register pressure and code bloat in the main sampling loop, as this is a relatively heavy operation and we want to keep it separate for better instruction cache usage. [MethodImpl(MethodImplOptions.NoInlining | MethodImplOptions.AggressiveOptimization)] private static Vector3 SampleEquirectangularMap(float* img, int w, int h, Vector3 dir) {