diff --git a/CMakeLists.txt b/CMakeLists.txt index 82c6894f3..bd2a7a1ea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -109,6 +109,7 @@ option_if_not_defined(GPGMM_ENABLE_ALLOCATOR_LEAK_CHECKS "Enables checking of al option_if_not_defined(GPGMM_ENABLE_ASSERT_ON_WARNING "Enables ASSERT on severity functionality" OFF) option_if_not_defined(GPGMM_DISABLE_SIZE_CACHE "Enables warming of caches with common resource sizes" OFF) option_if_not_defined(GPGMM_ENABLE_MEMORY_ALIGN_CHECKS "Enables checking of resource alignment." OFF) +option_if_not_defined(GPGMM_ENABLE_LOGGING_INTERNAL_OBJECTS "Enables log messages for internal objects." OFF) if(GPGMM_ENABLE_TESTS) # Vulkan tests require static linking. diff --git a/build_overrides/gpgmm_features.gni b/build_overrides/gpgmm_features.gni index b2445d682..5a8ec82fd 100644 --- a/build_overrides/gpgmm_features.gni +++ b/build_overrides/gpgmm_features.gni @@ -66,4 +66,8 @@ declare_args() { # Configures Vulkan functions by dynamically importing them (ie. using vkGetInstanceProcAddr and vkGetDeviceProcAddr). gpgmm_vk_dynamic_functions = false + + # Enables log messages for internal objects. + # Sets -dGPGMM_ENABLE_LOGGING_INTERNAL_OBJECTS + gpgmm_enable_logging_internal_objects = false } diff --git a/src/gpgmm/common/BUILD.gn b/src/gpgmm/common/BUILD.gn index 7a81bd33d..f02429d1c 100644 --- a/src/gpgmm/common/BUILD.gn +++ b/src/gpgmm/common/BUILD.gn @@ -79,6 +79,10 @@ config("gpgmm_common_config") { defines += [ "GPGMM_ENABLE_MEMORY_ALIGN_CHECKS" ] } + if (gpgmm_enable_logging_internal_objects) { + defines += [ "GPGMM_ENABLE_LOGGING_INTERNAL_OBJECTS" ] + } + # Only internal build targets can use this config, this means only targets in # this BUILD.gn file and related subdirs. visibility = [ "../../*" ] @@ -203,6 +207,8 @@ source_set("gpgmm_common_sources") { "MemoryPool.h", "Message.cpp", "Message.h", + "Object.cpp", + "Object.h", "PooledMemoryAllocator.cpp", "PooledMemoryAllocator.h", "SegmentedMemoryAllocator.cpp", diff --git a/src/gpgmm/common/CMakeLists.txt b/src/gpgmm/common/CMakeLists.txt index 0c9b96cec..fefecdba1 100644 --- a/src/gpgmm/common/CMakeLists.txt +++ b/src/gpgmm/common/CMakeLists.txt @@ -46,6 +46,8 @@ target_sources(gpgmm_common PRIVATE "MemoryPool.h" "Message.cpp" "Message.h" + "Object.cpp" + "Object.h" "PooledMemoryAllocator.cpp" "PooledMemoryAllocator.h" "SegmentedMemoryAllocator.cpp" diff --git a/src/gpgmm/common/Object.cpp b/src/gpgmm/common/Object.cpp new file mode 100644 index 000000000..1c3d12a01 --- /dev/null +++ b/src/gpgmm/common/Object.cpp @@ -0,0 +1,21 @@ +// Copyright 2022 The GPGMM Authors +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +#include "gpgmm/common/Object.h" + +namespace gpgmm { + bool ObjectBase::IsExternal() const { + return false; + } +} // namespace gpgmm diff --git a/src/gpgmm/common/Object.h b/src/gpgmm/common/Object.h index fdfb2b394..c73796c9a 100644 --- a/src/gpgmm/common/Object.h +++ b/src/gpgmm/common/Object.h @@ -26,6 +26,9 @@ namespace gpgmm { ObjectBase& operator=(const ObjectBase&) = default; virtual const char* GetTypename() const = 0; + + // Overridden for objects that are API exposed. + virtual bool IsExternal() const; }; } // namespace gpgmm diff --git a/src/gpgmm/d3d12/HeapD3D12.cpp b/src/gpgmm/d3d12/HeapD3D12.cpp index 1d893fb68..ce239c014 100644 --- a/src/gpgmm/d3d12/HeapD3D12.cpp +++ b/src/gpgmm/d3d12/HeapD3D12.cpp @@ -202,6 +202,10 @@ namespace gpgmm::d3d12 { return "Heap"; } + bool Heap::IsExternal() const { + return true; + } + uint64_t Heap::GetLastUsedFenceValue() const { return mLastUsedFenceValue; } diff --git a/src/gpgmm/d3d12/HeapD3D12.h b/src/gpgmm/d3d12/HeapD3D12.h index 97588563f..82594da00 100644 --- a/src/gpgmm/d3d12/HeapD3D12.h +++ b/src/gpgmm/d3d12/HeapD3D12.h @@ -60,6 +60,7 @@ namespace gpgmm::d3d12 { // ObjectBase interface const char* GetTypename() const override; + bool IsExternal() const override; HRESULT SetDebugNameImpl(LPCWSTR name) override; DXGI_MEMORY_SEGMENT_GROUP GetMemorySegmentGroup() const; diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index 078bd3ed7..2b2835856 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -313,6 +313,10 @@ namespace gpgmm::d3d12 { return "ResidencyManager"; } + bool ResidencyManager::IsExternal() const { + return true; + } + // Increments number of locks on a heap to ensure the heap remains resident. HRESULT ResidencyManager::LockHeap(IHeap* pHeap) { ReturnIfNullptr(pHeap); diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.h b/src/gpgmm/d3d12/ResidencyManagerD3D12.h index 97fee1873..f0c8be6a7 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.h +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.h @@ -96,6 +96,7 @@ namespace gpgmm::d3d12 { // ObjectBase interface const char* GetTypename() const override; + bool IsExternal() const override; // IDebugObject interface LPCWSTR GetDebugName() const override; diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp index 0a8132b8d..deab6f775 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp @@ -153,6 +153,10 @@ namespace gpgmm::d3d12 { return "ResourceAllocation"; } + bool ResourceAllocation::IsExternal() const { + return true; + } + IHeap* ResourceAllocation::GetMemory() const { return static_cast(MemoryAllocation::GetMemory()); } diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.h b/src/gpgmm/d3d12/ResourceAllocationD3D12.h index 8dfac2a65..9a94f01ba 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.h @@ -77,6 +77,7 @@ namespace gpgmm::d3d12 { // ObjectBase interface const char* GetTypename() const override; + bool IsExternal() const override; ResidencyManager* const mResidencyManager; ComPtr mResource; diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 49be60bd4..8a71771ea 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -878,6 +878,10 @@ namespace gpgmm::d3d12 { return "ResourceAllocator"; } + bool ResourceAllocator::IsExternal() const { + return true; + } + HRESULT ResourceAllocator::ReleaseResourceHeaps(uint64_t bytesToRelease, uint64_t* pBytesReleased) { std::lock_guard lock(mMutex); diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h index 48de5b29b..b93847bfc 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.h @@ -76,6 +76,7 @@ namespace gpgmm::d3d12 { // ObjectBase interface const char* GetTypename() const override; + bool IsExternal() const override; // IDebugObject interface LPCWSTR GetDebugName() const override; diff --git a/src/gpgmm/utils/Log.cpp b/src/gpgmm/utils/Log.cpp index 5c3d698b5..8b2af9dec 100644 --- a/src/gpgmm/utils/Log.cpp +++ b/src/gpgmm/utils/Log.cpp @@ -109,6 +109,13 @@ namespace gpgmm { return; } + // Ignore internal objects being logged unless the build is enabled for it. +#if !defined(GPGMM_ENABLE_LOGGING_INTERNAL_OBJECTS) + if (mObject != nullptr && !mObject->IsExternal()) { + return; + } +#endif + const char* severityName = SeverityName(mSeverity); FILE* outputStream = stdout;