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
77 changes: 0 additions & 77 deletions include/gpgmm.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_
72 changes: 70 additions & 2 deletions include/gpgmm_d3d12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/fuzzers/D3D12ResidencyManagerFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<gpgmm::d3d12::IResourceAllocation> allocation;
if (FAILED(gResourceAllocator->CreateResource({}, bufferDesc, D3D12_RESOURCE_STATE_COMMON,
nullptr, &allocation))) {
Expand Down
11 changes: 0 additions & 11 deletions src/gpgmm/common/JSONSerializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 1 addition & 3 deletions src/gpgmm/common/JSONSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,14 @@

namespace gpgmm {

// Forward declare common types.
struct MemoryAllocatorStats;
// Forward declare common types.;
struct MemoryAllocationRequest;
struct MessageInfo;

class JSONSerializer {
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);
};
Expand Down
30 changes: 30 additions & 0 deletions src/gpgmm/common/MemoryAllocation.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
45 changes: 45 additions & 0 deletions src/gpgmm/common/MemoryAllocator.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
5 changes: 0 additions & 5 deletions src/gpgmm/d3d12/JSONSerializerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 0 additions & 1 deletion src/gpgmm/d3d12/JSONSerializerD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
11 changes: 6 additions & 5 deletions src/gpgmm/d3d12/ResourceAllocationD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ namespace gpgmm::d3d12 {
: MemoryAllocation(allocator,
resourceHeap,
desc.HeapOffset,
desc.Method,
static_cast<AllocationMethod>(desc.Method),
block,
desc.SizeInBytes),
mResidencyManager(residencyManager),
Expand All @@ -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.";
Expand Down Expand Up @@ -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.";
Expand Down Expand Up @@ -146,7 +146,7 @@ namespace gpgmm::d3d12 {
}

RESOURCE_ALLOCATION_INFO ResourceAllocation::GetInfo() const {
return {GetSize(), GetAlignment(), GetMethod()};
return {GetSize(), GetAlignment(), static_cast<ALLOCATION_METHOD>(GetMethod())};
}

const char* ResourceAllocation::GetTypename() const {
Expand All @@ -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;
}

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/ResourceAllocationD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ namespace gpgmm::d3d12 {
uint64_t SizeInBytes;
uint64_t HeapOffset;
uint64_t OffsetFromResource;
AllocationMethod Method;
ALLOCATION_METHOD Method;
LPCWSTR DebugName;
};

Expand Down
Loading