Skip to content

Commit fbdd452

Browse files
committed
[hdEmbree] ensure we respect PXR_WORK_THREAD_LIMIT
1 parent 6a4f145 commit fbdd452

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

pxr/imaging/plugin/hdEmbree/renderer.cpp

+31
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,43 @@
1919

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

22+
#include <tbb/tbb_stddef.h>
23+
#if TBB_INTERFACE_VERSION_MAJOR < 12
24+
#include <tbb/task_scheduler_init.h>
25+
#endif
26+
2227
#include <chrono>
28+
#include <memory>
2329
#include <thread>
2430

2531
namespace {
2632

2733
PXR_NAMESPACE_USING_DIRECTIVE
2834

35+
// -------------------------------------------------------------------------
36+
// Old TBB workaround - can remove once OneTBB is mandatory
37+
// -------------------------------------------------------------------------
38+
39+
#if TBB_INTERFACE_VERSION_MAJOR < 12
40+
// Make the calling context respect PXR_WORK_THREAD_LIMIT, if run from a thread
41+
// other than the main thread (ie, the renderThread)
42+
class _ScopedThreadScheduler {
43+
public:
44+
_ScopedThreadScheduler() {
45+
auto limit = WorkGetConcurrencyLimitEnvSetting();
46+
if (limit != 0) {
47+
_tbbTaskSchedInit =
48+
std::make_unique<tbb::task_scheduler_init>(limit);
49+
}
50+
}
51+
52+
std::unique_ptr<tbb::task_scheduler_init> _tbbTaskSchedInit;
53+
};
54+
#else
55+
class _ScopedThreadScheduler {
56+
};
57+
#endif
58+
2959
// -------------------------------------------------------------------------
3060
// General Ray Utilities
3161
// -------------------------------------------------------------------------
@@ -453,6 +483,7 @@ HdEmbreeRenderer::Render(HdRenderThread *renderThread)
453483

454484
// Render by scheduling square tiles of the sample buffer in a parallel
455485
// for loop.
486+
_ScopedThreadScheduler scheduler;
456487
// Always pass the renderThread to _RenderTiles to allow the first frame
457488
// to be interrupted.
458489
WorkParallelForN(numTilesX*numTilesY,

0 commit comments

Comments
 (0)