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
19 changes: 6 additions & 13 deletions src/gpgmm/d3d12/HeapD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,9 @@ namespace gpgmm::d3d12 {
ResidencyManager* const pResidencyManager,
CreateHeapFn&& createHeapFn,
Heap** ppHeapOut) {

// Ensure enough free memory exists before allocating to avoid an out-of-memory error
// when over budget.
if (pResidencyManager != nullptr && descriptor.AlwaysInBudget) {
if (pResidencyManager != nullptr && (descriptor.Flags & HEAP_FLAG_ALWAYS_IN_BUDGET)) {
ReturnIfFailed(pResidencyManager->EnsureInBudget(descriptor.SizeInBytes,
descriptor.MemorySegmentGroup));
}
Expand All @@ -42,9 +41,7 @@ namespace gpgmm::d3d12 {
GPGMM_TRACE_EVENT_OBJECT_CALL("Heap.CreateHeap",
(CREATE_HEAP_DESC{descriptor, pageable.Get()}));

std::unique_ptr<Heap> heap(new Heap(std::move(pageable), descriptor.MemorySegmentGroup,
descriptor.SizeInBytes, descriptor.Alignment,
descriptor.IsExternal));
std::unique_ptr<Heap> heap(new Heap(std::move(pageable), descriptor));

if (pResidencyManager != nullptr) {
ReturnIfFailed(pResidencyManager->InsertHeap(heap.get()));
Expand All @@ -60,16 +57,12 @@ namespace gpgmm::d3d12 {
return S_OK;
}

Heap::Heap(ComPtr<ID3D12Pageable> pageable,
const DXGI_MEMORY_SEGMENT_GROUP& memorySegmentGroup,
uint64_t size,
uint64_t alignment,
bool isExternal)
: MemoryBase(size, alignment),
Heap::Heap(ComPtr<ID3D12Pageable> pageable, const HEAP_DESC& descriptor)
: MemoryBase(descriptor.SizeInBytes, descriptor.Alignment),
mPageable(std::move(pageable)),
mMemorySegmentGroup(memorySegmentGroup),
mMemorySegmentGroup(descriptor.MemorySegmentGroup),
mResidencyLock(0),
mIsExternal(isExternal) {
mIsExternal(descriptor.Flags & HEAP_FLAG_NEVER_USE_RESIDENCY) {
ASSERT(mPageable != nullptr);
if (!mIsExternal) {
GPGMM_TRACE_EVENT_OBJECT_NEW(this);
Expand Down
38 changes: 24 additions & 14 deletions src/gpgmm/d3d12/HeapD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,28 @@ namespace gpgmm::d3d12 {
bool IsResident;
};

/** \enum HEAPS_FLAGS
Specify creation options to configure the heap.
*/
enum HEAPS_FLAGS {

/** \brief Disables all option flags.
*/
HEAPS_FLAG_NONE = 0x0,

/** \brief Requires the heap to be created in budget.
*/
HEAP_FLAG_ALWAYS_IN_BUDGET = 0x1,

/** \brief Specifies to leave the heap unmanaged for residency.
*/
HEAP_FLAG_NEVER_USE_RESIDENCY = 0x2,
};

DEFINE_ENUM_FLAG_OPERATORS(HEAPS_FLAGS)

/** \struct HEAP_DESC
Specifies properties of a managed heap.
Specifies creation options for a residency managed heap.
*/
struct HEAP_DESC {
/** \brief Created size of the heap, in bytes.
Expand All @@ -56,15 +76,9 @@ namespace gpgmm::d3d12 {
*/
uint64_t Alignment;

/** \brief Requires the heap to be created in budget.
/** \brief Specifies heaps options.
*/
bool AlwaysInBudget;

/** \brief Specifies to leave the heap unmanaged by GPGMM.

External heaps are not supported for residency.
*/
bool IsExternal;
HEAPS_FLAGS Flags;

/** \brief Specifies the memory segment to use for residency.

Expand Down Expand Up @@ -157,11 +171,7 @@ namespace gpgmm::d3d12 {
friend ResidencyManager;
friend ResourceAllocator;

Heap(ComPtr<ID3D12Pageable> pageable,
const DXGI_MEMORY_SEGMENT_GROUP& memorySegmentGroup,
uint64_t size,
uint64_t alignment,
bool isExternal);
Heap(ComPtr<ID3D12Pageable> pageable, const HEAP_DESC& descriptor);

HRESULT SetDebugNameImpl(const std::string& name) override;
const char* GetTypename() const override;
Expand Down
3 changes: 1 addition & 2 deletions src/gpgmm/d3d12/JSONSerializerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ namespace gpgmm::d3d12 {
JSONDict dict;
dict.AddItem("SizeInBytes", desc.SizeInBytes);
dict.AddItem("Alignment", desc.Alignment);
dict.AddItem("AlwaysInBudget", desc.AlwaysInBudget);
dict.AddItem("IsExternal", desc.IsExternal);
dict.AddItem("Flags", desc.Flags);
dict.AddItem("MemorySegmentGroup", desc.MemorySegmentGroup);
dict.AddItem("DebugName", desc.DebugName);
return dict;
Expand Down
5 changes: 3 additions & 2 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1149,7 +1149,7 @@ namespace gpgmm::d3d12 {
HEAP_DESC resourceHeapDesc = {};
resourceHeapDesc.SizeInBytes = resourceInfo.SizeInBytes;
resourceHeapDesc.Alignment = resourceInfo.Alignment;
resourceHeapDesc.IsExternal = true;
resourceHeapDesc.Flags |= HEAP_FLAG_NEVER_USE_RESIDENCY;

Heap* resourceHeap = nullptr;
ReturnIfFailed(Heap::CreateHeap(
Expand Down Expand Up @@ -1222,7 +1222,8 @@ namespace gpgmm::d3d12 {
resourceHeapDesc.SizeInBytes = info.SizeInBytes;
resourceHeapDesc.DebugName = "Resource heap (committed)";
resourceHeapDesc.Alignment = info.Alignment;
resourceHeapDesc.AlwaysInBudget = mIsAlwaysInBudget;
resourceHeapDesc.Flags |=
(mIsAlwaysInBudget) ? HEAP_FLAG_ALWAYS_IN_BUDGET : HEAPS_FLAG_NONE;

if (IsResidencyEnabled()) {
resourceHeapDesc.MemorySegmentGroup = GetMemorySegmentGroup(
Expand Down
5 changes: 4 additions & 1 deletion src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,12 @@ namespace gpgmm::d3d12 {
class ResidencyManager;
class ResourceAllocation;

/** \enum ALLOCATOR_FLAGS
Specify creation options for allocator.
*/
enum ALLOCATOR_FLAGS {

/** \brief Disables all allocator flags.
/** \brief Disables all option flags.
*/
ALLOCATOR_FLAG_NONE = 0x0,

Expand Down
2 changes: 1 addition & 1 deletion src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ namespace gpgmm::d3d12 {
resourceHeapDesc.SizeInBytes = heapSize;
resourceHeapDesc.DebugName = "Resource heap";
resourceHeapDesc.Alignment = request.Alignment;
resourceHeapDesc.AlwaysInBudget = mAlwaysInBudget;
resourceHeapDesc.Flags |= (mAlwaysInBudget) ? HEAP_FLAG_ALWAYS_IN_BUDGET : HEAPS_FLAG_NONE;

if (mResidencyManager != nullptr) {
resourceHeapDesc.MemorySegmentGroup = GetMemorySegmentGroup(
Expand Down
1 change: 0 additions & 1 deletion src/include/min/gpgmm_d3d12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ namespace gpgmm::d3d12 {
HEAP_DESC resourceHeapDesc = {};
resourceHeapDesc.SizeInBytes = resourceInfo.SizeInBytes;
resourceHeapDesc.Alignment = resourceInfo.Alignment;
resourceHeapDesc.HeapType = allocationDescriptor.HeapType;

ReturnIfFailed(Heap::CreateHeap(
resourceHeapDesc, mResidencyManager.Get(),
Expand Down
12 changes: 9 additions & 3 deletions src/include/min/gpgmm_d3d12.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,18 @@ namespace gpgmm::d3d12 {
bool IsResident;
};

enum HEAPS_FLAGS {
HEAPS_FLAG_NONE = 0x0,
HEAP_FLAG_ALWAYS_IN_BUDGET = 0x1,
HEAP_FLAG_NEVER_USE_RESIDENCY = 0x2,
};

DEFINE_ENUM_FLAG_OPERATORS(HEAPS_FLAGS)

struct HEAP_DESC {
uint64_t SizeInBytes;
uint64_t Alignment;
D3D12_HEAP_TYPE HeapType;
bool AlwaysInBudget;
bool IsExternal;
HEAPS_FLAGS Flags;
DXGI_MEMORY_SEGMENT_GROUP MemorySegmentGroup;
std::string DebugName;
};
Expand Down
1 change: 0 additions & 1 deletion src/tests/capture_replay_tests/D3D12EventTraceReplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,6 @@ class D3D12EventTraceReplay : public D3D12TestBase, public CaptureReplayTestWith
HEAP_DESC resourceHeapDesc = {};
resourceHeapDesc.SizeInBytes = args["Heap"]["SizeInBytes"].asUInt64();
resourceHeapDesc.Alignment = args["Heap"]["Alignment"].asUInt64();
resourceHeapDesc.IsExternal = args["IsExternal"].asBool();
resourceHeapDesc.MemorySegmentGroup =
GetMemorySegmentGroup(heapProperties.MemoryPoolPreference, mIsUMA);

Expand Down