Skip to content

Commit

Permalink
[dxgi] Synchronize presentation to enforce maximum frame latency
Browse files Browse the repository at this point in the history
Some games may rely on the maximum number of frames in flight.
Might fix a related issue in Hard Reset (#503) and Okami HD (#283).
  • Loading branch information
doitsujin committed Jul 20, 2018
1 parent fd55520 commit adcc7a4
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
13 changes: 12 additions & 1 deletion src/dxgi/dxgi_presenter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,14 @@ namespace dxvk {
}


void DxgiVkPresenter::PresentImage(UINT SyncInterval) {
void DxgiVkPresenter::PresentImage(UINT SyncInterval, const Rc<DxvkEvent>& SyncEvent) {
if (m_hud != nullptr)
m_hud->update();

// Wait for frame event to be signaled. This is used
// to enforce the device's frame latency requirement.
SyncEvent->wait();

// Check whether the back buffer size is the same
// as the window size, in which case we should use
// VK_FILTER_NEAREST to avoid blurry output
Expand Down Expand Up @@ -198,6 +202,13 @@ namespace dxvk {
if (m_hud != nullptr)
m_hud->render(m_context, m_options.preferredBufferSize);

if (i == SyncInterval - 1) {
DxvkEventRevision eventRev;
eventRev.event = SyncEvent;
eventRev.revision = SyncEvent->reset();
m_context->signalEvent(eventRev);
}

m_device->submitCommandList(
m_context->endRecording(),
swapSemas.acquireSync,
Expand Down
2 changes: 1 addition & 1 deletion src/dxgi/dxgi_presenter.h
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ namespace dxvk {
* \brief Renders back buffer to the screen
* \param [in] SyncInterval Vsync interval
*/
void PresentImage(UINT SyncInterval);
void PresentImage(UINT SyncInterval, const Rc<DxvkEvent>& SyncEvent);

/**
* \brief Sets new back buffer
Expand Down
4 changes: 2 additions & 2 deletions src/dxgi/dxgi_swapchain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ namespace dxvk {
// Submit pending rendering commands
// before recording the present code.
m_presentDevice->FlushRenderingCommands();

// Update swap chain properties. This will not only set
// up vertical synchronization properly, but also apply
// changes that were made to the window size even if the
Expand All @@ -317,7 +317,7 @@ namespace dxvk {
: VK_PRESENT_MODE_FIFO_KHR;

m_presenter->RecreateSwapchain(m_desc.Format, presentMode, GetWindowSize());
m_presenter->PresentImage(SyncInterval);
m_presenter->PresentImage(SyncInterval, m_device->GetFrameSyncEvent());
return S_OK;
} catch (const DxvkError& err) {
Logger::err(err.message());
Expand Down

0 comments on commit adcc7a4

Please sign in to comment.