diff --git a/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp b/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp index d0fbc4985..3133f23aa 100644 --- a/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp +++ b/src/gpgmm/d3d12/ResidencyHeapD3D12.cpp @@ -327,10 +327,12 @@ namespace gpgmm::d3d12 { } uint64_t ResidencyHeap::GetLastUsedFenceValue() const { + std::lock_guard lock(mMutex); return mLastUsedFenceValue; } void ResidencyHeap::SetLastUsedFenceValue(uint64_t fenceValue) { + std::lock_guard lock(mMutex); mLastUsedFenceValue = fenceValue; } @@ -351,10 +353,12 @@ namespace gpgmm::d3d12 { } RESIDENCY_HEAP_INFO ResidencyHeap::GetInfo() const { + std::lock_guard lock(mMutex); return {GetSize(), GetAlignment(), IsResidencyLocked(), mState}; } HRESULT ResidencyHeap::SetDebugNameImpl(LPCWSTR name) { + std::lock_guard lock(mMutex); return SetDebugObjectName(mPageable.Get(), name); } @@ -371,6 +375,7 @@ namespace gpgmm::d3d12 { } void ResidencyHeap::SetResidencyStatus(RESIDENCY_HEAP_STATUS newStatus) { + std::lock_guard lock(mMutex); mState = newStatus; } diff --git a/src/gpgmm/d3d12/ResidencyHeapD3D12.h b/src/gpgmm/d3d12/ResidencyHeapD3D12.h index 966a343b7..aa9ba3abd 100644 --- a/src/gpgmm/d3d12/ResidencyHeapD3D12.h +++ b/src/gpgmm/d3d12/ResidencyHeapD3D12.h @@ -23,12 +23,17 @@ #include +#include + namespace gpgmm::d3d12 { class ResidencyManager; RESIDENCY_HEAP_FLAGS GetHeapFlags(D3D12_HEAP_FLAGS heapFlags, bool alwaysCreatedInBudget); + // Thread-safe managed heap type for performing residency operations. + // A ResidencyHeap wraps a ID3D12Pageable that can be temporarily or permanently made + // resident and can be explicitly or implicitly (through allocation) created. class ResidencyHeap final : public MemoryBase, public DebugObject, public LinkNode, @@ -98,11 +103,15 @@ namespace gpgmm::d3d12 { ComPtr mResidencyManager; ComPtr mPageable; - // mLastUsedFenceValue denotes the last time this pageable was submitted to the GPU. - uint64_t mLastUsedFenceValue = 0; DXGI_MEMORY_SEGMENT_GROUP mHeapSegment; RefCounted mResidencyLock; + + // Protects thread-access to the mutable members below. + mutable std::mutex mMutex; RESIDENCY_HEAP_STATUS mState; + + // mLastUsedFenceValue denotes the last time this pageable was submitted to the GPU. + uint64_t mLastUsedFenceValue = 0; }; } // namespace gpgmm::d3d12