/* * Copyright (c) Contributors to the Open 3D Engine Project. * For complete copyright and license terms please see the LICENSE at the root of this distribution. * * SPDX-License-Identifier: Apache-2.0 OR MIT * */ #pragma once #include #include #include #include #include #include #include #include #include #include #include namespace UnitTest { inline constexpr bool EnableLeakTracking = false; class RHITestFixture : public ScopedAllocatorSetupFixture { AZStd::unique_ptr m_reflectionManager; public: RHITestFixture() { { AZ::PoolAllocator::Descriptor desc; if constexpr (EnableLeakTracking) { desc.m_allocationRecords = true; desc.m_stackRecordLevels = 5; desc.m_isMemoryGuards = true; desc.m_isMarkUnallocatedMemory = true; } AZ::AllocatorInstance::Create(desc); } { AZ::ThreadPoolAllocator::Descriptor desc; if constexpr (EnableLeakTracking) { desc.m_allocationRecords = true; desc.m_stackRecordLevels = 5; desc.m_isMemoryGuards = true; desc.m_isMarkUnallocatedMemory = true; } AZ::AllocatorInstance::Create(desc); } if constexpr (EnableLeakTracking) { AZ::Debug::AllocationRecords* records = AZ::AllocatorInstance::GetAllocator().GetRecords(); if (records) { records->SetMode(AZ::Debug::AllocationRecords::RECORD_FULL); } } } AZ::SerializeContext* GetSerializeContext() { return m_reflectionManager ? m_reflectionManager->GetReflectContext() : nullptr; } virtual ~RHITestFixture() { AZ::AllocatorInstance::Destroy(); AZ::AllocatorInstance::Destroy(); } void SetUp() override { AZ::RHI::Validation::s_isEnabled = true; m_reflectionManager = AZStd::make_unique(); m_reflectionManager->AddReflectContext(); AZ::NameDictionary::Create(); } void TearDown() override { // Flushing the tick bus queue since AZ::RHI::Factory:Register queues a function AZ::SystemTickBus::ClearQueuedEvents(); AZ::NameDictionary::Destroy(); m_reflectionManager->Clear(); m_reflectionManager.reset(); } }; }