FIRE-34600 - minimise the change by using default operators

we're never realistically gonna mess with the memory order to optimise particles so just go with the easy option
master
Beq 2024-10-07 20:37:09 +01:00
parent 73aacfe2e0
commit 962214a90c
2 changed files with 25 additions and 81 deletions

View File

@ -82,7 +82,7 @@ LLViewerPart::LLViewerPart() :
mPartSourcep = NULL;
mParent = NULL;
mChild = NULL;
LLViewerPartSim::incParticleCount2( 1 ); // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
++LLViewerPartSim::sParticleCount2 ;
}
LLViewerPart::~LLViewerPart()
@ -107,7 +107,7 @@ LLViewerPart::~LLViewerPart()
mPartSourcep = NULL;
LLViewerPartSim::decParticleCount2( 1 ); // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
--LLViewerPartSim::sParticleCount2 ;
}
void LLViewerPart::init(LLPointer<LLViewerPartSource> sourcep, LLViewerTexture *imagep, LLVPCallback cb)
@ -205,7 +205,7 @@ LLViewerPartGroup::~LLViewerPartGroup()
}
mParticles.clear();
LLViewerPartSim::decParticleCount(count); // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
LLViewerPartSim::sParticleCount -= count; // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
}
void LLViewerPartGroup::cleanup()
@ -268,7 +268,7 @@ bool LLViewerPartGroup::addPart(LLViewerPart* part, F32 desired_size)
mParticles.push_back(part);
part->mSkipOffset=mSkippedTime;
LLViewerPartSim::incParticleCount(1); // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
++LLViewerPartSim::sParticleCount; // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
return true;
}
@ -279,15 +279,11 @@ void LLViewerPartGroup::updateParticles(const F32 lastdt)
LLVector3 gravity(0.f, 0.f, GRAVITY);
// <FS:Beq> FIRE-34600 off by one particle count triggering bugsplat (LL_ERR)
S32 end = (S32) mParticles.size();
LLViewerPartSim::checkParticleCount(static_cast<U32>(mParticles.size()));
std::atomic_signal_fence(std::memory_order_seq_cst);
// </FS:Beq>
LLViewerCamera* camera = LLViewerCamera::getInstance();
LLViewerRegion *regionp = getRegion();
//S32 end = (S32) mParticles.size();// <FS:Beq> FIRE-34600 off by one particle count triggering bugsplat (LL_ERR)
S32 end = (S32) mParticles.size();
for (S32 i = 0 ; i < (S32)mParticles.size();)
{
LLVector3 a(0.f, 0.f, 0.f);
@ -432,7 +428,7 @@ void LLViewerPartGroup::updateParticles(const F32 lastdt)
{
gPipeline.markRebuild(mVOPartGroupp->mDrawable, LLDrawable::REBUILD_ALL);
}
LLViewerPartSim::decParticleCount(removed); // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
LLViewerPartSim::sParticleCount -= removed; // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
}
// Kill the viewer object if this particle group is empty
@ -478,22 +474,14 @@ void LLViewerPartGroup::removeParticlesByID(const U32 source_id)
//static
void LLViewerPartSim::checkParticleCount(U32 size)
{
// <FS:Beq> FIRE-34600 - bugsplat AVX2 particle count mismatch
// if(LLViewerPartSim::sParticleCount2 != LLViewerPartSim::sParticleCount)
S32 count = LLViewerPartSim::getParticleCount();
S32 count2 = LLViewerPartSim::getParticleCount2();
if( count != count2 )
// <FS:Beq/>
if(LLViewerPartSim::sParticleCount2 != LLViewerPartSim::sParticleCount)
{
LL_ERRS() << "sParticleCount: " << count << " ; sParticleCount2: " << count2 << LL_ENDL ; //<FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
LL_ERRS() << "sParticleCount: " << LLViewerPartSim::sParticleCount << " ; sParticleCount2: " << LLViewerPartSim::sParticleCount2 << LL_ENDL ;
}
// <FS:Beq> FIRE-34600 - bugsplat AVX2 particle count mismatch
// if(size > (U32)LLViewerPartSim::sParticleCount2)
if( size > static_cast<U32>(count2) )
// <FS:Beq/>
if(size > (U32)LLViewerPartSim::sParticleCount2)
{
LL_ERRS() << "current particle size: " << count2 << " array size: " << size << LL_ENDL ; // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
LL_ERRS() << "current particle size: " << LLViewerPartSim::sParticleCount2 << " array size: " << size << LL_ENDL ; // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
}
}
@ -539,18 +527,14 @@ void LLViewerPartSim::destroyClass()
//static
bool LLViewerPartSim::shouldAddPart()
{
// <FS:Beq> FIRE-34600 - bugsplat AVX2 particle count mismatch
// if (sParticleCount < MAX_PART_COUNT)
auto count = LLViewerPartSim::getParticleCount();
if ( count >= MAX_PART_COUNT)
// <FS:Beq/>
if (sParticleCount < MAX_PART_COUNT)
{
return false;
}
if ( count > PART_THROTTLE_THRESHOLD*sMaxParticleCount) // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
if ( sParticleCount > PART_THROTTLE_THRESHOLD*sMaxParticleCount)
{
F32 frac = (F32)count/(F32)sMaxParticleCount; // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
F32 frac = (F32)sParticleCount/(F32)sMaxParticleCount;
frac -= PART_THROTTLE_THRESHOLD;
frac *= PART_THROTTLE_RESCALE;
if (ll_frand() < frac)
@ -572,7 +556,7 @@ bool LLViewerPartSim::shouldAddPart()
void LLViewerPartSim::addPart(LLViewerPart* part)
{
if (LLViewerPartSim::getParticleCount() < MAX_PART_COUNT)
if (LLViewerPartSim::sParticleCount < MAX_PART_COUNT)
{
put(part);
}
@ -806,19 +790,14 @@ void LLViewerPartSim::updateSimulation()
}
if (LLDrawable::getCurrentFrame()%16==0)
{
// <FS:Beq> FIRE-34600 - bugsplat AVX2 particle count mismatch
// if (sParticleCount > sMaxParticleCount * 0.875f
// && sParticleAdaptiveRate < 2.0f)
auto count = LLViewerPartSim::getParticleCount();
if ( count > sMaxParticleCount * 0.875f
&& sParticleAdaptiveRate < 2.0f)
// <FS:Beq/>
if (sParticleCount > sMaxParticleCount * 0.875f
&& sParticleAdaptiveRate < 2.0f)
{
sParticleAdaptiveRate *= PART_ADAPT_RATE_MULT;
}
else
{
if ( count < sMaxParticleCount * 0.5f // <FS:Beq/> FIRE-34600 - bugsplat AVX2 particle count mismatch
if ( sParticleCount < sMaxParticleCount * 0.5f
&& sParticleAdaptiveRate > 0.03125f)
{
sParticleAdaptiveRate *= PART_ADAPT_RATE_MULT_RECIP;
@ -835,25 +814,15 @@ void LLViewerPartSim::updatePartBurstRate()
{
if (!(LLDrawable::getCurrentFrame() & 0xf))
{
// <FS:Beq> FIRE-34600 - bugsplat AVX2 particle count mismatch
// if (sParticleCount >= MAX_PART_COUNT) //set rate to zero
auto count = LLViewerPartSim::getParticleCount();
if (count >= MAX_PART_COUNT) //set rate to zero
// <FS:Beq/>
if (sParticleCount >= MAX_PART_COUNT) //set rate to zero
{
sParticleBurstRate = 0.0f ;
}
// <FS:Beq> FIRE-34600 - bugsplat AVX2 particle count mismatch
// else if(sParticleCount > 0)
else if (count > 0)
// <FS:Beq/>
else if(sParticleCount > 0)
{
if(sParticleBurstRate > 0.0000001f)
{
// <FS:Beq> FIRE-34600 - bugsplat AVX2 particle count mismatch
// F32 total_particles = sParticleCount / sParticleBurstRate ; //estimated
F32 total_particles = count / sParticleBurstRate ; //estimated
// <FS:Beq/>
F32 total_particles = sParticleCount / sParticleBurstRate ; //estimated
F32 new_rate = llclamp(0.9f * sMaxParticleCount / total_particles, 0.0f, 1.0f) ;
F32 delta_rate_threshold = llmin(0.1f * llmax(new_rate, sParticleBurstRate), 0.1f) ;
F32 delta_rate = llclamp(new_rate - sParticleBurstRate, -1.0f * delta_rate_threshold, delta_rate_threshold) ;

View File

@ -155,25 +155,14 @@ public:
static bool shouldAddPart(); // Just decides whether this particle should be added or not (for particle count capping)
F32 maxRate() // Return maximum particle generation rate
{
// <FS:Beq> FIRE-34600 - bugsplat AVX2 particle count mismatch
// if (sParticleCount >= MAX_PART_COUNT)
// {
// return 1.f;
// }
// if (sParticleCount > PART_THROTTLE_THRESHOLD*sMaxParticleCount)
// {
// return (((F32)sParticleCount/(F32)sMaxParticleCount)-PART_THROTTLE_THRESHOLD)*PART_THROTTLE_RESCALE;
// }
const auto count = getParticleCount();
if ( count >= MAX_PART_COUNT)
if (sParticleCount >= MAX_PART_COUNT)
{
return 1.f;
}
if ( count > PART_THROTTLE_THRESHOLD*sMaxParticleCount)
if (sParticleCount > PART_THROTTLE_THRESHOLD*sMaxParticleCount)
{
return (((F32)count/(F32)sMaxParticleCount)-PART_THROTTLE_THRESHOLD)*PART_THROTTLE_RESCALE;
return (((F32)sParticleCount/(F32)sMaxParticleCount)-PART_THROTTLE_THRESHOLD)*PART_THROTTLE_RESCALE;
}
// </FS:Beq>
return 0.f;
}
F32 getRefRate() { return sParticleAdaptiveRate; }
@ -188,29 +177,15 @@ public:
friend class LLViewerPartGroup;
// <FS:Beq> FIRE-34600 - bugsplat AVX2 particle count mismatch
// bool aboveParticleLimit() const { return sParticleCount > sMaxParticleCount; }
bool aboveParticleLimit() const { return getParticleCount() > sMaxParticleCount; }
// </FS:Beq>
bool aboveParticleLimit() const { return sParticleCount > sMaxParticleCount; }
static void setMaxPartCount(const S32 max_parts) { sMaxParticleCount = max_parts; }
static S32 getMaxPartCount() { return sMaxParticleCount; }
// <FS:Beq> FIRE-34600 - bugsplat AVX2 particle count mismatch
// Deprecate these and use native operators for consistency
// static void incPartCount(const S32 count) { sParticleCount += count; }
// static void decPartCount(const S32 count) { sParticleCount -= count; }
static void incParticleCount(const S32 count, std::memory_order order = std::memory_order_seq_cst )
{ sParticleCount.fetch_add( count , std::memory_order_seq_cst ); }
static void decParticleCount(const S32 count, std::memory_order order = std::memory_order_seq_cst )
{ sParticleCount.fetch_sub( count , std::memory_order_seq_cst ); }
static void incParticleCount2(const S32 count, std::memory_order order = std::memory_order_seq_cst )
{ sParticleCount2.fetch_add( count , std::memory_order_seq_cst ); }
static void decParticleCount2(const S32 count, std::memory_order order = std::memory_order_seq_cst )
{ sParticleCount2.fetch_sub( count , std::memory_order_seq_cst ); }
static inline S32 getParticleCount(std::memory_order order = std::memory_order_seq_cst) { return sParticleCount.load(order); }
static inline S32 getParticleCount2(std::memory_order order = std::memory_order_seq_cst) { return sParticleCount2.load(order); }
// </FS:Beq>
U32 mID;
protected: