Skip to content

Commit

Permalink
Arnold Renderer : Avoid mutex lock in ProceduralRenderer
Browse files Browse the repository at this point in the history
This knocks around 30% off the runtime of `ArnoldRenderTest.testInstancerEncapsulatePerf` in PR GafferHQ#5453, testing with 64 threads.
  • Loading branch information
johnhaddon committed Oct 26, 2023
1 parent cacbae1 commit 7fdca52
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 15 deletions.
1 change: 1 addition & 0 deletions Changes.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ Improvements
------------

- LightTool : Changed spot light and quad light edge tool tip locations so that they follow the cone and edge during drag.
- Arnold : Improved speed of translation of encapsulated scenes when using many threads.

Fixes
-----
Expand Down
29 changes: 14 additions & 15 deletions src/IECoreArnold/Renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@

#include "tbb/concurrent_unordered_map.h"
#include "tbb/concurrent_vector.h"
#include "tbb/enumerable_thread_specific.h"
#include "tbb/partitioner.h"
#include "tbb/spin_mutex.h"

Expand Down Expand Up @@ -2964,9 +2965,9 @@ class ProceduralRenderer final : public ArnoldRendererBase
ArnoldRendererBase::light( name, object, attributes )
);

NodesCreatedMutex::scoped_lock lock( m_nodesCreatedMutex );
result->instance().nodesCreated( m_nodesCreated );
result->nodesCreated( m_nodesCreated );
auto &nodesCreatedLocal = m_nodesCreated.local();
result->instance().nodesCreated( nodesCreatedLocal );
result->nodesCreated( nodesCreatedLocal );
return result;
}

Expand All @@ -2976,9 +2977,9 @@ class ProceduralRenderer final : public ArnoldRendererBase
ArnoldRendererBase::lightFilter( name, object, attributes )
);

NodesCreatedMutex::scoped_lock lock( m_nodesCreatedMutex );
result->instance().nodesCreated( m_nodesCreated );
result->nodesCreated( m_nodesCreated );
auto &nodesCreatedLocal = m_nodesCreated.local();
result->instance().nodesCreated( nodesCreatedLocal );
result->nodesCreated( nodesCreatedLocal );
return result;
}

Expand All @@ -2988,8 +2989,7 @@ class ProceduralRenderer final : public ArnoldRendererBase
ArnoldRendererBase::object( name, object, attributes )
);

NodesCreatedMutex::scoped_lock lock( m_nodesCreatedMutex );
result->instance().nodesCreated( m_nodesCreated );
result->instance().nodesCreated( m_nodesCreated.local() );
return result;
}

Expand All @@ -2999,8 +2999,7 @@ class ProceduralRenderer final : public ArnoldRendererBase
ArnoldRendererBase::object( name, samples, times, attributes )
);

NodesCreatedMutex::scoped_lock lock( m_nodesCreatedMutex );
result->instance().nodesCreated( m_nodesCreated );
result->instance().nodesCreated( m_nodesCreated.local() );
return result;
}

Expand All @@ -3016,18 +3015,18 @@ class ProceduralRenderer final : public ArnoldRendererBase

void nodesCreated( vector<AtNode *> &nodes )
{
nodes.insert( nodes.begin(), m_nodesCreated.begin(), m_nodesCreated.end() );
for( auto &nodesCreated : m_nodesCreated )
{
nodes.insert( nodes.end(), nodesCreated.begin(), nodesCreated.end() );
}
m_instanceCache->nodesCreated( nodes );
m_shaderCache->nodesCreated( nodes );
}

private :

IECore::ConstCompoundObjectPtr m_attributesToInherit;

using NodesCreatedMutex = tbb::spin_mutex;
NodesCreatedMutex m_nodesCreatedMutex;
vector<AtNode *> m_nodesCreated;
tbb::enumerable_thread_specific<vector<AtNode *>> m_nodesCreated;

};

Expand Down

0 comments on commit 7fdca52

Please sign in to comment.