diff --git a/include/SpecialK/render/d3d11/d3d11_core.h b/include/SpecialK/render/d3d11/d3d11_core.h index de6741373..157c0c505 100644 --- a/include/SpecialK/render/d3d11/d3d11_core.h +++ b/include/SpecialK/render/d3d11/d3d11_core.h @@ -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 ( ¤t_->views [0], + dev_contexts * sizeof (ID3D11ShaderResourceView*) ); + num_draws = 0; num_deferred_draws = 0; diff --git a/src/thread.cpp b/src/thread.cpp index 09cc843e2..276ad1609 100644 --- a/src/thread.cpp +++ b/src/thread.cpp @@ -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 @@ -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)