mirror of
https://github.com/EduApps-CDG/OpenDX
synced 2024-12-30 09:45:37 +01:00
[dxgi] Implement RegisterVideoMemoryBudgetChangeNotificationEvent
Closes #1544.
This commit is contained in:
parent
904d3e6c90
commit
079cda1c0c
@ -66,7 +66,14 @@ namespace dxvk {
|
|||||||
|
|
||||||
|
|
||||||
DxgiAdapter::~DxgiAdapter() {
|
DxgiAdapter::~DxgiAdapter() {
|
||||||
|
if (m_eventThread.joinable()) {
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
m_eventCookie = ~0u;
|
||||||
|
m_cond.notify_one();
|
||||||
|
|
||||||
|
lock.unlock();
|
||||||
|
m_eventThread.join();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -349,8 +356,23 @@ namespace dxvk {
|
|||||||
HRESULT STDMETHODCALLTYPE DxgiAdapter::RegisterVideoMemoryBudgetChangeNotificationEvent(
|
HRESULT STDMETHODCALLTYPE DxgiAdapter::RegisterVideoMemoryBudgetChangeNotificationEvent(
|
||||||
HANDLE hEvent,
|
HANDLE hEvent,
|
||||||
DWORD* pdwCookie) {
|
DWORD* pdwCookie) {
|
||||||
Logger::err("DxgiAdapter::RegisterVideoMemoryBudgetChangeNotificationEvent: Not implemented");
|
if (!hEvent || !pdwCookie)
|
||||||
return E_NOTIMPL;
|
return E_INVALIDARG;
|
||||||
|
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
DWORD cookie = ++m_eventCookie;
|
||||||
|
|
||||||
|
m_eventMap.insert({ cookie, hEvent });
|
||||||
|
|
||||||
|
if (!m_eventThread.joinable())
|
||||||
|
m_eventThread = dxvk::thread([this] { runEventThread(); });
|
||||||
|
|
||||||
|
// This method seems to fire the
|
||||||
|
// event immediately on Windows
|
||||||
|
SetEvent(hEvent);
|
||||||
|
|
||||||
|
*pdwCookie = cookie;
|
||||||
|
return S_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -362,7 +384,8 @@ namespace dxvk {
|
|||||||
|
|
||||||
void STDMETHODCALLTYPE DxgiAdapter::UnregisterVideoMemoryBudgetChangeNotification(
|
void STDMETHODCALLTYPE DxgiAdapter::UnregisterVideoMemoryBudgetChangeNotification(
|
||||||
DWORD dwCookie) {
|
DWORD dwCookie) {
|
||||||
Logger::err("DxgiAdapter::UnregisterVideoMemoryBudgetChangeNotification: Not implemented");
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
m_eventMap.erase(dwCookie);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -374,5 +397,34 @@ namespace dxvk {
|
|||||||
Rc<DxvkInstance> STDMETHODCALLTYPE DxgiAdapter::GetDXVKInstance() {
|
Rc<DxvkInstance> STDMETHODCALLTYPE DxgiAdapter::GetDXVKInstance() {
|
||||||
return m_factory->GetDXVKInstance();
|
return m_factory->GetDXVKInstance();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void DxgiAdapter::runEventThread() {
|
||||||
|
std::unique_lock<std::mutex> lock(m_mutex);
|
||||||
|
DxvkAdapterMemoryInfo memoryInfoOld = m_adapter->getMemoryHeapInfo();
|
||||||
|
|
||||||
|
while (true) {
|
||||||
|
m_cond.wait_for(lock, std::chrono::milliseconds(1500),
|
||||||
|
[this] { return m_eventCookie == ~0u; });
|
||||||
|
|
||||||
|
if (m_eventCookie == ~0u)
|
||||||
|
return;
|
||||||
|
|
||||||
|
auto memoryInfoNew = m_adapter->getMemoryHeapInfo();
|
||||||
|
bool budgetChanged = false;
|
||||||
|
|
||||||
|
for (uint32_t i = 0; i < memoryInfoNew.heapCount; i++) {
|
||||||
|
budgetChanged |= memoryInfoNew.heaps[i].memoryBudget
|
||||||
|
!= memoryInfoOld.heaps[i].memoryBudget;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (budgetChanged) {
|
||||||
|
memoryInfoOld = memoryInfoNew;
|
||||||
|
|
||||||
|
for (const auto& pair : m_eventMap)
|
||||||
|
SetEvent(pair.second);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -111,6 +111,15 @@ namespace dxvk {
|
|||||||
|
|
||||||
UINT m_index;
|
UINT m_index;
|
||||||
UINT64 m_memReservation[2] = { 0, 0 };
|
UINT64 m_memReservation[2] = { 0, 0 };
|
||||||
|
|
||||||
|
std::mutex m_mutex;
|
||||||
|
std::condition_variable m_cond;
|
||||||
|
|
||||||
|
DWORD m_eventCookie = 0;
|
||||||
|
std::unordered_map<DWORD, HANDLE> m_eventMap;
|
||||||
|
dxvk::thread m_eventThread;
|
||||||
|
|
||||||
|
void runEventThread();
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user