From f261d24e34421b4977605d2f4e495358d6ae272c Mon Sep 17 00:00:00 2001 From: Sergei Shudler Date: Tue, 19 Jul 2022 16:13:48 +0300 Subject: [PATCH] Optimized sample generation in Sobol sequence code --- src/luxrays/accelerators/embreeaccel.cpp | 6 ++++++ src/slg/engines/pathcpu/pathcputhread.cpp | 6 ++++++ src/slg/samplers/sobolsequence.cpp | 14 ++++++++++---- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/src/luxrays/accelerators/embreeaccel.cpp b/src/luxrays/accelerators/embreeaccel.cpp index 7e6bf39e1..34cc9f37f 100644 --- a/src/luxrays/accelerators/embreeaccel.cpp +++ b/src/luxrays/accelerators/embreeaccel.cpp @@ -34,6 +34,12 @@ namespace luxrays { EmbreeAccel::EmbreeAccel(const Context *context) : ctx(context), uniqueRTCSceneByMesh(MeshPtrCompare), uniqueGeomByMesh(MeshPtrCompare), uniqueInstMatrixByMesh(MeshPtrCompare) { +#if defined (_MSC_VER) || defined (__INTEL_COMPILER) + // Embree recommends settings these flags to improve performance + _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); + _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); +#endif + embreeDevice = rtcNewDevice(NULL); embreeScene = NULL; } diff --git a/src/slg/engines/pathcpu/pathcputhread.cpp b/src/slg/engines/pathcpu/pathcputhread.cpp index 814741046..89682bac7 100644 --- a/src/slg/engines/pathcpu/pathcputhread.cpp +++ b/src/slg/engines/pathcpu/pathcputhread.cpp @@ -37,6 +37,12 @@ PathCPURenderThread::PathCPURenderThread(PathCPURenderEngine *engine, } void PathCPURenderThread::RenderFunc() { +#if defined (_MSC_VER) || defined (__INTEL_COMPILER) + // Embree recommends settings these flags in each thread to improve performance + _MM_SET_FLUSH_ZERO_MODE(_MM_FLUSH_ZERO_ON); + _MM_SET_DENORMALS_ZERO_MODE(_MM_DENORMALS_ZERO_ON); +#endif + //SLG_LOG("[PathCPURenderEngine::" << threadIndex << "] Rendering thread started"); //-------------------------------------------------------------------------- diff --git a/src/slg/samplers/sobolsequence.cpp b/src/slg/samplers/sobolsequence.cpp index f1f28a798..cb6e3626e 100644 --- a/src/slg/samplers/sobolsequence.cpp +++ b/src/slg/samplers/sobolsequence.cpp @@ -44,13 +44,19 @@ void SobolSequence::RequestSamples(const u_int size) { } u_int SobolSequence::SobolDimension(const u_int index, const u_int dimension) const { - const u_int offset = dimension * SOBOL_BITS; + u_int offset = dimension * SOBOL_BITS; u_int result = 0; u_int i = index; - for (u_int j = 0; i; i >>= 1, j++) { - if (i & 1) - result ^= directions[offset + j]; + while (i) { + result ^= ((i & 1) * directions[offset]); + i >>= 1; offset++; + result ^= ((i & 1) * directions[offset]); + i >>= 1; offset++; + result ^= ((i & 1) * directions[offset]); + i >>= 1; offset++; + result ^= ((i & 1) * directions[offset]); + i >>= 1; offset++; } return result;