Skip to content

Commit

Permalink
Optimize D3D11 state tracker clear operation
Browse files Browse the repository at this point in the history
  • Loading branch information
Kaldaien committed Dec 29, 2024
1 parent 427005d commit 1f5a8eb
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 10 deletions.
10 changes: 7 additions & 3 deletions include/SpecialK/render/d3d11/d3d11_core.h
Original file line number Diff line number Diff line change
Expand Up @@ -1609,13 +1609,17 @@ struct d3d11_shader_tracking_s
{
void clear (void)
{
for ( int i = 0 ; i < std::min ( SK_D3D11_AllocatedDevContexts + 1, SK_D3D11_MAX_DEV_CONTEXTS ); ++i )
const auto dev_contexts =
std::min ( SK_D3D11_AllocatedDevContexts + 1, SK_D3D11_MAX_DEV_CONTEXTS );

for ( int i = 0 ; i < dev_contexts ; ++i )
{
active.set (i, false);

RtlZeroMemory (current_->views [i], _MAX_VIEWS * sizeof (ID3D11ShaderResourceView*));
}

RtlZeroMemory ( &current_->views [0],
dev_contexts * sizeof (ID3D11ShaderResourceView*) );

num_draws = 0;
num_deferred_draws = 0;

Expand Down
91 changes: 84 additions & 7 deletions src/thread.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -632,17 +632,20 @@ SetThreadAffinityMask_Detour (
dwThreadAffinityMask );
}

SK_TLS* pTLS =
SK_TLS* pTLS =
(dwTid == dwCurrentTid) ?
SK_TLS_Bottom ( ) :
SK_TLS_BottomEx (dwTid);

SK_Sched_ThreadContext* scheduler =
pTLS != nullptr ? pTLS->scheduler.getPtr ()
: nullptr;

if ( pTLS != nullptr &&
pTLS->scheduler->lock_affinity )
if ( scheduler != nullptr &&
scheduler->lock_affinity )
{
dwRet =
pTLS->scheduler->affinity_mask;
scheduler->affinity_mask;
}

else
Expand All @@ -654,16 +657,90 @@ SetThreadAffinityMask_Detour (
}


if ( pTLS != nullptr && dwRet != 0 &&
(! pTLS->scheduler->lock_affinity) )
if ( scheduler != nullptr && dwRet != 0 &&
(! scheduler->lock_affinity) )
{
pTLS->scheduler->affinity_mask =
scheduler->affinity_mask =
dwThreadAffinityMask;
}

return dwRet;
}

#if 0
DWORD_PTR
WINAPI
SetThreadAffinityMask_Detour (
_In_ HANDLE hThread,
_In_ DWORD_PTR dwThreadAffinityMask )
{
SK_LOG_FIRST_CALL

static SYSTEM_INFO
sysinfo = { };

if (sysinfo.dwNumberOfProcessors == 0)
{
SK_GetSystemInfo (&sysinfo);
}

const
DWORD dwCurrentTid =
SK_Thread_GetCurrentId ();
DWORD_PTR dwRet = 0;
DWORD dwTid = ( hThread ==
SK_GetCurrentThread ( ) ) ?
dwCurrentTid :
GetThreadId (hThread);

if (dwTid == 0)
{
return
SetThreadAffinityMask_Original (
hThread,
dwThreadAffinityMask );
}

SK_TLS* pTLS =
(dwTid == dwCurrentTid) ?
SK_TLS_Bottom ( ) :
SK_TLS_BottomEx (dwTid);

SK_Sched_ThreadContext* scheduler =
pTLS != nullptr ? pTLS->scheduler.getPtr ()
: nullptr;


if ( scheduler != nullptr &&
scheduler->lock_affinity )
{
dwRet =
scheduler->affinity_mask;
}

else if ( scheduler != nullptr &&
scheduler->affinity_mask !=
dwThreadAffinityMask )
{
dwRet =
SetThreadAffinityMask_Original (
hThread,
dwThreadAffinityMask );
}


if ( dwRet != 0 && scheduler != nullptr &&
(! scheduler->lock_affinity) )
{
dwRet =
scheduler->affinity_mask;
scheduler->affinity_mask =
dwThreadAffinityMask;
}

return dwRet;
#endif

DWORD_PTR
WINAPI
SK_SetThreadAffinityMask (HANDLE hThread, DWORD_PTR mask)
Expand Down

0 comments on commit 1f5a8eb

Please sign in to comment.