Skip to content

Commit

Permalink
Improve deferred mode state tracking performance and correctness
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Nov 29, 2024
1 parent 8d793d8 commit 6f7052f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 10 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
+ Ensure that "LowSpecMode" is enabled even for Metaphor: ReFantazio users with
texture mods installer, and change the auto-disable feature to only apply
when staging texture cache is enabled.
+ Disable deferred context isolation in Metaphor by default for performance,
re-enable it if you need live texture modding or hudless screenshots.
+ Improved thread interlocking for XInput rumble

24.11.29.3
Expand Down
4 changes: 2 additions & 2 deletions include/SpecialK/render/d3d11/d3d11_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ SK_D3D11_ResetContextState ( ID3D11DeviceContext *pDevCtx,
extern std::pair <BOOL*, BOOL>
SK_ImGui_FlagDrawing_OnD3D11Ctx (UINT dev_idx);
extern bool
SK_ImGui_IsDrawing_OnD3D11Ctx (UINT dev_idx, ID3D11DeviceContext* pDevCtx);
SK_ImGui_IsDrawing_OnD3D11Ctx (UINT& dev_idx, ID3D11DeviceContext* pDevCtx);


struct shader_stage_s
Expand Down Expand Up @@ -2891,7 +2891,7 @@ struct SK_IMGUI_D3D11StateBlock {
};

extern std::pair <BOOL*, BOOL> SK_ImGui_FlagDrawing_OnD3D11Ctx (UINT dev_idx);
extern bool SK_ImGui_IsDrawing_OnD3D11Ctx (UINT dev_idx, ID3D11DeviceContext* pDevCtx);
extern bool SK_ImGui_IsDrawing_OnD3D11Ctx (UINT& dev_idx, ID3D11DeviceContext* pDevCtx);

void SK_D3D11_InitMutexes (void);
BOOL SK_D3D11_SetWrappedImmediateContext ( ID3D11Device *pDev,
Expand Down
18 changes: 11 additions & 7 deletions src/render/d3d11/d3d11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2993,8 +2993,10 @@ SK_D3D11_DrawHandler ( ID3D11DeviceContext *pDevCtx,
SK_D3D11DrawType draw_type,
UINT num_verts,
SK_TLS **ppTLS = nullptr,
UINT& dev_idx = NegativeOne )
UINT& _dev_idx = NegativeOne )
{
UINT dev_idx = _dev_idx;

std::ignore = draw_type;
std::ignore = num_verts;

Expand Down Expand Up @@ -3036,18 +3038,20 @@ SK_D3D11_DrawHandler ( ID3D11DeviceContext *pDevCtx,

///if (SK_D3D11_IsDevCtxDeferred (pDevCtx))
/// return false;
///

dev_idx = ( dev_idx == NegativeOne ? SK_D3D11_GetDeviceContextHandle (pDevCtx)
: dev_idx );

if (&_dev_idx != &NegativeOne)
_dev_idx = dev_idx;

// ImGui gets to pass-through without invoking the hook
if (SK_ImGui_IsDrawing_OnD3D11Ctx (dev_idx, pDevCtx))
{
return Normal;
}

std::scoped_lock <SK_Thread_HybridSpinlock> shader_lock (*cs_render_view);

using _Registry =
SK_D3D11_KnownShaders::ShaderRegistry <IUnknown>*;

Expand Down Expand Up @@ -3161,6 +3165,8 @@ const

if (SK_D3D11_EnableTracking)
{
std::scoped_lock <SK_Thread_HybridSpinlock> shader_lock (*cs_render_view);

SK_D3D11_DrawThreads->mark ();

bool rtv_active = false;
Expand Down Expand Up @@ -3209,8 +3215,6 @@ const

for ( auto* tracker : trackers )
{
std::scoped_lock <SK_Thread_HybridSpinlock> tracker_lock (*cs_render_view);

const bool active =
tracker->active.get (dev_idx);

Expand Down Expand Up @@ -9253,8 +9257,6 @@ D3D11Dev_GetImmediateContext3_Override (
void
SK_D3D11_EndFrame (SK_TLS* pTLS)
{
std::scoped_lock <SK_Thread_HybridSpinlock> auto_lock2 (*cs_render_view);

for ( auto end_frame_fn : plugin_mgr->end_frame_fns )
{
end_frame_fn ();
Expand All @@ -9277,6 +9279,8 @@ SK_D3D11_EndFrame (SK_TLS* pTLS)
return;
}

std::scoped_lock <SK_Thread_HybridSpinlock> auto_lock2 (*cs_render_view);

const SK_RenderBackend& rb =
SK_GetCurrentRenderBackend ();

Expand Down
2 changes: 1 addition & 1 deletion src/render/d3d11/d3d11_state_tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ volatile LONG
SK_D3D11_CBufferTrackingReqs = 0L;

bool
SK_ImGui_IsDrawing_OnD3D11Ctx (UINT dev_idx, ID3D11DeviceContext* pDevCtx)
SK_ImGui_IsDrawing_OnD3D11Ctx (UINT& dev_idx, ID3D11DeviceContext* pDevCtx)
{
if (pDevCtx == nullptr || dev_idx == UINT_MAX)
{
Expand Down

0 comments on commit 6f7052f

Please sign in to comment.