Skip to content

Commit

Permalink
use InterlockedCompareExchangePointer
Browse files Browse the repository at this point in the history
  • Loading branch information
Kethen committed Apr 23, 2024
1 parent 9744603 commit cf2fdbd
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions src/render/dxgi/dxgi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2360,7 +2360,7 @@ volatile LONG lSemaphoreCount1 = 0;
* Present -> Present1 double presentation hook firing, Far Cry 5
* with DXVK would spawn two swapchains for unknown reasons
*/
volatile LONGLONG llCurrentChain = 0;
volatile void *llCurrentChain = nullptr;
volatile LONG lChainMismatchCnt = 0;

HRESULT
Expand All @@ -2379,15 +2379,15 @@ SK_DXGI_PresentBase ( IDXGISwapChain *This,
// Far Cry 5 + DXVK multiple swapchain work-around
if (Source == SK_DXGI_PresentSource::Hook)
{
InterlockedCompareExchange64(&llCurrentChain, (LONGLONG)This, 0);
LONGLONG llCurrentChain_ = InterlockedOr64(&llCurrentChain, 0);
if ((LONGLONG)This != llCurrentChain_)
InterlockedCompareExchangePointer(&llCurrentChain, (void *)This, nullptr);
void *llCurrentChain_ = InterlockedCompareExchangePointer(&llCurrentChain, This, nullptr);
if ((void *)This != llCurrentChain_)
{
InterlockedIncrement(&lChainMismatchCnt);
LONG lChainMismatchCnt_ = InterlockedOr(&lChainMismatchCnt, 0);
if (lChainMismatchCnt_ < 20)
{
SK_LOG1 ( ( L"DXVK work around 0x%I64x, 0x%I64x, %d", (LONGLONG)This, llCurrentChain_, lChainMismatchCnt_),
SK_LOG1 ( ( L"DXVK work around %p, %p, %d", (void *)This, llCurrentChain_, lChainMismatchCnt_),
L" DXGI " );
// don't handle the present
if (DXGISwapChain1_Present1 != nullptr)
Expand All @@ -2404,10 +2404,10 @@ SK_DXGI_PresentBase ( IDXGISwapChain *This,
SyncInterval,
Flags );
}
SK_LOG1 ( ( L"DXVK work around setting current chain to 0x%I64x from 0x%I64x", (LONGLONG)This, llCurrentChain_),
SK_LOG1 ( ( L"DXVK work around setting current chain to %p from %p", (void *)This, llCurrentChain_),
L" DXGI " );
// swapchain definitely changed, update llCurrentChain then let SK swapchain change logic handle the change
InterlockedExchange64(&llCurrentChain, (LONGLONG)This);
InterlockedExchangePointer(&llCurrentChain, (void *)This);
InterlockedExchange(&lChainMismatchCnt, 0);
}

Expand Down

0 comments on commit cf2fdbd

Please sign in to comment.