Add memory profiling events to the main areas of the engine
This commit is contained in:
@@ -11,6 +11,7 @@
|
||||
#include "Engine/Physics/PhysicsBackend.h"
|
||||
#include "Engine/Physics/PhysicsScene.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Profiler/ProfilerMemory.h"
|
||||
#include "Engine/Serialization/Serialization.h"
|
||||
#include "Engine/Level/Actors/AnimatedModel.h"
|
||||
#include "Engine/Level/Scene/SceneRendering.h"
|
||||
@@ -132,6 +133,7 @@ Array<Float3> Cloth::GetParticles() const
|
||||
if (_cloth)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
PhysicsBackend::LockClothParticles(_cloth);
|
||||
const Span<const Float4> particles = PhysicsBackend::GetClothParticles(_cloth);
|
||||
result.Resize(particles.Length());
|
||||
@@ -148,6 +150,7 @@ Array<Float3> Cloth::GetParticles() const
|
||||
void Cloth::SetParticles(Span<const Float3> value)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
#if USE_CLOTH_SANITY_CHECKS
|
||||
{
|
||||
// Sanity check
|
||||
@@ -177,6 +180,7 @@ Span<float> Cloth::GetPaint() const
|
||||
void Cloth::SetPaint(Span<const float> value)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
#if USE_CLOTH_SANITY_CHECKS
|
||||
{
|
||||
// Sanity check
|
||||
@@ -302,6 +306,7 @@ void Cloth::Deserialize(DeserializeStream& stream, ISerializeModifier* modifier)
|
||||
{
|
||||
Actor::Deserialize(stream, modifier);
|
||||
|
||||
PROFILE_MEM(Physics);
|
||||
DESERIALIZE_MEMBER(Mesh, _mesh);
|
||||
_mesh.Actor = nullptr; // Don't store this reference
|
||||
DESERIALIZE_MEMBER(Force, _forceSettings);
|
||||
@@ -536,6 +541,7 @@ bool Cloth::CreateCloth()
|
||||
{
|
||||
#if WITH_CLOTH
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
|
||||
// Skip if all vertices are fixed so cloth sim doesn't make sense
|
||||
if (_paint.HasItems())
|
||||
@@ -631,6 +637,7 @@ void Cloth::CalculateInvMasses(Array<float>& invMasses)
|
||||
if (_paint.IsEmpty())
|
||||
return;
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
|
||||
// Get mesh data
|
||||
const ModelInstanceActor::MeshReference mesh = GetMesh();
|
||||
@@ -918,6 +925,7 @@ void Cloth::RunClothDeformer(const MeshBase* mesh, MeshDeformationData& deformat
|
||||
return;
|
||||
#if WITH_CLOTH
|
||||
PROFILE_CPU_NAMED("Cloth");
|
||||
PROFILE_MEM(Physics);
|
||||
PhysicsBackend::LockClothParticles(_cloth);
|
||||
const Span<const Float4> particles = PhysicsBackend::GetClothParticles(_cloth);
|
||||
auto vbCount = (uint32)mesh->GetVertexCount();
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
#include "Engine/Physics/PhysicsScene.h"
|
||||
#include "Engine/Engine/Time.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Profiler/ProfilerMemory.h"
|
||||
#include "Engine/Serialization/Serialization.h"
|
||||
|
||||
SplineRopeBody::SplineRopeBody(const SpawnParams& params)
|
||||
@@ -19,6 +20,7 @@ void SplineRopeBody::Tick()
|
||||
if (!_spline || _spline->GetSplinePointsCount() < 2)
|
||||
return;
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
|
||||
// Cache data
|
||||
const Vector3 gravity = GetPhysicsScene()->GetGravity() * GravityScale;
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
#include "Engine/Graphics/Models/MeshAccessor.h"
|
||||
#include "Engine/Threading/Threading.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Profiler/ProfilerMemory.h"
|
||||
#include "Engine/Core/Log.h"
|
||||
|
||||
bool CollisionCooking::CookCollision(const Argument& arg, CollisionData::SerializedOptions& outputOptions, BytesContainer& outputData)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
int32 convexVertexLimit = Math::Clamp(arg.ConvexVertexLimit, CONVEX_VERTEX_MIN, CONVEX_VERTEX_MAX);
|
||||
if (arg.ConvexVertexLimit == 0)
|
||||
convexVertexLimit = CONVEX_VERTEX_MAX;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include "Engine/Physics/PhysicsBackend.h"
|
||||
#include "Engine/Physics/CollisionCooking.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Profiler/ProfilerMemory.h"
|
||||
#include "Engine/Threading/Threading.h"
|
||||
|
||||
REGISTER_BINARY_ASSET(CollisionData, "FlaxEngine.CollisionData", true);
|
||||
@@ -35,6 +36,7 @@ bool CollisionData::CookCollision(CollisionDataType type, ModelBase* modelObj, i
|
||||
return true;
|
||||
}
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
|
||||
// Prepare
|
||||
CollisionCooking::Argument arg;
|
||||
@@ -64,6 +66,7 @@ bool CollisionData::CookCollision(CollisionDataType type, ModelBase* modelObj, i
|
||||
bool CollisionData::CookCollision(CollisionDataType type, const Span<Float3>& vertices, const Span<uint32>& triangles, ConvexMeshGenerationFlags convexFlags, int32 convexVertexLimit)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
CHECK_RETURN(vertices.Length() != 0, true);
|
||||
CHECK_RETURN(triangles.Length() != 0 && triangles.Length() % 3 == 0, true);
|
||||
ModelData modelData;
|
||||
@@ -78,6 +81,7 @@ bool CollisionData::CookCollision(CollisionDataType type, const Span<Float3>& ve
|
||||
bool CollisionData::CookCollision(CollisionDataType type, const Span<Float3>& vertices, const Span<int32>& triangles, ConvexMeshGenerationFlags convexFlags, int32 convexVertexLimit)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
CHECK_RETURN(vertices.Length() != 0, true);
|
||||
CHECK_RETURN(triangles.Length() != 0 && triangles.Length() % 3 == 0, true);
|
||||
ModelData modelData;
|
||||
@@ -99,6 +103,7 @@ bool CollisionData::CookCollision(CollisionDataType type, ModelData* modelData,
|
||||
return true;
|
||||
}
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
|
||||
// Prepare
|
||||
CollisionCooking::Argument arg;
|
||||
@@ -180,6 +185,7 @@ bool CollisionData::GetModelTriangle(uint32 faceIndex, MeshBase*& mesh, uint32&
|
||||
void CollisionData::ExtractGeometry(Array<Float3>& vertexBuffer, Array<int32>& indexBuffer) const
|
||||
{
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
vertexBuffer.Clear();
|
||||
indexBuffer.Clear();
|
||||
|
||||
@@ -197,6 +203,7 @@ const Array<Float3>& CollisionData::GetDebugLines()
|
||||
if (_hasMissingDebugLines && IsLoaded())
|
||||
{
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
ScopeLock lock(Locker);
|
||||
_hasMissingDebugLines = false;
|
||||
|
||||
@@ -250,6 +257,8 @@ Asset::LoadResult CollisionData::load()
|
||||
|
||||
CollisionData::LoadResult CollisionData::load(const SerializedOptions* options, byte* dataPtr, int32 dataSize)
|
||||
{
|
||||
PROFILE_MEM(Physics);
|
||||
|
||||
// Load options
|
||||
_options.Type = options->Type;
|
||||
_options.Model = options->Model;
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "Engine/Platform/CPUInfo.h"
|
||||
#include "Engine/Platform/CriticalSection.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Profiler/ProfilerMemory.h"
|
||||
#include "Engine/Serialization/WriteStream.h"
|
||||
#include <ThirdParty/PhysX/PxPhysicsAPI.h>
|
||||
#include <ThirdParty/PhysX/PxQueryFiltering.h>
|
||||
@@ -117,6 +118,7 @@ class AllocatorPhysX : public PxAllocatorCallback
|
||||
void* allocate(size_t size, const char* typeName, const char* filename, int line) override
|
||||
{
|
||||
ASSERT(size < 1024 * 1024 * 1024); // Prevent invalid allocation size
|
||||
PROFILE_MEM(Physics);
|
||||
return Allocator::Allocate(size, 16);
|
||||
}
|
||||
|
||||
@@ -725,6 +727,7 @@ void ScenePhysX::UpdateVehicles(float dt)
|
||||
if (WheelVehicles.IsEmpty())
|
||||
return;
|
||||
PROFILE_CPU_NAMED("Physics.Vehicles");
|
||||
PROFILE_MEM(Physics);
|
||||
|
||||
// Update vehicles steering
|
||||
WheelVehiclesCache.Clear();
|
||||
@@ -1861,6 +1864,7 @@ void PhysicsBackend::DestroyScene(void* scene)
|
||||
|
||||
void PhysicsBackend::StartSimulateScene(void* scene, float dt)
|
||||
{
|
||||
PROFILE_MEM(Physics);
|
||||
auto scenePhysX = (ScenePhysX*)scene;
|
||||
const auto& settings = *PhysicsSettings::Get();
|
||||
|
||||
@@ -1895,6 +1899,7 @@ void PhysicsBackend::StartSimulateScene(void* scene, float dt)
|
||||
|
||||
void PhysicsBackend::EndSimulateScene(void* scene)
|
||||
{
|
||||
PROFILE_MEM(Physics);
|
||||
auto scenePhysX = (ScenePhysX*)scene;
|
||||
|
||||
{
|
||||
@@ -3880,6 +3885,7 @@ void PhysicsBackend::RemoveVehicle(void* scene, WheeledVehicle* actor)
|
||||
void* PhysicsBackend::CreateCloth(const PhysicsClothDesc& desc)
|
||||
{
|
||||
PROFILE_CPU();
|
||||
PROFILE_MEM(Physics);
|
||||
#if USE_CLOTH_SANITY_CHECKS
|
||||
{
|
||||
// Sanity check
|
||||
|
||||
@@ -6,6 +6,7 @@
|
||||
#include "Engine/Physics/Colliders/Collider.h"
|
||||
#include "Engine/Physics/Joints/Joint.h"
|
||||
#include "Engine/Physics/Actors/RigidBody.h"
|
||||
#include "Engine/Profiler/ProfilerMemory.h"
|
||||
#include <ThirdParty/PhysX/extensions/PxJoint.h>
|
||||
#include <ThirdParty/PhysX/PxShape.h>
|
||||
|
||||
@@ -91,6 +92,7 @@ void SimulationEventCallback::OnJointRemoved(Joint* joint)
|
||||
|
||||
void SimulationEventCallback::onConstraintBreak(PxConstraintInfo* constraints, PxU32 count)
|
||||
{
|
||||
PROFILE_MEM(Physics);
|
||||
for (uint32 i = 0; i < count; i++)
|
||||
{
|
||||
PxJoint* joint = reinterpret_cast<PxJoint*>(constraints[i].externalReference);
|
||||
@@ -114,6 +116,7 @@ void SimulationEventCallback::onContact(const PxContactPairHeader& pairHeader, c
|
||||
// Skip sending events to removed actors
|
||||
if (pairHeader.flags & (PxContactPairHeaderFlag::eREMOVED_ACTOR_0 | PxContactPairHeaderFlag::eREMOVED_ACTOR_1))
|
||||
return;
|
||||
PROFILE_MEM(Physics);
|
||||
|
||||
Collision c;
|
||||
PxContactPairExtraDataIterator j(pairHeader.extraDataStream, pairHeader.extraDataStreamSize);
|
||||
@@ -185,6 +188,7 @@ void SimulationEventCallback::onContact(const PxContactPairHeader& pairHeader, c
|
||||
|
||||
void SimulationEventCallback::onTrigger(PxTriggerPair* pairs, PxU32 count)
|
||||
{
|
||||
PROFILE_MEM(Physics);
|
||||
for (PxU32 i = 0; i < count; i++)
|
||||
{
|
||||
const PxTriggerPair& pair = pairs[i];
|
||||
|
||||
@@ -10,6 +10,7 @@
|
||||
#include "Engine/Engine/Time.h"
|
||||
#include "Engine/Engine/EngineService.h"
|
||||
#include "Engine/Profiler/ProfilerCPU.h"
|
||||
#include "Engine/Profiler/ProfilerMemory.h"
|
||||
#include "Engine/Serialization/Serialization.h"
|
||||
#include "Engine/Threading/Threading.h"
|
||||
|
||||
@@ -117,6 +118,8 @@ PhysicalMaterial::~PhysicalMaterial()
|
||||
|
||||
bool PhysicsService::Init()
|
||||
{
|
||||
PROFILE_MEM(Physics);
|
||||
|
||||
// Initialize backend
|
||||
if (PhysicsBackend::Init())
|
||||
return true;
|
||||
@@ -153,6 +156,7 @@ void PhysicsService::Dispose()
|
||||
|
||||
PhysicsScene* Physics::FindOrCreateScene(const StringView& name)
|
||||
{
|
||||
PROFILE_MEM(Physics);
|
||||
auto scene = FindScene(name);
|
||||
if (scene == nullptr)
|
||||
{
|
||||
@@ -244,6 +248,7 @@ bool Physics::IsDuringSimulation()
|
||||
void Physics::FlushRequests()
|
||||
{
|
||||
PROFILE_CPU_NAMED("Physics.FlushRequests");
|
||||
PROFILE_MEM(Physics);
|
||||
for (PhysicsScene* scene : Scenes)
|
||||
PhysicsBackend::FlushRequests(scene->GetPhysicsScene());
|
||||
PhysicsBackend::FlushRequests();
|
||||
@@ -492,6 +497,7 @@ PhysicsStatistics PhysicsScene::GetStatistics() const
|
||||
|
||||
bool PhysicsScene::Init(const StringView& name, const PhysicsSettings& settings)
|
||||
{
|
||||
PROFILE_MEM(Physics);
|
||||
if (_scene)
|
||||
{
|
||||
PhysicsBackend::DestroyScene(_scene);
|
||||
|
||||
Reference in New Issue
Block a user