@@ -1029,7 +1029,7 @@ bool CMaterialSystem::AllowThreading( bool bAllow, int nServiceThread )
10291029
10301030 bool bOldAllow = m_bAllowQueuedRendering;
10311031
1032- if ( GetCPUInformation ()->m_nPhysicalProcessors >= 2 )
1032+ if ( GetCPUInformation ()->m_nLogicalProcessors >= 2 )
10331033 {
10341034 m_bAllowQueuedRendering = bAllow;
10351035 bool bQueued = m_IdealThreadMode != MATERIAL_SINGLE_THREADED;
@@ -1806,11 +1806,7 @@ static ConVar mat_normalmaps( "mat_normalmaps", "0", FCVAR_CHEAT );
18061806static ConVar mat_measurefillrate ( " mat_measurefillrate" , " 0" , FCVAR_CHEAT );
18071807static ConVar mat_fillrate ( " mat_fillrate" , " 0" , FCVAR_CHEAT );
18081808static ConVar mat_reversedepth ( " mat_reversedepth" , " 0" , FCVAR_CHEAT );
1809- #ifdef DX_TO_GL_ABSTRACTION
1810- static ConVar mat_bufferprimitives ( " mat_bufferprimitives" , " 0" ); // I'm not seeing any benefit speed wise for buffered primitives on GLM/POSIX (checked via TF2 timedemo) - default to zero
1811- #else
18121809static ConVar mat_bufferprimitives ( " mat_bufferprimitives" , " 1" );
1813- #endif
18141810static ConVar mat_drawflat ( " mat_drawflat" ," 0" , FCVAR_CHEAT );
18151811static ConVar mat_softwarelighting ( " mat_softwarelighting" , " 0" , FCVAR_ALLOWED_IN_COMPETITIVE );
18161812static ConVar mat_proxy ( " mat_proxy" , " 0" , FCVAR_CHEAT, " " , MatProxyCallback );
@@ -2780,8 +2776,8 @@ IMaterial* CMaterialSystem::FindMaterialEx( char const* pMaterialName, const cha
27802776{
27812777 // We need lower-case symbols for this to work
27822778 int nLen = Q_strlen ( pMaterialName ) + 1 ;
2783- char *pFixedNameTemp = (char *)malloc ( nLen );
2784- char *pTemp = (char *)malloc ( nLen );
2779+ char *pFixedNameTemp = (char *)stackalloc ( nLen );
2780+ char *pTemp = (char *)stackalloc ( nLen );
27852781 Q_strncpy ( pFixedNameTemp, pMaterialName, nLen );
27862782 Q_strlower ( pFixedNameTemp );
27872783#ifdef POSIX
@@ -2883,9 +2879,6 @@ IMaterial* CMaterialSystem::FindMaterialEx( char const* pMaterialName, const cha
28832879 }
28842880 }
28852881
2886- free (pTemp);
2887- free (pFixedNameTemp);
2888-
28892882 return g_pErrorMaterial->GetRealTimeVersion ();
28902883}
28912884
@@ -3103,20 +3096,12 @@ void CMaterialSystem::ResetTempHWMemory( bool bExitingLevel )
31033096// -----------------------------------------------------------------------------
31043097void CMaterialSystem::CacheUsedMaterials ( )
31053098{
3099+ printf (" Cache materials\n " );
3100+
31063101 g_pShaderAPI->EvictManagedResources ();
3107- size_t count = 0 ;
3102+
31083103 for (MaterialHandle_t i = FirstMaterial (); i != InvalidMaterial (); i = NextMaterial (i) )
31093104 {
3110- // Some (mac) drivers (amd) seem to keep extra resources around on uploads until the next frame swap. This
3111- // injects pointless synthetic swaps (between already-static load frames)
3112- if ( mat_texture_reload_frame_swap_workaround.GetBool () )
3113- {
3114- if ( count++ % 20 == 0 )
3115- {
3116- Flush (true );
3117- SwapBuffers (); // Not the right thing to call
3118- }
3119- }
31203105 IMaterialInternal* pMat = GetMaterialInternal (i);
31213106 Assert ( pMat->GetReferenceCount () >= 0 );
31223107 if ( pMat->GetReferenceCount () > 0 )
@@ -3703,9 +3688,13 @@ void CMaterialSystem::EndFrame( void )
37033688 ThreadAcquire ( true );
37043689 }
37053690
3691+ IThreadPool* pThreadPool = CreateMatQueueThreadPool ();
3692+
37063693 if ( m_pActiveAsyncJob && !m_pActiveAsyncJob->IsFinished () )
37073694 {
3708- m_pActiveAsyncJob->WaitForFinish ();
3695+ m_pActiveAsyncJob->WaitForFinish (TT_INFINITE, pThreadPool);
3696+
3697+ // Sync with GPU if we had a job for it, even if it finished early on CPU!
37093698 if ( !IsPC () && g_config.ForceHWSync () )
37103699 {
37113700 g_pShaderAPI->ForceHardwareSync ();
@@ -3730,7 +3719,6 @@ void CMaterialSystem::EndFrame( void )
37303719 }
37313720 }
37323721
3733- IThreadPool *pThreadPool = CreateMatQueueThreadPool ();
37343722 pThreadPool->AddJob ( m_pActiveAsyncJob );
37353723 break ;
37363724 }
@@ -4664,20 +4652,9 @@ void CMaterialSystem::BeginRenderTargetAllocation( void )
46644652
46654653void CMaterialSystem::EndRenderTargetAllocation ( void )
46664654{
4667- // Any GPU newer than 2005 doesn't need to do this, and it eats up ~40% of our level load time!
4668- const bool cbRequiresRenderTargetAllocationFirst = mat_requires_rt_alloc_first.GetBool ();
4669-
46704655 g_pShaderAPI->FlushBufferedPrimitives ();
46714656 m_bAllocatingRenderTargets = false ;
46724657
4673- if ( IsPC () && cbRequiresRenderTargetAllocationFirst && g_pShaderAPI->CanDownloadTextures () )
4674- {
4675- // Simulate an Alt-Tab...will cause RTs to be allocated first
4676-
4677- g_pShaderDevice->ReleaseResources ();
4678- g_pShaderDevice->ReacquireResources ();
4679- }
4680-
46814658 TextureManager ()->CacheExternalStandardRenderTargets ();
46824659}
46834660
0 commit comments