|
19 | 19 |
|
20 | 20 | #include "pxr/base/tf/hash.h"
|
21 | 21 |
|
| 22 | +#include <tbb/tbb_stddef.h> |
| 23 | +#if TBB_INTERFACE_VERSION_MAJOR < 12 |
| 24 | +#include <tbb/task_scheduler_init.h> |
| 25 | +#endif |
| 26 | + |
22 | 27 | #include <chrono>
|
| 28 | +#include <memory> |
23 | 29 | #include <thread>
|
24 | 30 |
|
25 | 31 | namespace {
|
26 | 32 |
|
27 | 33 | PXR_NAMESPACE_USING_DIRECTIVE
|
28 | 34 |
|
| 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 | + |
29 | 59 | // -------------------------------------------------------------------------
|
30 | 60 | // General Ray Utilities
|
31 | 61 | // -------------------------------------------------------------------------
|
@@ -453,6 +483,7 @@ HdEmbreeRenderer::Render(HdRenderThread *renderThread)
|
453 | 483 |
|
454 | 484 | // Render by scheduling square tiles of the sample buffer in a parallel
|
455 | 485 | // for loop.
|
| 486 | + _ScopedThreadScheduler scheduler; |
456 | 487 | // Always pass the renderThread to _RenderTiles to allow the first frame
|
457 | 488 | // to be interrupted.
|
458 | 489 | WorkParallelForN(numTilesX*numTilesY,
|
|
0 commit comments