diff --git a/src/gpgmm/d3d12/CapsD3D12.cpp b/src/gpgmm/d3d12/CapsD3D12.cpp index c621a9ac..43503300 100644 --- a/src/gpgmm/d3d12/CapsD3D12.cpp +++ b/src/gpgmm/d3d12/CapsD3D12.cpp @@ -27,7 +27,7 @@ namespace gpgmm::d3d12 { HRESULT SetMaxResourceSize(ID3D12Device* device, uint64_t* sizeOut) { D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT feature = {}; - GPGMM_RETURN_IF_FAILED_ON_DEVICE( + GPGMM_RETURN_IF_FAILED( device->CheckFeatureSupport(D3D12_FEATURE_GPU_VIRTUAL_ADDRESS_SUPPORT, &feature, sizeof(D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT)), device); @@ -43,7 +43,7 @@ namespace gpgmm::d3d12 { HRESULT SetMaxResourceHeapSize(ID3D12Device* device, uint64_t* sizeOut) { D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT feature = {}; - GPGMM_RETURN_IF_FAILED_ON_DEVICE( + GPGMM_RETURN_IF_FAILED( device->CheckFeatureSupport(D3D12_FEATURE_GPU_VIRTUAL_ADDRESS_SUPPORT, &feature, sizeof(D3D12_FEATURE_DATA_GPU_VIRTUAL_ADDRESS_SUPPORT)), device); @@ -76,7 +76,7 @@ namespace gpgmm::d3d12 { HRESULT SetMaxResourceHeapTierSupported(ID3D12Device* device, D3D12_RESOURCE_HEAP_TIER* maxResourceHeapTierOut) { D3D12_FEATURE_DATA_D3D12_OPTIONS options = {}; - GPGMM_RETURN_IF_FAILED_ON_DEVICE( + GPGMM_RETURN_IF_FAILED( device->CheckFeatureSupport(D3D12_FEATURE_D3D12_OPTIONS, &options, sizeof(options)), device); *maxResourceHeapTierOut = options.ResourceHeapTier; @@ -88,22 +88,23 @@ namespace gpgmm::d3d12 { GPGMM_RETURN_IF_NULLPTR(device); std::unique_ptr caps(new Caps()); - GPGMM_RETURN_IF_FAILED(SetMaxResourceSize(device, &caps->mMaxResourceSize)); - GPGMM_RETURN_IF_FAILED(SetMaxResourceHeapSize(device, &caps->mMaxResourceHeapSize)); + 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( - SetMaxResourceHeapTierSupported(device, &caps->mMaxResourceHeapTier)); - GPGMM_RETURN_IF_FAILED( - SetCreateHeapNotResidentSupported(device, &caps->mIsCreateHeapNotResidentSupported)); + SetCreateHeapNotResidentSupported(device, &caps->mIsCreateHeapNotResidentSupported), + device); D3D12_FEATURE_DATA_ARCHITECTURE arch = {}; - GPGMM_RETURN_IF_FAILED_ON_DEVICE( + GPGMM_RETURN_IF_FAILED( device->CheckFeatureSupport(D3D12_FEATURE_ARCHITECTURE, &arch, sizeof(arch)), device); caps->mIsAdapterUMA = arch.UMA; caps->mIsAdapterCacheCoherentUMA = arch.CacheCoherentUMA; if (adapter != nullptr) { DXGI_ADAPTER_DESC adapterDesc; - GPGMM_RETURN_IF_FAILED(adapter->GetDesc(&adapterDesc)); + GPGMM_RETURN_IF_FAILED(adapter->GetDesc(&adapterDesc), device); caps->mSharedSegmentSize = adapterDesc.SharedSystemMemory; caps->mDedicatedSegmentSize = adapterDesc.DedicatedVideoMemory; diff --git a/src/gpgmm/d3d12/ErrorD3D12.h b/src/gpgmm/d3d12/ErrorD3D12.h index 60528daa..ed6fcc04 100644 --- a/src/gpgmm/d3d12/ErrorD3D12.h +++ b/src/gpgmm/d3d12/ErrorD3D12.h @@ -31,9 +31,7 @@ for (;;) \ break -#define GPGMM_RETURN_IF_FAILED(expr) GPGMM_RETURN_IF_FAILED_ON_DEVICE(expr, nullptr) - -#define GPGMM_RETURN_IF_FAILED_ON_DEVICE(expr, device) \ +#define GPGMM_RETURN_IF_FAILED(expr, device) \ { \ HRESULT hr = expr; \ if (GPGMM_UNLIKELY(FAILED(hr))) { \ diff --git a/src/gpgmm/d3d12/FenceD3D12.cpp b/src/gpgmm/d3d12/FenceD3D12.cpp index b539b2d1..f874926c 100644 --- a/src/gpgmm/d3d12/FenceD3D12.cpp +++ b/src/gpgmm/d3d12/FenceD3D12.cpp @@ -15,6 +15,7 @@ #include "gpgmm/d3d12/FenceD3D12.h" #include "gpgmm/d3d12/ErrorD3D12.h" +#include "gpgmm/d3d12/UtilsD3D12.h" #include "gpgmm/utils/Assert.h" namespace gpgmm::d3d12 { @@ -23,7 +24,7 @@ namespace gpgmm::d3d12 { HRESULT Fence::CreateFence(ID3D12Device* device, uint64_t initialValue, Fence** fenceOut) { ComPtr fence; GPGMM_RETURN_IF_FAILED( - device->CreateFence(initialValue, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence))); + device->CreateFence(initialValue, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&fence)), device); *fenceOut = new Fence(fence, initialValue); return S_OK; } @@ -52,7 +53,8 @@ namespace gpgmm::d3d12 { HRESULT Fence::WaitFor(uint64_t fenceValue) { if (!IsCompleted(fenceValue)) { - GPGMM_RETURN_IF_FAILED(mFence->SetEventOnCompletion(fenceValue, mCompletionEvent)); + GPGMM_RETURN_IF_FAILED(mFence->SetEventOnCompletion(fenceValue, mCompletionEvent), + GetDevice(mFence.Get())); // Wait for the event to complete (it will automatically reset). const uint32_t result = WaitForSingleObject(mCompletionEvent, INFINITE); @@ -80,7 +82,8 @@ namespace gpgmm::d3d12 { HRESULT Fence::Signal(ID3D12CommandQueue* pCommandQueue) { ASSERT(mLastSignaledFence != mCurrentFence); - GPGMM_RETURN_IF_FAILED(pCommandQueue->Signal(mFence.Get(), mCurrentFence)); + GPGMM_RETURN_IF_FAILED(pCommandQueue->Signal(mFence.Get(), mCurrentFence), + GetDevice(pCommandQueue)); mLastSignaledFence = mCurrentFence; mCurrentFence++; return S_OK; diff --git a/src/gpgmm/d3d12/HeapD3D12.cpp b/src/gpgmm/d3d12/HeapD3D12.cpp index 4ba0748c..453538b7 100644 --- a/src/gpgmm/d3d12/HeapD3D12.cpp +++ b/src/gpgmm/d3d12/HeapD3D12.cpp @@ -38,7 +38,8 @@ namespace gpgmm::d3d12 { ComPtr committedResource; if (SUCCEEDED(pageable.As(&committedResource))) { - GPGMM_RETURN_IF_FAILED(committedResource->GetHeapProperties(nullptr, heapFlags)); + GPGMM_RETURN_IF_FAILED(committedResource->GetHeapProperties(nullptr, heapFlags), + GetDevice(committedResource.Get())); return S_OK; } @@ -78,8 +79,10 @@ namespace gpgmm::d3d12 { // Ensure enough budget exists before creating the heap to avoid an out-of-memory error. if (!isResidencyDisabled && (descriptor.Flags & HEAP_FLAG_ALWAYS_IN_BUDGET)) { uint64_t bytesEvicted = descriptor.SizeInBytes; - GPGMM_RETURN_IF_FAILED(residencyManager->EvictInternal( - descriptor.SizeInBytes, descriptor.HeapSegment, &bytesEvicted)); + GPGMM_RETURN_IF_FAILED( + residencyManager->EvictInternal(descriptor.SizeInBytes, descriptor.HeapSegment, + &bytesEvicted), + residencyManager->mDevice); if (bytesEvicted < descriptor.SizeInBytes) { DXGI_QUERY_VIDEO_MEMORY_INFO currentVideoInfo = {}; @@ -99,8 +102,8 @@ namespace gpgmm::d3d12 { } ComPtr pageable; - GPGMM_RETURN_IF_FAILED_ON_DEVICE(createHeapFn(pCreateHeapContext, &pageable), - GetDevice(pageable.Get())); + GPGMM_RETURN_IF_FAILED(createHeapFn(pCreateHeapContext, &pageable), + GetDevice(pageable.Get())); // Pageable-based type is required for residency-managed heaps. GPGMM_RETURN_IF_NULLPTR(pageable); @@ -137,11 +140,14 @@ namespace gpgmm::d3d12 { // descriptor heap), they must be manually locked and unlocked to be inserted into the // residency cache. if (heap->mState != RESIDENCY_STATUS_UNKNOWN) { - GPGMM_RETURN_IF_FAILED(residencyManager->InsertHeap(heap.get())); + GPGMM_RETURN_IF_FAILED(residencyManager->InsertHeap(heap.get()), + GetDevice(pageable.Get())); } else { if (descriptor.Flags & HEAP_FLAG_ALWAYS_IN_RESIDENCY) { - GPGMM_RETURN_IF_FAILED(residencyManager->LockHeap(heap.get())); - GPGMM_RETURN_IF_FAILED(residencyManager->UnlockHeap(heap.get())); + GPGMM_RETURN_IF_FAILED(residencyManager->LockHeap(heap.get()), + GetDevice(pageable.Get())); + GPGMM_RETURN_IF_FAILED(residencyManager->UnlockHeap(heap.get()), + GetDevice(pageable.Get())); ASSERT(heap->mState == RESIDENCY_STATUS_CURRENT_RESIDENT); } } @@ -154,7 +160,7 @@ namespace gpgmm::d3d12 { } } - GPGMM_RETURN_IF_FAILED(heap->SetDebugName(descriptor.DebugName)); + GPGMM_RETURN_IF_FAILED(heap->SetDebugName(descriptor.DebugName), GetDevice(pageable.Get())); GPGMM_TRACE_EVENT_OBJECT_SNAPSHOT(heap.get(), descriptor); DebugLog(heap.get(), MessageId::kObjectCreated) diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index 46b99622..d7f35520 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -180,7 +180,7 @@ namespace gpgmm::d3d12 { std::unique_ptr caps; { Caps* ptr = nullptr; - GPGMM_RETURN_IF_FAILED(Caps::CreateCaps(pDevice, pAdapter, &ptr)); + GPGMM_RETURN_IF_FAILED(Caps::CreateCaps(pDevice, pAdapter, &ptr), pDevice); caps.reset(ptr); } @@ -211,13 +211,13 @@ namespace gpgmm::d3d12 { // Require automatic video memory budget updates. if (!(descriptor.Flags & RESIDENCY_FLAG_DISABLE_BUDGET_UPDATES_ON_WORKER_THREAD)) { - GPGMM_RETURN_IF_FAILED(residencyManager->StartBudgetNotificationUpdates()); + GPGMM_RETURN_IF_FAILED(residencyManager->StartBudgetNotificationUpdates(), pDevice); DebugLog(residencyManager.get(), MessageId::kBudgetUpdated) << "OS based memory budget updates were successfully enabled."; } // Set the initial video memory limits. - GPGMM_RETURN_IF_FAILED(residencyManager->UpdateMemorySegments()); + GPGMM_RETURN_IF_FAILED(residencyManager->UpdateMemorySegments(), pDevice); DXGI_QUERY_VIDEO_MEMORY_INFO* localVideoMemorySegmentInfo = residencyManager->GetVideoMemoryInfo(DXGI_MEMORY_SEGMENT_GROUP_LOCAL); @@ -324,8 +324,8 @@ namespace gpgmm::d3d12 { if (!heap->IsInList() && !heap->IsResidencyLocked()) { ComPtr pageable; - GPGMM_RETURN_IF_FAILED(heap->QueryInterface(IID_PPV_ARGS(&pageable))); - GPGMM_RETURN_IF_FAILED_ON_DEVICE( + GPGMM_RETURN_IF_FAILED(heap->QueryInterface(IID_PPV_ARGS(&pageable)), mDevice); + GPGMM_RETURN_IF_FAILED( MakeResident(heap->GetHeapSegment(), heap->GetSize(), 1, pageable.GetAddressOf()), mDevice); heap->SetResidencyState(RESIDENCY_STATUS_CURRENT_RESIDENT); @@ -384,7 +384,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)); + GPGMM_RETURN_IF_FAILED(InsertHeapInternal(heap), mDevice); // Heaps inserted into the residency cache are already attributed in residency usage. mStats.CurrentHeapCount--; @@ -466,7 +466,7 @@ namespace gpgmm::d3d12 { videoMemorySegmentInfo->AvailableForReservation = availableForReservation; if (IsBudgetNotificationUpdatesDisabled()) { - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment)); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment), mDevice); } if (pCurrentReservationOut != nullptr) { @@ -485,7 +485,7 @@ namespace gpgmm::d3d12 { DXGI_QUERY_VIDEO_MEMORY_INFO queryVideoMemoryInfoOut; GPGMM_RETURN_IF_FAILED( - mAdapter->QueryVideoMemoryInfo(0, heapSegment, &queryVideoMemoryInfoOut)); + mAdapter->QueryVideoMemoryInfo(0, heapSegment, &queryVideoMemoryInfoOut), mDevice); // The video memory budget provided by QueryVideoMemoryInfo is defined by the operating // system, and may be lower than expected in certain scenarios. Under memory pressure, we @@ -591,8 +591,10 @@ namespace gpgmm::d3d12 { HRESULT ResidencyManager::UpdateMemorySegments() { std::lock_guard lock(mMutex); - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_LOCAL)); - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL)); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_LOCAL), + mDevice); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL), + mDevice); return S_OK; } @@ -601,7 +603,7 @@ namespace gpgmm::d3d12 { DXGI_QUERY_VIDEO_MEMORY_INFO* pVideoMemoryInfoOut) { std::lock_guard lock(mMutex); if (IsBudgetNotificationUpdatesDisabled()) { - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment)); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment), mDevice); } if (pVideoMemoryInfoOut != nullptr) { @@ -620,7 +622,7 @@ namespace gpgmm::d3d12 { DXGI_QUERY_VIDEO_MEMORY_INFO* pVideoMemoryInfo = GetVideoMemoryInfo(heapSegment); if (IsBudgetNotificationUpdatesDisabled()) { - GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment)); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(heapSegment), mDevice); } // If a budget wasn't provided, it not possible to evict. This is because either the budget @@ -652,7 +654,7 @@ namespace gpgmm::d3d12 { return S_OK; } - GPGMM_RETURN_IF_FAILED(EnsureResidencyFenceExists()); + GPGMM_RETURN_IF_FAILED(EnsureResidencyFenceExists(), mDevice); uint64_t bytesEvicted = 0; while (bytesEvicted < bytesNeededToBeUnderBudget) { @@ -680,7 +682,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)); + GPGMM_RETURN_IF_FAILED(mResidencyFence->WaitFor(lastUsedFenceValue), mDevice); heap->RemoveFromList(); heap->SetResidencyState(RESIDENCY_STATUS_PENDING_RESIDENCY); @@ -688,7 +690,7 @@ namespace gpgmm::d3d12 { bytesEvicted += heap->GetSize(); ComPtr pageable; - GPGMM_RETURN_IF_FAILED(heap->QueryInterface(IID_PPV_ARGS(&pageable))); + GPGMM_RETURN_IF_FAILED(heap->QueryInterface(IID_PPV_ARGS(&pageable)), mDevice); objectsToEvict.push_back(pageable.Get()); } @@ -697,8 +699,8 @@ namespace gpgmm::d3d12 { GPGMM_TRACE_EVENT_METRIC("GPU memory page-out (MB)", GPGMM_BYTES_TO_MB(bytesEvicted)); const uint32_t objectEvictCount = static_cast(objectsToEvict.size()); - GPGMM_RETURN_IF_FAILED_ON_DEVICE( - mDevice->Evict(objectEvictCount, objectsToEvict.data()), mDevice); + GPGMM_RETURN_IF_FAILED(mDevice->Evict(objectEvictCount, objectsToEvict.data()), + mDevice); DebugEvent(this, MessageId::kBudgetExceeded) << "GPU page-out. Number of allocations: " << objectsToEvict.size() << " (" @@ -739,7 +741,7 @@ namespace gpgmm::d3d12 { return E_NOTIMPL; } - GPGMM_RETURN_IF_FAILED(EnsureResidencyFenceExists()); + GPGMM_RETURN_IF_FAILED(EnsureResidencyFenceExists(), mDevice); ResidencyList* residencyList = static_cast(ppResidencyLists[0]); @@ -767,7 +769,7 @@ namespace gpgmm::d3d12 { heap->RemoveFromList(); } else { ComPtr pageable; - GPGMM_RETURN_IF_FAILED(heap->QueryInterface(IID_PPV_ARGS(&pageable))); + GPGMM_RETURN_IF_FAILED(heap->QueryInterface(IID_PPV_ARGS(&pageable)), mDevice); if (heap->GetHeapSegment() == DXGI_MEMORY_SEGMENT_GROUP_LOCAL) { localSizeToMakeResident += heap->GetSize(); @@ -805,14 +807,14 @@ namespace gpgmm::d3d12 { if (localSizeToMakeResident > 0) { const uint32_t numberOfObjectsToMakeResident = static_cast(localHeapsToMakeResident.size()); - GPGMM_RETURN_IF_FAILED_ON_DEVICE( + GPGMM_RETURN_IF_FAILED( MakeResident(DXGI_MEMORY_SEGMENT_GROUP_LOCAL, localSizeToMakeResident, numberOfObjectsToMakeResident, localHeapsToMakeResident.data()), mDevice); } else if (nonLocalSizeToMakeResident > 0) { const uint32_t numberOfObjectsToMakeResident = static_cast(nonLocalHeapsToMakeResident.size()); - GPGMM_RETURN_IF_FAILED_ON_DEVICE( + GPGMM_RETURN_IF_FAILED( MakeResident(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL, nonLocalSizeToMakeResident, numberOfObjectsToMakeResident, nonLocalHeapsToMakeResident.data()), mDevice); @@ -837,16 +839,17 @@ 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)); + GPGMM_RETURN_IF_FAILED(mResidencyFence->Signal(pQueue), mDevice); } // 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)); - GPGMM_RETURN_IF_FAILED( - UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL)); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_LOCAL), + mDevice); + GPGMM_RETURN_IF_FAILED(UpdateMemorySegmentInternal(DXGI_MEMORY_SEGMENT_GROUP_NON_LOCAL), + mDevice); } GPGMM_TRACE_EVENT_OBJECT_CALL("ResidencyManager.ExecuteCommandLists", @@ -861,7 +864,7 @@ namespace gpgmm::d3d12 { ID3D12Pageable** allocations) { GPGMM_TRACE_EVENT_DURATION(TraceEventCategory::kDefault, "ResidencyManager.MakeResident"); - GPGMM_RETURN_IF_FAILED(EvictInternal(sizeToMakeResident, heapSegment, nullptr)); + GPGMM_RETURN_IF_FAILED(EvictInternal(sizeToMakeResident, heapSegment, nullptr), mDevice); DebugEvent(this, MessageId::kBudgetExceeded) << "GPU page-in. Number of allocations: " << numberOfObjectsToMakeResident << " (" @@ -873,7 +876,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()); + GPGMM_RETURN_IF_FAILED(EnsureResidencyFenceExists(), mDevice); GPGMM_RETURN_IF_SUCCEEDED(device3->EnqueueMakeResident( (mIsAlwaysInBudget) ? D3D12_RESIDENCY_FLAG_DENY_OVERBUDGET : D3D12_RESIDENCY_FLAG_NONE, @@ -890,7 +893,7 @@ namespace gpgmm::d3d12 { // execution and must throw a fatal error. uint64_t evictedSizeInBytes = 0; GPGMM_RETURN_IF_FAILED( - EvictInternal(mEvictSizeInBytes, heapSegment, &evictedSizeInBytes)); + EvictInternal(mEvictSizeInBytes, heapSegment, &evictedSizeInBytes), mDevice); if (evictedSizeInBytes == 0) { ErrorLog(this, MessageId::kBudgetInvalid) << "Unable to evict enough heaps to stay within budget. This " @@ -1029,7 +1032,7 @@ namespace gpgmm::d3d12 { } Fence* fencePtr = nullptr; - GPGMM_RETURN_IF_FAILED(Fence::CreateFence(mDevice, mInitialFenceValue, &fencePtr)); + GPGMM_RETURN_IF_FAILED(Fence::CreateFence(mDevice, mInitialFenceValue, &fencePtr), mDevice); mResidencyFence.reset(fencePtr); return S_OK; } diff --git a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp index 1df6b8e5..b95c268d 100644 --- a/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocationD3D12.cpp @@ -86,7 +86,8 @@ namespace gpgmm::d3d12 { } if (mResidencyManager != nullptr) { - GPGMM_RETURN_IF_FAILED(mResidencyManager->LockHeap(GetMemory())); + GPGMM_RETURN_IF_FAILED(mResidencyManager->LockHeap(GetMemory()), + GetDevice(mResource.Get())); } // Range coordinates are always subresource-relative so the range should only be @@ -101,8 +102,8 @@ namespace gpgmm::d3d12 { } void* mappedData = nullptr; - GPGMM_RETURN_IF_FAILED_ON_DEVICE(mResource->Map(subresource, newReadRangePtr, &mappedData), - GetDevice(mResource.Get())); + GPGMM_RETURN_IF_FAILED(mResource->Map(subresource, newReadRangePtr, &mappedData), + GetDevice(mResource.Get())); if (ppDataOut != nullptr) { *ppDataOut = static_cast(mappedData) + mOffsetFromResource; diff --git a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp index 4c8bf7ab..9cda57b5 100644 --- a/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceAllocatorD3D12.cpp @@ -393,7 +393,7 @@ namespace gpgmm::d3d12 { if (ppResidencyManagerOut != nullptr) { ComPtr adapter3; if (pAdapter != nullptr) { - GPGMM_RETURN_IF_FAILED(pAdapter->QueryInterface(IID_PPV_ARGS(&adapter3))); + GPGMM_RETURN_IF_FAILED(pAdapter->QueryInterface(IID_PPV_ARGS(&adapter3)), pDevice); } RESIDENCY_DESC residencyDesc = {}; @@ -405,12 +405,14 @@ namespace gpgmm::d3d12 { } GPGMM_RETURN_IF_FAILED(ResidencyManager::CreateResidencyManager( - residencyDesc, pDevice, adapter3.Get(), &residencyManager)); + residencyDesc, pDevice, adapter3.Get(), &residencyManager), + pDevice); } ComPtr resourceAllocator; GPGMM_RETURN_IF_FAILED(CreateResourceAllocator(allocatorDescriptor, pDevice, pAdapter, - residencyManager.Get(), &resourceAllocator)); + residencyManager.Get(), &resourceAllocator), + pDevice); if (ppResourceAllocatorOut != nullptr) { *ppResourceAllocatorOut = resourceAllocator.Detach(); @@ -435,7 +437,7 @@ namespace gpgmm::d3d12 { std::unique_ptr caps; { Caps* ptr = nullptr; - GPGMM_RETURN_IF_FAILED(Caps::CreateCaps(pDevice, pAdapter, &ptr)); + GPGMM_RETURN_IF_FAILED(Caps::CreateCaps(pDevice, pAdapter, &ptr), pDevice); caps.reset(ptr); } @@ -549,7 +551,7 @@ namespace gpgmm::d3d12 { ComPtr leakMessageQueue; if (SUCCEEDED(newDescriptor.Device.As(&leakMessageQueue))) { D3D12_INFO_QUEUE_FILTER emptyFilter{}; - GPGMM_RETURN_IF_FAILED(leakMessageQueue->PushRetrievalFilter(&emptyFilter)); + GPGMM_RETURN_IF_FAILED(leakMessageQueue->PushRetrievalFilter(&emptyFilter), mDevice); } else { WarningLog(MessageId::kInvalidArgument, true) << "GPGMM_ENABLE_DEVICE_LEAK_CHECKS has no effect because the D3D12 debug " @@ -881,7 +883,7 @@ namespace gpgmm::d3d12 { // Update allocation metrics. if (bytesReleased > 0) { - GPGMM_RETURN_IF_FAILED(QueryStatsInternal(nullptr)); + GPGMM_RETURN_IF_FAILED(QueryStatsInternal(nullptr), mDevice); } if (pBytesReleased != nullptr) { @@ -947,7 +949,7 @@ namespace gpgmm::d3d12 { std::lock_guard lock(mMutex); ComPtr allocation; - GPGMM_RETURN_IF_FAILED_ON_DEVICE( + GPGMM_RETURN_IF_FAILED( CreateResourceInternal(allocationDescriptor, resourceDescriptor, initialResourceState, pClearValue, &allocation), mDevice); @@ -955,13 +957,14 @@ namespace gpgmm::d3d12 { ASSERT(allocation->GetResource() != nullptr); if (GPGMM_UNLIKELY(mDebugAllocator)) { - GPGMM_RETURN_IF_FAILED(allocation->SetDebugName(allocationDescriptor.DebugName)); + GPGMM_RETURN_IF_FAILED(allocation->SetDebugName(allocationDescriptor.DebugName), + mDevice); mDebugAllocator->AddLiveAllocation(static_cast(allocation.Get())); } // Update the current usage counters. if (mUseDetailedTimingEvents) { - GPGMM_RETURN_IF_FAILED(QueryStatsInternal(nullptr)); + GPGMM_RETURN_IF_FAILED(QueryStatsInternal(nullptr), mDevice); } if (allocationDescriptor.Flags & ALLOCATION_FLAG_ALWAYS_WARN_ON_ALIGNMENT_MISMATCH) { @@ -1002,7 +1005,7 @@ namespace gpgmm::d3d12 { // If the heap type was not specified, infer it using the initial resource state. D3D12_HEAP_TYPE heapType = allocationDescriptor.HeapType; if (heapType == 0 || heapType == D3D12_HEAP_TYPE_CUSTOM) { - GPGMM_RETURN_IF_FAILED(GetHeapType(initialResourceState, &heapType)); + GPGMM_RETURN_IF_FAILED(GetHeapType(initialResourceState, &heapType), mDevice); } // Attribution of heaps may be abandoned but the original heap type is needed to @@ -1134,7 +1137,7 @@ namespace gpgmm::d3d12 { // TODO: Consider optimizing GetStatsInternal(). if (currentVideoInfo->CurrentUsage + request.SizeInBytes > currentVideoInfo->Budget) { ALLOCATOR_STATS allocationStats = {}; - GPGMM_RETURN_IF_FAILED(QueryStatsInternal(&allocationStats)); + GPGMM_RETURN_IF_FAILED(QueryStatsInternal(&allocationStats), mDevice); request.AvailableForAllocation = allocationStats.FreeHeapUsage; @@ -1187,7 +1190,7 @@ namespace gpgmm::d3d12 { ComPtr committedResource; Heap* resourceHeap = static_cast(subAllocation.GetMemory()); GPGMM_RETURN_IF_FAILED( - resourceHeap->QueryInterface(IID_PPV_ARGS(&committedResource))); + resourceHeap->QueryInterface(IID_PPV_ARGS(&committedResource)), mDevice); RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.SizeInBytes = resourceDescriptor.Width; @@ -1224,9 +1227,11 @@ namespace gpgmm::d3d12 { // memory is can be aliased or will overlap. ComPtr placedResource; Heap* resourceHeap = static_cast(subAllocation.GetMemory()); - GPGMM_RETURN_IF_FAILED(CreatePlacedResource( - resourceHeap, subAllocation.GetOffset(), &newResourceDesc, clearValue, - initialResourceState, &placedResource)); + GPGMM_RETURN_IF_FAILED( + CreatePlacedResource(resourceHeap, subAllocation.GetOffset(), + &newResourceDesc, clearValue, initialResourceState, + &placedResource), + mDevice); RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.SizeInBytes = request.SizeInBytes; @@ -1267,7 +1272,8 @@ namespace gpgmm::d3d12 { ComPtr placedResource; GPGMM_RETURN_IF_FAILED( CreatePlacedResource(resourceHeap, allocation.GetOffset(), &newResourceDesc, - clearValue, initialResourceState, &placedResource)); + clearValue, initialResourceState, &placedResource), + mDevice); RESOURCE_ALLOCATION_DESC allocationDesc = {}; allocationDesc.SizeInBytes = request.SizeInBytes; @@ -1318,9 +1324,11 @@ namespace gpgmm::d3d12 { ComPtr committedResource; ComPtr resourceHeap; - GPGMM_RETURN_IF_FAILED(CreateCommittedResource( - heapProperties, heapFlags, resourceInfo, &newResourceDesc, clearValue, - initialResourceState, &committedResource, &resourceHeap)); + GPGMM_RETURN_IF_FAILED( + CreateCommittedResource(heapProperties, heapFlags, resourceInfo, &newResourceDesc, + clearValue, initialResourceState, &committedResource, + &resourceHeap), + mDevice); if (resourceInfo.SizeInBytes > request.SizeInBytes) { DebugLog(this, MessageId::kAlignmentMismatch) @@ -1364,7 +1372,8 @@ namespace gpgmm::d3d12 { D3D12_HEAP_PROPERTIES heapProperties; D3D12_HEAP_FLAGS heapFlags; - GPGMM_RETURN_IF_FAILED(pCommittedResource->GetHeapProperties(&heapProperties, &heapFlags)); + GPGMM_RETURN_IF_FAILED(pCommittedResource->GetHeapProperties(&heapProperties, &heapFlags), + mDevice); // TODO: enable validation conditionally? if (allocationDescriptor.HeapType != 0 && @@ -1411,7 +1420,7 @@ namespace gpgmm::d3d12 { ImportResourceCallbackContext importResourceCallbackContext(pCommittedResource); ComPtr resourceHeap; - GPGMM_RETURN_IF_FAILED_ON_DEVICE( + GPGMM_RETURN_IF_FAILED( Heap::CreateHeap(resourceHeapDesc, (allocationDescriptor.Flags & ALLOCATION_FLAG_NEVER_RESIDENT) ? nullptr @@ -1451,10 +1460,10 @@ namespace gpgmm::d3d12 { ComPtr placedResource; { ComPtr heap; - GPGMM_RETURN_IF_FAILED(resourceHeap->QueryInterface(IID_PPV_ARGS(&heap))); + GPGMM_RETURN_IF_FAILED(resourceHeap->QueryInterface(IID_PPV_ARGS(&heap)), mDevice); ScopedResidencyLock residencyLock(mResidencyManager.Get(), resourceHeap); - GPGMM_RETURN_IF_FAILED_ON_DEVICE( + GPGMM_RETURN_IF_FAILED( mDevice->CreatePlacedResource(heap.Get(), resourceOffset, resourceDescriptor, initialResourceState, clearValue, IID_PPV_ARGS(&placedResource)), @@ -1497,11 +1506,12 @@ namespace gpgmm::d3d12 { GPGMM_RETURN_IF_FAILED(Heap::CreateHeap(resourceHeapDesc, mResidencyManager.Get(), CreateCommittedResourceCallbackContext::CreateHeap, - &callbackContext, &resourceHeap)); + &callbackContext, &resourceHeap), + mDevice); if (commitedResourceOut != nullptr) { ComPtr committedResource; - GPGMM_RETURN_IF_FAILED(resourceHeap.As(&committedResource)); + GPGMM_RETURN_IF_FAILED(resourceHeap.As(&committedResource), mDevice); *commitedResourceOut = committedResource.Detach(); } @@ -1601,21 +1611,23 @@ namespace gpgmm::d3d12 { } const D3D12_RLDO_FLAGS rldoFlags = D3D12_RLDO_DETAIL | D3D12_RLDO_IGNORE_INTERNAL; - GPGMM_RETURN_IF_FAILED(debugDevice->ReportLiveDeviceObjects(rldoFlags)); + GPGMM_RETURN_IF_FAILED(debugDevice->ReportLiveDeviceObjects(rldoFlags), mDevice); ComPtr leakMessageQueue; - GPGMM_RETURN_IF_FAILED(mDevice->QueryInterface(IID_PPV_ARGS(&leakMessageQueue))); + GPGMM_RETURN_IF_FAILED(mDevice->QueryInterface(IID_PPV_ARGS(&leakMessageQueue)), mDevice); // Report live device objects that could be created by GPGMM by checking the global filter. // This is because the allowList filter cannot easily be made exclusive to these IDs. for (uint64_t i = 0; i < leakMessageQueue->GetNumStoredMessagesAllowedByRetrievalFilter(); ++i) { SIZE_T messageLength = 0; - GPGMM_RETURN_IF_FAILED(leakMessageQueue->GetMessage(i, nullptr, &messageLength)); + GPGMM_RETURN_IF_FAILED(leakMessageQueue->GetMessage(i, nullptr, &messageLength), + mDevice); std::unique_ptr messageData(new uint8_t[messageLength]); D3D12_MESSAGE* message = reinterpret_cast(messageData.get()); - GPGMM_RETURN_IF_FAILED(leakMessageQueue->GetMessage(i, message, &messageLength)); + GPGMM_RETURN_IF_FAILED(leakMessageQueue->GetMessage(i, message, &messageLength), + mDevice); switch (message->ID) { case D3D12_MESSAGE_ID_LIVE_HEAP: @@ -1739,7 +1751,7 @@ namespace gpgmm::d3d12 { } ComPtr committedResource; - GPGMM_RETURN_IF_FAILED_ON_DEVICE( + GPGMM_RETURN_IF_FAILED( mDevice->CreateCommittedResource(mHeapProperties, mHeapFlags, mResourceDescriptor, mInitialResourceState, mClearValue, IID_PPV_ARGS(&committedResource)), diff --git a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp index d11458b4..1375773a 100644 --- a/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp +++ b/src/gpgmm/d3d12/ResourceHeapAllocatorD3D12.cpp @@ -122,8 +122,7 @@ namespace gpgmm::d3d12 { } ComPtr heap; - GPGMM_RETURN_IF_FAILED_ON_DEVICE(mDevice->CreateHeap(mHeapDesc, IID_PPV_ARGS(&heap)), - mDevice); + GPGMM_RETURN_IF_FAILED(mDevice->CreateHeap(mHeapDesc, IID_PPV_ARGS(&heap)), mDevice); *ppPageableOut = heap.Detach();