From e3b98c902bd60a0f96c16d859abc4baa859a4dc6 Mon Sep 17 00:00:00 2001 From: Wojtek Figat Date: Mon, 30 Aug 2021 20:30:52 +0200 Subject: [PATCH] Optimize CPU particles impl parts --- .../CPU/ParticleEmitterGraph.CPU.ParticleModules.cpp | 6 ++++-- .../Graph/CPU/ParticleEmitterGraph.CPU.Particles.cpp | 2 +- .../Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp | 8 ++++---- .../Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.h | 3 ++- 4 files changed, 11 insertions(+), 8 deletions(-) diff --git a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.ParticleModules.cpp b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.ParticleModules.cpp index 24a584852..de06e6435 100644 --- a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.ParticleModules.cpp +++ b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.ParticleModules.cpp @@ -610,10 +610,11 @@ void ParticleEmitterGraphCPUExecutor::ProcessModule(ParticleEmitterGraphCPUNode* ValueType type(GetVariantType(attribute.ValueType)); if (node->UsePerParticleDataResolve()) { + Value value; for (int32 particleIndex = particlesStart; particleIndex < particlesEnd; particleIndex++) { context.ParticleIndex = particleIndex; - const Value value = GetValue(box, 4).Cast(type); + value = GetValue(box, 4).Cast(type); Platform::MemoryCopy(dataPtr, &value.AsPointer, dataSize); dataPtr += stride; } @@ -667,10 +668,11 @@ void ParticleEmitterGraphCPUExecutor::ProcessModule(ParticleEmitterGraphCPUNode* ValueType type(GetVariantType(attribute.ValueType)); if (node->UsePerParticleDataResolve()) { + Value value; for (int32 particleIndex = particlesStart; particleIndex < particlesEnd; particleIndex++) { context.ParticleIndex = particleIndex; - const Value value = GetValue(box, 2).Cast(type); + value = GetValue(box, 2).Cast(type); Platform::MemoryCopy(dataPtr, &value.AsPointer, dataSize); dataPtr += stride; } diff --git a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.Particles.cpp b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.Particles.cpp index 6d9ba3722..ee71f8d09 100644 --- a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.Particles.cpp +++ b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.Particles.cpp @@ -419,7 +419,7 @@ void ParticleEmitterGraphCPUExecutor::ProcessGroupFunction(Box* box, Node* node, Node* functionCallNode = nullptr; ASSERT(context.GraphStack.Count() >= 2); Graph* graph; - for (int32 i = context.CallStack.Count() - 1; i >= 0; i--) + for (int32 i = context.CallStackSize - 1; i >= 0; i--) { if (context.CallStack[i]->Type == GRAPH_NODE_MAKE_TYPE(14, 300) && context.Functions.TryGet(context.CallStack[i], graph) && context.GraphStack[context.GraphStack.Count() - 1] == graph) { diff --git a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp index ba22564bd..0c459ec96 100644 --- a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp +++ b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.cpp @@ -131,7 +131,7 @@ void ParticleEmitterGraphCPUExecutor::Init(ParticleEmitter* emitter, ParticleEff context.DeltaTime = dt; context.ParticleIndex = 0; context.ViewTask = effect->GetRenderTask(); - context.CallStack.Clear(); + context.CallStackSize = 0; context.Functions.Clear(); } @@ -588,7 +588,7 @@ VisjectExecutor::Value ParticleEmitterGraphCPUExecutor::eatBox(Node* caller, Box { // Check if graph is looped or is too deep auto& context = Context.Get(); - if (context.CallStack.Count() >= PARTICLE_EMITTER_MAX_CALL_STACK) + if (context.CallStackSize >= PARTICLE_EMITTER_MAX_CALL_STACK) { OnError(caller, box, TEXT("Graph is looped or too deep!")); return Value::Zero; @@ -602,7 +602,7 @@ VisjectExecutor::Value ParticleEmitterGraphCPUExecutor::eatBox(Node* caller, Box #endif // Add to the calling stack - context.CallStack.Add(caller); + context.CallStack[context.CallStackSize++] = caller; // Call per group custom processing event Value value; @@ -611,7 +611,7 @@ VisjectExecutor::Value ParticleEmitterGraphCPUExecutor::eatBox(Node* caller, Box (this->*func)(box, parentNode, value); // Remove from the calling stack - context.CallStack.RemoveLast(); + context.CallStackSize--; return value; } diff --git a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.h b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.h index 34834a2cd..a1e06f850 100644 --- a/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.h +++ b/Source/Engine/Particles/Graph/CPU/ParticleEmitterGraph.CPU.h @@ -120,9 +120,10 @@ struct ParticleEmitterGraphCPUContext ParticleEmitter* Emitter; ParticleEffect* Effect; class SceneRenderTask* ViewTask; - Array> CallStack; Array> GraphStack; Dictionary Functions; + int32 CallStackSize = 0; + VisjectExecutor::Node* CallStack[PARTICLE_EMITTER_MAX_CALL_STACK]; }; ///