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
20 changes: 11 additions & 9 deletions src/gpgmm/d3d12/ErrorD3D12.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,17 @@ namespace gpgmm::d3d12 {
for (;;) \
break

#define ReturnIfFailed(expr) \
{ \
HRESULT hr = expr; \
if (GPGMM_UNLIKELY(FAILED(hr))) { \
gpgmm::ErrorLog() << #expr << ": " << GetErrorMessage(hr); \
return hr; \
} \
} \
for (;;) \
#define ReturnIfFailed(expr) ReturnIfFailedDevice(expr, nullptr)

#define ReturnIfFailedDevice(expr, device) \
{ \
HRESULT hr = expr; \
if (GPGMM_UNLIKELY(FAILED(hr))) { \
gpgmm::ErrorLog() << #expr << ": " << GetDeviceErrorMessage(device, hr); \
return hr; \
} \
} \
for (;;) \
break

#define ReturnIfSucceeded(expr) \
Expand Down
22 changes: 13 additions & 9 deletions src/gpgmm/d3d12/ResidencyManagerD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,8 +308,9 @@ namespace gpgmm::d3d12 {
if (!heap->IsInList() && !heap->IsResidencyLocked()) {
ComPtr<ID3D12Pageable> pageable;
ReturnIfFailed(heap->QueryInterface(IID_PPV_ARGS(&pageable)));
ReturnIfFailed(MakeResident(heap->GetMemorySegmentGroup(), heap->GetSize(), 1,
pageable.GetAddressOf()));
ReturnIfFailedDevice(MakeResident(heap->GetMemorySegmentGroup(), heap->GetSize(), 1,
pageable.GetAddressOf()),
mDevice);
heap->SetResidencyState(RESIDENCY_STATUS_CURRENT_RESIDENT);

// Untracked heaps, created not resident, are not already attributed toward residency
Expand Down Expand Up @@ -573,7 +574,8 @@ namespace gpgmm::d3d12 {
const DXGI_MEMORY_SEGMENT_GROUP& memorySegmentGroup) {
std::lock_guard<std::mutex> lock(mMutex);
uint64_t bytesEvicted = bytesInBudget;
ReturnIfFailed(EvictInternal(bytesInBudget, memorySegmentGroup, &bytesEvicted));
ReturnIfFailedDevice(EvictInternal(bytesInBudget, memorySegmentGroup, &bytesEvicted),
mDevice);
return (bytesEvicted >= bytesInBudget) ? S_OK : E_FAIL;
}

Expand Down Expand Up @@ -769,15 +771,17 @@ namespace gpgmm::d3d12 {
if (localSizeToMakeResident > 0) {
const uint32_t numberOfObjectsToMakeResident =
static_cast<uint32_t>(localHeapsToMakeResident.size());
ReturnIfFailed(MakeResident(DXGI_MEMORY_SEGMENT_GROUP_LOCAL, localSizeToMakeResident,
numberOfObjectsToMakeResident,
localHeapsToMakeResident.data()));
ReturnIfFailedDevice(
MakeResident(DXGI_MEMORY_SEGMENT_GROUP_LOCAL, localSizeToMakeResident,
numberOfObjectsToMakeResident, localHeapsToMakeResident.data()),
mDevice);
} else if (nonLocalSizeToMakeResident > 0) {
const uint32_t numberOfObjectsToMakeResident =
static_cast<uint32_t>(nonLocalHeapsToMakeResident.size());
ReturnIfFailed(MakeResident(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL,
nonLocalSizeToMakeResident, numberOfObjectsToMakeResident,
nonLocalHeapsToMakeResident.data()));
ReturnIfFailedDevice(
MakeResident(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, nonLocalSizeToMakeResident,
numberOfObjectsToMakeResident, nonLocalHeapsToMakeResident.data()),
mDevice);
}

// Once MakeResident succeeds, we must assume the heaps are resident since D3D12 provides
Expand Down
22 changes: 12 additions & 10 deletions src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -322,8 +322,7 @@ namespace gpgmm::d3d12 {
HRESULT hr = createResourceFn(*allocation);
if (FAILED(hr)) {
InfoEvent(allocator, MessageId::kAllocatorFailed)
<< "Failed to create resource using allocation: " +
GetDeviceErrorMessage(device, hr);
<< "Failed to create resource using allocation.";
allocator->DeallocateMemory(std::move(allocation));
}
return hr;
Expand Down Expand Up @@ -896,8 +895,9 @@ namespace gpgmm::d3d12 {

std::lock_guard<std::mutex> lock(mMutex);
ComPtr<IResourceAllocation> allocation;
ReturnIfFailed(CreateResourceInternal(allocationDescriptor, resourceDescriptor,
initialResourceState, pClearValue, &allocation));
ReturnIfFailedDevice(CreateResourceInternal(allocationDescriptor, resourceDescriptor,
initialResourceState, pClearValue, &allocation),
mDevice);

ASSERT(allocation->GetResource() != nullptr);

Expand Down Expand Up @@ -1338,12 +1338,14 @@ namespace gpgmm::d3d12 {
ImportResourceCallbackContext importResourceCallbackContext(pCommittedResource);

ComPtr<IHeap> resourceHeap;
ReturnIfFailed(Heap::CreateHeap(
resourceHeapDesc,
(allocationDescriptor.Flags & ALLOCATION_FLAG_DISABLE_RESIDENCY)
? nullptr
: mResidencyManager.Get(),
ImportResourceCallbackContext::GetHeap, &importResourceCallbackContext, &resourceHeap));
ReturnIfFailedDevice(
Heap::CreateHeap(resourceHeapDesc,
(allocationDescriptor.Flags & ALLOCATION_FLAG_DISABLE_RESIDENCY)
? nullptr
: mResidencyManager.Get(),
ImportResourceCallbackContext::GetHeap, &importResourceCallbackContext,
&resourceHeap),
mDevice);

const uint64_t& allocationSize = resourceInfo.SizeInBytes;
mStats.UsedMemoryUsage += allocationSize;
Expand Down