diff --git a/src/gpgmm/d3d12/FenceD3D12.cpp b/src/gpgmm/d3d12/FenceD3D12.cpp index 611628a88..5ef0da1cb 100644 --- a/src/gpgmm/d3d12/FenceD3D12.cpp +++ b/src/gpgmm/d3d12/FenceD3D12.cpp @@ -95,4 +95,9 @@ namespace gpgmm { namespace d3d12 { uint64_t Fence::GetCurrentFence() const { return mCurrentFence; } + + ID3D12Fence* Fence::GetFence() const { + return mFence.Get(); + } + }} // namespace gpgmm::d3d12 diff --git a/src/gpgmm/d3d12/FenceD3D12.h b/src/gpgmm/d3d12/FenceD3D12.h index 139f0fb6c..94ccdda11 100644 --- a/src/gpgmm/d3d12/FenceD3D12.h +++ b/src/gpgmm/d3d12/FenceD3D12.h @@ -35,6 +35,8 @@ namespace gpgmm { namespace d3d12 { uint64_t GetLastSignaledFence() const; uint64_t GetCurrentFence() const; + ID3D12Fence* GetFence() const; + private: Fence(ComPtr fence, uint64_t initialValue); diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp index 3b49ce318..67501f9af 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.cpp @@ -448,6 +448,16 @@ namespace gpgmm { namespace d3d12 { ReturnIfFailed(Evict(sizeToMakeResident, memorySegmentGroup, nullptr)); + // Decrease the overhead from using MakeResident, a synchronous call, by calling the + // asynchronous MakeResident, called EnqueueMakeResident, instead first. Should + // EnqueueMakeResident fail, fall-back to using synchronous MakeResident since we may be + // able to continue after calling Evict again. + if (mDevice3 != nullptr) { + ReturnIfSucceeded(mDevice3->EnqueueMakeResident( + D3D12_RESIDENCY_FLAG_NONE, numberOfObjectsToMakeResident, allocations, + mFence->GetFence(), mFence->GetLastSignaledFence() + 1)); + } + // A MakeResident call can fail if there's not enough available memory. This // could occur when there's significant fragmentation or if the allocation size // estimates are incorrect. We may be able to continue execution by evicting some diff --git a/src/gpgmm/d3d12/ResidencyManagerD3D12.h b/src/gpgmm/d3d12/ResidencyManagerD3D12.h index 18231699b..7d84c4b1f 100644 --- a/src/gpgmm/d3d12/ResidencyManagerD3D12.h +++ b/src/gpgmm/d3d12/ResidencyManagerD3D12.h @@ -91,6 +91,7 @@ namespace gpgmm { namespace d3d12 { ComPtr mDevice; ComPtr mAdapter; + ComPtr mDevice3; std::unique_ptr mFence;