Skip to content

Commit

Permalink
[hdEmbree] ensure we respect PXR_WORK_THREAD_LIMIT
Browse files Browse the repository at this point in the history
  • Loading branch information
pmolodo committed Oct 19, 2024
1 parent 6a4f145 commit fbdd452
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions pxr/imaging/plugin/hdEmbree/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,43 @@

#include "pxr/base/tf/hash.h"

#include <tbb/tbb_stddef.h>
#if TBB_INTERFACE_VERSION_MAJOR < 12
#include <tbb/task_scheduler_init.h>
#endif

#include <chrono>
#include <memory>
#include <thread>

namespace {

PXR_NAMESPACE_USING_DIRECTIVE

// -------------------------------------------------------------------------
// Old TBB workaround - can remove once OneTBB is mandatory
// -------------------------------------------------------------------------

#if TBB_INTERFACE_VERSION_MAJOR < 12
// Make the calling context respect PXR_WORK_THREAD_LIMIT, if run from a thread
// other than the main thread (ie, the renderThread)
class _ScopedThreadScheduler {
public:
_ScopedThreadScheduler() {
auto limit = WorkGetConcurrencyLimitEnvSetting();
if (limit != 0) {
_tbbTaskSchedInit =
std::make_unique<tbb::task_scheduler_init>(limit);
}
}

std::unique_ptr<tbb::task_scheduler_init> _tbbTaskSchedInit;
};
#else
class _ScopedThreadScheduler {
};
#endif

// -------------------------------------------------------------------------
// General Ray Utilities
// -------------------------------------------------------------------------
Expand Down Expand Up @@ -453,6 +483,7 @@ HdEmbreeRenderer::Render(HdRenderThread *renderThread)

// Render by scheduling square tiles of the sample buffer in a parallel
// for loop.
_ScopedThreadScheduler scheduler;
// Always pass the renderThread to _RenderTiles to allow the first frame
// to be interrupted.
WorkParallelForN(numTilesX*numTilesY,
Expand Down

0 comments on commit fbdd452

Please sign in to comment.