diff --git a/src/gpgmm/common/BuddyMemoryAllocator.cpp b/src/gpgmm/common/BuddyMemoryAllocator.cpp index cd7f4e120..de850f35d 100644 --- a/src/gpgmm/common/BuddyMemoryAllocator.cpp +++ b/src/gpgmm/common/BuddyMemoryAllocator.cpp @@ -43,7 +43,7 @@ namespace gpgmm { std::unique_ptr BuddyMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::Default, "BuddyMemoryAllocator.TryAllocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "BuddyMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -100,7 +100,7 @@ namespace gpgmm { void BuddyMemoryAllocator::DeallocateMemory(std::unique_ptr subAllocation) { std::lock_guard lock(mMutex); - TRACE_EVENT0(TraceEventCategory::Default, "BuddyMemoryAllocator.DeallocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "BuddyMemoryAllocator.DeallocateMemory"); ASSERT(subAllocation != nullptr); diff --git a/src/gpgmm/common/ConditionalMemoryAllocator.cpp b/src/gpgmm/common/ConditionalMemoryAllocator.cpp index 2bf343e04..4f2952dd4 100644 --- a/src/gpgmm/common/ConditionalMemoryAllocator.cpp +++ b/src/gpgmm/common/ConditionalMemoryAllocator.cpp @@ -30,7 +30,7 @@ namespace gpgmm { std::unique_ptr ConditionalMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::Default, "ConditionalMemoryAllocator.TryAllocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ConditionalMemoryAllocator.TryAllocateMemory"); if (request.SizeInBytes <= mConditionalSize) { return mFirstAllocator->TryAllocateMemory(request); } else { diff --git a/src/gpgmm/common/DedicatedMemoryAllocator.cpp b/src/gpgmm/common/DedicatedMemoryAllocator.cpp index c4c021c8b..324a8f8d0 100644 --- a/src/gpgmm/common/DedicatedMemoryAllocator.cpp +++ b/src/gpgmm/common/DedicatedMemoryAllocator.cpp @@ -26,7 +26,7 @@ namespace gpgmm { std::unique_ptr DedicatedMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::Default, "DedicatedMemoryAllocator.TryAllocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "DedicatedMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -44,7 +44,7 @@ namespace gpgmm { } void DedicatedMemoryAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::Default, "DedicatedMemoryAllocator.DeallocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "DedicatedMemoryAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); diff --git a/src/gpgmm/common/EventMessage.cpp b/src/gpgmm/common/EventMessage.cpp index 3116d2e0a..2705adf95 100644 --- a/src/gpgmm/common/EventMessage.cpp +++ b/src/gpgmm/common/EventMessage.cpp @@ -45,14 +45,14 @@ namespace gpgmm { // EventMessage - EventMessage::EventMessage(const LogSeverity& level, const char* name, int messageId) + EventMessage::EventMessage(const LogSeverity& level, const char* name, EventMessageId messageId) : mSeverity(level), mName(name), mMessageId(messageId) { } EventMessage::~EventMessage() { const std::string description = mStream.str(); - gpgmm::Log(mSeverity) << mName << "(" << mMessageId << ")" + gpgmm::Log(mSeverity) << mName << "(" << static_cast(mMessageId) << ")" << ": " << description; #if defined(GPGMM_ENABLE_ASSERT_ON_WARNING) @@ -65,19 +65,19 @@ namespace gpgmm { } } - EventMessage DebugEvent(const char* name, int messageId) { + EventMessage DebugEvent(const char* name, EventMessageId messageId) { return {LogSeverity::Debug, name, messageId}; } - EventMessage InfoEvent(const char* name, int messageId) { + EventMessage InfoEvent(const char* name, EventMessageId messageId) { return {LogSeverity::Info, name, messageId}; } - EventMessage WarnEvent(const char* name, int messageId) { + EventMessage WarnEvent(const char* name, EventMessageId messageId) { return {LogSeverity::Warning, name, messageId}; } - EventMessage ErrorEvent(const char* name, int messageId) { + EventMessage ErrorEvent(const char* name, EventMessageId messageId) { return {LogSeverity::Error, name, messageId}; } diff --git a/src/gpgmm/common/EventMessage.h b/src/gpgmm/common/EventMessage.h index 132250875..25c2356cc 100644 --- a/src/gpgmm/common/EventMessage.h +++ b/src/gpgmm/common/EventMessage.h @@ -23,27 +23,27 @@ namespace gpgmm { - enum EventMessageId { - Unknown, - SizeExceeded, - AlignmentMismatch, - AllocatorFailed, - PrefetchFailed, - BudgetExceeded, - BudgetUpdated, - BudgetInvalid, + enum class EventMessageId { + kUnknown, + kSizeExceeded, + kAlignmentMismatch, + kAllocatorFailed, + kPrefetchFailed, + kBudgetExceeded, + kBudgetUpdated, + kBudgetInvalid, }; struct EventMessageInfo { std::string Description; - int ID; + EventMessageId ID; }; class EventMessage { public: EventMessage(const LogSeverity& level, const char* name, - int messageId = EventMessageId::Unknown); + EventMessageId messageId = EventMessageId::kUnknown); ~EventMessage(); EventMessage(EventMessage&& other) = default; @@ -58,15 +58,15 @@ namespace gpgmm { private: LogSeverity mSeverity; const char* mName = nullptr; - int mMessageId = 0; + EventMessageId mMessageId = EventMessageId::kUnknown; std::ostringstream mStream; }; - EventMessage DebugEvent(const char* name, int messageId = EventMessageId::Unknown); - EventMessage InfoEvent(const char* name, int messageId = EventMessageId::Unknown); - EventMessage WarnEvent(const char* name, int messageId = EventMessageId::Unknown); - EventMessage ErrorEvent(const char* name, int messageId = EventMessageId::Unknown); + EventMessage DebugEvent(const char* name, EventMessageId messageId = EventMessageId::kUnknown); + EventMessage InfoEvent(const char* name, EventMessageId messageId = EventMessageId::kUnknown); + EventMessage WarnEvent(const char* name, EventMessageId messageId = EventMessageId::kUnknown); + EventMessage ErrorEvent(const char* name, EventMessageId messageId = EventMessageId::kUnknown); // Messages of a given severity to be recorded. void SetEventMessageLevel(const LogSeverity& level); diff --git a/src/gpgmm/common/EventTraceWriter.cpp b/src/gpgmm/common/EventTraceWriter.cpp index 804335e48..d233c084d 100644 --- a/src/gpgmm/common/EventTraceWriter.cpp +++ b/src/gpgmm/common/EventTraceWriter.cpp @@ -126,11 +126,11 @@ namespace gpgmm { eventData.AddItem("name", traceEvent.mName); switch (traceEvent.mCategory) { - case TraceEventCategory::Default: + case TraceEventCategory::kDefault: eventData.AddItem("cat", "default"); break; - case TraceEventCategory::Metadata: + case TraceEventCategory::kMetadata: eventData.AddItem("cat", "__metadata"); break; diff --git a/src/gpgmm/common/GPUInfo.h b/src/gpgmm/common/GPUInfo.h index ab6e6e69d..071253f3f 100644 --- a/src/gpgmm/common/GPUInfo.h +++ b/src/gpgmm/common/GPUInfo.h @@ -17,7 +17,7 @@ namespace gpgmm { - enum GPUVendor { + enum class GPUVendor { kAMD_VkVendor = 4098, kARM_VkVendor = 5045, kImagination_VkVendor = 4112, diff --git a/src/gpgmm/common/JSONSerializer.cpp b/src/gpgmm/common/JSONSerializer.cpp index 868e7a2b0..b39ecdb98 100644 --- a/src/gpgmm/common/JSONSerializer.cpp +++ b/src/gpgmm/common/JSONSerializer.cpp @@ -37,7 +37,7 @@ namespace gpgmm { JSONDict JSONSerializer::Serialize(const EventMessageInfo& info) { JSONDict dict; dict.AddItem("Description", info.Description); - dict.AddItem("ID", info.ID); + dict.AddItem("ID", static_cast(info.ID)); return dict; } diff --git a/src/gpgmm/common/MemoryAllocation.h b/src/gpgmm/common/MemoryAllocation.h index 4f9916f89..6339fcc88 100644 --- a/src/gpgmm/common/MemoryAllocation.h +++ b/src/gpgmm/common/MemoryAllocation.h @@ -24,7 +24,7 @@ namespace gpgmm { /** \enum AllocationMethod Represents how memory was allocated. */ - enum AllocationMethod { + enum class AllocationMethod { /** \brief Not yet allocated or invalid. diff --git a/src/gpgmm/common/MemoryAllocator.cpp b/src/gpgmm/common/MemoryAllocator.cpp index e17b272ff..4b14a31b3 100644 --- a/src/gpgmm/common/MemoryAllocator.cpp +++ b/src/gpgmm/common/MemoryAllocator.cpp @@ -159,7 +159,7 @@ namespace gpgmm { // Check request size cannot overflow. if (request.SizeInBytes > std::numeric_limits::max() - (request.Alignment - 1)) { - DebugEvent(GetTypename(), EventMessageId::SizeExceeded) + DebugEvent(GetTypename(), EventMessageId::kSizeExceeded) << "Requested size rejected due to overflow: " + std::to_string(request.SizeInBytes) << " bytes."; return false; @@ -168,7 +168,7 @@ namespace gpgmm { // Check request size cannot overflow |this| memory allocator. const uint64_t alignedSize = AlignTo(request.SizeInBytes, request.Alignment); if (GetMemorySize() != kInvalidSize && alignedSize > GetMemorySize()) { - DebugEvent(GetTypename(), EventMessageId::SizeExceeded) + DebugEvent(GetTypename(), EventMessageId::kSizeExceeded) << "Requested size exceeds memory size (" + std::to_string(alignedSize) + " vs " + std::to_string(GetMemorySize()) + " bytes)."; return false; @@ -178,7 +178,7 @@ namespace gpgmm { // Alignment value of 1 means no alignment required. if (GetMemoryAlignment() == 0 || (GetMemoryAlignment() > 1 && !IsAligned(GetMemoryAlignment(), request.Alignment))) { - DebugEvent(GetTypename(), EventMessageId::AlignmentMismatch) + DebugEvent(GetTypename(), EventMessageId::kAlignmentMismatch) << "Requested alignment exceeds memory alignment (" + std::to_string(request.Alignment) + " vs " + std::to_string(GetMemoryAlignment()) + " bytes)."; @@ -204,7 +204,7 @@ namespace gpgmm { void MemoryAllocator::CheckAndReportAllocationMisalignment(const MemoryAllocation& allocation) { if (allocation.GetSize() > allocation.GetRequestSize()) { - DebugEvent(GetTypename(), EventMessageId::AlignmentMismatch) + DebugEvent(GetTypename(), EventMessageId::kAlignmentMismatch) << "Resource allocation is larger then the requested size (" + std::to_string(allocation.GetSize()) + " vs " + std::to_string(allocation.GetRequestSize()) + " bytes)."; diff --git a/src/gpgmm/common/PooledMemoryAllocator.cpp b/src/gpgmm/common/PooledMemoryAllocator.cpp index 265cb0af6..6bed848d8 100644 --- a/src/gpgmm/common/PooledMemoryAllocator.cpp +++ b/src/gpgmm/common/PooledMemoryAllocator.cpp @@ -36,7 +36,7 @@ namespace gpgmm { std::unique_ptr PooledMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::Default, "PooledMemoryAllocator.TryAllocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "PooledMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -61,7 +61,7 @@ namespace gpgmm { } void PooledMemoryAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::Default, "PooledMemoryAllocator.DeallocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "PooledMemoryAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); diff --git a/src/gpgmm/common/SegmentedMemoryAllocator.cpp b/src/gpgmm/common/SegmentedMemoryAllocator.cpp index 86e85d22c..c50e73bef 100644 --- a/src/gpgmm/common/SegmentedMemoryAllocator.cpp +++ b/src/gpgmm/common/SegmentedMemoryAllocator.cpp @@ -121,7 +121,7 @@ namespace gpgmm { std::unique_ptr SegmentedMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::Default, "SegmentedMemoryAllocator.TryAllocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "SegmentedMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -152,7 +152,7 @@ namespace gpgmm { } void SegmentedMemoryAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::Default, "SegmentedMemoryAllocator.DeallocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "SegmentedMemoryAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); diff --git a/src/gpgmm/common/SlabMemoryAllocator.cpp b/src/gpgmm/common/SlabMemoryAllocator.cpp index 9f8707054..330b4e1ce 100644 --- a/src/gpgmm/common/SlabMemoryAllocator.cpp +++ b/src/gpgmm/common/SlabMemoryAllocator.cpp @@ -192,7 +192,7 @@ namespace gpgmm { std::unique_ptr SlabMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::Default, "SlabMemoryAllocator.TryAllocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "SlabMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -281,7 +281,7 @@ namespace gpgmm { } if (prefetchedSlabAllocation != nullptr) { - DebugEvent(GetTypename(), EventMessageId::PrefetchFailed) + DebugEvent(GetTypename(), EventMessageId::kPrefetchFailed) << "Pre-fetch slab memory is incompatible (" << slabSize << " vs " << prefetchedSlabAllocation->GetSize() << " bytes."; } @@ -382,7 +382,7 @@ namespace gpgmm { } void SlabMemoryAllocator::DeallocateMemory(std::unique_ptr subAllocation) { - TRACE_EVENT0(TraceEventCategory::Default, "SlabMemoryAllocator.DeallocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "SlabMemoryAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); @@ -458,7 +458,7 @@ namespace gpgmm { SafeDivide(mInfo.PrefetchedMemoryMissesEliminated, mInfo.PrefetchedMemoryMissesEliminated + mInfo.PrefetchedMemoryMisses); if (currentCoverage < kPrefetchCoverageWarnMinThreshold) { - WarnEvent(GetTypename(), EventMessageId::PrefetchFailed) + WarnEvent(GetTypename(), EventMessageId::kPrefetchFailed) << "Prefetch coverage is below threshold (%): " << currentCoverage * 100 << " vs " << kPrefetchCoverageWarnMinThreshold * 100; return false; @@ -493,7 +493,7 @@ namespace gpgmm { std::unique_ptr SlabCacheAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::Default, "SlabCacheAllocator.TryAllocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "SlabCacheAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -527,7 +527,7 @@ namespace gpgmm { } void SlabCacheAllocator::DeallocateMemory(std::unique_ptr subAllocation) { - TRACE_EVENT0(TraceEventCategory::Default, "SlabCacheAllocator.DeallocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "SlabCacheAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); diff --git a/src/gpgmm/common/TraceEvent.cpp b/src/gpgmm/common/TraceEvent.cpp index cd5ccb650..106be1038 100644 --- a/src/gpgmm/common/TraceEvent.cpp +++ b/src/gpgmm/common/TraceEvent.cpp @@ -40,7 +40,7 @@ namespace gpgmm { #endif GetInstance()->SetConfiguration(traceFile, ignoreMask); - TRACE_EVENT_METADATA1(TraceEventCategory::Metadata, "thread_name", "name", + TRACE_EVENT_METADATA1(TraceEventCategory::kMetadata, "thread_name", "name", "GPGMM_MainThread"); } diff --git a/src/gpgmm/common/TraceEvent.h b/src/gpgmm/common/TraceEvent.h index 1888b14e9..ea2fcc05e 100644 --- a/src/gpgmm/common/TraceEvent.h +++ b/src/gpgmm/common/TraceEvent.h @@ -121,26 +121,26 @@ const uint64_t kNoId = 0; #define GPGMM_TRACE_EVENT_OBJECT_NEW(objPtr) \ do { \ - TRACE_EVENT_OBJECT_CREATED_WITH_ID(TraceEventCategory::Default, \ + TRACE_EVENT_OBJECT_CREATED_WITH_ID(TraceEventCategory::kDefault, \ (*objPtr).GetTypename(), objPtr); \ } while (false) #define GPGMM_TRACE_EVENT_OBJECT_DESTROY(objPtr) \ do { \ - TRACE_EVENT_OBJECT_DELETED_WITH_ID(TraceEventCategory::Default, \ + TRACE_EVENT_OBJECT_DELETED_WITH_ID(TraceEventCategory::kDefault, \ (*objPtr).GetTypename(), objPtr); \ } while (false) #define GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(objPtr, desc) \ do { \ TRACE_EVENT_OBJECT_SNAPSHOT_WITH_ID( \ - TraceEventCategory::Default, (*objPtr).GetTypename(), objPtr, \ + TraceEventCategory::kDefault, (*objPtr).GetTypename(), objPtr, \ GPGMM_LAZY_SERIALIZE(desc, IsEventTraceEnabled())); \ } while (false) #define GPGMM_TRACE_EVENT_OBJECT_CALL(name, desc) \ do { \ - TRACE_EVENT_INSTANT1(TraceEventCategory::Default, name, \ + TRACE_EVENT_INSTANT1(TraceEventCategory::kDefault, name, \ GPGMM_LAZY_SERIALIZE(desc, IsEventTraceEnabled())); \ } while (false) @@ -152,16 +152,16 @@ const uint64_t kNoId = 0; #define GPGMM_TRACE_EVENT_METRIC(name, value) \ do { \ if (value == 0) break; \ - TRACE_COUNTER1(TraceEventCategory::Default, name, value); \ + TRACE_COUNTER1(TraceEventCategory::kDefault, name, value); \ } while (false) #endif namespace gpgmm { - enum TraceEventCategory { - Default = 0, - Metadata = 1, + enum class TraceEventCategory { + kDefault = 0, + kMetadata = 1, }; enum TraceEventPhase { diff --git a/src/gpgmm/common/WorkerThread.cpp b/src/gpgmm/common/WorkerThread.cpp index 1bb74603a..14833e476 100644 --- a/src/gpgmm/common/WorkerThread.cpp +++ b/src/gpgmm/common/WorkerThread.cpp @@ -28,7 +28,7 @@ namespace gpgmm { AsyncEventImpl() = default; void Wait() override { - TRACE_EVENT0(TraceEventCategory::Default, "AsyncEventImpl.Wait"); + TRACE_EVENT0(TraceEventCategory::kDefault, "AsyncEventImpl.Wait"); std::unique_lock lock(mMutex); mCondition.wait(lock, [this] { return mIsSignaled; }); @@ -63,7 +63,7 @@ namespace gpgmm { std::shared_ptr event = std::make_shared(); std::thread thread([callback, event, name]() { SetThreadName(name); - TRACE_EVENT_METADATA1(TraceEventCategory::Metadata, "thread_name", "name", name); + TRACE_EVENT_METADATA1(TraceEventCategory::kMetadata, "thread_name", "name", name); (*callback)(); event->Signal(); }); diff --git a/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp b/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp index 5a4b90cc3..a1199fd1c 100644 --- a/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/BufferAllocatorD3D12.cpp @@ -38,7 +38,7 @@ namespace gpgmm::d3d12 { std::unique_ptr BufferAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::Default, "BufferAllocator.TryAllocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "BufferAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -48,7 +48,7 @@ namespace gpgmm::d3d12 { const uint64_t heapSize = AlignTo(request.SizeInBytes, request.Alignment); if (heapSize > request.SizeInBytes) { - DebugEvent(GetTypename(), EventMessageId::AlignmentMismatch) + DebugEvent(GetTypename(), EventMessageId::kAlignmentMismatch) << "Resource heap size is larger then the requested size (" + std::to_string(heapSize) + " vs " + std::to_string(request.SizeInBytes) + " bytes)."; @@ -87,7 +87,7 @@ namespace gpgmm::d3d12 { } void BufferAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::Default, "BufferAllocator.DeallocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "BufferAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); mInfo.UsedMemoryUsage -= allocation->GetSize(); diff --git a/src/gpgmm/d3d12/CapsD3D12.cpp b/src/gpgmm/d3d12/CapsD3D12.cpp index ee2891398..ac8066e5b 100644 --- a/src/gpgmm/d3d12/CapsD3D12.cpp +++ b/src/gpgmm/d3d12/CapsD3D12.cpp @@ -98,7 +98,7 @@ namespace gpgmm::d3d12 { caps->mIsAdapterCacheCoherentUMA = arch.CacheCoherentUMA; // D3D12 has no feature to detect support and must be set manually. - if (adapterDesc.VendorId == kIntel_VkVendor) { + if (adapterDesc.VendorId == static_cast(GPUVendor::kIntel_VkVendor)) { caps->mIsResourceAllocationWithinCoherent = true; } diff --git a/src/gpgmm/d3d12/JSONSerializerD3D12.cpp b/src/gpgmm/d3d12/JSONSerializerD3D12.cpp index 4e8a901ac..629ed921d 100644 --- a/src/gpgmm/d3d12/JSONSerializerD3D12.cpp +++ b/src/gpgmm/d3d12/JSONSerializerD3D12.cpp @@ -190,7 +190,7 @@ namespace gpgmm::d3d12 { dict.AddItem("SizeInBytes", desc.SizeInBytes); dict.AddItem("HeapOffset", desc.HeapOffset); dict.AddItem("OffsetFromResource", desc.OffsetFromResource); - dict.AddItem("Method", desc.Method); + dict.AddItem("Method", static_cast(desc.Method)); if (desc.DebugName != nullptr) { dict.AddItem("DebugName", WCharToUTF8(desc.DebugName)); } diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index 3f59a733e..36f548368 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -69,7 +69,7 @@ namespace gpgmm::d3d12 { break; } - gpgmm::DebugEvent("ResidencyManager", EventMessageId::BudgetUpdated) + gpgmm::DebugEvent("ResidencyManager", EventMessageId::kBudgetUpdated) << "Recieved budget notification from OS."; break; } @@ -436,7 +436,7 @@ namespace gpgmm::d3d12 { const DXGI_MEMORY_SEGMENT_GROUP& memorySegmentGroup, uint64_t availableForReservation, uint64_t* pCurrentReservationOut) { - TRACE_EVENT0(TraceEventCategory::Default, "ResidencyManager.SetVideoMemoryReservation"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ResidencyManager.SetVideoMemoryReservation"); std::lock_guard lock(mMutex); @@ -516,7 +516,7 @@ namespace gpgmm::d3d12 { // Ignore when no budget was specified. if (pVideoMemoryInfo->Budget > 0 && pVideoMemoryInfo->CurrentUsage > pVideoMemoryInfo->Budget) { - WarnEvent("ResidencyManager", EventMessageId::BudgetExceeded) + WarnEvent("ResidencyManager", EventMessageId::kBudgetExceeded) << GetMemorySegmentName(memorySegmentGroup, mIsUMA) << " GPU memory exceeds budget: " << GPGMM_BYTES_TO_MB(pVideoMemoryInfo->CurrentUsage) << " vs " @@ -576,7 +576,7 @@ namespace gpgmm::d3d12 { HRESULT ResidencyManager::EvictInternal(uint64_t bytesToEvict, const DXGI_MEMORY_SEGMENT_GROUP& memorySegmentGroup, uint64_t* bytesEvictedOut) { - TRACE_EVENT0(TraceEventCategory::Default, "ResidencyManager.Evict"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ResidencyManager.Evict"); DXGI_QUERY_VIDEO_MEMORY_INFO* pVideoMemoryInfo = GetVideoMemoryInfo(memorySegmentGroup); if (IsBudgetNotificationUpdatesDisabled()) { @@ -586,7 +586,7 @@ namespace gpgmm::d3d12 { // If a budget wasn't provided, it not possible to evict. This is because either the budget // update event has not happened yet or was invalid. if (pVideoMemoryInfo->Budget == 0) { - WarnEvent("GPU page-out", EventMessageId::BudgetInvalid) + WarnEvent("GPU page-out", EventMessageId::kBudgetInvalid) << "GPU memory segment (" << GetMemorySegmentName(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, IsUMA()) << ") was unable to evict memory because a budget was not specified."; @@ -657,7 +657,7 @@ namespace gpgmm::d3d12 { const uint32_t objectEvictCount = static_cast(objectsToEvict.size()); ReturnIfFailed(mDevice->Evict(objectEvictCount, objectsToEvict.data())); - DebugEvent("GPU page-out", EventMessageId::BudgetExceeded) + DebugEvent("GPU page-out", EventMessageId::kBudgetExceeded) << "Number of allocations: " << objectsToEvict.size() << " (" << bytesEvicted << " bytes)."; } @@ -676,7 +676,7 @@ namespace gpgmm::d3d12 { ID3D12CommandList* const* ppCommandLists, ResidencyList* const* ppResidencyLists, uint32_t count) { - TRACE_EVENT0(TraceEventCategory::Default, "ResidencyManager.ExecuteCommandLists"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ResidencyManager.ExecuteCommandLists"); std::lock_guard lock(mMutex); @@ -788,11 +788,11 @@ namespace gpgmm::d3d12 { uint64_t sizeToMakeResident, uint32_t numberOfObjectsToMakeResident, ID3D12Pageable** allocations) { - TRACE_EVENT0(TraceEventCategory::Default, "ResidencyManager.MakeResident"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ResidencyManager.MakeResident"); ReturnIfFailed(EvictInternal(sizeToMakeResident, memorySegmentGroup, nullptr)); - DebugEvent("GPU page-in", EventMessageId::BudgetExceeded) + DebugEvent("GPU page-in", EventMessageId::kBudgetExceeded) << "Number of allocations: " << numberOfObjectsToMakeResident << " (" << sizeToMakeResident << " bytes)."; diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index de062f5ee..05d72a4d5 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -309,7 +309,7 @@ namespace gpgmm::d3d12 { if (allocation == nullptr) { // NeverAllocate always fails, so suppress it. if (!request.NeverAllocate) { - DebugEvent(allocator->GetTypename(), EventMessageId::AllocatorFailed) + DebugEvent(allocator->GetTypename(), EventMessageId::kAllocatorFailed) << "Unable to allocate memory for request."; } return E_FAIL; @@ -317,7 +317,7 @@ namespace gpgmm::d3d12 { HRESULT hr = createResourceFn(*allocation); if (FAILED(hr)) { - InfoEvent(allocator->GetTypename(), EventMessageId::AllocatorFailed) + InfoEvent(allocator->GetTypename(), EventMessageId::kAllocatorFailed) << "Failed to create resource using allocation: " + GetDeviceErrorMessage(device, hr); allocator->DeallocateMemory(std::move(allocation)); @@ -884,7 +884,7 @@ namespace gpgmm::d3d12 { D3D12_RESOURCE_STATES initialResourceState, const D3D12_CLEAR_VALUE* clearValue, ResourceAllocation** ppResourceAllocationOut) { - TRACE_EVENT0(TraceEventCategory::Default, "ResourceAllocator.CreateResource"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.CreateResource"); // If d3d tells us the resource size is invalid, treat the error as OOM. // Otherwise, creating a very large resource could overflow the allocator. @@ -1172,7 +1172,7 @@ namespace gpgmm::d3d12 { if (allocationDescriptor.Flags & ALLOCATION_FLAG_NEVER_FALLBACK) { return E_FAIL; } - InfoEvent(GetTypename(), EventMessageId::AllocatorFailed) + InfoEvent(GetTypename(), EventMessageId::kAllocatorFailed) << "Unable to allocate by using a heap, falling back to a committed resource."; } @@ -1262,7 +1262,7 @@ namespace gpgmm::d3d12 { const D3D12_CLEAR_VALUE* clearValue, D3D12_RESOURCE_STATES initialResourceState, ID3D12Resource** placedResourceOut) { - TRACE_EVENT0(TraceEventCategory::Default, "ResourceAllocator.CreatePlacedResource"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.CreatePlacedResource"); // Before calling CreatePlacedResource, we must ensure the target heap is resident or // CreatePlacedResource will fail. @@ -1291,7 +1291,7 @@ namespace gpgmm::d3d12 { D3D12_RESOURCE_STATES initialResourceState, ID3D12Resource** commitedResourceOut, Heap** resourceHeapOut) { - TRACE_EVENT0(TraceEventCategory::Default, "ResourceAllocator.CreateCommittedResource"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.CreateCommittedResource"); HEAP_DESC resourceHeapDesc = {}; resourceHeapDesc.SizeInBytes = info.SizeInBytes; @@ -1348,7 +1348,7 @@ namespace gpgmm::d3d12 { } RESOURCE_ALLOCATOR_INFO ResourceAllocator::GetInfoInternal() const { - TRACE_EVENT0(TraceEventCategory::Default, "ResourceAllocator.GetInfo"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.GetInfo"); // ResourceAllocator itself could call CreateCommittedResource directly. RESOURCE_ALLOCATOR_INFO result = mInfo; @@ -1426,7 +1426,7 @@ namespace gpgmm::d3d12 { } void ResourceAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::Default, "ResourceAllocator.DeallocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); diff --git a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp index ec7c4d360..02828b76b 100644 --- a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp @@ -38,7 +38,7 @@ namespace gpgmm::d3d12 { std::unique_ptr ResourceHeapAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::Default, "ResourceHeapAllocator.TryAllocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceHeapAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -87,7 +87,7 @@ namespace gpgmm::d3d12 { } if (resourceHeapDesc.SizeInBytes > request.SizeInBytes) { - DebugEvent(GetTypename(), EventMessageId::AlignmentMismatch) + DebugEvent(GetTypename(), EventMessageId::kAlignmentMismatch) << "Resource heap was larger then the requested size (" + std::to_string(resourceHeapDesc.SizeInBytes) + " vs " + std::to_string(request.SizeInBytes) + " bytes)."; @@ -102,7 +102,7 @@ namespace gpgmm::d3d12 { void ResourceHeapAllocator::DeallocateMemory(std::unique_ptr allocation) { std::lock_guard lock(mMutex); - TRACE_EVENT0(TraceEventCategory::Default, "ResourceHeapAllocator.DeallocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceHeapAllocator.DeallocateMemory"); mInfo.UsedMemoryUsage -= allocation->GetSize(); mInfo.UsedMemoryCount--; diff --git a/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp b/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp index 9cbca1400..e2c27cd4c 100644 --- a/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp +++ b/src/gpgmm/vk/DeviceMemoryAllocatorVk.cpp @@ -30,7 +30,7 @@ namespace gpgmm::vk { std::unique_ptr DeviceMemoryAllocator::TryAllocateMemory( const MemoryAllocationRequest& request) { - TRACE_EVENT0(TraceEventCategory::Default, "DeviceMemoryAllocator.TryAllocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "DeviceMemoryAllocator.TryAllocateMemory"); if (request.NeverAllocate) { return {}; @@ -39,7 +39,7 @@ namespace gpgmm::vk { const uint64_t maxDeviceMemoryAllocationCount = mResourceAllocator->GetCaps()->GetMaxDeviceAllocationCount(); if (mInfo.UsedMemoryCount + 1 >= maxDeviceMemoryAllocationCount) { - DebugEvent("DeviceMemoryAllocator.TryAllocateMemory", EventMessageId::AllocatorFailed) + DebugEvent("DeviceMemoryAllocator.TryAllocateMemory", EventMessageId::kAllocatorFailed) << "Device exceeded max number of device memory allocations (" + std::to_string(mInfo.UsedMemoryCount) + " vs " + std::to_string(maxDeviceMemoryAllocationCount) + ")."; @@ -72,7 +72,7 @@ namespace gpgmm::vk { } void DeviceMemoryAllocator::DeallocateMemory(std::unique_ptr allocation) { - TRACE_EVENT0(TraceEventCategory::Default, "DeviceMemoryAllocator.DeallocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "DeviceMemoryAllocator.DeallocateMemory"); VkDeviceMemory deviceMemory = ToBackend(allocation->GetMemory())->GetDeviceMemory(); mResourceAllocator->GetFunctions().FreeMemory(mResourceAllocator->GetDevice(), deviceMemory, diff --git a/src/gpgmm/vk/ResourceAllocatorVk.cpp b/src/gpgmm/vk/ResourceAllocatorVk.cpp index 555c81539..93b04baa5 100644 --- a/src/gpgmm/vk/ResourceAllocatorVk.cpp +++ b/src/gpgmm/vk/ResourceAllocatorVk.cpp @@ -350,7 +350,7 @@ namespace gpgmm::vk { } if (memoryAllocation == nullptr) { - ErrorEvent("GpResourceAllocator.TryAllocateResource", EventMessageId::AllocatorFailed) + ErrorEvent("GpResourceAllocator.TryAllocateResource", EventMessageId::kAllocatorFailed) << "Unable to allocate memory for resource."; return VK_ERROR_UNKNOWN; diff --git a/src/include/min/gpgmm.h b/src/include/min/gpgmm.h index 071199eb3..c1a38d78c 100644 --- a/src/include/min/gpgmm.h +++ b/src/include/min/gpgmm.h @@ -62,7 +62,7 @@ namespace gpgmm { uint64_t Alignment; }; - enum AllocationMethod { + enum class AllocationMethod { kUndefined = 0, kStandalone = 1, kSubAllocated = 2, diff --git a/src/tests/DummyMemoryAllocator.h b/src/tests/DummyMemoryAllocator.h index ad26c82d2..eb4878446 100644 --- a/src/tests/DummyMemoryAllocator.h +++ b/src/tests/DummyMemoryAllocator.h @@ -31,7 +31,7 @@ namespace gpgmm { std::unique_ptr TryAllocateMemory( const MemoryAllocationRequest& request) override { - TRACE_EVENT0(TraceEventCategory::Default, "DummyMemoryAllocator.TryAllocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "DummyMemoryAllocator.TryAllocateMemory"); std::lock_guard lock(mMutex); @@ -47,7 +47,7 @@ namespace gpgmm { } void DeallocateMemory(std::unique_ptr allocation) override { - TRACE_EVENT0(TraceEventCategory::Default, "DummyMemoryAllocator.DeallocateMemory"); + TRACE_EVENT0(TraceEventCategory::kDefault, "DummyMemoryAllocator.DeallocateMemory"); std::lock_guard lock(mMutex); diff --git a/src/tests/unittests/EventTraceWriterTests.cpp b/src/tests/unittests/EventTraceWriterTests.cpp index d7cb8a147..7dc13c27c 100644 --- a/src/tests/unittests/EventTraceWriterTests.cpp +++ b/src/tests/unittests/EventTraceWriterTests.cpp @@ -37,7 +37,7 @@ class EventTraceWriterTests : public testing::Test { TEST_F(EventTraceWriterTests, SingleThreadWrites) { constexpr uint32_t kEventCount = 64u; for (size_t i = 0; i < kEventCount; i++) { - TRACE_EVENT_INSTANT0(TraceEventCategory::Default, "InstantEvent"); + TRACE_EVENT_INSTANT0(TraceEventCategory::kDefault, "InstantEvent"); } // 1 event per thread + 1 metadata event for main thread name. @@ -49,7 +49,7 @@ TEST_F(EventTraceWriterTests, MultiThreadWrites) { std::vector threads(kThreadCount); for (size_t threadIdx = 0; threadIdx < threads.size(); threadIdx++) { threads[threadIdx] = std::thread( - [&]() { TRACE_EVENT_INSTANT0(TraceEventCategory::Default, "InstantEvent"); }); + [&]() { TRACE_EVENT_INSTANT0(TraceEventCategory::kDefault, "InstantEvent"); }); } for (std::thread& thread : threads) {