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

Arnold Renderer : Avoid mutex lock in ProceduralRenderer #5513

Merged
merged 1 commit into from
Nov 1, 2023
Merged
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
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( const 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
Loading