Skip to content

Commit

Permalink
Fixed missing draw calls in Reflex latency widget in some D3D11 games
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Dec 29, 2024
1 parent 7c8eb46 commit 76b5507
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 25 deletions.
2 changes: 1 addition & 1 deletion include/SpecialK/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -920,7 +920,7 @@ struct sk_config_t
bool allow_refresh_change = true;
bool aspect_ratio_stretch = false;
bool focus_mode = false;
bool focus_mode_if_focused= false;
bool focus_mode_if_focused= true;
bool confirm_mode_changes = true;
bool save_monitor_prefs = true;
bool warn_no_mpo_planes = false;
Expand Down
44 changes: 44 additions & 0 deletions include/SpecialK/render/d3d11/d3d11_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,14 @@ class SK_D3D11_HookTallyWhacker
_lastDeferredCheck2;\
static std::pair<ID3D11DeviceContext*,bool> \
_lastDeferredCheck3;\
static std::pair<ID3D11DeviceContext*,bool> \
_lastDeferredCheck4;\
static std::pair<ID3D11DeviceContext*,bool> \
_lastDeferredCheck5;\
static std::pair<ID3D11DeviceContext*,bool> \
_lastDeferredCheck6;\
static std::pair<ID3D11DeviceContext*,bool> \
_lastDeferredCheck7;\
static std::pair<ID3D11DeviceContext*,bool>* \
_pLastDeferredCheck = &_lastDeferredCheck0; \
\
Expand All @@ -157,6 +165,14 @@ class SK_D3D11_HookTallyWhacker
_pLastDeferredCheck = &_lastDeferredCheck2;\
else if ( _pLastDeferredCheck == &_lastDeferredCheck2)\
_pLastDeferredCheck = &_lastDeferredCheck3;\
else if ( _pLastDeferredCheck == &_lastDeferredCheck3)\
_pLastDeferredCheck = &_lastDeferredCheck4;\
else if ( _pLastDeferredCheck == &_lastDeferredCheck4)\
_pLastDeferredCheck = &_lastDeferredCheck5;\
else if ( _pLastDeferredCheck == &_lastDeferredCheck5)\
_pLastDeferredCheck = &_lastDeferredCheck6;\
else if ( _pLastDeferredCheck == &_lastDeferredCheck6)\
_pLastDeferredCheck = &_lastDeferredCheck7;\
else _pLastDeferredCheck = &_lastDeferredCheck0;\
\
bool bMustNotIgnore = \
Expand Down Expand Up @@ -188,6 +204,14 @@ SK_D3D11_IsDevCtxDeferred (ID3D11DeviceContext* ctx)
_lastDeferredCheck2;
static std::pair<ID3D11DeviceContext*,bool>
_lastDeferredCheck3;
static std::pair<ID3D11DeviceContext*,bool>
_lastDeferredCheck4;
static std::pair<ID3D11DeviceContext*,bool>
_lastDeferredCheck5;
static std::pair<ID3D11DeviceContext*,bool>
_lastDeferredCheck6;
static std::pair<ID3D11DeviceContext*,bool>
_lastDeferredCheck7;
static std::pair<ID3D11DeviceContext*,bool>*
_pLastDeferredCheck = &_lastDeferredCheck0;

Expand All @@ -206,6 +230,14 @@ SK_D3D11_IsDevCtxDeferred (ID3D11DeviceContext* ctx)
_pLastDeferredCheck = &_lastDeferredCheck2;
else if ( _pLastDeferredCheck == &_lastDeferredCheck2)
_pLastDeferredCheck = &_lastDeferredCheck3;
else if ( _pLastDeferredCheck == &_lastDeferredCheck3)
_pLastDeferredCheck = &_lastDeferredCheck4;
else if ( _pLastDeferredCheck == &_lastDeferredCheck4)
_pLastDeferredCheck = &_lastDeferredCheck5;
else if ( _pLastDeferredCheck == &_lastDeferredCheck5)
_pLastDeferredCheck = &_lastDeferredCheck6;
else if ( _pLastDeferredCheck == &_lastDeferredCheck6)
_pLastDeferredCheck = &_lastDeferredCheck7;
else _pLastDeferredCheck = &_lastDeferredCheck0;

return bIsDevCtxDeferred;
Expand Down Expand Up @@ -234,6 +266,10 @@ SK_D3D11_IgnoreWrappedOrDeferred ( bool bWrapped,
static std::pair<ID3D11DeviceContext*,bool> _lastVerdict1;
static std::pair<ID3D11DeviceContext*,bool> _lastVerdict2;
static std::pair<ID3D11DeviceContext*,bool> _lastVerdict3;
static std::pair<ID3D11DeviceContext*,bool> _lastVerdict4;
static std::pair<ID3D11DeviceContext*,bool> _lastVerdict5;
static std::pair<ID3D11DeviceContext*,bool> _lastVerdict6;
static std::pair<ID3D11DeviceContext*,bool> _lastVerdict7;
static std::pair<ID3D11DeviceContext*,bool>* _pLastVerdict = &_lastVerdict0;

std::pair<ID3D11DeviceContext*,bool>* pLastVerdict = _pLastVerdict;
Expand All @@ -248,6 +284,14 @@ SK_D3D11_IgnoreWrappedOrDeferred ( bool bWrapped,
_pLastVerdict = &_lastVerdict2;
else if ( _pLastVerdict == &_lastVerdict2)
_pLastVerdict = &_lastVerdict3;
else if ( _pLastVerdict == &_lastVerdict3)
_pLastVerdict = &_lastVerdict4;
else if ( _pLastVerdict == &_lastVerdict4)
_pLastVerdict = &_lastVerdict5;
else if ( _pLastVerdict == &_lastVerdict5)
_pLastVerdict = &_lastVerdict6;
else if ( _pLastVerdict == &_lastVerdict6)
_pLastVerdict = &_lastVerdict7;
else _pLastVerdict = &_lastVerdict0;

pLastVerdict = _pLastVerdict;
Expand Down
44 changes: 21 additions & 23 deletions src/render/d3d11/d3d11_state_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -191,12 +191,31 @@ SK_D3D11_ShouldTrackRenderOp ( ID3D11DeviceContext* pDevCtx,
if (pDevCtx == nullptr)
return false;

if (SK_D3D11_DontTrackUnlessModToolsAreOpen && (! SK_D3D11_EnableTracking) && (! SK_D3D11_IsTrackingRequired ()))
return false;

const SK_RenderBackend& rb =
SK_GetCurrentRenderBackend ();

// Don't let D3D11On12 confuse things
if (rb.api == SK_RenderAPI::D3D11 && (! rb.in_present_call))
{
const auto frame_id =
SK_GetFramesDrawn ();

static ULONG64
last_frame = 0;
if (std::exchange (last_frame, frame_id) < frame_id)
{
if (InterlockedExchange (&SK_Reflex_LastFrameMarked, frame_id) < frame_id)
{
rb.setLatencyMarkerNV (SIMULATION_END);
rb.setLatencyMarkerNV (RENDERSUBMIT_START);
}
}
}

if (SK_D3D11_DontTrackUnlessModToolsAreOpen && (! SK_D3D11_EnableTracking) && (! SK_D3D11_IsTrackingRequired ()))
return false;

if ( rb.d3d11.immediate_ctx == nullptr ||
rb.device == nullptr ||
rb.swapchain == nullptr )
Expand Down Expand Up @@ -586,27 +605,6 @@ SK_D3D11_ShouldTrackDrawCall ( ID3D11DeviceContext* pDevCtx,
const SK_D3D11DrawType draw_type,
UINT dev_idx )
{
const SK_RenderBackend& rb =
SK_GetCurrentRenderBackend ();

// Don't let D3D11On12 confuse things
if (rb.api == SK_RenderAPI::D3D11)
{
const auto frame_id =
SK_GetFramesDrawn ();

static ULONG64 last_frame = 0;
if (std::exchange (last_frame, frame_id) < frame_id)
{
if ( InterlockedExchange (&SK_Reflex_LastFrameMarked, frame_id) <
frame_id )
{
rb.setLatencyMarkerNV (SIMULATION_END);
rb.setLatencyMarkerNV (RENDERSUBMIT_START);
}
}
}

// If ReShade (custom version) is loaded, state tracking is non-optional
if ( (intptr_t)hModReShade < (intptr_t)nullptr )
hModReShade = SK_ReShade_GetDLL ();
Expand Down
2 changes: 1 addition & 1 deletion src/widgets/latency.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -875,7 +875,7 @@ SK_ImGui_DrawGraph_Latency (bool predraw)
ImGui::EndGroup ();

if ( ReadULong64Acquire (&SK_Reflex_LastFrameMarked) <
ReadULong64Acquire (&SK_RenderBackend::frames_drawn) - 1 )
ReadULong64Acquire (&SK_RenderBackend::frames_drawn) - 2 )
{
static bool bRTSS64 =
SK_GetModuleHandle (L"RTSSHooks64.dll") != 0;
Expand Down

0 comments on commit 76b5507

Please sign in to comment.