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
14 changes: 7 additions & 7 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -616,7 +616,8 @@ namespace gpgmm::d3d12 {
EventRecordScope::kPerInstance),
mUseDetailedTimingEvents(descriptor.RecordOptions.UseDetailedTimingEvents),
mIsCustomHeapsDisabled(descriptor.Flags & ALLOCATOR_FLAG_DISABLE_UNIFIED_MEMORY),
mIsAlwaysCreateResident(descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_RESIDENT) {
mIsAlwaysCreateResident(descriptor.Flags & ALLOCATOR_FLAG_ALWAYS_RESIDENT),
mMaxResourceHeapSize(descriptor.MaxResourceHeapSize) {
ASSERT(mDevice != nullptr);

GPGMM_TRACE_EVENT_OBJECT_NEW(this);
Expand Down Expand Up @@ -745,12 +746,11 @@ namespace gpgmm::d3d12 {
double memoryGrowthFactor,
bool isPrefetchAllowed,
std::unique_ptr<MemoryAllocator> underlyingAllocator) {
const uint64_t maxResourceHeapSize = mCaps->GetMaxResourceHeapSize();
switch (algorithm) {
case ALLOCATOR_ALGORITHM_BUDDY_SYSTEM: {
// System and memory size must be aligned at creation-time.
return std::make_unique<BuddyMemoryAllocator>(
/*systemSize*/ PrevPowerOfTwo(maxResourceHeapSize),
/*systemSize*/ PrevPowerOfTwo(mMaxResourceHeapSize),
/*memorySize*/ NextPowerOfTwo(memorySize),
/*memoryAlignment*/ memoryAlignment,
/*memoryAllocator*/ std::move(underlyingAllocator));
Expand All @@ -759,7 +759,7 @@ namespace gpgmm::d3d12 {
// Min slab size is always equal to the memory size because the
// slab allocator aligns the slab size at allocate-time.
return std::make_unique<SlabCacheAllocator>(
/*maxSlabSize*/ PrevPowerOfTwo(maxResourceHeapSize),
/*maxSlabSize*/ PrevPowerOfTwo(mMaxResourceHeapSize),
/*minSlabSize*/ memorySize,
/*slabAlignment*/ memoryAlignment,
/*slabFragmentationLimit*/ memoryFragmentationLimit,
Expand Down Expand Up @@ -975,12 +975,12 @@ namespace gpgmm::d3d12 {
D3D12_RESOURCE_DESC newResourceDesc = resourceDescriptor;
const D3D12_RESOURCE_ALLOCATION_INFO resourceInfo =
GetResourceAllocationInfo(mDevice, newResourceDesc);
if (resourceInfo.SizeInBytes > mCaps->GetMaxResourceSize()) {
if (resourceInfo.SizeInBytes > mMaxResourceHeapSize) {
ErrorLog(MessageId::kSizeExceeded)
<< "Unable to create resource allocation because the resource size exceeded "
"the capabilities of the device: "
<< GPGMM_BYTES_TO_GB(resourceInfo.SizeInBytes) << " vs "
<< GPGMM_BYTES_TO_GB(mCaps->GetMaxResourceSize()) << " GBs.";
<< GPGMM_BYTES_TO_GB(mMaxResourceHeapSize) << " GBs.";
return E_OUTOFMEMORY;
}

Expand Down Expand Up @@ -1069,7 +1069,7 @@ namespace gpgmm::d3d12 {
request.AlwaysPrefetch =
(allocationDescriptor.Flags & ALLOCATION_FLAG_ALWAYS_PREFETCH_MEMORY);
request.AlwaysCacheSize = (allocationDescriptor.Flags & ALLOCATION_FLAG_ALWAYS_CACHE_SIZE);
request.AvailableForAllocation = mCaps->GetMaxResourceHeapSize();
request.AvailableForAllocation = mMaxResourceHeapSize;

// Apply extra padding to the resource heap size, if specified.
// Padding can only be applied to standalone non-committed resources.
Expand Down
1 change: 1 addition & 0 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,7 @@ namespace gpgmm::d3d12 {
const bool mUseDetailedTimingEvents;
const bool mIsCustomHeapsDisabled;
const bool mIsAlwaysCreateResident;
const uint64_t mMaxResourceHeapSize;

static constexpr uint64_t kNumOfResourceHeapTypes = 12u;

Expand Down
14 changes: 14 additions & 0 deletions src/tests/end2end/D3D12ResourceAllocatorTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -689,6 +689,20 @@ TEST_F(D3D12ResourceAllocatorTests, CreateBuffer) {
{}, CreateBasicBufferDesc(kBufferOf4MBAllocationSize),
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, &allocation));
}

// Create a buffer that exceeds the max size should always fail.
{
ALLOCATOR_DESC allocatorDesc = CreateBasicAllocatorDesc();
allocatorDesc.MaxResourceHeapSize = kBufferOf4MBAllocationSize;

ComPtr<IResourceAllocator> resourceAllocatorLimitedTo4MB;
ASSERT_SUCCEEDED(CreateResourceAllocator(allocatorDesc, mDevice.Get(), mAdapter.Get(),
&resourceAllocatorLimitedTo4MB, nullptr));

ASSERT_FAILED(resourceAllocatorLimitedTo4MB->CreateResource(
{}, CreateBasicBufferDesc(kBufferOf4MBAllocationSize + 1),
D3D12_RESOURCE_STATE_UNORDERED_ACCESS, nullptr, nullptr));
}
}

TEST_F(D3D12ResourceAllocatorTests, CreateBufferLeaked) {
Expand Down