Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions build_overrides/gpgmm_features.gni
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
6 changes: 6 additions & 0 deletions src/gpgmm/common/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -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 = [ "../../*" ]
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 2 additions & 0 deletions src/gpgmm/common/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
21 changes: 21 additions & 0 deletions src/gpgmm/common/Object.cpp
Original file line number Diff line number Diff line change
@@ -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
3 changes: 3 additions & 0 deletions src/gpgmm/common/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/gpgmm/d3d12/HeapD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,10 @@ namespace gpgmm::d3d12 {
return "Heap";
}

bool Heap::IsExternal() const {
return true;
}

uint64_t Heap::GetLastUsedFenceValue() const {
return mLastUsedFenceValue;
}
Expand Down
1 change: 1 addition & 0 deletions src/gpgmm/d3d12/HeapD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 1 addition & 0 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ namespace gpgmm::d3d12 {

// ObjectBase interface
const char* GetTypename() const override;
bool IsExternal() const override;

// IDebugObject interface
LPCWSTR GetDebugName() const override;
Expand Down
4 changes: 4 additions & 0 deletions src/gpgmm/d3d12/ResourceAllocationD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,10 @@ namespace gpgmm::d3d12 {
return "ResourceAllocation";
}

bool ResourceAllocation::IsExternal() const {
return true;
}

IHeap* ResourceAllocation::GetMemory() const {
return static_cast<Heap*>(MemoryAllocation::GetMemory());
}
Expand Down
1 change: 1 addition & 0 deletions src/gpgmm/d3d12/ResourceAllocationD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ namespace gpgmm::d3d12 {

// ObjectBase interface
const char* GetTypename() const override;
bool IsExternal() const override;

ResidencyManager* const mResidencyManager;
ComPtr<ID3D12Resource> mResource;
Expand Down
4 changes: 4 additions & 0 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::mutex> lock(mMutex);
Expand Down
1 change: 1 addition & 0 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ namespace gpgmm::d3d12 {

// ObjectBase interface
const char* GetTypename() const override;
bool IsExternal() const override;

// IDebugObject interface
LPCWSTR GetDebugName() const override;
Expand Down
7 changes: 7 additions & 0 deletions src/gpgmm/utils/Log.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down