Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

d9vk double processing fix #179

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 22 additions & 9 deletions src/render/d3d9/d3d9.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,19 @@ SK_D3D9_Present_GrandCentral ( sk_d3d9_swap_dispatch_s* dispatch )
if (dispatch->Type != SK_D3D9_PresentType::Device9Ex_PresentEx)
pDevEx = nullptr;

/*
* avoid double processing when d9vk is used
*
* while there are instances of chained creation/presentation that might
* make sense to fix on d9vk's side, fixing D3D9SwapChainEx::Present
* vftable hook from d9vk is extremely messy, given D3D9Device(Ex)::Present
* on that side runs D3D9SwapChainEx::Present on an internally allocated
* implicit swapchain
*/
thread_local bool processing = false;

bool process =
SK_D3D9_ShouldProcessPresentCall (dispatch->Source) && !processing;

auto CallFunc = [&](void) ->
HRESULT
Expand All @@ -1614,9 +1627,12 @@ SK_D3D9_Present_GrandCentral ( sk_d3d9_swap_dispatch_s* dispatch )
{
if (config.render.framerate.target_fps > 0.0f) // Limit Configured
{
// Now we WaitForVBLANK
extern void SK_D3DKMT_WaitForVBlank (void);
SK_D3DKMT_WaitForVBlank ();
if (process)
{
// Now we WaitForVBLANK
extern void SK_D3DKMT_WaitForVBlank (void);
SK_D3DKMT_WaitForVBlank ();
}
}
}
}
Expand Down Expand Up @@ -1714,17 +1730,13 @@ SK_D3D9_Present_GrandCentral ( sk_d3d9_swap_dispatch_s* dispatch )
return E_NOTIMPL;
};

bool process =
SK_D3D9_ShouldProcessPresentCall (dispatch->Source);



SK_RenderBackend& rb =
SK_GetCurrentRenderBackend ();


if (process || trigger_reset != reset_stage_e::Clear)
{
processing = true;
if ( rb.api == SK_RenderAPI::D3D9 ||
rb.api == SK_RenderAPI::D3D9Ex ||
rb.api == SK_RenderAPI::Reserved )
Expand Down Expand Up @@ -1759,6 +1771,7 @@ SK_D3D9_Present_GrandCentral ( sk_d3d9_swap_dispatch_s* dispatch )

SK_D3D9_EndFrame ();

processing = false;
return hr;
}
#endif
Expand Down Expand Up @@ -1876,7 +1889,7 @@ SK_D3D9_Present_GrandCentral ( sk_d3d9_swap_dispatch_s* dispatch )
if (hr != D3D_OK && trigger_reset == reset_stage_e::Clear)
trigger_reset = reset_stage_e::Initiate;


processing = false;
return hr;
}

Expand Down