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

Switch from deprecated tbb::atomic to std::atomic #7

Open
wants to merge 1 commit into
base: release
Choose a base branch
from
Open
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
8 changes: 3 additions & 5 deletions lib/rendering/geom/Procedural.cc
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
#include <moonray/rendering/geom/PrimitiveGroup.h>
#include <moonray/rendering/geom/PrimitiveVisitor.h>

#include <tbb/atomic.h>

#include <numeric>

namespace moonray {
Expand All @@ -25,7 +23,7 @@ class PrimitiveMemoryAccumulator : public PrimitiveVisitor
{
public:
PrimitiveMemoryAccumulator(
tbb::atomic<Primitive::size_type>& usage,
std::atomic<Primitive::size_type>& usage,
SharedPrimitiveSet& sharedPrimitives,
bool inPrimitiveGroup = false) :
mUsage(usage), mSharedPrimitives(sharedPrimitives),
Expand Down Expand Up @@ -63,7 +61,7 @@ class PrimitiveMemoryAccumulator : public PrimitiveVisitor
}

private:
tbb::atomic<Primitive::size_type>& mUsage;
std::atomic<Primitive::size_type>& mUsage;
SharedPrimitiveSet& mSharedPrimitives;
bool mInPrimitiveGroup;
};
Expand Down Expand Up @@ -123,7 +121,7 @@ class StatisticsAccumulator : public PrimitiveVisitor
Procedural::size_type
Procedural::getMemory()
{
tbb::atomic<Primitive::size_type> usage {0u};
std::atomic<Primitive::size_type> usage {0u};
SharedPrimitiveSet sharedPrimitives;
PrimitiveMemoryAccumulator accumulator(usage, sharedPrimitives);
forEachPrimitive(accumulator);
Expand Down
17 changes: 12 additions & 5 deletions lib/rendering/geom/Procedural.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,18 @@ struct GeometryStatistics {
GeometryStatistics(): mFaceCount {0}, mMeshVertexCount {0},
mCurvesCount {0}, mCVCount {0}, mInstanceCount {0} {}

tbb::atomic<Primitive::size_type> mFaceCount;
tbb::atomic<Primitive::size_type> mMeshVertexCount;
tbb::atomic<Primitive::size_type> mCurvesCount;
tbb::atomic<Primitive::size_type> mCVCount;
tbb::atomic<Primitive::size_type> mInstanceCount;
GeometryStatistics(const GeometryStatistics &other):
mFaceCount(other.mFaceCount.load()),
mMeshVertexCount(other.mMeshVertexCount.load()),
mCurvesCount(other.mCurvesCount.load()),
mCVCount(other.mCVCount.load()),
mInstanceCount(other.mInstanceCount.load()) {}

std::atomic<Primitive::size_type> mFaceCount;
std::atomic<Primitive::size_type> mMeshVertexCount;
std::atomic<Primitive::size_type> mCurvesCount;
std::atomic<Primitive::size_type> mCVCount;
std::atomic<Primitive::size_type> mInstanceCount;
};

//----------------------------------------------------------------------------
Expand Down
6 changes: 3 additions & 3 deletions lib/rendering/mcrt_common/Bundle.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ class LocalQueue
return unsigned(entriesToFlush);
}

tbb::atomic<uint32_t> mQueueSize; // must not exceed mMaxEntries
std::atomic<uint32_t> mQueueSize; // must not exceed mMaxEntries
uint32_t mMaxEntries;
EntryType * mEntries; // all data offsets are relative to this address
Handler mHandler;
Expand Down Expand Up @@ -502,7 +502,7 @@ class LocalLargeEntryQueue
return unsigned(entriesToFlush);
}

tbb::atomic<uint32_t> mQueueSize; // must not exceed mMaxEntries
std::atomic<uint32_t> mQueueSize; // must not exceed mMaxEntries
uint32_t mMaxEntries;
EntryType * mEntries; // all data offsets are relative to this address
Handler mHandler;
Expand Down Expand Up @@ -788,7 +788,7 @@ class CACHE_ALIGN SharedQueue
return unsigned(entriesToFlush);
}

tbb::atomic<uint32_t> mQueueSize; // must not exceed mMaxEntries
std::atomic<uint32_t> mQueueSize; // must not exceed mMaxEntries
uint32_t mMaxEntries;
EntryType * mEntries; // all data offsets are relative to this address
Handler mHandler;
Expand Down
4 changes: 2 additions & 2 deletions lib/rendering/mcrt_common/ThreadLocalState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,15 @@ namespace
{

// Counter to hand out unique indices to TLSProxy objects.
tbb::atomic<unsigned> gNextFrameUpdateTLSIndex;
std::atomic<unsigned> gNextFrameUpdateTLSIndex;

// These are lightweight objects which we put into a tbb::enumerable_thread_specific
// container so that we can map OS thread ids to consistent top level ThreadLocalState
// objects. We have one type for frame updates, and a second type for rendering.
struct FrameUpdateTLSProxy
{
FrameUpdateTLSProxy() :
mTLSIndex(gNextFrameUpdateTLSIndex.fetch_and_increment())
mTLSIndex(gNextFrameUpdateTLSIndex++)
{
}

Expand Down
1 change: 0 additions & 1 deletion lib/rendering/pbr/Types.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include <scene_rdl2/common/math/Vec3.h>
#include <scene_rdl2/common/math/Vec4.h>

#include <tbb/atomic.h>
#include <vector>


Expand Down
6 changes: 3 additions & 3 deletions lib/rendering/pbr/Types.hh
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ enum OcclTestType


#define DEEP_DATA_MEMBERS \
HUD_CPP_MEMBER(tbb::atomic<int>, mRefCount, 4); \
HUD_CPP_MEMBER(std::atomic<int>, mRefCount, 4); \
HUD_MEMBER(uint32_t, mHitDeep); \
HUD_MEMBER(float, mSubpixelX); \
HUD_MEMBER(float, mSubpixelY); \
Expand All @@ -182,7 +182,7 @@ enum OcclTestType


#define CRYPTOMATTE_DATA_MEMBERS \
HUD_CPP_MEMBER(tbb::atomic<int>, mRefCount, 4); \
HUD_CPP_MEMBER(std::atomic<int>, mRefCount, 4); \
HUD_CPP_PTR(pbr::CryptomatteBuffer*, mCryptomatteBuffer); \
HUD_MEMBER(uint32_t, mHit); \
HUD_MEMBER(uint32_t, mPrevPresence); \
Expand Down Expand Up @@ -211,7 +211,7 @@ enum OcclTestType
// bytes in size due to them being allocated as one cache line.

#define CRYPTOMATTE_DATA_MEMBERS_2 \
HUD_CPP_MEMBER(tbb::atomic<int>, mRefCount, 4); \
HUD_CPP_MEMBER(std::atomic<int>, mRefCount, 4); \
HUD_MEMBER(HVD_NAMESPACE(scene_rdl2::math, Vec3f), mRefP); \
HUD_MEMBER(HVD_NAMESPACE(scene_rdl2::math, Vec3f), mRefN); \
HUD_MEMBER(HVD_NAMESPACE(scene_rdl2::math, Vec2f), mUV)
Expand Down
6 changes: 3 additions & 3 deletions lib/rendering/pbr/core/PbrTLState.cc
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ MNRY_STATIC_ASSERT(ALLOC_LIST_MAX_NUM_ITEMS <=
((ALLOC_LIST_INFO_BITS >> ALLOC_LIST_INFO_BIT_SHIFT) + 1));

// Per frame counter, gets reset each frame.
CACHE_ALIGN tbb::atomic<unsigned> gFailedRayStateAllocs;
CACHE_ALIGN tbb::atomic<unsigned> gFailedCL1Allocs;
CACHE_ALIGN std::atomic<unsigned> gFailedRayStateAllocs;
CACHE_ALIGN std::atomic<unsigned> gFailedCL1Allocs;

// For memory profiling, see DEBUG_RECORD_PEAK_RAYSTATE_USAGE.
unsigned MAYBE_UNUSED gPeakRayStateUsage = 0;
Expand Down Expand Up @@ -416,7 +416,7 @@ TLState::poolAlloc(const char * const typeName,
unsigned numEntries,
ResType **entries,
OverlappedAccType accumStall,
tbb::atomic<unsigned> &numFailedAllocs)
std::atomic<unsigned> &numFailedAllocs)
{
// 99.9999% case, allocation should succeed.
bool success = pool.allocList(numEntries, entries);
Expand Down
2 changes: 1 addition & 1 deletion lib/rendering/pbr/core/PbrTLState.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ class CACHE_ALIGN TLState : public mcrt_common::BaseTLState
unsigned numEntries,
ResType **entries,
OverlappedAccType accumStall,
tbb::atomic<unsigned> &numFailedAlloc);
std::atomic<unsigned> &numFailedAlloc);

DISALLOW_COPY_OR_ASSIGNMENT(TLState);
};
Expand Down
4 changes: 2 additions & 2 deletions lib/rendering/rndr/RenderFramePasses.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ RenderDriver::renderPasses(RenderDriver *driver, const FrameState &fs,

// This counter verifies that we don't leave this function until all threads
// have started working.
CACHE_ALIGN tbb::atomic<unsigned> numTBBThreads;
CACHE_ALIGN tbb::atomic<bool> canceled;
CACHE_ALIGN std::atomic<unsigned> numTBBThreads;
CACHE_ALIGN std::atomic<bool> canceled;

numTBBThreads = 0;
canceled = false;
Expand Down
20 changes: 10 additions & 10 deletions lib/rendering/rndr/RenderStatistics.cc
Original file line number Diff line number Diff line change
Expand Up @@ -963,24 +963,24 @@ RenderStats::logGeometryUsage(const geom::GeometryStatistics& totalGeomStatistic

for(std::size_t i = 0; i < geomStateInfo.size(); ++i) {
geomTable.emplace_back(geomStateInfo[i].first,
geomStateInfo[i].second.mFaceCount,
geomStateInfo[i].second.mMeshVertexCount,
geomStateInfo[i].second.mCurvesCount,
geomStateInfo[i].second.mCVCount,
geomStateInfo[i].second.mInstanceCount);
geomStateInfo[i].second.mFaceCount.load(),
geomStateInfo[i].second.mMeshVertexCount.load(),
geomStateInfo[i].second.mCurvesCount.load(),
geomStateInfo[i].second.mCVCount.load(),
geomStateInfo[i].second.mInstanceCount.load());
}

StatsTable<2> summaryTable("Geometry Statistics Summary");
summaryTable.emplace_back("Total Face Count",
totalGeomStatistics.mFaceCount);
totalGeomStatistics.mFaceCount.load());
summaryTable.emplace_back("Total Mesh Vertex Count",
totalGeomStatistics.mMeshVertexCount);
totalGeomStatistics.mMeshVertexCount.load());
summaryTable.emplace_back("Total Curves Count",
totalGeomStatistics.mCurvesCount);
totalGeomStatistics.mCurvesCount.load());
summaryTable.emplace_back("Total Curves CV Count",
totalGeomStatistics.mCVCount);
totalGeomStatistics.mCVCount.load());
summaryTable.emplace_back("Total Instance Count",
totalGeomStatistics.mInstanceCount);
totalGeomStatistics.mInstanceCount.load());

auto writeCSV = [&](std::ostream& outs, bool athenaFormat) {
outs.precision(2);
Expand Down
2 changes: 1 addition & 1 deletion lib/rendering/rt/EmbreeAccelerator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ namespace rt {


typedef tbb::concurrent_unordered_map<std::shared_ptr<geom::SharedPrimitive>,
tbb::atomic<bool>, geom::SharedPtrHash> SharedSceneMap;
std::atomic<bool>, geom::SharedPtrHash> SharedSceneMap;


class BVHBuilder : public geom::PrimitiveVisitor
Expand Down
4 changes: 2 additions & 2 deletions lib/rendering/rt/GeometryManager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1361,7 +1361,7 @@ GeometryManager::getEmissiveRegions(const scene_rdl2::rdl2::Layer* layer,
}

// Counter to provide unique thread ids
tbb::atomic<unsigned> gThreadIdCounter;
std::atomic<unsigned> gThreadIdCounter;

GeometryManager::GM_RESULT
GeometryManager::tessellate(scene_rdl2::rdl2::Layer* layer,
Expand Down Expand Up @@ -1396,7 +1396,7 @@ GeometryManager::tessellate(scene_rdl2::rdl2::Layer* layer,
struct ThreadID {
// When we create a ThreadID, the counter increments and so
// each thread gets a unique human readable id.
ThreadID() : mId(gThreadIdCounter.fetch_and_increment()){}
ThreadID() : mId(gThreadIdCounter++){}
unsigned mId;
};
typedef tbb::enumerable_thread_specific< ThreadID > EnumerableThreadID;
Expand Down
6 changes: 3 additions & 3 deletions lib/rendering/rt/GeometryManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace rt {

enum class ChangeFlag;

typedef tbb::concurrent_unordered_map<geom::internal::Primitive *, tbb::atomic<unsigned int>> PrimitiveReferenceCountMap;
typedef tbb::concurrent_unordered_map<geom::internal::Primitive *, std::atomic<unsigned int>> PrimitiveReferenceCountMap;

struct GeometryManagerStats
{
Expand Down Expand Up @@ -187,7 +187,7 @@ class GeometryManager

finline void compareAndSwapFlag(ChangeFlag swapFlag, ChangeFlag compareFlag)
{
mChangeStatus.compare_and_swap(swapFlag, compareFlag);
mChangeStatus.compare_exchange_strong(swapFlag, compareFlag);
}

void updateGPUAccelerator(const scene_rdl2::rdl2::Layer* layer);
Expand Down Expand Up @@ -255,7 +255,7 @@ class GeometryManager

GeometryManagerOptions mOptions;

typedef tbb::atomic<ChangeFlag> ChangeFlagAtomic;
typedef std::atomic<ChangeFlag> ChangeFlagAtomic;

/// Tracks current change status
ChangeFlagAtomic mChangeStatus;
Expand Down
2 changes: 1 addition & 1 deletion lib/rendering/rt/gpu/GPUAcceleratorImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ namespace rt {

// Also in EmbreeAccelerator.cc
typedef tbb::concurrent_unordered_map<std::shared_ptr<geom::SharedPrimitive>,
tbb::atomic<GPUPrimitiveGroup*>, geom::SharedPtrHash> SharedGroupMap;
std::atomic<GPUPrimitiveGroup*>, geom::SharedPtrHash> SharedGroupMap;


class GPUAcceleratorImpl
Expand Down
6 changes: 3 additions & 3 deletions lib/rendering/shading/Material.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ MaterialPtrList Material::sQueuelessMaterials;
tbb::mutex Material::sShadeQueueMutex;
ShadeQueueList Material::sShadeQueues;

tbb::atomic<size_t> Material::sFlushCycleIdx;
std::atomic<size_t> Material::sFlushCycleIdx;

tbb::atomic<uint32_t> Material::sDeferredEntryCalls;
tbb::atomic<uint32_t> Material::sTotalDeferredEntries;
std::atomic<uint32_t> Material::sDeferredEntryCalls;
std::atomic<uint32_t> Material::sTotalDeferredEntries;

Material::Material(const scene_rdl2::rdl2::SceneObject & owner) :
RootShader(owner),
Expand Down
6 changes: 3 additions & 3 deletions lib/rendering/shading/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -180,11 +180,11 @@ class Material : public RootShader
// This is used by the flushNonEmptyShadeQueue function to iterate through all queues
// in a cyclic fashion as opposed to starting the iteration at the beginning of the
// queue list each time.
static tbb::atomic<size_t> sFlushCycleIdx;
static std::atomic<size_t> sFlushCycleIdx;

// Shared between all Materials.
static tbb::atomic<uint32_t> sDeferredEntryCalls;
static tbb::atomic<uint32_t> sTotalDeferredEntries;
static std::atomic<uint32_t> sDeferredEntryCalls;
static std::atomic<uint32_t> sTotalDeferredEntries;
};

template <typename Body>
Expand Down
20 changes: 10 additions & 10 deletions tests/lib/rendering/pbr/TestLights.cc
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,7 @@ testLightPDF(const Vec3f &p, const Vec3f &n, const LightTester *lightTester,
// compute ref pdfs (only for unit test debugging)
//

tbb::atomic<unsigned> refValidSampleCount;
std::atomic<unsigned> refValidSampleCount;
refValidSampleCount = 0;

double refPdf = doReductionOverUnitSquare<double>(0.0,
Expand Down Expand Up @@ -326,7 +326,7 @@ testLightPDF(const Vec3f &p, const Vec3f &n, const LightTester *lightTester,
// compute test pdf
//

tbb::atomic<unsigned> testValidSampleCount;
std::atomic<unsigned> testValidSampleCount;
testValidSampleCount = 0;

double testPdf = doReductionOverUnitSquare<double>(0.0,
Expand Down Expand Up @@ -394,7 +394,7 @@ testLightPDF(const Vec3f &p, const Vec3f &n, const LightTester *lightTester,
// compute test pdf of ISPC light
//

tbb::atomic<unsigned> testIspcValidSampleCount;
std::atomic<unsigned> testIspcValidSampleCount;
testIspcValidSampleCount = 0;

double testIspcPdf = doReductionOverUnitSquare<double>(0.0,
Expand Down Expand Up @@ -525,7 +525,7 @@ testLightCanIlluminate(const Vec3f &, const Vec3f &, const LightTester *lightTes
// Test C++ light implementation
//

tbb::atomic<int32_t> seed;
std::atomic<int32_t> seed;
seed = initialSeed;

tbb::parallel_for(tbb::blocked_range<unsigned>(0, NUM_CAN_ILLUMINATE_TESTS,
Expand Down Expand Up @@ -651,11 +651,11 @@ testLightIntersection(const Vec3f &p, const Vec3f &n, const LightTester *lightTe
// Test C++ implementation
//

tbb::atomic<unsigned> cppIsectsEqual;
std::atomic<unsigned> cppIsectsEqual;
cppIsectsEqual = 0;
tbb::atomic<unsigned> cppNoIntersection;
std::atomic<unsigned> cppNoIntersection;
cppNoIntersection = 0;
tbb::atomic<unsigned> cppInvalidSamples;
std::atomic<unsigned> cppInvalidSamples;
cppInvalidSamples = 0;

tbb::parallel_for (tbb::blocked_range<unsigned>(0u, NUM_SAMPLES_PER_AXIS, GRAINSIZE_PER_AXIS),
Expand Down Expand Up @@ -780,11 +780,11 @@ testLightIntersection(const Vec3f &p, const Vec3f &n, const LightTester *lightTe
// Test ISPC implementation
//

tbb::atomic<unsigned> ispcIsectsEqual;
std::atomic<unsigned> ispcIsectsEqual;
ispcIsectsEqual = 0;
tbb::atomic<unsigned> ispcNoIntersection;
std::atomic<unsigned> ispcNoIntersection;
ispcNoIntersection = 0;
tbb::atomic<unsigned> ispcInvalidSamples;
std::atomic<unsigned> ispcInvalidSamples;
ispcInvalidSamples = 0;

tbb::parallel_for (tbb::blocked_range<unsigned>(0u, NUM_SAMPLES_PER_AXIS, GRAINSIZE_PER_AXIS),
Expand Down