diff --git a/include/gpgmm.h b/include/gpgmm.h index 72e67fea0..ac73df3c6 100644 --- a/include/gpgmm.h +++ b/include/gpgmm.h @@ -24,83 +24,6 @@ namespace gpgmm { - /** \struct MemoryAllocatorStats - Additional information about the memory allocator usage. - */ - struct MemoryAllocatorStats { - /** \brief Number of used sub-allocated blocks within the same memory. - */ - uint32_t UsedBlockCount; - - /** \brief Total size, in bytes, of used sub-allocated blocks. - */ - uint64_t UsedBlockUsage; - - /** \brief Number of used memory allocations. - */ - uint32_t UsedMemoryCount; - - /** \brief Total size, in bytes, of used memory. - */ - uint64_t UsedMemoryUsage; - - /** \brief Total size, in bytes, of free memory. - */ - uint64_t FreeMemoryUsage; - - /** \brief Cache misses not eliminated by prefetching. - */ - uint64_t PrefetchedMemoryMisses; - - /** \brief Cache misses eliminated because of prefetching. - */ - uint64_t PrefetchedMemoryMissesEliminated; - - /** \brief Requested size was NOT cached. - */ - uint64_t SizeCacheMisses; - - /** \brief Requested size was cached. - */ - uint64_t SizeCacheHits; - - /** \brief Adds or sums together two infos. - */ - MemoryAllocatorStats& operator+=(const MemoryAllocatorStats& rhs); - }; - - /** \enum AllocationMethod - Represents how memory was allocated. - */ - enum class AllocationMethod { - - /** \brief Not yet allocated or invalid. - - This is an invalid state that assigned temporary before the actual method is known. - */ - kUndefined = 0, - - /** \brief Not sub-divided. - - One and only one allocation exists for the memory. - */ - kStandalone = 1, - - /** \brief Sub-divided using one or more allocations. - - Underlying memory will be broken up into one or more memory allocations. - */ - kSubAllocated = 2, - - /** \brief Sub-divided within a single memory allocation. - - A single memory allocation will be broken into one or more sub-allocations. - */ - kSubAllocatedWithin = 3, - }; - - - } // namespace gpgmm #endif // INCLUDE_GPGMM_H_ diff --git a/include/gpgmm_d3d12.h b/include/gpgmm_d3d12.h index 78a5cb697..e64981741 100644 --- a/include/gpgmm_d3d12.h +++ b/include/gpgmm_d3d12.h @@ -504,6 +504,35 @@ namespace gpgmm::d3d12 { uint64_t CurrentMemoryCount; }; + /** \enum ALLOCATION_METHOD + Represents how memory was allocated. + */ + enum ALLOCATION_METHOD { + /** \brief Not yet allocated or invalid. + + This is an invalid state that assigned temporary before the actual method is known. + */ + ALLOCATION_METHOD_UNKNOWN = 0, + + /** \brief Not sub-divided. + + One and only one allocation exists for the memory. + */ + ALLOCATION_METHOD_STANDALONE = 1, + + /** \brief Sub-divided using one or more allocations. + + Underlying memory will be broken up into one or more memory allocations. + */ + ALLOCATION_METHOD_SUBALLOCATED = 2, + + /** \brief Sub-divided within a single memory allocation. + + A single memory allocation will be broken into one or more sub-allocations. + */ + ALLOCATION_METHOD_SUBALLOCATED_WITHIN = 3, + }; + /** \brief ResidencyManager tracks and maintains one or more Heap within a residency cache. A Heap is considered "resident" when it is accessible by the GPU. A Heap can be made explicitly @@ -633,7 +662,7 @@ namespace gpgmm::d3d12 { /** \brief Method used to allocate memory for the resource. */ - AllocationMethod Method; + ALLOCATION_METHOD Method; }; /** \brief ResourceAllocation is MemoryAllocation that contains a ID3D12Resource. @@ -1152,7 +1181,46 @@ namespace gpgmm::d3d12 { ALLOCATOR_FEATURE_RESOURCE_ALLOCATION_SUPPORT, }; - using RESOURCE_ALLOCATOR_STATS = MemoryAllocatorStats; + /** \struct RESOURCE_ALLOCATOR_STATS + Additional information about the resource allocator usage. + */ + struct RESOURCE_ALLOCATOR_STATS { + /** \brief Number of used sub-allocated blocks within the same memory. + */ + uint32_t UsedBlockCount; + + /** \brief Total size, in bytes, of used sub-allocated blocks. + */ + uint64_t UsedBlockUsage; + + /** \brief Number of used memory allocations. + */ + uint32_t UsedHeapCount; + + /** \brief Total size, in bytes, of used memory. + */ + uint64_t UsedHeapUsage; + + /** \brief Total size, in bytes, of free memory. + */ + uint64_t FreeHeapUsage; + + /** \brief Cache misses not eliminated by prefetching. + */ + uint64_t PrefetchedHeapMisses; + + /** \brief Cache misses eliminated because of prefetching. + */ + uint64_t PrefetchedHeapMissesEliminated; + + /** \brief Requested size was NOT cached. + */ + uint64_t SizeCacheMisses; + + /** \brief Requested size was cached. + */ + uint64_t SizeCacheHits; + }; /** \brief ResourceAllocator is a MemoryAllocator that creates ID3D12Resources in a ResourceAllocation. diff --git a/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp b/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp index 1a9e7c245..cd63b5ae1 100644 --- a/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp +++ b/src/fuzzers/D3D12ResidencyManagerFuzzer.cpp @@ -96,7 +96,7 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) { // Keep allocating until we reach the budget. uint64_t memoryUnderBudget = GetBudgetLeft(gResidencyManager.Get(), bufferMemorySegment); - while (GetStats(gResourceAllocator).UsedMemoryUsage + kBufferMemorySize < memoryUnderBudget) { + while (GetStats(gResourceAllocator).UsedHeapUsage + kBufferMemorySize < memoryUnderBudget) { ComPtr allocation; if (FAILED(gResourceAllocator->CreateResource({}, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation))) { diff --git a/src/gpgmm/common/JSONSerializer.cpp b/src/gpgmm/common/JSONSerializer.cpp index 835649383..eb3c6f601 100644 --- a/src/gpgmm/common/JSONSerializer.cpp +++ b/src/gpgmm/common/JSONSerializer.cpp @@ -34,17 +34,6 @@ namespace gpgmm { return dict; } - // static - JSONDict JSONSerializer::Serialize(const MemoryAllocatorStats& info) { - JSONDict dict; - dict.AddItem("UsedBlockCount", info.UsedBlockCount); - dict.AddItem("UsedMemoryCount", info.UsedMemoryCount); - dict.AddItem("UsedBlockUsage", info.UsedBlockUsage); - dict.AddItem("FreeMemoryUsage", info.FreeMemoryUsage); - dict.AddItem("UsedMemoryUsage", info.UsedMemoryUsage); - return dict; - } - // static JSONDict JSONSerializer::Serialize(const MemoryAllocationRequest& desc) { JSONDict dict; diff --git a/src/gpgmm/common/JSONSerializer.h b/src/gpgmm/common/JSONSerializer.h index a4aaa0308..cdf67a8ed 100644 --- a/src/gpgmm/common/JSONSerializer.h +++ b/src/gpgmm/common/JSONSerializer.h @@ -19,8 +19,7 @@ namespace gpgmm { - // Forward declare common types. - struct MemoryAllocatorStats; + // Forward declare common types.; struct MemoryAllocationRequest; struct MessageInfo; @@ -28,7 +27,6 @@ namespace gpgmm { public: static JSONDict Serialize(); static JSONDict Serialize(const MessageInfo& info); - static JSONDict Serialize(const MemoryAllocatorStats& info); static JSONDict Serialize(const MemoryAllocationRequest& desc); static JSONDict Serialize(const void* objectPtr); }; diff --git a/src/gpgmm/common/MemoryAllocation.h b/src/gpgmm/common/MemoryAllocation.h index 6c66084f5..0ca0cf77f 100644 --- a/src/gpgmm/common/MemoryAllocation.h +++ b/src/gpgmm/common/MemoryAllocation.h @@ -23,6 +23,36 @@ namespace gpgmm { + /** \enum AllocationMethod + Represents how memory was allocated. + */ + enum class AllocationMethod { + + /** \brief Not yet allocated or invalid. + + This is an invalid state that assigned temporary before the actual method is known. + */ + kUndefined = 0, + + /** \brief Not sub-divided. + + One and only one allocation exists for the memory. + */ + kStandalone = 1, + + /** \brief Sub-divided using one or more allocations. + + Underlying memory will be broken up into one or more memory allocations. + */ + kSubAllocated = 2, + + /** \brief Sub-divided within a single memory allocation. + + A single memory allocation will be broken into one or more sub-allocations. + */ + kSubAllocatedWithin = 3, + }; + class MemoryBase; struct MemoryBlock; class MemoryAllocator; diff --git a/src/gpgmm/common/MemoryAllocator.h b/src/gpgmm/common/MemoryAllocator.h index d9c9b535e..d47fb9028 100644 --- a/src/gpgmm/common/MemoryAllocator.h +++ b/src/gpgmm/common/MemoryAllocator.h @@ -110,6 +110,51 @@ namespace gpgmm { uint64_t AvailableForAllocation; }; + /** \struct MemoryAllocatorStats + Additional information about the memory allocator usage. + */ + struct MemoryAllocatorStats { + /** \brief Number of used sub-allocated blocks within the same memory. + */ + uint32_t UsedBlockCount; + + /** \brief Total size, in bytes, of used sub-allocated blocks. + */ + uint64_t UsedBlockUsage; + + /** \brief Number of used memory allocations. + */ + uint32_t UsedMemoryCount; + + /** \brief Total size, in bytes, of used memory. + */ + uint64_t UsedMemoryUsage; + + /** \brief Total size, in bytes, of free memory. + */ + uint64_t FreeMemoryUsage; + + /** \brief Cache misses not eliminated by prefetching. + */ + uint64_t PrefetchedMemoryMisses; + + /** \brief Cache misses eliminated because of prefetching. + */ + uint64_t PrefetchedMemoryMissesEliminated; + + /** \brief Requested size was NOT cached. + */ + uint64_t SizeCacheMisses; + + /** \brief Requested size was cached. + */ + uint64_t SizeCacheHits; + + /** \brief Adds or sums together two infos. + */ + MemoryAllocatorStats& operator+=(const MemoryAllocatorStats& rhs); + }; + class BlockAllocator; /** \brief MemoryAllocator services a fixed or variable sized MemoryAllocationRequest. diff --git a/src/gpgmm/d3d12/JSONSerializerD3D12.cpp b/src/gpgmm/d3d12/JSONSerializerD3D12.cpp index 841a32e84..cd5e6cffa 100644 --- a/src/gpgmm/d3d12/JSONSerializerD3D12.cpp +++ b/src/gpgmm/d3d12/JSONSerializerD3D12.cpp @@ -30,11 +30,6 @@ namespace gpgmm::d3d12 { return {}; } - // static - JSONDict JSONSerializer::Serialize(const RESOURCE_ALLOCATOR_STATS& info) { - return gpgmm::JSONSerializer::Serialize(info); - } - // static JSONDict JSONSerializer::Serialize(const ALLOCATOR_DESC& desc) { JSONDict dict; diff --git a/src/gpgmm/d3d12/JSONSerializerD3D12.h b/src/gpgmm/d3d12/JSONSerializerD3D12.h index a6730c125..887889be0 100644 --- a/src/gpgmm/d3d12/JSONSerializerD3D12.h +++ b/src/gpgmm/d3d12/JSONSerializerD3D12.h @@ -44,7 +44,6 @@ namespace gpgmm::d3d12 { class JSONSerializer final : public gpgmm::JSONSerializer { public: static JSONDict Serialize(); - static JSONDict Serialize(const RESOURCE_ALLOCATOR_STATS& info); static JSONDict Serialize(const ALLOCATOR_DESC& desc); static JSONDict Serialize(const CREATE_RESOURCE_DESC& desc); static JSONDict Serialize(const ALLOCATION_DESC& desc); diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp index 0a8132b8d..486a3c7e4 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp @@ -50,7 +50,7 @@ namespace gpgmm::d3d12 { : MemoryAllocation(allocator, resourceHeap, desc.HeapOffset, - desc.Method, + static_cast(desc.Method), block, desc.SizeInBytes), mResidencyManager(residencyManager), @@ -77,7 +77,7 @@ namespace gpgmm::d3d12 { void** ppDataOut) { // Allocation coordinates relative to the resource cannot be used when specifying // subresource-relative coordinates. - if (subresource > 0 && GetMethod() == AllocationMethod::kSubAllocatedWithin) { + if (subresource > 0 && GetInfo().Method == ALLOCATION_METHOD_SUBALLOCATED_WITHIN) { gpgmm::ErrorEvent(MessageId::kBadOperation, this) << "Mapping a sub-allocation within a resource cannot use " "non-zero subresource-relative coordinates."; @@ -113,7 +113,7 @@ namespace gpgmm::d3d12 { void ResourceAllocation::Unmap(uint32_t subresource, const D3D12_RANGE* pWrittenRange) { // Allocation coordinates relative to the resource cannot be used when specifying // subresource-relative coordinates. - if (subresource > 0 && GetMethod() == AllocationMethod::kSubAllocatedWithin) { + if (subresource > 0 && GetInfo().Method == ALLOCATION_METHOD_SUBALLOCATED_WITHIN) { gpgmm::ErrorEvent(MessageId::kBadOperation, this) << "Unmapping a sub-allocation within a resource cannot use " "non-zero subresource-relative coordinates."; @@ -146,7 +146,7 @@ namespace gpgmm::d3d12 { } RESOURCE_ALLOCATION_INFO ResourceAllocation::GetInfo() const { - return {GetSize(), GetAlignment(), GetMethod()}; + return {GetSize(), GetAlignment(), static_cast(GetMethod())}; } const char* ResourceAllocation::GetTypename() const { @@ -163,7 +163,8 @@ namespace gpgmm::d3d12 { HRESULT ResourceAllocation::SetDebugNameImpl(LPCWSTR name) { // D3D name is set per resource. - if (GetDebugName() != nullptr && GetMethod() == AllocationMethod::kSubAllocatedWithin) { + if (GetDebugName() != nullptr && + GetInfo().Method == ALLOCATION_METHOD_SUBALLOCATED_WITHIN) { return S_FALSE; } diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.h b/src/gpgmm/d3d12/ResourceAllocationD3D12.h index 8dfac2a65..e4c5b202e 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.h +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.h @@ -32,7 +32,7 @@ namespace gpgmm::d3d12 { uint64_t SizeInBytes; uint64_t HeapOffset; uint64_t OffsetFromResource; - AllocationMethod Method; + ALLOCATION_METHOD Method; LPCWSTR DebugName; }; diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 3b85232ee..1abffd7c9 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -1132,7 +1132,7 @@ namespace gpgmm::d3d12 { RESOURCE_ALLOCATOR_STATS allocationStats = {}; ReturnIfFailed(QueryStatsInternal(&allocationStats)); - request.AvailableForAllocation = allocationStats.FreeMemoryUsage; + request.AvailableForAllocation = allocationStats.FreeHeapUsage; DebugLog(MessageId::kBudgetExceeded) << "Current usage exceeded budget: " @@ -1188,7 +1188,7 @@ namespace gpgmm::d3d12 { RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.SizeInBytes = resourceDescriptor.Width; allocationDesc.HeapOffset = kInvalidOffset; - allocationDesc.Method = AllocationMethod::kSubAllocatedWithin; + allocationDesc.Method = ALLOCATION_METHOD_SUBALLOCATED_WITHIN; allocationDesc.OffsetFromResource = subAllocation.GetOffset(); allocationDesc.DebugName = allocationDescriptor.DebugName; @@ -1227,7 +1227,8 @@ namespace gpgmm::d3d12 { RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.SizeInBytes = request.SizeInBytes; allocationDesc.HeapOffset = subAllocation.GetOffset(); - allocationDesc.Method = subAllocation.GetMethod(); + allocationDesc.Method = + static_cast(subAllocation.GetMethod()); allocationDesc.OffsetFromResource = 0; allocationDesc.DebugName = allocationDescriptor.DebugName; @@ -1267,7 +1268,7 @@ namespace gpgmm::d3d12 { RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.SizeInBytes = request.SizeInBytes; allocationDesc.HeapOffset = allocation.GetOffset(); - allocationDesc.Method = allocation.GetMethod(); + allocationDesc.Method = static_cast(allocation.GetMethod()); allocationDesc.OffsetFromResource = 0; allocationDesc.DebugName = allocationDescriptor.DebugName; @@ -1333,7 +1334,7 @@ namespace gpgmm::d3d12 { RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapOffset = kInvalidOffset; allocationDesc.SizeInBytes = request.SizeInBytes; - allocationDesc.Method = AllocationMethod::kStandalone; + allocationDesc.Method = ALLOCATION_METHOD_STANDALONE; allocationDesc.DebugName = allocationDescriptor.DebugName; if (ppResourceAllocationOut != nullptr) { @@ -1424,7 +1425,7 @@ namespace gpgmm::d3d12 { RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapOffset = kInvalidSize; allocationDesc.SizeInBytes = allocationSize; - allocationDesc.Method = AllocationMethod::kStandalone; + allocationDesc.Method = ALLOCATION_METHOD_STANDALONE; *ppResourceAllocationOut = new ResourceAllocation(allocationDesc, nullptr, this, static_cast(resourceHeap.Detach()), @@ -1517,7 +1518,7 @@ namespace gpgmm::d3d12 { TRACE_EVENT0(TraceEventCategory::kDefault, "ResourceAllocator.QueryStats"); // ResourceAllocator itself could call CreateCommittedResource directly. - RESOURCE_ALLOCATOR_STATS result = mStats; + MemoryAllocatorStats result = mStats; for (uint32_t resourceHeapTypeIndex = 0; resourceHeapTypeIndex < kNumOfResourceHeapTypes; resourceHeapTypeIndex++) { @@ -1571,7 +1572,16 @@ namespace gpgmm::d3d12 { SafeDivide(result.SizeCacheHits, result.SizeCacheMisses + result.SizeCacheHits) * 100); if (pResourceAllocatorStats != nullptr) { - *pResourceAllocatorStats = result; + pResourceAllocatorStats->UsedBlockCount = result.UsedBlockCount; + pResourceAllocatorStats->UsedBlockUsage = result.UsedBlockUsage; + pResourceAllocatorStats->UsedHeapCount = result.UsedMemoryCount; + pResourceAllocatorStats->UsedHeapUsage = result.UsedMemoryUsage; + pResourceAllocatorStats->FreeHeapUsage = result.FreeMemoryUsage; + pResourceAllocatorStats->PrefetchedHeapMisses = result.PrefetchedMemoryMisses; + pResourceAllocatorStats->PrefetchedHeapMissesEliminated = + result.PrefetchedMemoryMissesEliminated; + pResourceAllocatorStats->SizeCacheMisses = result.SizeCacheMisses; + pResourceAllocatorStats->SizeCacheHits = result.SizeCacheHits; } else { return S_FALSE; } diff --git a/src/mvi/gpgmm.cpp b/src/mvi/gpgmm.cpp index d88f8f423..43e545545 100644 --- a/src/mvi/gpgmm.cpp +++ b/src/mvi/gpgmm.cpp @@ -35,10 +35,6 @@ namespace gpgmm { return 0; } - MemoryAllocatorStats MemoryAllocator::GetStats() const { - return mStats; - } - // MemoryAllocation MemoryAllocation::MemoryAllocation(MemoryAllocator* allocator, MemoryBase* memory) diff --git a/src/mvi/gpgmm.h b/src/mvi/gpgmm.h index 32994b6cd..3509517ab 100644 --- a/src/mvi/gpgmm.h +++ b/src/mvi/gpgmm.h @@ -39,10 +39,6 @@ namespace gpgmm { public: virtual void DeallocateMemory(std::unique_ptr allocation) = 0; virtual uint64_t ReleaseMemory(uint64_t bytesToRelease); - virtual MemoryAllocatorStats GetStats() const; - - protected: - MemoryAllocatorStats mStats = {}; }; // MemoryAllocation represents a range of memory. A MemoryAllocation object will be held alive diff --git a/src/mvi/gpgmm_d3d12.cpp b/src/mvi/gpgmm_d3d12.cpp index da6604c2a..febbb9791 100644 --- a/src/mvi/gpgmm_d3d12.cpp +++ b/src/mvi/gpgmm_d3d12.cpp @@ -383,11 +383,6 @@ namespace gpgmm::d3d12 { CreateCommittedResourceCallbackContext::CreateHeap, &callbackContext, &resourceHeap)); - const uint64_t allocationSize = resourceHeapDesc.SizeInBytes; - mStats.UsedMemoryUsage += allocationSize; - mStats.UsedMemoryCount++; - mStats.UsedBlockUsage += allocationSize; - *ppResourceAllocationOut = new ResourceAllocation(this, static_cast(resourceHeap), std::move(committedResource)); @@ -421,10 +416,6 @@ namespace gpgmm::d3d12 { } void ResourceAllocator::DeallocateMemory(std::unique_ptr allocation) { - const uint64_t& allocationSize = allocation->GetSize(); - mStats.UsedMemoryUsage -= allocationSize; - mStats.UsedMemoryCount--; - mStats.UsedBlockUsage -= allocationSize; delete allocation->GetMemory(); } diff --git a/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp b/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp index 0dd1445d9..95c0f0358 100644 --- a/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp +++ b/src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp @@ -331,7 +331,7 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith } mReplayedMemoryStats.PeakUsage = - std::max(GetStats(resourceAllocator).UsedMemoryUsage, + std::max(GetStats(resourceAllocator).UsedHeapUsage, mReplayedMemoryStats.PeakUsage); } break; diff --git a/src/tests/end2end/D3D12ResidencyManagerTests.cpp b/src/tests/end2end/D3D12ResidencyManagerTests.cpp index a3c77578a..b28fad7ff 100644 --- a/src/tests/end2end/D3D12ResidencyManagerTests.cpp +++ b/src/tests/end2end/D3D12ResidencyManagerTests.cpp @@ -482,7 +482,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudget) { // Keep allocating until we reach the budget. std::vector> allocationsBelowBudget = {}; - while (GetStats(resourceAllocator).UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { + while (GetStats(resourceAllocator).UsedHeapUsage + kBufferMemorySize <= kDefaultBudget) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( bufferAllocationDesc, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); @@ -499,9 +499,9 @@ TEST_F(D3D12ResidencyManagerTests, OverBudget) { // Allocating the same amount over budget, where older allocations will be evicted. std::vector> allocationsAboveBudget = {}; - const uint64_t currentMemoryUsage = GetStats(resourceAllocator).UsedMemoryUsage; + const uint64_t currentMemoryUsage = GetStats(resourceAllocator).UsedHeapUsage; - while (currentMemoryUsage + kMemoryOverBudget > GetStats(resourceAllocator).UsedMemoryUsage) { + while (currentMemoryUsage + kMemoryOverBudget > GetStats(resourceAllocator).UsedHeapUsage) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( bufferAllocationDesc, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); @@ -555,7 +555,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetAsync) { // Keep allocating until we reach the budget. Should a budget change occur, we must also // terminate the loop since we cannot guarantee all allocations will be created resident. std::vector> allocations = {}; - while (GetStats(resourceAllocator).UsedMemoryUsage + kBufferMemorySize < memoryUnderBudget && + while (GetStats(resourceAllocator).UsedHeapUsage + kBufferMemorySize < memoryUnderBudget && GetBudgetLeft(residencyManager.Get(), bufferMemorySegment) >= kBufferMemorySize) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( @@ -596,7 +596,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetDisablesGrowth) { ALLOCATION_DESC bufferAllocationDesc = {}; bufferAllocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT; - while (GetStats(resourceAllocator).UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { + while (GetStats(resourceAllocator).UsedHeapUsage + kBufferMemorySize <= kDefaultBudget) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( bufferAllocationDesc, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); @@ -639,7 +639,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetWithLockedHeaps) { // Keep allocating until we reach the budget. std::vector> allocationsBelowBudget = {}; - while (GetStats(resourceAllocator).UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { + while (GetStats(resourceAllocator).UsedHeapUsage + kBufferMemorySize <= kDefaultBudget) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( bufferAllocationDesc, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); @@ -693,7 +693,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetExecuteCommandList) { // Create the first set of heaps below the budget. std::vector> firstSetOfHeaps = {}; - while (GetStats(resourceAllocator).UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { + while (GetStats(resourceAllocator).UsedHeapUsage + kBufferMemorySize <= kDefaultBudget) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( {}, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); @@ -798,7 +798,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetImported) { // Keep importing externally allocated resources until we reach the budget. std::vector> allocationsBelowBudget = {}; - while (GetStats(resourceAllocator).UsedMemoryUsage + kBufferMemorySize <= kDefaultBudget) { + while (GetStats(resourceAllocator).UsedHeapUsage + kBufferMemorySize <= kDefaultBudget) { D3D12_HEAP_PROPERTIES heapProperties = {}; heapProperties.Type = D3D12_HEAP_TYPE_DEFAULT; @@ -823,9 +823,9 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetImported) { // Allocating the same amount over budget, where older allocations will be evicted. std::vector> allocationsAboveBudget = {}; - const uint64_t currentMemoryUsage = GetStats(resourceAllocator).UsedMemoryUsage; + const uint64_t currentMemoryUsage = GetStats(resourceAllocator).UsedHeapUsage; - while (currentMemoryUsage + kMemoryOverBudget > GetStats(resourceAllocator).UsedMemoryUsage) { + while (currentMemoryUsage + kMemoryOverBudget > GetStats(resourceAllocator).UsedHeapUsage) { ComPtr allocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( {}, bufferDesc, D3D12_RESOURCE_STATE_COMMON, nullptr, &allocation)); diff --git a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp index 8844a44fb..d81c08845 100644 --- a/src/tests/end2end/D3D12ResourceAllocatorTests.cpp +++ b/src/tests/end2end/D3D12ResourceAllocatorTests.cpp @@ -210,7 +210,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSameHeap) { nullptr, &bufferAllocation)); } - EXPECT_EQ(GetStats(resourceAllocator).FreeMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(GetStats(resourceAllocator).FreeHeapUsage, kBufferOf4MBAllocationSize); // Reuse memory for texture in Heap A. { @@ -220,7 +220,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSameHeap) { D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &textureAllocation)); } - EXPECT_EQ(GetStats(resourceAllocator).FreeMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(GetStats(resourceAllocator).FreeHeapUsage, kBufferOf4MBAllocationSize); } // Exceeding the max resource heap size should always fail. @@ -246,7 +246,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSeperateHeap) { allocatorDesc.PreferredResourceHeapSize); } - EXPECT_EQ(GetStats(resourceAllocator).FreeMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(GetStats(resourceAllocator).FreeHeapUsage, kBufferOf4MBAllocationSize); // Reuse memory for texture in Heap A. { @@ -259,7 +259,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAndTextureInSeperateHeap) { allocatorDesc.PreferredResourceHeapSize); } - EXPECT_EQ(GetStats(resourceAllocator).FreeMemoryUsage, kBufferOf4MBAllocationSize * 2); + EXPECT_EQ(GetStats(resourceAllocator).FreeHeapUsage, kBufferOf4MBAllocationSize * 2); } // Exceeding the max resource heap size should always fail. @@ -736,13 +736,13 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferUMA) { resourceAllocator->CreateResource({}, CreateBasicBufferDesc(kBufferOf4MBAllocationSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, nullptr)); - EXPECT_EQ(GetStats(resourceAllocator).FreeMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(GetStats(resourceAllocator).FreeHeapUsage, kBufferOf4MBAllocationSize); ASSERT_SUCCEEDED( resourceAllocator->CreateResource({}, CreateBasicBufferDesc(kBufferOf4MBAllocationSize), D3D12_RESOURCE_STATE_COPY_DEST, nullptr, nullptr)); - EXPECT_EQ(GetStats(resourceAllocator).FreeMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(GetStats(resourceAllocator).FreeHeapUsage, kBufferOf4MBAllocationSize); ALLOCATION_DESC allocationDesc = {}; allocationDesc.HeapType = D3D12_HEAP_TYPE_READBACK; @@ -751,7 +751,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferUMA) { allocationDesc, CreateBasicBufferDesc(kBufferOf4MBAllocationSize), D3D12_RESOURCE_STATE_COPY_DEST, nullptr, nullptr)); - EXPECT_EQ(GetStats(resourceAllocator).FreeMemoryUsage, kBufferOf4MBAllocationSize * 2); + EXPECT_EQ(GetStats(resourceAllocator).FreeHeapUsage, kBufferOf4MBAllocationSize * 2); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferDisableUMA) { @@ -799,7 +799,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferDisableUMA) { allocationDesc, CreateBasicBufferDesc(kBufferOf4MBAllocationSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, nullptr)); - EXPECT_EQ(GetStats(resourceAllocator).FreeMemoryUsage, kBufferOf4MBAllocationSize * 2); + EXPECT_EQ(GetStats(resourceAllocator).FreeHeapUsage, kBufferOf4MBAllocationSize * 2); } } @@ -871,10 +871,10 @@ TEST_F(D3D12ResourceAllocatorTests, CreateMultisampledTexture) { allocation->GetInfo().SizeInBytes, static_cast(D3D12_DEFAULT_MSAA_RESOURCE_PLACEMENT_ALIGNMENT))); - EXPECT_EQ(GetStats(resourceAllocator).UsedMemoryCount, 1u); + EXPECT_EQ(GetStats(resourceAllocator).UsedHeapCount, 1u); } - EXPECT_EQ(GetStats(resourceAllocator).UsedMemoryCount, 0u); + EXPECT_EQ(GetStats(resourceAllocator).UsedHeapCount, 0u); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferImported) { @@ -970,9 +970,9 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferAlwaysCommitted) { ASSERT_FAILED(resourceHeap.As(&heap)); // Commited resources must use all the memory allocated. - EXPECT_EQ(GetStats(resourceAllocator).UsedMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(GetStats(resourceAllocator).UsedHeapUsage, kBufferOf4MBAllocationSize); EXPECT_EQ(GetStats(resourceAllocator).UsedBlockUsage, - GetStats(resourceAllocator).UsedMemoryUsage); + GetStats(resourceAllocator).UsedHeapUsage); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverAllocate) { @@ -1031,13 +1031,13 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { smallBufferDesc, CreateBasicBufferDesc(4u, 1), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &smallBuffer)); - EXPECT_EQ(smallBuffer->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(smallBuffer->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); EXPECT_EQ(smallBuffer->GetInfo().SizeInBytes, 4u); EXPECT_EQ(smallBuffer->GetOffsetFromResource(), 0u); EXPECT_EQ(smallBuffer->GetInfo().Alignment, 4u); // Must re-align. EXPECT_EQ(GetStats(resourceAllocator).UsedBlockCount, 1u); - EXPECT_EQ(GetStats(resourceAllocator).UsedMemoryCount, 1u); + EXPECT_EQ(GetStats(resourceAllocator).UsedHeapCount, 1u); EXPECT_EQ(GetStats(resourceAllocator).UsedBlockUsage, smallBuffer->GetInfo().SizeInBytes); } { @@ -1049,13 +1049,13 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { smallBufferWithinDesc, CreateBasicBufferDesc(4u, 16), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &smallBuffer)); - EXPECT_EQ(smallBuffer->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(smallBuffer->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); EXPECT_EQ(smallBuffer->GetInfo().SizeInBytes, 16u); EXPECT_EQ(smallBuffer->GetOffsetFromResource(), 0u); EXPECT_EQ(smallBuffer->GetInfo().Alignment, 16u); EXPECT_EQ(GetStats(resourceAllocator).UsedBlockCount, 1u); - EXPECT_EQ(GetStats(resourceAllocator).UsedMemoryCount, 1u); + EXPECT_EQ(GetStats(resourceAllocator).UsedHeapCount, 1u); EXPECT_EQ(GetStats(resourceAllocator).UsedBlockUsage, smallBuffer->GetInfo().SizeInBytes); } { @@ -1067,13 +1067,13 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { smallBufferWithinDesc, CreateBasicBufferDesc(4u), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &smallBuffer)); - EXPECT_EQ(smallBuffer->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(smallBuffer->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); EXPECT_EQ(smallBuffer->GetInfo().SizeInBytes, 256u); EXPECT_EQ(smallBuffer->GetOffsetFromResource(), 0u); EXPECT_EQ(smallBuffer->GetInfo().Alignment, 256u); // Re-align EXPECT_EQ(GetStats(resourceAllocator).UsedBlockCount, 1u); - EXPECT_EQ(GetStats(resourceAllocator).UsedMemoryCount, 1u); + EXPECT_EQ(GetStats(resourceAllocator).UsedHeapCount, 1u); EXPECT_EQ(GetStats(resourceAllocator).UsedBlockUsage, smallBuffer->GetInfo().SizeInBytes); } { @@ -1085,7 +1085,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { smallBufferWithinDesc, CreateBasicBufferDesc(4u), D3D12_RESOURCE_STATE_COPY_DEST, nullptr, &smallBuffer)); - EXPECT_EQ(smallBuffer->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(smallBuffer->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); EXPECT_EQ(smallBuffer->GetInfo().SizeInBytes, 4u); EXPECT_EQ(smallBuffer->GetOffsetFromResource(), 0u); EXPECT_EQ(smallBuffer->GetInfo().Alignment, 4u); @@ -1099,7 +1099,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { smallBufferWithinDesc, CreateBasicBufferDesc(3u), D3D12_RESOURCE_STATE_COPY_DEST, nullptr, &smallBuffer)); - EXPECT_EQ(smallBuffer->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(smallBuffer->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); EXPECT_EQ(smallBuffer->GetInfo().SizeInBytes, 4u); EXPECT_EQ(smallBuffer->GetOffsetFromResource(), 0u); EXPECT_EQ(smallBuffer->GetInfo().Alignment, 4u); // Re-align @@ -1114,7 +1114,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { ASSERT_SUCCEEDED(resourceAllocator->CreateResource( invalidSmallBufferWithinDesc, CreateBasicBufferDesc(3u), D3D12_RESOURCE_STATE_COPY_DEST, nullptr, &smallBuffer)); - EXPECT_NE(smallBuffer->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_NE(smallBuffer->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); } // Non-compatible heap type is not allowed reguardless of resource state specified. @@ -1126,7 +1126,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { ASSERT_SUCCEEDED(resourceAllocator->CreateResource( invalidSmallBufferWithinDesc, CreateBasicBufferDesc(3u), D3D12_RESOURCE_STATE_COMMON, nullptr, &smallBuffer)); - EXPECT_NE(smallBuffer->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_NE(smallBuffer->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); } // Custom heaps should use a heap type inferred by the resource state required. @@ -1138,7 +1138,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { ASSERT_SUCCEEDED(resourceAllocator->CreateResource( smallBufferWithinDesc, CreateBasicBufferDesc(3u), D3D12_RESOURCE_STATE_COPY_DEST, nullptr, &smallBuffer)); - EXPECT_EQ(smallBuffer->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(smallBuffer->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); } // Unspecified heap type should use the heap type inferred by the resource state @@ -1148,14 +1148,14 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { ASSERT_SUCCEEDED(resourceAllocator->CreateResource( baseAllocationDesc, CreateBasicBufferDesc(3u), D3D12_RESOURCE_STATE_COPY_DEST, nullptr, &smallBuffer)); - EXPECT_EQ(smallBuffer->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(smallBuffer->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); } { ComPtr smallBuffer; ASSERT_SUCCEEDED( resourceAllocator->CreateResource(baseAllocationDesc, CreateBasicBufferDesc(3u), D3D12_RESOURCE_STATE_COMMON, nullptr, &smallBuffer)); - EXPECT_NE(smallBuffer->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_NE(smallBuffer->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); } // Resource flags are not allowed. @@ -1167,7 +1167,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithin) { ASSERT_SUCCEEDED(resourceAllocator->CreateResource( baseAllocationDesc, resourceDescWithFlags, D3D12_RESOURCE_STATE_COPY_DEST, nullptr, &smallBuffer)); - EXPECT_NE(smallBuffer->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_NE(smallBuffer->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); } } @@ -1191,7 +1191,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinMany) { D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &smallBufferA)); ASSERT_NE(smallBufferA, nullptr); - EXPECT_EQ(smallBufferA->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(smallBufferA->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); EXPECT_EQ(smallBufferA->GetInfo().SizeInBytes, smallBufferDesc.Width); ComPtr smallBufferB; @@ -1201,7 +1201,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinMany) { D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &smallBufferB)); ASSERT_NE(smallBufferB, nullptr); - EXPECT_EQ(smallBufferB->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(smallBufferB->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); EXPECT_EQ(smallBufferB->GetInfo().SizeInBytes, smallBufferDesc.Width); ComPtr smallBufferC; @@ -1211,11 +1211,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinMany) { D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &smallBufferC)); ASSERT_NE(smallBufferC, nullptr); - EXPECT_EQ(smallBufferC->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(smallBufferC->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); EXPECT_EQ(smallBufferC->GetInfo().SizeInBytes, smallBufferDesc.Width); EXPECT_EQ(GetStats(resourceAllocator).UsedBlockCount, 3u); - EXPECT_EQ(GetStats(resourceAllocator).UsedMemoryCount, 1u); + EXPECT_EQ(GetStats(resourceAllocator).UsedHeapCount, 1u); // Should be allocated in sequence, back-to-back. EXPECT_EQ(smallBufferA->GetOffsetFromResource() + smallBufferDesc.Width, @@ -1286,7 +1286,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinMany) { smallBufferC = nullptr; EXPECT_EQ(GetStats(resourceAllocator).UsedBlockCount, 0u); - EXPECT_EQ(GetStats(resourceAllocator).UsedMemoryCount, 0u); + EXPECT_EQ(GetStats(resourceAllocator).UsedHeapCount, 0u); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverSubAllocated) { @@ -1307,7 +1307,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverSubAllocated) { nullptr, &subAllocation)); ASSERT_NE(subAllocation, nullptr); EXPECT_NE(subAllocation->GetResource(), nullptr); - EXPECT_NE(subAllocation->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocated); + EXPECT_NE(subAllocation->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferNeverPooled) { @@ -1390,7 +1390,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &allocation)); ASSERT_NE(allocation, nullptr); EXPECT_NE(allocation->GetResource(), nullptr); - EXPECT_EQ(allocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(allocation->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); } // Create buffer of size B with it's own resource heap that will be returned to the pool. @@ -1401,7 +1401,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &allocation)); ASSERT_NE(allocation, nullptr); EXPECT_NE(allocation->GetResource(), nullptr); - EXPECT_EQ(allocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(allocation->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); } // Create buffer of size A again with it's own resource heap from the pool. @@ -1415,7 +1415,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &allocation)); ASSERT_NE(allocation, nullptr); EXPECT_NE(allocation->GetResource(), nullptr); - EXPECT_EQ(allocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(allocation->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); } // Create buffer of size B again with it's own resource heap from the pool. @@ -1429,17 +1429,17 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &allocation)); ASSERT_NE(allocation, nullptr); EXPECT_NE(allocation->GetResource(), nullptr); - EXPECT_EQ(allocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(allocation->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); } - EXPECT_EQ(GetStats(poolAllocator).FreeMemoryUsage, bufferSize + bufferSize / 2); + EXPECT_EQ(GetStats(poolAllocator).FreeHeapUsage, bufferSize + bufferSize / 2); uint64_t releasedMemory = 0; ASSERT_SUCCEEDED(poolAllocator->ReleaseResourceHeaps(kReleaseAllMemory, &releasedMemory)); EXPECT_EQ(releasedMemory, bufferSize + bufferSize / 2); - EXPECT_EQ(GetStats(poolAllocator).FreeMemoryUsage, 0u); + EXPECT_EQ(GetStats(poolAllocator).FreeHeapUsage, 0u); // Create buffer of size A again with it's own resource heap from the empty pool. { @@ -1477,10 +1477,10 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferPooled) { standaloneAllocationDesc, CreateBasicBufferDesc(1024), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &allocation)); ASSERT_NE(allocation, nullptr); - EXPECT_EQ(allocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(allocation->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); } - EXPECT_EQ(GetStats(poolAllocator).FreeMemoryUsage, 0u); + EXPECT_EQ(GetStats(poolAllocator).FreeHeapUsage, 0u); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { @@ -1500,11 +1500,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { standaloneAllocationDesc, CreateBasicBufferDesc(kBufferOf4MBAllocationSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &firstAllocation)); ASSERT_NE(firstAllocation, nullptr); - EXPECT_EQ(firstAllocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(firstAllocation->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); RESOURCE_ALLOCATOR_STATS stats = GetStats(resourceAllocator); - EXPECT_EQ(stats.UsedMemoryCount, 1u); - EXPECT_EQ(stats.UsedMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(stats.UsedHeapCount, 1u); + EXPECT_EQ(stats.UsedHeapUsage, kBufferOf4MBAllocationSize); } // Calculate info for two pooled standalone allocations. @@ -1525,22 +1525,22 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { standaloneAllocationDesc, CreateBasicBufferDesc(kBufferOf4MBAllocationSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &firstAllocation)); ASSERT_NE(firstAllocation, nullptr); - EXPECT_EQ(firstAllocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(firstAllocation->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); RESOURCE_ALLOCATOR_STATS stats = GetStats(resourceAllocator); - EXPECT_EQ(stats.UsedMemoryCount, 1u); - EXPECT_EQ(stats.UsedMemoryUsage, kBufferOf4MBAllocationSize); + EXPECT_EQ(stats.UsedHeapCount, 1u); + EXPECT_EQ(stats.UsedHeapUsage, kBufferOf4MBAllocationSize); ComPtr secondAllocation; ASSERT_SUCCEEDED(resourceAllocator->CreateResource( standaloneAllocationDesc, CreateBasicBufferDesc(kBufferOf4MBAllocationSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &secondAllocation)); ASSERT_NE(secondAllocation, nullptr); - EXPECT_EQ(secondAllocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(secondAllocation->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); stats = GetStats(resourceAllocator); - EXPECT_EQ(stats.UsedMemoryCount, 2u); - EXPECT_EQ(stats.UsedMemoryUsage, kBufferOf4MBAllocationSize * 2); + EXPECT_EQ(stats.UsedHeapCount, 2u); + EXPECT_EQ(stats.UsedHeapUsage, kBufferOf4MBAllocationSize * 2); } // Calculate info for two sub-allocations. @@ -1563,12 +1563,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { // Depending on the device, sub-allocation could fail. Since this test relies on a // sub-allocator's info counts, it must be skipped. // TODO: Consider testing counts by allocator type. - GPGMM_SKIP_TEST_IF(firstAllocation->GetInfo().Method != - gpgmm::AllocationMethod::kSubAllocated); + GPGMM_SKIP_TEST_IF(firstAllocation->GetInfo().Method != ALLOCATION_METHOD_SUBALLOCATED); RESOURCE_ALLOCATOR_STATS stats = GetStats(resourceAllocator); - EXPECT_EQ(stats.UsedMemoryCount, 1u); - EXPECT_GE(stats.UsedMemoryUsage, stats.UsedBlockUsage); + EXPECT_EQ(stats.UsedHeapCount, 1u); + EXPECT_GE(stats.UsedHeapUsage, stats.UsedBlockUsage); EXPECT_EQ(stats.UsedBlockCount, 1u); EXPECT_GE(stats.UsedBlockUsage, kBufferSize); @@ -1577,11 +1576,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { subAllocationDesc, CreateBasicBufferDesc(kBufferSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &secondAllocation)); ASSERT_NE(secondAllocation, nullptr); - EXPECT_EQ(secondAllocation->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocated); + EXPECT_EQ(secondAllocation->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED); stats = GetStats(resourceAllocator); - EXPECT_GE(stats.UsedMemoryCount, 1u); - EXPECT_GE(stats.UsedMemoryUsage, stats.UsedBlockUsage); + EXPECT_GE(stats.UsedHeapCount, 1u); + EXPECT_GE(stats.UsedHeapUsage, stats.UsedBlockUsage); EXPECT_EQ(stats.UsedBlockCount, 2u); EXPECT_GE(stats.UsedBlockUsage, kBufferSize * 2); } @@ -1604,11 +1603,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { allocationWithinDesc, CreateBasicBufferDesc(kBufferSize, 1), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &firstAllocation)); ASSERT_NE(firstAllocation, nullptr); - EXPECT_EQ(firstAllocation->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(firstAllocation->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); RESOURCE_ALLOCATOR_STATS stats = GetStats(resourceAllocator); - EXPECT_EQ(stats.UsedMemoryCount, 1u); - EXPECT_EQ(stats.UsedMemoryUsage, 64u * 1024u); + EXPECT_EQ(stats.UsedHeapCount, 1u); + EXPECT_EQ(stats.UsedHeapUsage, 64u * 1024u); EXPECT_EQ(stats.UsedBlockCount, 1u); EXPECT_EQ(stats.UsedBlockUsage, kBufferSize); @@ -1617,11 +1616,11 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferStats) { allocationWithinDesc, CreateBasicBufferDesc(kBufferSize, 1), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &secondAllocation)); ASSERT_NE(secondAllocation, nullptr); - EXPECT_EQ(secondAllocation->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(secondAllocation->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); stats = GetStats(resourceAllocator); - EXPECT_EQ(stats.UsedMemoryCount, 1u); - EXPECT_EQ(stats.UsedMemoryUsage, 64u * 1024u); + EXPECT_EQ(stats.UsedHeapCount, 1u); + EXPECT_EQ(stats.UsedHeapUsage, 64u * 1024u); EXPECT_EQ(stats.UsedBlockCount, 2u); EXPECT_EQ(stats.UsedBlockUsage, kBufferSize * 2); } @@ -1649,7 +1648,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateTexturePooled) { standaloneAllocationDesc, CreateBasicTextureDesc(DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &firstAllocation)); ASSERT_NE(firstAllocation, nullptr); - EXPECT_EQ(firstAllocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(firstAllocation->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); } ALLOCATION_DESC reusePoolOnlyDesc = standaloneAllocationDesc; @@ -1663,7 +1662,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateTexturePooled) { reusePoolOnlyDesc, CreateBasicTextureDesc(DXGI_FORMAT_R8G8B8A8_UNORM, 1, 1), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &secondAllocation)); ASSERT_NE(secondAllocation, nullptr); - EXPECT_EQ(secondAllocation->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(secondAllocation->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); } } @@ -1795,7 +1794,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferManyThreaded) { thread.join(); } - EXPECT_EQ(GetStats(resourceAllocator).UsedMemoryUsage, 0u); + EXPECT_EQ(GetStats(resourceAllocator).UsedHeapUsage, 0u); } // Creates a bunch of buffers concurrently. @@ -1820,7 +1819,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinManyThreaded) { allocationDesc, CreateBasicBufferDesc(kSmallBufferSize), D3D12_RESOURCE_STATE_GENERIC_READ, nullptr, &allocation)); ASSERT_NE(allocation, nullptr); - EXPECT_EQ(allocation->GetInfo().Method, gpgmm::AllocationMethod::kSubAllocatedWithin); + EXPECT_EQ(allocation->GetInfo().Method, ALLOCATION_METHOD_SUBALLOCATED_WITHIN); }); } @@ -1828,7 +1827,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithinManyThreaded) { thread.join(); } - EXPECT_EQ(GetStats(resourceAllocator).UsedMemoryUsage, 0u); + EXPECT_EQ(GetStats(resourceAllocator).UsedHeapUsage, 0u); } TEST_F(D3D12ResourceAllocatorTests, CreateBufferCacheSize) { @@ -1958,7 +1957,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBufferWithPadding) { allocationDesc.RequireResourceHeapPadding); // Padded resources are only supported for standalone allocations. - EXPECT_EQ(allocationWithPadding->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(allocationWithPadding->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); } // Verify two textures, with and without padding, allocate the correct size. @@ -1987,7 +1986,7 @@ TEST_F(D3D12ResourceAllocatorTests, CreateTextureWithPadding) { allocationDesc.RequireResourceHeapPadding); // Padded resources are only supported for standalone allocations. - EXPECT_EQ(allocationWithPadding->GetInfo().Method, gpgmm::AllocationMethod::kStandalone); + EXPECT_EQ(allocationWithPadding->GetInfo().Method, ALLOCATION_METHOD_STANDALONE); } TEST_F(D3D12ResourceAllocatorTests, AllocatorFeatures) {