From fd555203011f8f5792b17fe17be39076fc126095 Mon Sep 17 00:00:00 2001 From: Philip Rebohle Date: Fri, 20 Jul 2018 11:39:51 +0200 Subject: [PATCH] [dxgi] Implement IDXGIDevice::SetMaximumFrameLatency We'll be doing the CPU synchronization with DXVK events during presentation. --- src/dxgi/dxgi_device.cpp | 22 +++++++++++++++++++--- src/dxgi/dxgi_device.h | 9 ++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/dxgi/dxgi_device.cpp b/src/dxgi/dxgi_device.cpp index 28a0ba15..dfba4b9d 100644 --- a/src/dxgi/dxgi_device.cpp +++ b/src/dxgi/dxgi_device.cpp @@ -2,6 +2,8 @@ #include "dxgi_factory.h" namespace dxvk { + + constexpr uint32_t DxgiDevice::DefaultFrameLatency; DxgiDevice::DxgiDevice( IDXGIObject* pContainer, @@ -10,6 +12,9 @@ namespace dxvk { : m_container (pContainer), m_adapter (pAdapter) { m_device = m_adapter->GetDXVKAdapter()->createDevice(*pFeatures); + + for (uint32_t i = 0; i < m_frameEvents.size(); i++) + m_frameEvents[i] = new DxvkEvent(); } @@ -107,15 +112,20 @@ namespace dxvk { HRESULT STDMETHODCALLTYPE DxgiDevice::GetMaximumFrameLatency( UINT* pMaxLatency) { - Logger::warn("DxgiDevice::GetMaximumFrameLatency: Stub"); - *pMaxLatency = 1; + *pMaxLatency = m_frameLatency; return S_OK; } HRESULT STDMETHODCALLTYPE DxgiDevice::SetMaximumFrameLatency( UINT MaxLatency) { - Logger::warn("DxgiDevice::SetMaximumFrameLatency: Stub"); + if (MaxLatency == 0) + MaxLatency = DefaultFrameLatency; + + if (MaxLatency > m_frameEvents.size()) + MaxLatency = m_frameEvents.size(); + + m_frameLatency = MaxLatency; return S_OK; } @@ -149,4 +159,10 @@ namespace dxvk { return m_device; } + + Rc STDMETHODCALLTYPE DxgiDevice::GetFrameSyncEvent() { + uint32_t frameId = m_frameId++ % m_frameLatency; + return m_frameEvents[frameId]; + } + } diff --git a/src/dxgi/dxgi_device.h b/src/dxgi/dxgi_device.h index d1dcf61c..54114a06 100644 --- a/src/dxgi/dxgi_device.h +++ b/src/dxgi/dxgi_device.h @@ -10,7 +10,7 @@ namespace dxvk { class DxgiFactory; class DxgiDevice : public IDXGIVkDevice { - + constexpr static uint32_t DefaultFrameLatency = 3; public: DxgiDevice( @@ -86,6 +86,8 @@ namespace dxvk { HANDLE hEvent) final; Rc STDMETHODCALLTYPE GetDXVKDevice() final; + + Rc STDMETHODCALLTYPE GetFrameSyncEvent(); private: @@ -93,6 +95,11 @@ namespace dxvk { Com m_adapter; Rc m_device; + + uint32_t m_frameLatency = DefaultFrameLatency; + uint32_t m_frameId = 0; + + std::array, 16> m_frameEvents; };