diff --git a/src/gpgmm/d3d12/BudgetUpdateD3D12.cpp b/src/gpgmm/d3d12/BudgetUpdateD3D12.cpp index 69bbb9ce..84651b44 100644 --- a/src/gpgmm/d3d12/BudgetUpdateD3D12.cpp +++ b/src/gpgmm/d3d12/BudgetUpdateD3D12.cpp @@ -77,7 +77,7 @@ namespace gpgmm::d3d12 { if (FAILED(hr)) { ErrorLog(ErrorCode::kBudgetInvalid, mResidencyManager) << "Unable to update budget: " + - GetErrorResultWithRemovalReason(hr, mResidencyManager->mDevice); + GetErrorResultMessage(hr, mResidencyManager->mDevice); } SetLastError(hr); diff --git a/src/gpgmm/d3d12/CapsD3D12.cpp b/src/gpgmm/d3d12/CapsD3D12.cpp index 7769fe6b..b4d90666 100644 --- a/src/gpgmm/d3d12/CapsD3D12.cpp +++ b/src/gpgmm/d3d12/CapsD3D12.cpp @@ -85,16 +85,15 @@ namespace gpgmm::d3d12 { // static HRESULT Caps::CreateCaps(ID3D12Device* device, IDXGIAdapter* adapter, Caps** capsOut) { - GPGMM_RETURN_IF_NULLPTR(device); + GPGMM_RETURN_IF_NULL(device); std::unique_ptr caps(new Caps()); - GPGMM_RETURN_IF_FAILED(SetMaxResourceSize(device, &caps->mMaxResourceSize), device); - GPGMM_RETURN_IF_FAILED(SetMaxResourceHeapSize(device, &caps->mMaxResourceHeapSize), device); - GPGMM_RETURN_IF_FAILED(SetMaxResourceHeapTierSupported(device, &caps->mMaxResourceHeapTier), - device); + GPGMM_RETURN_IF_FAILED(SetMaxResourceSize(device, &caps->mMaxResourceSize)); + GPGMM_RETURN_IF_FAILED(SetMaxResourceHeapSize(device, &caps->mMaxResourceHeapSize)); GPGMM_RETURN_IF_FAILED( - SetCreateHeapNotResidentSupported(device, &caps->mIsCreateHeapNotResidentSupported), - device); + SetMaxResourceHeapTierSupported(device, &caps->mMaxResourceHeapTier)); + GPGMM_RETURN_IF_FAILED( + SetCreateHeapNotResidentSupported(device, &caps->mIsCreateHeapNotResidentSupported)); D3D12_FEATURE_DATA_ARCHITECTURE arch = {}; GPGMM_RETURN_IF_FAILED( @@ -104,7 +103,7 @@ namespace gpgmm::d3d12 { if (adapter != nullptr) { DXGI_ADAPTER_DESC adapterDesc; - GPGMM_RETURN_IF_FAILED(adapter->GetDesc(&adapterDesc), device); + GPGMM_RETURN_IF_FAILED(adapter->GetDesc(&adapterDesc)); caps->mSharedSegmentSize = adapterDesc.SharedSystemMemory; caps->mDedicatedSegmentSize = adapterDesc.DedicatedVideoMemory; diff --git a/src/gpgmm/d3d12/ErrorD3D12.cpp b/src/gpgmm/d3d12/ErrorD3D12.cpp index 2fbf23a1..ff5e3137 100644 --- a/src/gpgmm/d3d12/ErrorD3D12.cpp +++ b/src/gpgmm/d3d12/ErrorD3D12.cpp @@ -70,11 +70,15 @@ namespace gpgmm::d3d12 { return ss.str(); } - std::string GetErrorResultWithRemovalReason(HRESULT error, ID3D12Device* device) { + std::string GetErrorResultMessage(HRESULT error) { + // Device must be supplied when device removal errors are possible. + ASSERT(error != DXGI_ERROR_DEVICE_REMOVED); + return GetErrorResultToString(error); + } + + std::string GetErrorResultMessage(HRESULT error, ID3D12Device* device) { if (error == DXGI_ERROR_DEVICE_REMOVED) { - if (device == nullptr) { - return "Device was not found but removed " + GetErrorResultToString(error); - } + ASSERT(device != nullptr); return GetErrorResultToString(error) + " with reason: " + GetErrorResultToString(device->GetDeviceRemovedReason()); } diff --git a/src/gpgmm/d3d12/ErrorD3D12.h b/src/gpgmm/d3d12/ErrorD3D12.h index 1bdc5ad5..39bf61b9 100644 --- a/src/gpgmm/d3d12/ErrorD3D12.h +++ b/src/gpgmm/d3d12/ErrorD3D12.h @@ -22,20 +22,21 @@ #include -#define GPGMM_RETURN_IF_NULLPTR(ptr) \ +#define GPGMM_RETURN_IF_NULL(ptr) \ GPGMM_RETURN_IF_FAILED((ptr == nullptr ? E_POINTER : S_OK), nullptr) -#define GPGMM_RETURN_IF_FAILED(expr, device) \ - { \ - auto GPGMM_LOCAL_VAR(HRESULT) = expr; \ - if (GPGMM_UNLIKELY(FAILED(GPGMM_LOCAL_VAR(HRESULT)))) { \ - gpgmm::ErrorLog(GetErrorCode(GPGMM_LOCAL_VAR(HRESULT))) \ - << #expr << ": " \ - << GetErrorResultWithRemovalReason(GPGMM_LOCAL_VAR(HRESULT), device); \ - return GPGMM_LOCAL_VAR(HRESULT); \ - } \ - } \ - for (;;) \ +// For D3D12 calls that could remove device, the (optional) device ptr should be supplied as the +// last argument so the reason can be appended the result message. +#define GPGMM_RETURN_IF_FAILED(expr, ...) \ + { \ + auto GPGMM_LOCAL_VAR(HRESULT) = expr; \ + if (GPGMM_UNLIKELY(FAILED(GPGMM_LOCAL_VAR(HRESULT)))) { \ + gpgmm::ErrorLog(GetErrorCode(GPGMM_LOCAL_VAR(HRESULT))) \ + << #expr << ": " << GetErrorResultMessage(GPGMM_LOCAL_VAR(HRESULT), __VA_ARGS__); \ + return GPGMM_LOCAL_VAR(HRESULT); \ + } \ + } \ + for (;;) \ break #define GPGMM_RETURN_IF_SUCCEEDED(expr) \ @@ -48,12 +49,9 @@ for (;;) \ break -#define GPGMM_ASSERT_FAILED(hr) ASSERT(SUCCEEDED(hr)); -#define GPGMM_ASSERT_SUCCEEDED(hr) ASSERT(FAILED(hr)); - // Same as FAILED but also returns true if S_FALSE. -// S_FALSE is used to denote a result where the operation didn't do anything. -// For example, passing NULL to create an object without returning it will destroy it. +// S_FALSE is used to denote a HRESULT where the operation didn't do anything. +// For example, passing NULL to create an object without returning it. #define GPGMM_UNSUCCESSFUL(hr) (FAILED(hr) || (hr == S_FALSE)) namespace gpgmm::d3d12 { @@ -61,9 +59,12 @@ namespace gpgmm::d3d12 { HRESULT GetErrorResult(ErrorCode error); ErrorCode GetErrorCode(HRESULT error); - // Returns HRESULT error as a printable message. - // If the device is also specified and removed, a detailed message is supplied. - std::string GetErrorResultWithRemovalReason(HRESULT error, ID3D12Device* device); + // Returns non device removal HRESULT error as a printable message. + std::string GetErrorResultMessage(HRESULT error); + + // Returns device removal HRESULT error as a printable message. + std::string GetErrorResultMessage(HRESULT error, ID3D12Device* device); + std::string GetErrorResultToString(HRESULT error) noexcept; } // namespace gpgmm::d3d12 diff --git a/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp b/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp index ea7d3d8e..fc65fbc4 100644 --- a/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp @@ -128,7 +128,7 @@ namespace gpgmm::d3d12 { "Heap.CreateResidencyHeap", (RESIDENCY_HEAP_CREATE_RESIDENCY_HEAP_PARAMS{descriptor, pPageable})); - GPGMM_RETURN_IF_NULLPTR(pPageable); + GPGMM_RETURN_IF_NULL(pPageable); ResidencyManager* residencyManager = static_cast(pResidencyManager); const bool isResidencyDisabled = (pResidencyManager == nullptr); @@ -183,18 +183,17 @@ namespace gpgmm::d3d12 { // descriptor heap), they must be manually locked and unlocked to be inserted into the // residency cache. if (heap->GetInfo().Status != RESIDENCY_HEAP_STATUS_UNKNOWN) { - GPGMM_RETURN_IF_FAILED(residencyManager->InsertHeap(heap.get()), - GetDevice(pPageable).Get()); + GPGMM_RETURN_IF_FAILED(residencyManager->InsertHeap(heap.get())); } else { if (newDescriptor.Flags & RESIDENCY_HEAP_FLAG_CREATE_RESIDENT) { - GPGMM_RETURN_IF_FAILED(heap->Lock(), GetDevice(pPageable).Get()); - GPGMM_RETURN_IF_FAILED(heap->Unlock(), GetDevice(pPageable).Get()); + GPGMM_RETURN_IF_FAILED(heap->Lock()); + GPGMM_RETURN_IF_FAILED(heap->Unlock()); ASSERT(heap->GetInfo().Status == RESIDENCY_HEAP_STATUS_RESIDENT); } } if (descriptor.Flags & RESIDENCY_HEAP_FLAG_CREATE_LOCKED) { - GPGMM_RETURN_IF_FAILED(heap->Lock(), GetDevice(pPageable).Get()); + GPGMM_RETURN_IF_FAILED(heap->Lock()); } } else { @@ -232,7 +231,7 @@ namespace gpgmm::d3d12 { CreateHeapFn createHeapFn, void* pCreateHeapContext, IResidencyHeap** ppResidencyHeapOut) { - GPGMM_RETURN_IF_NULLPTR(pCreateHeapContext); + GPGMM_RETURN_IF_NULL(pCreateHeapContext); const bool isResidencyDisabled = (pResidencyManager == nullptr); @@ -254,10 +253,8 @@ namespace gpgmm::d3d12 { // Ensure enough budget exists before creating the heap to avoid an out-of-memory error. if (!isResidencyDisabled && (descriptor.Flags & RESIDENCY_HEAP_FLAG_CREATE_IN_BUDGET)) { uint64_t bytesEvicted = descriptor.SizeInBytes; - GPGMM_RETURN_IF_FAILED( - residencyManager->EvictInternal(descriptor.SizeInBytes, descriptor.HeapSegment, - &bytesEvicted), - residencyManager->mDevice); + GPGMM_RETURN_IF_FAILED(residencyManager->EvictInternal( + descriptor.SizeInBytes, descriptor.HeapSegment, &bytesEvicted)); if (bytesEvicted < descriptor.SizeInBytes) { DXGI_QUERY_VIDEO_MEMORY_INFO currentVideoInfo = {}; @@ -277,8 +274,7 @@ namespace gpgmm::d3d12 { } ComPtr pageable; - GPGMM_RETURN_IF_FAILED(createHeapFn(pCreateHeapContext, &pageable), - GetDevice(pageable.Get()).Get()); + GPGMM_RETURN_IF_FAILED(createHeapFn(pCreateHeapContext, &pageable)); return CreateResidencyHeap(descriptor, pResidencyManager, pageable.Get(), ppResidencyHeapOut); @@ -397,7 +393,7 @@ namespace gpgmm::d3d12 { HRESULT ResidencyHeap::GetResidencyManager(IResidencyManager** ppResidencyManagerOut) const { ComPtr residencyManager(mResidencyManager.Get()); - GPGMM_RETURN_IF_NULLPTR(residencyManager.Get()); + GPGMM_RETURN_IF_NULL(residencyManager.Get()); if (ppResidencyManagerOut != nullptr) { *ppResidencyManagerOut = residencyManager.Detach(); } else { diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index c3aa39f5..87ca3775 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -52,13 +52,13 @@ namespace gpgmm::d3d12 { ID3D12Device* pDevice, IDXGIAdapter3* pAdapter, IResidencyManager** ppResidencyManagerOut) { - GPGMM_RETURN_IF_NULLPTR(pAdapter); - GPGMM_RETURN_IF_NULLPTR(pDevice); + GPGMM_RETURN_IF_NULL(pAdapter); + GPGMM_RETURN_IF_NULL(pDevice); std::unique_ptr caps; { Caps* ptr = nullptr; - GPGMM_RETURN_IF_FAILED(Caps::CreateCaps(pDevice, pAdapter, &ptr), pDevice); + GPGMM_RETURN_IF_FAILED(Caps::CreateCaps(pDevice, pAdapter, &ptr)); caps.reset(ptr); } @@ -98,7 +98,7 @@ namespace gpgmm::d3d12 { } // Set the initial video memory limits. - GPGMM_RETURN_IF_FAILED(residencyManager->UpdateMemorySegments(), pDevice); + GPGMM_RETURN_IF_FAILED(residencyManager->UpdateMemorySegments()); DXGI_QUERY_VIDEO_MEMORY_INFO* localVideoMemorySegmentInfo = residencyManager->GetVideoMemoryInfo(DXGI_MEMORY_SEGMENT_GROUP_LOCAL); @@ -195,7 +195,7 @@ namespace gpgmm::d3d12 { // Increments number of locks on a heap to ensure the heap remains resident. HRESULT ResidencyManager::LockHeap(IResidencyHeap* pHeap) { - GPGMM_RETURN_IF_NULLPTR(pHeap); + GPGMM_RETURN_IF_NULL(pHeap); std::lock_guard lock(mMutex); @@ -206,8 +206,7 @@ namespace gpgmm::d3d12 { ComPtr pageable; GPGMM_RETURN_IF_FAILED(heap->QueryInterface(IID_PPV_ARGS(&pageable)), mDevice); GPGMM_RETURN_IF_FAILED( - MakeResident(heap->GetHeapSegment(), heap->GetSize(), 1, pageable.GetAddressOf()), - mDevice); + MakeResident(heap->GetHeapSegment(), heap->GetSize(), 1, pageable.GetAddressOf())); heap->SetResidencyStatus(RESIDENCY_HEAP_STATUS_RESIDENT); // Untracked heaps, created not resident, are not already attributed toward residency @@ -236,7 +235,7 @@ namespace gpgmm::d3d12 { // Decrements number of locks on a heap. When the number of locks becomes zero, the heap is // inserted into the LRU cache and becomes eligible for eviction. HRESULT ResidencyManager::UnlockHeap(IResidencyHeap* pHeap) { - GPGMM_RETURN_IF_NULLPTR(pHeap); + GPGMM_RETURN_IF_NULL(pHeap); std::lock_guard lock(mMutex); ResidencyHeap* heap = static_cast(pHeap); @@ -264,7 +263,7 @@ namespace gpgmm::d3d12 { // When all locks have been removed, the resource remains resident and becomes tracked in // the corresponding LRU. - GPGMM_RETURN_IF_FAILED(InsertHeapInternal(heap), mDevice); + GPGMM_RETURN_IF_FAILED(InsertHeapInternal(heap)); // Heaps inserted into the residency cache are already attributed in residency usage. mStats.CurrentHeapCount--; @@ -346,7 +345,7 @@ namespace gpgmm::d3d12 { videoMemorySegmentInfo->AvailableForReservation = availableForReservation; if (IsBudgetNotificationUpdatesDisabled()) { - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment), mDevice); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment)); } if (pCurrentReservationOut != nullptr) { @@ -472,10 +471,8 @@ namespace gpgmm::d3d12 { HRESULT ResidencyManager::UpdateMemorySegments() { std::lock_guard lock(mMutex); - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_LOCAL), - mDevice); - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL), - mDevice); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_LOCAL)); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL)); return S_OK; } @@ -484,7 +481,7 @@ namespace gpgmm::d3d12 { DXGI_QUERY_VIDEO_MEMORY_INFO* pVideoMemoryInfoOut) { std::lock_guard lock(mMutex); if (IsBudgetNotificationUpdatesDisabled()) { - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment), mDevice); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment)); } if (pVideoMemoryInfoOut != nullptr) { @@ -503,7 +500,7 @@ namespace gpgmm::d3d12 { DXGI_QUERY_VIDEO_MEMORY_INFO* pVideoMemoryInfo = GetVideoMemoryInfo(heapSegment); if (IsBudgetNotificationUpdatesDisabled()) { - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment), mDevice); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment)); } // If a budget wasn't provided, it not possible to evict. This is because either the budget @@ -535,7 +532,7 @@ namespace gpgmm::d3d12 { return S_OK; } - GPGMM_RETURN_IF_FAILED(EnsureResidencyFenceExists(), mDevice); + GPGMM_RETURN_IF_FAILED(EnsureResidencyFenceExists()); uint64_t bytesEvicted = 0; while (bytesEvicted < bytesNeededToBeUnderBudget) { @@ -563,7 +560,7 @@ namespace gpgmm::d3d12 { // We must ensure that any previous use of a resource has completed before the resource // can be evicted. - GPGMM_RETURN_IF_FAILED(mResidencyFence->WaitFor(lastUsedFenceValue), mDevice); + GPGMM_RETURN_IF_FAILED(mResidencyFence->WaitFor(lastUsedFenceValue)); heap->RemoveFromList(); heap->SetResidencyStatus(RESIDENCY_HEAP_STATUS_EVICTED); @@ -571,7 +568,7 @@ namespace gpgmm::d3d12 { bytesEvicted += heap->GetSize(); ComPtr pageable; - GPGMM_RETURN_IF_FAILED(heap->QueryInterface(IID_PPV_ARGS(&pageable)), mDevice); + GPGMM_RETURN_IF_FAILED(heap->QueryInterface(IID_PPV_ARGS(&pageable))); objectsToEvict.push_back(pageable.Get()); } @@ -622,7 +619,7 @@ namespace gpgmm::d3d12 { return GetErrorResult(ErrorCode::kUnsupported); } - GPGMM_RETURN_IF_FAILED(EnsureResidencyFenceExists(), mDevice); + GPGMM_RETURN_IF_FAILED(EnsureResidencyFenceExists()); ResidencyList* residencyList = static_cast(ppResidencyLists[0]); @@ -650,7 +647,7 @@ namespace gpgmm::d3d12 { heap->RemoveFromList(); } else { ComPtr pageable; - GPGMM_RETURN_IF_FAILED(heap->QueryInterface(IID_PPV_ARGS(&pageable)), mDevice); + GPGMM_RETURN_IF_FAILED(heap->QueryInterface(IID_PPV_ARGS(&pageable))); if (heap->GetHeapSegment() == DXGI_MEMORY_SEGMENT_GROUP_LOCAL) { localSizeToMakeResident += heap->GetSize(); @@ -690,15 +687,13 @@ namespace gpgmm::d3d12 { static_cast(localHeapsToMakeResident.size()); GPGMM_RETURN_IF_FAILED( MakeResident(DXGI_MEMORY_SEGMENT_GROUP_LOCAL, localSizeToMakeResident, - numberOfObjectsToMakeResident, localHeapsToMakeResident.data()), - mDevice); + numberOfObjectsToMakeResident, localHeapsToMakeResident.data())); } else if (nonLocalSizeToMakeResident > 0) { const uint32_t numberOfObjectsToMakeResident = static_cast(nonLocalHeapsToMakeResident.size()); GPGMM_RETURN_IF_FAILED( MakeResident(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, nonLocalSizeToMakeResident, - numberOfObjectsToMakeResident, nonLocalHeapsToMakeResident.data()), - mDevice); + numberOfObjectsToMakeResident, nonLocalHeapsToMakeResident.data())); } // Once MakeResident succeeds, we must assume the heaps are resident since D3D12 provides @@ -720,17 +715,16 @@ namespace gpgmm::d3d12 { // ExecuteCommandLists themself. We must continue to keep the residency state of heaps // synchronized with the GPU in either case. if (pQueue != nullptr) { - GPGMM_RETURN_IF_FAILED(mResidencyFence->Signal(pQueue), mDevice); + GPGMM_RETURN_IF_FAILED(mResidencyFence->Signal(pQueue)); } // Keep video memory segments up-to-date. This must always happen because if the budget // never changes (ie. not manually updated or through budget change events), the // residency manager wouldn't know what to page in or out. if (IsBudgetNotificationUpdatesDisabled()) { - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_LOCAL), - mDevice); - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL), - mDevice); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_LOCAL)); + GPGMM_RETURN_IF_FAILED( + UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL)); } GPGMM_TRACE_EVENT_OBJECT_CALL( @@ -746,7 +740,7 @@ namespace gpgmm::d3d12 { ID3D12Pageable** allocations) { GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, "ResidencyManager.MakeResident"); - GPGMM_RETURN_IF_FAILED(EvictInternal(sizeToMakeResident, heapSegment, nullptr), mDevice); + GPGMM_RETURN_IF_FAILED(EvictInternal(sizeToMakeResident, heapSegment, nullptr)); DebugEvent(MessageId::kBudgetExceeded, this) << "GPU page-in. Number of allocations: " << numberOfObjectsToMakeResident << " (" @@ -758,7 +752,7 @@ namespace gpgmm::d3d12 { // able to continue after calling Evict again. ComPtr device3; if (SUCCEEDED(mDevice->QueryInterface(IID_PPV_ARGS(&device3)))) { - GPGMM_RETURN_IF_FAILED(EnsureResidencyFenceExists(), mDevice); + GPGMM_RETURN_IF_FAILED(EnsureResidencyFenceExists()); GPGMM_RETURN_IF_SUCCEEDED(device3->EnqueueMakeResident( (mIsAlwaysInBudget) ? D3D12_RESIDENCY_FLAG_DENY_OVERBUDGET : D3D12_RESIDENCY_FLAG_NONE, @@ -775,7 +769,7 @@ namespace gpgmm::d3d12 { // execution and must throw a fatal error. uint64_t evictedSizeInBytes = 0; GPGMM_RETURN_IF_FAILED( - EvictInternal(mEvictSizeInBytes, heapSegment, &evictedSizeInBytes), mDevice); + EvictInternal(mEvictSizeInBytes, heapSegment, &evictedSizeInBytes)); if (evictedSizeInBytes == 0) { ErrorLog(ErrorCode::kBudgetInvalid, this) << "Unable to evict enough heaps to stay within budget. This " @@ -885,7 +879,7 @@ namespace gpgmm::d3d12 { HRESULT ResidencyManager::SetResidencyStatus(IResidencyHeap* pHeap, const RESIDENCY_HEAP_STATUS& newStatus) { - GPGMM_RETURN_IF_NULLPTR(pHeap); + GPGMM_RETURN_IF_NULL(pHeap); ResidencyHeap* heap = static_cast(pHeap); if (heap->GetInfo().IsLocked) { @@ -916,7 +910,7 @@ namespace gpgmm::d3d12 { } Fence* fencePtr = nullptr; - GPGMM_RETURN_IF_FAILED(Fence::CreateFence(mDevice, mInitialFenceValue, &fencePtr), mDevice); + GPGMM_RETURN_IF_FAILED(Fence::CreateFence(mDevice, mInitialFenceValue, &fencePtr)); mResidencyFence.reset(fencePtr); return S_OK; } diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp index 37f9885e..0ef3b0d6 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp @@ -135,7 +135,7 @@ namespace gpgmm::d3d12 { ResidencyHeap* residencyHeap = static_cast(GetMemory()); if (SUCCEEDED(residencyHeap->GetResidencyManager(nullptr))) { - GPGMM_RETURN_IF_FAILED(residencyHeap->Lock(), GetDevice(mResource.Get()).Get()); + GPGMM_RETURN_IF_FAILED(residencyHeap->Lock()); } // Range coordinates are always subresource-relative so the range should only be diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index e2ca2036..c6b76bc2 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -400,13 +400,13 @@ namespace gpgmm::d3d12 { IDXGIAdapter* pAdapter, IResourceAllocator** ppResourceAllocatorOut, IResidencyManager** ppResidencyManagerOut) { - GPGMM_RETURN_IF_NULLPTR(pDevice); + GPGMM_RETURN_IF_NULL(pDevice); ComPtr residencyManager; if (ppResidencyManagerOut != nullptr) { ComPtr adapter3; if (pAdapter != nullptr) { - GPGMM_RETURN_IF_FAILED(pAdapter->QueryInterface(IID_PPV_ARGS(&adapter3)), pDevice); + GPGMM_RETURN_IF_FAILED(pAdapter->QueryInterface(IID_PPV_ARGS(&adapter3))); } RESIDENCY_MANAGER_DESC residencyDesc = {}; @@ -418,14 +418,12 @@ namespace gpgmm::d3d12 { } GPGMM_RETURN_IF_FAILED(ResidencyManager::CreateResidencyManager( - residencyDesc, pDevice, adapter3.Get(), &residencyManager), - pDevice); + residencyDesc, pDevice, adapter3.Get(), &residencyManager)); } ComPtr resourceAllocator; GPGMM_RETURN_IF_FAILED(CreateResourceAllocator(allocatorDescriptor, pDevice, pAdapter, - residencyManager.Get(), &resourceAllocator), - pDevice); + residencyManager.Get(), &resourceAllocator)); if (ppResourceAllocatorOut != nullptr) { *ppResourceAllocatorOut = resourceAllocator.Detach(); @@ -445,12 +443,12 @@ namespace gpgmm::d3d12 { IDXGIAdapter* pAdapter, IResidencyManager* pResidencyManager, IResourceAllocator** ppResourceAllocatorOut) { - GPGMM_RETURN_IF_NULLPTR(pDevice); + GPGMM_RETURN_IF_NULL(pDevice); std::unique_ptr caps; { Caps* ptr = nullptr; - GPGMM_RETURN_IF_FAILED(Caps::CreateCaps(pDevice, pAdapter, &ptr), pDevice); + GPGMM_RETURN_IF_FAILED(Caps::CreateCaps(pDevice, pAdapter, &ptr)); caps.reset(ptr); } @@ -564,7 +562,7 @@ namespace gpgmm::d3d12 { ComPtr leakMessageQueue; if (SUCCEEDED(newDescriptor.Device.As(&leakMessageQueue))) { D3D12_INFO_QUEUE_FILTER emptyFilter{}; - GPGMM_RETURN_IF_FAILED(leakMessageQueue->PushRetrievalFilter(&emptyFilter), mDevice); + GPGMM_RETURN_IF_FAILED(leakMessageQueue->PushRetrievalFilter(&emptyFilter)); } else { WarnLog(MessageId::kInvalidArgument) << "GPGMM_ENABLE_DEVICE_LEAK_CHECKS has no effect because the D3D12 debug " @@ -1030,7 +1028,7 @@ namespace gpgmm::d3d12 { const uint64_t bytesToRelease = std::max(mReleaseSizeInBytes, resourceInfo.SizeInBytes); GPGMM_RETURN_IF_FAILED( - ReleaseResourceHeapsInternal(bytesToRelease, &freedSizeInBytes), mDevice); + ReleaseResourceHeapsInternal(bytesToRelease, &freedSizeInBytes)); // If not enough memory can be freed after ReleaseResourceHeaps(), we cannot // continue creation and must return E_OUTOFMEMORY for real. if (freedSizeInBytes < resourceInfo.SizeInBytes) { @@ -1335,12 +1333,9 @@ namespace gpgmm::d3d12 { ResidencyHeap* resourceHeap = static_cast(subAllocation.GetMemory()); - GPGMM_RETURN_IF_FAILED( - ResourceAllocation::CreateResourceAllocation( - allocationDesc, /*resourceAllocator*/ this, - subAllocation.GetAllocator(), resourceHeap, subAllocation.GetBlock(), - nullptr, ppResourceAllocationOut), - mDevice); + GPGMM_RETURN_IF_FAILED(ResourceAllocation::CreateResourceAllocation( + allocationDesc, /*resourceAllocator*/ this, subAllocation.GetAllocator(), + resourceHeap, subAllocation.GetBlock(), nullptr, ppResourceAllocationOut)); return S_OK; })); @@ -1365,11 +1360,9 @@ namespace gpgmm::d3d12 { ComPtr placedResource; ResidencyHeap* resourceHeap = static_cast(subAllocation.GetMemory()); - GPGMM_RETURN_IF_FAILED( - CreatePlacedResource(resourceHeap, subAllocation.GetOffset(), - &newResourceDesc, clearValue, initialResourceState, - &placedResource), - mDevice); + GPGMM_RETURN_IF_FAILED(CreatePlacedResource( + resourceHeap, subAllocation.GetOffset(), &newResourceDesc, clearValue, + initialResourceState, &placedResource)); RESOURCE_RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.SizeInBytes = request.SizeInBytes; @@ -1378,12 +1371,10 @@ namespace gpgmm::d3d12 { static_cast(subAllocation.GetMethod()); allocationDesc.OffsetFromResource = 0; - GPGMM_RETURN_IF_FAILED( - ResourceAllocation::CreateResourceAllocation( - allocationDesc, /*resourceAllocator*/ this, - subAllocation.GetAllocator(), resourceHeap, subAllocation.GetBlock(), - std::move(placedResource), ppResourceAllocationOut), - mDevice); + GPGMM_RETURN_IF_FAILED(ResourceAllocation::CreateResourceAllocation( + allocationDesc, /*resourceAllocator*/ this, subAllocation.GetAllocator(), + resourceHeap, subAllocation.GetBlock(), std::move(placedResource), + ppResourceAllocationOut)); return S_OK; })); @@ -1414,8 +1405,7 @@ namespace gpgmm::d3d12 { ComPtr placedResource; GPGMM_RETURN_IF_FAILED( CreatePlacedResource(resourceHeap, allocation.GetOffset(), &newResourceDesc, - clearValue, initialResourceState, &placedResource), - mDevice); + clearValue, initialResourceState, &placedResource)); RESOURCE_RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.SizeInBytes = dedicatedRequest.SizeInBytes; @@ -1424,12 +1414,10 @@ namespace gpgmm::d3d12 { static_cast(allocation.GetMethod()); allocationDesc.OffsetFromResource = 0; - GPGMM_RETURN_IF_FAILED( - ResourceAllocation::CreateResourceAllocation( - allocationDesc, /*resourceAllocator*/ this, allocation.GetAllocator(), - resourceHeap, allocation.GetBlock(), std::move(placedResource), - ppResourceAllocationOut), - mDevice); + GPGMM_RETURN_IF_FAILED(ResourceAllocation::CreateResourceAllocation( + allocationDesc, /*resourceAllocator*/ this, allocation.GetAllocator(), + resourceHeap, allocation.GetBlock(), std::move(placedResource), + ppResourceAllocationOut)); return S_OK; })); @@ -1497,7 +1485,7 @@ namespace gpgmm::d3d12 { HRESULT ResourceAllocator::CreateResource(const RESOURCE_ALLOCATION_DESC& allocationDescriptor, ID3D12Resource* pCommittedResource, IResourceAllocation** ppResourceAllocationOut) { - GPGMM_RETURN_IF_NULLPTR(pCommittedResource); + GPGMM_RETURN_IF_NULL(pCommittedResource); std::lock_guard lock(mMutex); @@ -1555,15 +1543,12 @@ namespace gpgmm::d3d12 { ImportResourceCallbackContext importResourceCallbackContext(pCommittedResource); ComPtr resourceHeap; - GPGMM_RETURN_IF_FAILED( - ResidencyHeap::CreateResidencyHeap( - resourceHeapDesc, - (allocationDescriptor.Flags & RESOURCE_ALLOCATION_FLAG_NEVER_RESIDENT) - ? nullptr - : mResidencyManager.Get(), - ImportResourceCallbackContext::GetHeap, &importResourceCallbackContext, - &resourceHeap), - mDevice); + GPGMM_RETURN_IF_FAILED(ResidencyHeap::CreateResidencyHeap( + resourceHeapDesc, + (allocationDescriptor.Flags & RESOURCE_ALLOCATION_FLAG_NEVER_RESIDENT) + ? nullptr + : mResidencyManager.Get(), + ImportResourceCallbackContext::GetHeap, &importResourceCallbackContext, &resourceHeap)); const uint64_t& allocationSize = resourceInfo.SizeInBytes; mStats.UsedMemoryUsage += allocationSize; @@ -1596,7 +1581,7 @@ namespace gpgmm::d3d12 { ComPtr placedResource; { ComPtr heap; - GPGMM_RETURN_IF_FAILED(resourceHeap->QueryInterface(IID_PPV_ARGS(&heap)), mDevice); + GPGMM_RETURN_IF_FAILED(resourceHeap->QueryInterface(IID_PPV_ARGS(&heap))); ScopedResidencyLock residencyLock(mResidencyManager.Get(), resourceHeap); GPGMM_RETURN_IF_FAILED( @@ -1638,13 +1623,11 @@ namespace gpgmm::d3d12 { resourceDescriptor, clearValue, initialResourceState); - GPGMM_RETURN_IF_FAILED( - ResidencyHeap::CreateResidencyHeap(resourceHeapDesc, mResidencyManager.Get(), - CreateCommittedResourceCallbackContext::CreateHeap, - &callbackContext, &resourceHeap), - mDevice); + GPGMM_RETURN_IF_FAILED(ResidencyHeap::CreateResidencyHeap( + resourceHeapDesc, mResidencyManager.Get(), + CreateCommittedResourceCallbackContext::CreateHeap, &callbackContext, &resourceHeap)); - GPGMM_RETURN_IF_FAILED(resourceHeap->SetDebugName(L"Resource heap (committed)"), mDevice); + GPGMM_RETURN_IF_FAILED(resourceHeap->SetDebugName(L"Resource heap (committed)")); if (resourceHeapOut != nullptr) { *resourceHeapOut = static_cast(resourceHeap.Detach()); @@ -1775,13 +1758,11 @@ namespace gpgmm::d3d12 { for (uint64_t i = 0; i < leakMessageQueue->GetNumStoredMessagesAllowedByRetrievalFilter(); ++i) { SIZE_T messageLength = 0; - GPGMM_RETURN_IF_FAILED(leakMessageQueue->GetMessage(i, nullptr, &messageLength), - mDevice); + GPGMM_RETURN_IF_FAILED(leakMessageQueue->GetMessage(i, nullptr, &messageLength)); std::unique_ptr messageData(new uint8_t[messageLength]); D3D12_MESSAGE* message = reinterpret_cast(messageData.get()); - GPGMM_RETURN_IF_FAILED(leakMessageQueue->GetMessage(i, message, &messageLength), - mDevice); + GPGMM_RETURN_IF_FAILED(leakMessageQueue->GetMessage(i, message, &messageLength)); switch (message->ID) { case D3D12_MESSAGE_ID_LIVE_HEAP: