/* * Copyright (c) Contributors to the Open 3D Engine Project * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #ifdef HAVE_BENCHMARK #include #include #include #include namespace PhysX::Benchmarks { PhysXBenchmarkEnvironment::~PhysXBenchmarkEnvironment() { //within our scene queries we use thread_locals, as a result the allocator needs to be around until the module is cleaned up. //having the allocator cleaned up here rather then in TeardownInternal() allows it to be around long enough to clean up resource nicely. AZ::AllocatorInstance::Destroy(); } void PhysXBenchmarkEnvironment::SetUpBenchmark() { PhysX::Environment::SetupInternal(); } void PhysXBenchmarkEnvironment::TearDownBenchmark() { PhysX::Environment::TeardownInternal(); } AzPhysics::SceneHandle PhysXBaseBenchmarkFixture::GetDefaultSceneHandle() const { return m_testSceneHandle; } void PhysXBaseBenchmarkFixture::UpdateSimulation(unsigned int numFrames, float timeStep /*= DefaultTimeStep*/) { if (auto* physicsSystem = AZ::Interface::Get()) { for (AZ::u32 i = 0; i < numFrames; i++) { physicsSystem->Simulate(timeStep); } } } void PhysXBaseBenchmarkFixture::StepScene1Tick(float timeStep /*= DefaultTimeStep*/) { m_defaultScene->StartSimulation(timeStep); m_defaultScene->FinishSimulation(); } void PhysXBaseBenchmarkFixture::SetUpInternal() { m_testSceneHandle = CreateDefaultTestScene(); //create the default scene if (auto* physicsSystem = AZ::Interface::Get()) { m_defaultScene = physicsSystem->GetScene(m_testSceneHandle); } m_dummyTerrainComponentDescriptor = DummyTestTerrainComponent::CreateDescriptor(); Physics::DefaultWorldBus::Handler::BusConnect(); } void PhysXBaseBenchmarkFixture::TearDownInternal() { //cleanup materials in case some where created PhysX::MaterialManagerRequestsBus::Broadcast(&PhysX::MaterialManagerRequestsBus::Events::ReleaseAllMaterials); Physics::DefaultWorldBus::Handler::BusDisconnect(); //Clean up the test scene m_defaultScene = nullptr; if (auto* physicsSystem = AZ::Interface::Get()) { physicsSystem->RemoveScene(m_testSceneHandle); } m_testSceneHandle = AzPhysics::InvalidSceneHandle; TestUtils::ResetPhysXSystem(); m_dummyTerrainComponentDescriptor->ReleaseDescriptor(); m_dummyTerrainComponentDescriptor = nullptr; } AzPhysics::SceneHandle PhysXBaseBenchmarkFixture::CreateDefaultTestScene() { if (auto* physicsSystem = AZ::Interface::Get()) { AzPhysics::SceneConfiguration sceneConfiguration = GetDefaultSceneConfiguration(); sceneConfiguration.m_sceneName = "BenchmarkWorld"; AzPhysics::SceneHandle sceneHandle = physicsSystem->AddScene(sceneConfiguration); return sceneHandle; } return AzPhysics::InvalidSceneHandle; } } //namespace PhysX::Benchmarks #endif //HAVE_BENCHMARK