Skip to content

Commit

Permalink
Reduce GdiEngine input latency (#15608)
Browse files Browse the repository at this point in the history
This commit reduces GdiEngine's average display latency by 8ms,
which caused it to miss a v-blank about half the time at 60Hz.

Closes #15607

## Validation Steps Performed
Input latency with `frarees/typometer` matches conhost from Win10 ✅
  • Loading branch information
lhecker committed Jun 27, 2023
1 parent 99c18ce commit 72b4488
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions src/renderer/base/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,11 @@ DWORD WINAPI RenderThread::_ThreadProc()
{
while (_fKeepRunning)
{
// Between waiting on _hEvent and calling PaintFrame() there should be a minimal delay,
// so that a key press progresses to a drawing operation as quickly as possible.
// As such, we wait for the renderer to complete _before_ waiting on _hEvent.
_pRenderer->WaitUntilCanRender();

WaitForSingleObject(_hPaintEnabledEvent, INFINITE);

if (!_fNextFrameRequested.exchange(false, std::memory_order_acq_rel))
Expand Down Expand Up @@ -209,10 +214,7 @@ DWORD WINAPI RenderThread::_ThreadProc()
}

ResetEvent(_hPaintCompletedEvent);

_pRenderer->WaitUntilCanRender();
LOG_IF_FAILED(_pRenderer->PaintFrame());

SetEvent(_hPaintCompletedEvent);
}

Expand Down

0 comments on commit 72b4488

Please sign in to comment.