Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimized sample generation in Sobol sequence code #593

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/luxrays/accelerators/embreeaccel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions src/slg/engines/pathcpu/pathcputhread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");

//--------------------------------------------------------------------------
Expand Down
14 changes: 10 additions & 4 deletions src/slg/samplers/sobolsequence.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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++;
Comment on lines +52 to +59

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is no longer a bounds check on i for 3 of the 4 indexes into directions before the loop repeats, how do you ensure the offset is always a valid index?

Copy link
Author

@sshudler sshudler Oct 18, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Before the change and after the change i wasn't used as an index into directions. Whenever the loop was hitting a 1 bit in i it would index into directions by that bit's offset. The way directions defined, starting from the offset it has SOBOL_BITS range for access, so in the new code the access to directions is valid and when i becomes 0 none of these directions values will be used in the result because of & with (0 & 1). Also, SOBOL_BITS == sizeof(i).

}

return result;
Expand Down