1
0
mirror of https://github.com/doitsujin/dxvk.git synced 2025-01-18 20:52:10 +01:00

[d3d11] Create frame latency event for swap chain

Needed in order to support the DXGI 1.3 frame latency API.
This commit is contained in:
Philip Rebohle 2019-11-26 00:24:33 +01:00
parent 6ebf3e1656
commit 65cc8c2b31
No known key found for this signature in database
GPG Key ID: C8CC613427A31C99
2 changed files with 35 additions and 5 deletions

View File

@ -26,7 +26,7 @@ namespace dxvk {
m_device (pDevice->GetDXVKDevice()),
m_context (m_device->createContext()),
m_frameLatencyCap(pDevice->GetOptions()->maxFrameLatency) {
CreateFrameLatencySignal();
CreateFrameLatencyEvent();
if (!pDevice->GetOptions()->deferSurfaceCreation)
CreatePresenter();
@ -45,6 +45,8 @@ namespace dxvk {
if (m_backBuffer)
m_backBuffer->ReleasePrivate();
DestroyFrameLatencyEvent();
}
@ -175,6 +177,9 @@ namespace dxvk {
return DXGI_ERROR_INVALID_CALL;
m_frameLatency = MaxLatency;
m_frameLatencySignal->wait(m_frameId - GetActualFrameLatency());
SignalFrameLatencyEvent();
return S_OK;
}
@ -330,6 +335,8 @@ namespace dxvk {
SubmitPresent(immediateContext, sync);
}
SignalFrameLatencyEvent();
}
@ -384,8 +391,11 @@ namespace dxvk {
}
void D3D11SwapChain::CreateFrameLatencySignal() {
m_frameLatencySignal = new sync::Fence(m_frameId);
void D3D11SwapChain::CreateFrameLatencyEvent() {
m_frameLatencySignal = new sync::Win32Fence(m_frameId);
if (m_desc.Flags & DXGI_SWAP_CHAIN_FLAG_FRAME_LATENCY_WAITABLE_OBJECT)
m_frameLatencyEvent = CreateEvent(nullptr, false, true, nullptr);
}
@ -621,6 +631,11 @@ namespace dxvk {
}
void D3D11SwapChain::DestroyFrameLatencyEvent() {
CloseHandle(m_frameLatencyEvent);
}
void D3D11SwapChain::DestroyGammaTexture() {
m_gammaTexture = nullptr;
m_gammaTextureView = nullptr;
@ -732,6 +747,14 @@ namespace dxvk {
}
void D3D11SwapChain::SignalFrameLatencyEvent() {
if (m_frameLatencyEvent) {
// Signal event with the same value that we'd wait for during the next present.
m_frameLatencySignal->setEvent(m_frameLatencyEvent, m_frameId - GetActualFrameLatency() + 1);
}
}
uint32_t D3D11SwapChain::GetActualFrameLatency() {
uint32_t maxFrameLatency = m_frameLatency;

View File

@ -4,6 +4,8 @@
#include "../dxvk/hud/dxvk_hud.h"
#include "../util/sync/sync_signal_win32.h"
namespace dxvk {
class D3D11Device;
@ -125,7 +127,8 @@ namespace dxvk {
uint64_t m_frameId = DXGI_MAX_SWAP_CHAIN_BUFFERS;
uint32_t m_frameLatency = DefaultFrameLatency;
uint32_t m_frameLatencyCap = 0;
Rc<sync::Signal> m_frameLatencySignal;
HANDLE m_frameLatencyEvent = nullptr;
Rc<sync::Win32Fence> m_frameLatencySignal;
bool m_dirty = true;
bool m_vsync = true;
@ -141,7 +144,7 @@ namespace dxvk {
void RecreateSwapChain(
BOOL Vsync);
void CreateFrameLatencySignal();
void CreateFrameLatencyEvent();
void CreatePresenter();
@ -153,6 +156,8 @@ namespace dxvk {
UINT NumControlPoints,
const D3D11_VK_GAMMA_CP* pControlPoints);
void DestroyFrameLatencyEvent();
void DestroyGammaTexture();
void CreateHud();
@ -163,6 +168,8 @@ namespace dxvk {
void InitShaders();
void SignalFrameLatencyEvent();
uint32_t GetActualFrameLatency();
uint32_t PickFormats(