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
4 changes: 3 additions & 1 deletion src/fuzzers/D3D12ResidencyManagerFuzzer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

#include "D3D12Fuzzer.h"
#include "gpgmm/common/SizeClass.h"
#include "gpgmm/d3d12/UtilsD3D12.h"

namespace {

Expand Down Expand Up @@ -80,7 +81,8 @@ extern "C" int LLVMFuzzerInitialize(int* argc, char*** argv) {
allocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT;

const DXGI_MEMORY_SEGMENT_GROUP bufferMemorySegment =
gResidencyManager->GetMemorySegmentGroup(allocationDesc.HeapType);
gpgmm::d3d12::GetDefaultMemorySegmentGroup(residencyDesc.Device.Get(),
allocationDesc.HeapType, residencyDesc.IsUMA);

constexpr uint64_t kBufferMemorySize = GPGMM_MB_TO_BYTES(1);
const D3D12_RESOURCE_DESC bufferDesc = CreateBufferDesc(kBufferMemorySize);
Expand Down
12 changes: 1 addition & 11 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -767,17 +767,7 @@ namespace gpgmm::d3d12 {

DXGI_MEMORY_SEGMENT_GROUP ResidencyManager::GetMemorySegmentGroup(
D3D12_HEAP_TYPE heapType) const {
if (mIsUMA) {
return DXGI_MEMORY_SEGMENT_GROUP_LOCAL;
}

D3D12_HEAP_PROPERTIES heapProperties = mDevice->GetCustomHeapProperties(0, heapType);

if (heapProperties.MemoryPoolPreference == D3D12_MEMORY_POOL_L1) {
return DXGI_MEMORY_SEGMENT_GROUP_LOCAL;
}

return DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL;
return GetDefaultMemorySegmentGroup(mDevice.Get(), heapType, mIsUMA);
}

} // namespace gpgmm::d3d12
12 changes: 2 additions & 10 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,16 +226,6 @@ namespace gpgmm::d3d12 {
*/
RESIDENCY_INFO GetInfo() const;

/** \brief Divugles the memory segment used for the specified heap type.

@param heapType A D3D12_HEAP_TYPE-typed value that specifies the heap to get the memory
segment for.

\return A DXGI_MEMORY_SEGMENT_GROUP that provides the memory segment for the specified heap
type.
*/
DXGI_MEMORY_SEGMENT_GROUP GetMemorySegmentGroup(D3D12_HEAP_TYPE heapType) const;

private:
friend Heap;
friend ResourceAllocator;
Expand All @@ -253,6 +243,8 @@ namespace gpgmm::d3d12 {

HRESULT InsertHeapInternal(Heap* heap);

DXGI_MEMORY_SEGMENT_GROUP GetMemorySegmentGroup(D3D12_HEAP_TYPE heapType) const;

const char* GetTypename() const;

using LRUCache = LinkedList<Heap>;
Expand Down
16 changes: 16 additions & 0 deletions src/gpgmm/d3d12/UtilsD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -437,4 +437,20 @@ namespace gpgmm::d3d12 {
return object->SetName(TCharToWString(name.c_str()).c_str());
}

DXGI_MEMORY_SEGMENT_GROUP GetDefaultMemorySegmentGroup(ID3D12Device* device,
D3D12_HEAP_TYPE heapType,
bool isUMA) {
if (isUMA) {
return DXGI_MEMORY_SEGMENT_GROUP_LOCAL;
}

D3D12_HEAP_PROPERTIES heapProperties = device->GetCustomHeapProperties(0, heapType);

if (heapProperties.MemoryPoolPreference == D3D12_MEMORY_POOL_L1) {
return DXGI_MEMORY_SEGMENT_GROUP_LOCAL;
}

return DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL;
}

} // namespace gpgmm::d3d12
3 changes: 3 additions & 0 deletions src/gpgmm/d3d12/UtilsD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ namespace gpgmm::d3d12 {
bool IsDepthFormat(DXGI_FORMAT format);
bool IsAllowedToUseSmallAlignment(const D3D12_RESOURCE_DESC& Desc);
HRESULT SetDebugObjectName(ID3D12Object* object, const std::string& name);
DXGI_MEMORY_SEGMENT_GROUP GetDefaultMemorySegmentGroup(ID3D12Device* device,
D3D12_HEAP_TYPE heapType,
bool isUMA);

} // namespace gpgmm::d3d12

Expand Down
9 changes: 5 additions & 4 deletions src/tests/end2end/D3D12ResidencyManagerTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "tests/D3D12Test.h"

#include "gpgmm/common/SizeClass.h"
#include "gpgmm/d3d12/UtilsD3D12.h"

#include <gpgmm_d3d12.h>

Expand Down Expand Up @@ -88,7 +89,7 @@ class D3D12ResidencyManagerTests : public D3D12TestBase, public ::testing::Test
}
};

TEST_F(D3D12ResidencyManagerTests, CreateResourceHeap) {
TEST_F(D3D12ResidencyManagerTests, CreateHeap) {
ComPtr<ResidencyManager> residencyManager;
ASSERT_SUCCEEDED(ResidencyManager::CreateResidencyManager(
CreateBasicResidencyDesc(kDefaultBudget), &residencyManager));
Expand Down Expand Up @@ -248,7 +249,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudget) {
bufferAllocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT;

const DXGI_MEMORY_SEGMENT_GROUP bufferMemorySegment =
residencyManager->GetMemorySegmentGroup(bufferAllocationDesc.HeapType);
GetDefaultMemorySegmentGroup(mDevice.Get(), bufferAllocationDesc.HeapType, mIsUMA);
const uint64_t memoryUnderBudget = GetBudgetLeft(residencyManager.Get(), bufferMemorySegment);

// Keep allocating until we reach the budget.
Expand Down Expand Up @@ -310,7 +311,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetUsingBudgetNotifications) {
bufferAllocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT;

const DXGI_MEMORY_SEGMENT_GROUP bufferMemorySegment =
residencyManager->GetMemorySegmentGroup(bufferAllocationDesc.HeapType);
GetDefaultMemorySegmentGroup(mDevice.Get(), bufferAllocationDesc.HeapType, mIsUMA);

const uint64_t memoryUnderBudget = GetBudgetLeft(residencyManager.Get(), bufferMemorySegment);

Expand Down Expand Up @@ -354,7 +355,7 @@ TEST_F(D3D12ResidencyManagerTests, OverBudgetWithGrowth) {
bufferAllocationDesc.HeapType = D3D12_HEAP_TYPE_DEFAULT;

const DXGI_MEMORY_SEGMENT_GROUP bufferMemorySegment =
residencyManager->GetMemorySegmentGroup(bufferAllocationDesc.HeapType);
GetDefaultMemorySegmentGroup(mDevice.Get(), bufferAllocationDesc.HeapType, mIsUMA);
const uint64_t memoryUnderBudget = GetBudgetLeft(residencyManager.Get(), bufferMemorySegment);

while (resourceAllocator->GetInfo().UsedMemoryUsage + kBufferMemorySize < memoryUnderBudget) {
Expand Down