From 892fc662e4effe066aff9d65150daaa9172eac0d Mon Sep 17 00:00:00 2001 From: nillerusr <42746659+nillerusr@users.noreply.github.com> Date: Sat, 17 Dec 2022 18:27:04 +0300 Subject: [PATCH 01/12] sse2neon: fix armhf build( fixes #157 ) --- common/sse2neon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/sse2neon.h b/common/sse2neon.h index 490c0a45..006e870d 100644 --- a/common/sse2neon.h +++ b/common/sse2neon.h @@ -420,7 +420,7 @@ FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t, uint8_t); // Older gcc does not define vld1q_u8_x4 type #if defined(__GNUC__) && !defined(__clang__) && \ - ((__GNUC__ <= 10 && defined(__arm__)) || \ + (defined(__arm__)) || \ (__GNUC__ == 10 && __GNUC_MINOR__ < 3 && defined(__aarch64__)) || \ (__GNUC__ <= 9 && defined(__aarch64__))) FORCE_INLINE uint8x16x4_t _sse2neon_vld1q_u8_x4(const uint8_t *p) From 4f4e74273a8ef01e847d3447c1dd7210d5f8d7ba Mon Sep 17 00:00:00 2001 From: nillerusr <42746659+nillerusr@users.noreply.github.com> Date: Sat, 17 Dec 2022 19:55:22 +0300 Subject: [PATCH 02/12] sse2neon: typo fix --- common/sse2neon.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/common/sse2neon.h b/common/sse2neon.h index 006e870d..4da3ba03 100644 --- a/common/sse2neon.h +++ b/common/sse2neon.h @@ -420,7 +420,7 @@ FORCE_INLINE uint32_t _mm_crc32_u8(uint32_t, uint8_t); // Older gcc does not define vld1q_u8_x4 type #if defined(__GNUC__) && !defined(__clang__) && \ - (defined(__arm__)) || \ + (defined(__arm__) || \ (__GNUC__ == 10 && __GNUC_MINOR__ < 3 && defined(__aarch64__)) || \ (__GNUC__ <= 9 && defined(__aarch64__))) FORCE_INLINE uint8x16x4_t _sse2neon_vld1q_u8_x4(const uint8_t *p) From c44ae6211c66df04cad776cbf560654b2f2d0c4a Mon Sep 17 00:00:00 2001 From: nillerusr Date: Sun, 18 Dec 2022 20:24:28 +0300 Subject: [PATCH 03/12] restore MAXSTUDIOBONES value --- public/studio.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/public/studio.h b/public/studio.h index 488d3a72..5742d3f4 100644 --- a/public/studio.h +++ b/public/studio.h @@ -79,14 +79,14 @@ Studio models are position independent, so the cache manager can move them. #define MAXSTUDIOFLEXVERTS 5000 #endif #define MAXSTUDIOSKINS 32 // total textures -#define MAXSTUDIOBONES 256 // total bones actually used +#define MAXSTUDIOBONES 128 // total bones actually used #define MAXSTUDIOFLEXDESC 1024 // maximum number of low level flexes (actual morph targets) #define MAXSTUDIOFLEXCTRL 96 // maximum number of flexcontrollers (input sliders) #define MAXSTUDIOPOSEPARAM 24 #define MAXSTUDIOBONECTRLS 5 #define MAXSTUDIOANIMBLOCKS 256 -#define MAXSTUDIOBONEBITS 8 // NOTE: MUST MATCH MAXSTUDIOBONES +#define MAXSTUDIOBONEBITS 7 // NOTE: MUST MATCH MAXSTUDIOBONES // NOTE!!! : Changing this number also changes the vtx file format!!!!! #define MAX_NUM_BONES_PER_VERT 3 From be3d0e301f2bf7c53267378ad8c932084077967f Mon Sep 17 00:00:00 2001 From: nillerusr <42746659+nillerusr@users.noreply.github.com> Date: Mon, 19 Dec 2022 00:37:13 +0300 Subject: [PATCH 04/12] Update README.md --- README.md | 65 ++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 45 insertions(+), 20 deletions(-) diff --git a/README.md b/README.md index 4655f6ad..40075f0c 100644 --- a/README.md +++ b/README.md @@ -1,23 +1,48 @@ -# source-engine -Welcome to source engine:) +# Source Engine +[![GitHub Actions Status](https://github.com/nillerusr/source-engine/actions/workflows/build.yml/badge.svg)](https://github.com/nillerusr/source-engine/actions/workflows/build.yml) [![GitHub Actions Status](https://github.com/nillerusr/source-engine/actions/workflows/tests.yml/badge.svg)](https://github.com/nillerusr/source-engine/actions/workflows/tests.yml) + Discord: [![Discord Server](https://img.shields.io/discord/672055862608658432.svg)](https://discord.gg/hZRB7WMgGw) + -Discord: https://discord.gg/hZRB7WMgGw +Information from [wikipedia](https://wikipedia.org/wiki/Source_(game_engine)): + +Source is a 3D game engine developed by Valve. +It debuted as the successor to GoldSrc with Half-Life: Source in June 2004, +followed by Counter-Strike: Source and Half-Life 2 later that year. +Source does not have a concise version numbering scheme; instead, it was released in incremental versions + +Source code is based on TF2 2018 leak. Don't use it for commercial purposes. + +This project is using waf buildsystem. If you have waf-related questions look https://waf.io/book + +# Features: +- Android, OSX, FreeBSD, Windows support +- Arm support( except windows ) +- 64bit support +- Modern toolchains support +- Fixed many undefined behaviours +- Touch support( even on windows/linux/osx ) +- PBR support +- bsp v19-v21 support( bsp v21 support is partial, portal 2 and csgo maps works fine ) +- mdl v46-49 support +- Removed useless/unnecessary dependencies +- Achivement system working without steam +- Fixed many bugs # Current tasks -- [x] Windows build support for waf -- [x] NEON support -- [x] remove unnecessary dependencies -- [x] Arm(android) port -- [x] replace current buildsystem with waf -- [x] rewrite achivement system( to work without steam ) -- [x] 64-bit support -- [x] VTF 7.5 support -- [x] PBR support -- [ ] improve performance -- [ ] fixing bugs -- [ ] dxvk-native support -- [ ] Elbrus port -- [ ] rewrite serverbrowser to work without steam - - -# [How to Build?](https://github.com/nillerusr/source-engine/wiki/How-to-build) +- Rewrite materialsystem for OpenGL render +- dxvk-native support +- Elbrus port +- Bink audio support( for video_bink ) +- Rewrite serverbrowser to work without steam + +# How to Build? +- [Windows](https://github.com/nillerusr/source-engine/wiki/How-to-build#on-windows) +- [Linux](https://github.com/nillerusr/source-engine/wiki/How-to-build#on-linux) +- [For Android under Linux](https://github.com/nillerusr/source-engine/wiki/How-to-build#on-linux-for-android) + +# Support me +BTC: `bc1qnjq92jj9uqjtafcx2zvnwd48q89hgtd6w8a6na` + +ETH: `0x5d0D561146Ed758D266E59B56e85Af0b03ABAF46` + +XMR: `48iXvX61MU24m5VGc77rXQYKmoww3dZh6hn7mEwDaLVTfGhyBKq2teoPpeBq6xvqj4itsGh6EzNTzBty6ZDDevApCFNpsJ` From 44fef251c58031a492b384e6cf3846a20f31cfdb Mon Sep 17 00:00:00 2001 From: LegendGuard <49716252+LegendaryGuard@users.noreply.github.com> Date: Thu, 29 Dec 2022 15:31:44 +0100 Subject: [PATCH 05/12] Add forgotten VTF 7.5 support (#160) VTF 7.5 support was added some time ago, the issue #83 was solved. This is important for making artists, mappers and modelers know. --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 40075f0c..a4925ccf 100644 --- a/README.md +++ b/README.md @@ -21,6 +21,7 @@ This project is using waf buildsystem. If you have waf-related questions look ht - Modern toolchains support - Fixed many undefined behaviours - Touch support( even on windows/linux/osx ) +- VTF 7.5 support - PBR support - bsp v19-v21 support( bsp v21 support is partial, portal 2 and csgo maps works fine ) - mdl v46-49 support From 7ca36e7b43e9cea9a5f25dd183781b5b1bc37e81 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Sat, 31 Dec 2022 19:14:30 +0300 Subject: [PATCH 06/12] launcher(android): fix crashhandler initialization --- launcher/android/main.cpp | 3 +++ 1 file changed, 3 insertions(+) diff --git a/launcher/android/main.cpp b/launcher/android/main.cpp index e044ae6c..10133e83 100644 --- a/launcher/android/main.cpp +++ b/launcher/android/main.cpp @@ -27,6 +27,7 @@ char *LauncherArgv[512]; char java_args[4096]; int iLastArgs = 0; +extern void InitCrashHandler(); DLL_EXPORT int LauncherMain( int argc, char **argv ); // from launcher.cpp DLL_EXPORT int Java_com_valvesoftware_ValveActivity2_setenv(JNIEnv *jenv, jclass *jclass, jstring env, jstring value, jint over) @@ -118,6 +119,8 @@ void android_property_print(const char *name) DLL_EXPORT int LauncherMainAndroid( int argc, char **argv ) { + InitCrashHandler(); + Msg("GetTotalMemory() = %.2f \n", GetTotalMemory()); android_property_print("ro.build.version.sdk"); From f63849bb34f10e6137aebc73274337aa63951a21 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Mon, 2 Jan 2023 16:39:44 +0300 Subject: [PATCH 07/12] vtf: fix cubemap loading for vtf versions less than 7.5 --- vtf/vtf.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/vtf/vtf.cpp b/vtf/vtf.cpp index 63fc107e..9209d569 100644 --- a/vtf/vtf.cpp +++ b/vtf/vtf.cpp @@ -432,7 +432,7 @@ bool CVTFTexture::Init( int nWidth, int nHeight, int nDepth, ImageFormat fmt, in m_nFrameCount = iFrameCount; - m_nFaceCount = (iFlags & TEXTUREFLAGS_ENVMAP) ? (CUBEMAP_FACE_COUNT-1) : 1; + m_nFaceCount = (iFlags & TEXTUREFLAGS_ENVMAP) ? CUBEMAP_FACE_COUNT : 1; #if defined( _X360 ) m_nMipSkipCount = 0; @@ -601,7 +601,7 @@ void CVTFTexture::ImageFileInfo( int nFrame, int nFace, int nMipLevel, int *pSta int nFacesToRead = m_nFaceCount; if ( IsCubeMap() ) { - if ((m_nVersion[0] == 7) && (m_nVersion[1] < 1)) + if ((m_nVersion[0] == 7) && (m_nVersion[1] < 1 || m_nVersion[1] > 4)) { nFacesToRead = 6; if (nFace == CUBEMAP_FACE_SPHEREMAP) @@ -1068,7 +1068,7 @@ bool CVTFTexture::UnserializeEx( CUtlBuffer &buf, bool bHeaderOnly, int nForceFl m_nFrameCount = header.numFrames; - m_nFaceCount = (m_nFlags & TEXTUREFLAGS_ENVMAP) ? (CUBEMAP_FACE_COUNT-1) : 1; + m_nFaceCount = (m_nFlags & TEXTUREFLAGS_ENVMAP) ? CUBEMAP_FACE_COUNT : 1; // NOTE: We're going to store space for all mip levels, even if we don't // have data on disk for them. This is for backward compatibility From e26b40d889b09eeda705c9ce52fb2a653c4b2692 Mon Sep 17 00:00:00 2001 From: exstrim401 Date: Sun, 8 Jan 2023 17:38:24 +0500 Subject: [PATCH 08/12] Basic Steam Dick support (#166) Without gamepadui library --- engine/sys_getmodes.cpp | 19 +++++++++++++++---- engine/vgui_baseui_interface.cpp | 4 ++-- game/client/hud_crosshair.cpp | 10 +++++++++- gameui/BasePanel.cpp | 5 ++++- public/tier1/KeyValues.h | 2 ++ tier1/KeyValues.cpp | 32 ++++++++++++++++++++++++++++++-- 6 files changed, 62 insertions(+), 10 deletions(-) diff --git a/engine/sys_getmodes.cpp b/engine/sys_getmodes.cpp index 939b010f..43dce4d0 100644 --- a/engine/sys_getmodes.cpp +++ b/engine/sys_getmodes.cpp @@ -819,10 +819,13 @@ void CVideoMode_Common::SetupStartupGraphic() // loading.vtf buf.Clear(); // added this Clear() because we saw cases where LoadVTF was not emptying the buf fully in the above section - m_pLoadingTexture = LoadVTF( buf, "materials/console/startup_loading.vtf" ); + const char* loading = "materials/console/startup_loading.vtf"; + if ( IsSteamDeck() ) + loading = "materials/gamepadui/game_logo.vtf"; + m_pLoadingTexture = LoadVTF( buf, loading ); if ( !m_pLoadingTexture ) { - Error( "Can't find background image materials/console/startup_loading.vtf\n" ); + Error( "Can't find background image '%s'\n", loading ); return; } } @@ -883,8 +886,12 @@ void CVideoMode_Common::DrawStartupGraphic() pVMTKeyValues->SetInt( "$nocull", 1 ); IMaterial *pMaterial = g_pMaterialSystem->CreateMaterial( "__background", pVMTKeyValues ); + const char* loading = "console/startup_loading.vtf"; + if ( IsSteamDeck() ) + loading = "gamepadui/game_logo.vtf"; + pVMTKeyValues = new KeyValues( "UnlitGeneric" ); - pVMTKeyValues->SetString( "$basetexture", "Console/startup_loading.vtf" ); + pVMTKeyValues->SetString( "$basetexture", loading ); pVMTKeyValues->SetInt( "$translucent", 1 ); pVMTKeyValues->SetInt( "$ignorez", 1 ); pVMTKeyValues->SetInt( "$nofog", 1 ); @@ -922,7 +929,11 @@ void CVideoMode_Common::DrawStartupGraphic() slide = 0; DrawScreenSpaceRectangle( pMaterial, 0, 0+slide, w, h-50, 0, 0, tw-1, th-1, tw, th, NULL,1,1,depth ); - DrawScreenSpaceRectangle( pLoadingMaterial, w-lw, h-lh+slide/2, lw, lh, 0, 0, lw-1, lh-1, lw, lh, NULL,1,1,depth-0.1 ); + if ( !IsSteamDeck() ) + DrawScreenSpaceRectangle( pLoadingMaterial, w-lw, h-lh+slide/2, lw, lh, 0, 0, lw-1, lh-1, lw, lh, NULL,1,1,depth-0.1 ); + else + // TODO: Steam Deck + DrawScreenSpaceRectangle( pLoadingMaterial, w-lw, h-lh+slide/2, lw, lh, 0, 0, lw-1, lh-1, lw, lh, NULL,1,1,depth-0.1 ); } if(0) diff --git a/engine/vgui_baseui_interface.cpp b/engine/vgui_baseui_interface.cpp index 2f29683c..9fa8c899 100644 --- a/engine/vgui_baseui_interface.cpp +++ b/engine/vgui_baseui_interface.cpp @@ -613,7 +613,7 @@ void CEngineVGui::Init() return; } - if ( IsX360() ) + if ( IsX360() || IsSteamDeck() ) { CCommand ccommand; if ( CL_ShouldLoadBackgroundLevel( ccommand ) ) @@ -1273,7 +1273,7 @@ void CEngineVGui::OnLevelLoadingStarted() } } - if ( IsX360() ) + if ( IsX360() || IsSteamDeck() ) { // TCR requirement, always!!! m_bShowProgressDialog = true; diff --git a/game/client/hud_crosshair.cpp b/game/client/hud_crosshair.cpp index fc7714fe..6dd5e2f6 100644 --- a/game/client/hud_crosshair.cpp +++ b/game/client/hud_crosshair.cpp @@ -258,7 +258,15 @@ void CHudCrosshair::Paint( void ) pWeapon->GetWeaponCrosshairScale( flWeaponScale ); } - float flPlayerScale = 1.0f; + int iScreenDiv = 1600; + if ( IsSteamDeck() ) + iScreenDiv = 1440; + + float flPlayerScale; + if ( !m_pCrosshair->bRenderUsingFont ) + flPlayerScale = (ScreenHeight() / iScreenDiv) + 1; + else + flPlayerScale = 1.0f; #ifdef TF_CLIENT_DLL Color clr( cl_crosshair_red.GetInt(), cl_crosshair_green.GetInt(), cl_crosshair_blue.GetInt(), 255 ); flPlayerScale = cl_crosshair_scale.GetFloat() / 32.0f; // the player can change the scale in the options/multiplayer tab diff --git a/gameui/BasePanel.cpp b/gameui/BasePanel.cpp index c6e4051e..41d52d63 100644 --- a/gameui/BasePanel.cpp +++ b/gameui/BasePanel.cpp @@ -1801,8 +1801,11 @@ void CBasePanel::ApplySchemeSettings(IScheme *pScheme) // load the loading icon if ( m_iLoadingImageID == -1 ) { + const char* loading = "console/startup_loading"; + if ( IsSteamDeck() ) + loading = "gamepadui/game_logo"; m_iLoadingImageID = surface()->CreateNewTextureID(); - surface()->DrawSetTextureFile( m_iLoadingImageID, "Console/startup_loading", false, false ); + surface()->DrawSetTextureFile( m_iLoadingImageID, loading, false, false ); } } } diff --git a/public/tier1/KeyValues.h b/public/tier1/KeyValues.h index 151aa281..3a6af814 100644 --- a/public/tier1/KeyValues.h +++ b/public/tier1/KeyValues.h @@ -428,6 +428,8 @@ inline bool KeyValues::IsEmpty( int keySymbol ) return dat ? dat->IsEmpty( ) : true; } +bool IsSteamDeck(); + bool EvaluateConditional( const char *str ); class CUtlSortVectorKeyValuesByName diff --git a/tier1/KeyValues.cpp b/tier1/KeyValues.cpp index 8e855a78..75664e43 100644 --- a/tier1/KeyValues.cpp +++ b/tier1/KeyValues.cpp @@ -2179,6 +2179,34 @@ void KeyValues::RecursiveMergeKeyValues( KeyValues *baseKV ) } } +static int s_nSteamDeckCached = -1; + +bool IsSteamDeck() +{ + if (s_nSteamDeckCached == -1) { + if ( CommandLine()->CheckParm( "-nogamepadui" ) != 0 ) + { + s_nSteamDeckCached = 0; + } + else + { + if ( CommandLine()->CheckParm( "-gamepadui" ) != 0 ) + { + s_nSteamDeckCached = 1; + } + else + { + char *deck = getenv("SteamDeck"); + if ( deck == 0 || *deck == 0 ) + s_nSteamDeckCached = 0; + else + s_nSteamDeckCached = atoi(deck) != 0; + } + } + } + return s_nSteamDeckCached; +} + //----------------------------------------------------------------------------- // Returns whether a keyvalues conditional evaluates to true or false // Needs more flexibility with conditionals, checking convars would be nice. @@ -2195,8 +2223,8 @@ bool EvaluateConditional( const char *str ) if ( *str == '!' ) bNot = true; - if( Q_stristr( str, "$DECK" ) ) - return false ^ bNot; // Steam deck unsupported + if ( Q_stristr( str, "$DECK" ) ) + return IsSteamDeck() ^ bNot; if ( Q_stristr( str, "$X360" ) ) return IsX360() ^ bNot; From 3d43e9fe3a6a9475d1a965771d46922514df5e66 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Thu, 12 Jan 2023 20:48:13 +0300 Subject: [PATCH 09/12] togles: optimize PBO usage --- public/togles/linuxwin/glmgr.h | 2 ++ togles/linuxwin/cglmtex.cpp | 8 ++++---- togles/linuxwin/dx9asmtogl2.cpp | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/public/togles/linuxwin/glmgr.h b/public/togles/linuxwin/glmgr.h index 111d8501..1d70adcc 100644 --- a/public/togles/linuxwin/glmgr.h +++ b/public/togles/linuxwin/glmgr.h @@ -69,6 +69,8 @@ #define GL_ALPHA_TEST_FUNC_QCOM 0x0BC1 #define GL_ALPHA_TEST_REF_QCOM 0x0BC2 +#define GLSL_VERSION "#version 300 es\n" + extern void GLMDebugPrintf( const char *pMsg, ... ); extern uint g_nTotalDrawsOrClears, g_nTotalVBLockBytes, g_nTotalIBLockBytes; diff --git a/togles/linuxwin/cglmtex.cpp b/togles/linuxwin/cglmtex.cpp index a5811f3b..5ed83df2 100644 --- a/togles/linuxwin/cglmtex.cpp +++ b/togles/linuxwin/cglmtex.cpp @@ -427,7 +427,7 @@ bool GLMGenTexels( GLMGenTexelParams *params ) DebuggerBreak(); return FALSE; } - + // verify that the amount you want to write will not exceed the limit byte count unsigned long destByteCount = chunksize * params->m_chunkCount; @@ -3828,7 +3828,7 @@ void CGLMTex::Lock( GLMTexLockParams *params, char** addressOut, int* yStrideOut // d - the params of the lock request have been saved in the lock table (in the context) // so step 1 is unambiguous. If there's no backing storage, make some. - if (!m_backing) + if (!m_backing && !(m_layout->m_key.m_texFlags & kGLMTexDynamic)) { if ( gl_pow2_tempmem.GetBool() ) { @@ -3940,7 +3940,7 @@ void CGLMTex::Lock( GLMTexLockParams *params, char** addressOut, int* yStrideOut desc->m_sliceRegionOffset = offsetInSlice + desc->m_sliceBaseOffset; - if ( copyout && ( (m_layout->m_key.m_texFlags & kGLMTexDynamic) || params->m_readonly ) ) + if ( (m_layout->m_key.m_texFlags & kGLMTexDynamic) || (params->m_readonly && copyout) ) { // read the whole slice // (odds are we'll never request anything but a whole slice to be read..) @@ -4080,7 +4080,7 @@ void CGLMTex::Unlock( GLMTexLockParams *params ) // because it reuploads the whole thing each slice; we only use 3D textures // for the 32x32x32 colorpsace conversion lookups and debugging the problem // would not save any more memory. - if ( !m_texClientStorage && ( m_texGLTarget == GL_TEXTURE_2D ) ) + if ( !m_texClientStorage && ( m_texGLTarget == GL_TEXTURE_2D ) && m_backing ) { free(m_backing); m_backing = NULL; diff --git a/togles/linuxwin/dx9asmtogl2.cpp b/togles/linuxwin/dx9asmtogl2.cpp index 41d08a94..578bcad9 100644 --- a/togles/linuxwin/dx9asmtogl2.cpp +++ b/togles/linuxwin/dx9asmtogl2.cpp @@ -3287,13 +3287,13 @@ int D3DToGL::TranslateShader( uint32* code, CUtlBuffer *pBufDisassembledCode, bo if ( ( dwToken & 0xFFFF0000 ) == 0xFFFF0000 ) { // must explicitly enable extensions if emitting GLSL - V_snprintf( (char *)m_pBufHeaderCode->Base(), m_pBufHeaderCode->Size(), "#version 300 es\nprecision highp float;\n#define varying in\n\n%s", glslExtText ); + V_snprintf( (char *)m_pBufHeaderCode->Base(), m_pBufHeaderCode->Size(), GLSL_VERSION "precision highp float;\n#define varying in\n\n%s", glslExtText ); m_bVertexShader = false; } else // vertex shader { m_bGenerateSRGBWriteSuffix = false; - V_snprintf( (char *)m_pBufHeaderCode->Base(), m_pBufHeaderCode->Size(), "#version 300 es\nprecision highp float;\n#define attribute in\n#define varying out\n%s//ATTRIBMAP-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx\n", glslExtText ); + V_snprintf( (char *)m_pBufHeaderCode->Base(), m_pBufHeaderCode->Size(), GLSL_VERSION "precision highp float;\n#define attribute in\n#define varying out\n%s//ATTRIBMAP-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx-xx\n", glslExtText ); // find that first '-xx' which is where the attrib map will be written later. pAttribMapStart = strstr( (char *)m_pBufHeaderCode->Base(), "-xx" ) + 1; From 3458c36d5aa57053e2aaff91e94c7c0c9b57a365 Mon Sep 17 00:00:00 2001 From: nillerusr Date: Fri, 13 Jan 2023 01:51:19 +0300 Subject: [PATCH 10/12] datacache: enable async mode(was disabled in TF2 branch, lol?) --- datacache/mdlcache.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/datacache/mdlcache.cpp b/datacache/mdlcache.cpp index 9ef8c6f3..9af1150c 100644 --- a/datacache/mdlcache.cpp +++ b/datacache/mdlcache.cpp @@ -81,7 +81,7 @@ namespace { #if defined( _X360 ) #define AsyncMdlCache() 0 // Explicitly OFF for 360 (incompatible) #else -#define AsyncMdlCache() 0 +#define AsyncMdlCache() 1 #endif #define ERROR_MODEL "models/error.mdl" From a15db00bc0cc57c42ca0dc7113f12d766dbcdfba Mon Sep 17 00:00:00 2001 From: nillerusr Date: Sat, 14 Jan 2023 14:48:22 +0300 Subject: [PATCH 11/12] materialsystem: threaded optimizations, fix mat_queue_mode on some android devices --- materialsystem/cmaterialsystem.cpp | 45 +++++------------- materialsystem/cmatqueuedrendercontext.cpp | 9 ++-- materialsystem/ctexture.cpp | 15 +----- public/tier0/threadtools.h | 44 ++++++++++++++++-- public/tier1/memhelpers.h | 16 ++----- public/vstdlib/jobthread.h | 4 +- tier0/threadtools.cpp | 53 ---------------------- vstdlib/jobthread.cpp | 20 ++------ 8 files changed, 66 insertions(+), 140 deletions(-) diff --git a/materialsystem/cmaterialsystem.cpp b/materialsystem/cmaterialsystem.cpp index a3c1c233..2293af42 100644 --- a/materialsystem/cmaterialsystem.cpp +++ b/materialsystem/cmaterialsystem.cpp @@ -1029,7 +1029,7 @@ bool CMaterialSystem::AllowThreading( bool bAllow, int nServiceThread ) bool bOldAllow = m_bAllowQueuedRendering; - if ( GetCPUInformation()->m_nPhysicalProcessors >= 2 ) + if ( GetCPUInformation()->m_nLogicalProcessors >= 2 ) { m_bAllowQueuedRendering = bAllow; bool bQueued = m_IdealThreadMode != MATERIAL_SINGLE_THREADED; @@ -1806,11 +1806,7 @@ static ConVar mat_normalmaps( "mat_normalmaps", "0", FCVAR_CHEAT ); static ConVar mat_measurefillrate( "mat_measurefillrate", "0", FCVAR_CHEAT ); static ConVar mat_fillrate( "mat_fillrate", "0", FCVAR_CHEAT ); static ConVar mat_reversedepth( "mat_reversedepth", "0", FCVAR_CHEAT ); -#ifdef DX_TO_GL_ABSTRACTION -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 -#else static ConVar mat_bufferprimitives( "mat_bufferprimitives", "1" ); -#endif static ConVar mat_drawflat( "mat_drawflat","0", FCVAR_CHEAT ); static ConVar mat_softwarelighting( "mat_softwarelighting", "0", FCVAR_ALLOWED_IN_COMPETITIVE ); static ConVar mat_proxy( "mat_proxy", "0", FCVAR_CHEAT, "", MatProxyCallback ); @@ -2780,8 +2776,8 @@ IMaterial* CMaterialSystem::FindMaterialEx( char const* pMaterialName, const cha { // We need lower-case symbols for this to work int nLen = Q_strlen( pMaterialName ) + 1; - char *pFixedNameTemp = (char*)malloc( nLen ); - char *pTemp = (char*)malloc( nLen ); + char *pFixedNameTemp = (char*)stackalloc( nLen ); + char *pTemp = (char*)stackalloc( nLen ); Q_strncpy( pFixedNameTemp, pMaterialName, nLen ); Q_strlower( pFixedNameTemp ); #ifdef POSIX @@ -2883,9 +2879,6 @@ IMaterial* CMaterialSystem::FindMaterialEx( char const* pMaterialName, const cha } } - free(pTemp); - free(pFixedNameTemp); - return g_pErrorMaterial->GetRealTimeVersion(); } @@ -3103,20 +3096,12 @@ void CMaterialSystem::ResetTempHWMemory( bool bExitingLevel ) //----------------------------------------------------------------------------- void CMaterialSystem::CacheUsedMaterials( ) { + printf("Cache materials\n"); + g_pShaderAPI->EvictManagedResources(); - size_t count = 0; + for (MaterialHandle_t i = FirstMaterial(); i != InvalidMaterial(); i = NextMaterial(i) ) { - // Some (mac) drivers (amd) seem to keep extra resources around on uploads until the next frame swap. This - // injects pointless synthetic swaps (between already-static load frames) - if ( mat_texture_reload_frame_swap_workaround.GetBool() ) - { - if ( count++ % 20 == 0 ) - { - Flush(true); - SwapBuffers(); // Not the right thing to call - } - } IMaterialInternal* pMat = GetMaterialInternal(i); Assert( pMat->GetReferenceCount() >= 0 ); if( pMat->GetReferenceCount() > 0 ) @@ -3703,9 +3688,13 @@ void CMaterialSystem::EndFrame( void ) ThreadAcquire( true ); } + IThreadPool* pThreadPool = CreateMatQueueThreadPool(); + if ( m_pActiveAsyncJob && !m_pActiveAsyncJob->IsFinished() ) { - m_pActiveAsyncJob->WaitForFinish(); + m_pActiveAsyncJob->WaitForFinish(TT_INFINITE, pThreadPool); + + // Sync with GPU if we had a job for it, even if it finished early on CPU! if ( !IsPC() && g_config.ForceHWSync() ) { g_pShaderAPI->ForceHardwareSync(); @@ -3730,7 +3719,6 @@ void CMaterialSystem::EndFrame( void ) } } - IThreadPool *pThreadPool = CreateMatQueueThreadPool(); pThreadPool->AddJob( m_pActiveAsyncJob ); break; } @@ -4664,20 +4652,9 @@ void CMaterialSystem::BeginRenderTargetAllocation( void ) void CMaterialSystem::EndRenderTargetAllocation( void ) { - // Any GPU newer than 2005 doesn't need to do this, and it eats up ~40% of our level load time! - const bool cbRequiresRenderTargetAllocationFirst = mat_requires_rt_alloc_first.GetBool(); - g_pShaderAPI->FlushBufferedPrimitives(); m_bAllocatingRenderTargets = false; - if ( IsPC() && cbRequiresRenderTargetAllocationFirst && g_pShaderAPI->CanDownloadTextures() ) - { - // Simulate an Alt-Tab...will cause RTs to be allocated first - - g_pShaderDevice->ReleaseResources(); - g_pShaderDevice->ReacquireResources(); - } - TextureManager()->CacheExternalStandardRenderTargets(); } diff --git a/materialsystem/cmatqueuedrendercontext.cpp b/materialsystem/cmatqueuedrendercontext.cpp index 96d5bb0f..12e98858 100644 --- a/materialsystem/cmatqueuedrendercontext.cpp +++ b/materialsystem/cmatqueuedrendercontext.cpp @@ -455,14 +455,11 @@ public: } else { - ALIGN16 uint16 tempIndices[16]; + static ALIGN16 uint16 tempIndices[256]; + // original method int i = 0; - if ( (size_t)desc.m_pIndices % 4 == 2 ) - { - desc.m_pIndices[i] = pIndexData[i] + desc.m_nFirstVertex; - i++; - } + while ( i < nIndices ) { int nToCopy = min( (int)ARRAYSIZE(tempIndices), nIndices - i ); diff --git a/materialsystem/ctexture.cpp b/materialsystem/ctexture.cpp index 977d2deb..03998591 100644 --- a/materialsystem/ctexture.cpp +++ b/materialsystem/ctexture.cpp @@ -2458,15 +2458,8 @@ bool CTexture::AsyncReadTextureFromFile( IVTFTexture* pVTFTexture, unsigned int return false; } - if ( V_strstr( GetName(), "c_sniperrifle_scope" ) ) - { - int i = 0; - i = 3; - } - - tmZone( TELEMETRY_LEVEL0, TMZF_NONE, "%s - %s", __FUNCTION__, tmDynamicString( TELEMETRY_LEVEL0, pCacheFileName ) ); - + // OSX hackery int nPreserveFlags = nAdditionalCreationFlags; if ( m_nFlags & TEXTUREFLAGS_SRGB ) @@ -4189,12 +4182,6 @@ bool SLoadTextureBitsFromFile( IVTFTexture **ppOutVtfTexture, FileHandle_t hFile // NOTE! NOTE! NOTE! or by the streaming texture code! Assert( ppOutVtfTexture != NULL && *ppOutVtfTexture != NULL ); - if ( V_strstr( pName, "c_rocketlauncher/c_rocketlauncher" ) ) - { - int i = 0; - i = 3; - } - CUtlBuffer buf; { diff --git a/public/tier0/threadtools.h b/public/tier0/threadtools.h index 2b18dda7..b7216193 100644 --- a/public/tier0/threadtools.h +++ b/public/tier0/threadtools.h @@ -52,6 +52,12 @@ #pragma once #pragma warning(push) #pragma warning(disable:4251) + +extern "C" +{ + void __declspec(dllimport) __stdcall Sleep( unsigned long ); +} + #endif #ifdef COMPILER_MSVC64 @@ -194,8 +200,6 @@ PLATFORM_INTERFACE bool ReleaseThreadHandle( ThreadHandle_t ); //----------------------------------------------------------------------------- -PLATFORM_INTERFACE void ThreadSleep(unsigned duration = 0); -PLATFORM_INTERFACE void ThreadNanoSleep(unsigned ns); PLATFORM_INTERFACE ThreadId_t ThreadGetCurrentId(); PLATFORM_INTERFACE ThreadHandle_t ThreadGetCurrentHandle(); PLATFORM_INTERFACE int ThreadGetPriority( ThreadHandle_t hThread = NULL ); @@ -229,10 +233,10 @@ inline void ThreadPause() { #if defined( COMPILER_PS3 ) __db16cyc(); -#elif defined(__arm__) || defined(__aarch64__) - sched_yield(); -#elif defined( COMPILER_GCC ) +#elif defined( COMPILER_GCC ) && (defined( __i386__ ) || defined( __x86_64__ )) __asm __volatile( "pause" ); +#elif defined( POSIX ) + sched_yield(); #elif defined ( COMPILER_MSVC64 ) _mm_pause(); #elif defined( COMPILER_MSVC32 ) @@ -247,6 +251,36 @@ inline void ThreadPause() #endif } +inline void ThreadSleep(unsigned nMilliseconds = 0) +{ + if( nMilliseconds == 0 ) + { + ThreadPause(); + return; + } + +#ifdef _WIN32 + +#ifdef _WIN32_PC + static bool bInitialized = false; + if ( !bInitialized ) + { + bInitialized = true; + // Set the timer resolution to 1 ms (default is 10.0, 15.6, 2.5, 1.0 or + // some other value depending on hardware and software) so that we can + // use Sleep( 1 ) to avoid wasting CPU time without missing our frame + // rate. + timeBeginPeriod( 1 ); + } +#endif + Sleep( nMilliseconds ); +#elif PS3 + sys_timer_usleep( nMilliseconds * 1000 ); +#elif defined(POSIX) + usleep( nMilliseconds * 1000 ); +#endif +} + PLATFORM_INTERFACE bool ThreadJoin( ThreadHandle_t, unsigned timeout = TT_INFINITE ); PLATFORM_INTERFACE void ThreadSetDebugName( ThreadHandle_t hThread, const char *pszName ); diff --git a/public/tier1/memhelpers.h b/public/tier1/memhelpers.h index 898cafb2..35cd513e 100644 --- a/public/tier1/memhelpers.h +++ b/public/tier1/memhelpers.h @@ -11,21 +11,15 @@ namespace memutils template inline void copy( T *dest, const T *src, size_t n ) { - do - { - --n; - *(dest+n) = *(src+n); - } while( n ); + for(; n; n--) + *(dest++) = *(src++); } template - inline void set( T *dest, T value, size_t n ) + inline void set( T *dest, const T& value, size_t n ) { - do - { - --n; - *(dest+n) = value; - } while( n ); + for(; n; n--) + *(dest++) = value; } } diff --git a/public/vstdlib/jobthread.h b/public/vstdlib/jobthread.h index 05798a2c..4e722a5d 100644 --- a/public/vstdlib/jobthread.h +++ b/public/vstdlib/jobthread.h @@ -492,8 +492,8 @@ public: //----------------------------------------------------- // Thread event support (safe for NULL this to simplify code ) //----------------------------------------------------- - bool WaitForFinish( uint32 dwTimeout = TT_INFINITE ) { if (!this) return true; return ( !IsFinished() ) ? g_pThreadPool->YieldWait( this, dwTimeout ) : true; } - bool WaitForFinishAndRelease( uint32 dwTimeout = TT_INFINITE ) { if (!this) return true; bool bResult = WaitForFinish( dwTimeout); Release(); return bResult; } + inline bool WaitForFinish( uint32 dwTimeout = TT_INFINITE, IThreadPool *pool = g_pThreadPool ) { if (!this) return true; return ( !IsFinished() ) ? pool->YieldWait( this, dwTimeout ) : true; } + inline bool WaitForFinishAndRelease( uint32 dwTimeout = TT_INFINITE ) { if (!this) return true; bool bResult = WaitForFinish( dwTimeout); Release(); return bResult; } CThreadEvent *AccessEvent() { return &m_CompleteEvent; } //----------------------------------------------------- diff --git a/tier0/threadtools.cpp b/tier0/threadtools.cpp index b0dbb645..06c8296f 100644 --- a/tier0/threadtools.cpp +++ b/tier0/threadtools.cpp @@ -485,59 +485,6 @@ bool ReleaseThreadHandle( ThreadHandle_t hThread ) // //----------------------------------------------------------------------------- -void ThreadSleep(unsigned nMilliseconds) -{ -#ifdef _WIN32 - -#ifdef _WIN32_PC - static bool bInitialized = false; - if ( !bInitialized ) - { - bInitialized = true; - // Set the timer resolution to 1 ms (default is 10.0, 15.6, 2.5, 1.0 or - // some other value depending on hardware and software) so that we can - // use Sleep( 1 ) to avoid wasting CPU time without missing our frame - // rate. - timeBeginPeriod( 1 ); - } -#endif - - Sleep( nMilliseconds ); -#elif PS3 - if( nMilliseconds == 0 ) - { - // sys_ppu_thread_yield doesn't seem to function properly, so sleep instead. -// sys_timer_usleep( 60 ); - sys_ppu_thread_yield(); - } - else - { - sys_timer_usleep( nMilliseconds * 1000 ); - } -#elif defined(POSIX) - usleep( nMilliseconds * 1000 ); -#endif -} - -//----------------------------------------------------------------------------- -void ThreadNanoSleep(unsigned ns) -{ -#ifdef _WIN32 - // ceil - Sleep( ( ns + 999 ) / 1000 ); -#elif PS3 - sys_timer_usleep( ns ); -#elif defined(POSIX) - struct timespec tm; - tm.tv_sec = 0; - tm.tv_nsec = ns; - nanosleep( &tm, NULL ); -#endif -} - - -//----------------------------------------------------------------------------- - #ifndef ThreadGetCurrentId ThreadId_t ThreadGetCurrentId() { diff --git a/vstdlib/jobthread.cpp b/vstdlib/jobthread.cpp index 922b770f..634d5358 100644 --- a/vstdlib/jobthread.cpp +++ b/vstdlib/jobthread.cpp @@ -214,7 +214,11 @@ public: //----------------------------------------------------- virtual int YieldWait( CThreadEvent **pEvents, int nEvents, bool bWaitAll = true, unsigned timeout = TT_INFINITE ); virtual int YieldWait( CJob **, int nJobs, bool bWaitAll = true, unsigned timeout = TT_INFINITE ); - void Yield( unsigned timeout ); + inline void Yield( unsigned timeout ) + { + Assert( ThreadInMainThread() ); + ThreadSleep( timeout ); + } //----------------------------------------------------- // Add a native job to the queue (master thread) @@ -656,20 +660,6 @@ int CThreadPool::YieldWait( CJob **ppJobs, int nJobs, bool bWaitAll, unsigned ti return YieldWait( handles.Base(), handles.Count(), bWaitAll, timeout); } -//--------------------------------------------------------- - -void CThreadPool::Yield( unsigned timeout ) -{ - // @MULTICORE (toml 10/24/2006): not implemented - Assert( ThreadInMainThread() ); - if ( !ThreadInMainThread() ) - { - ThreadSleep( timeout ); - return; - } - ThreadSleep( timeout ); -} - //--------------------------------------------------------- // Add a job to the queue //--------------------------------------------------------- From f735e7a0364bf4fa6401aca7cfc720467ef81fb4 Mon Sep 17 00:00:00 2001 From: Er2 Date: Sat, 14 Jan 2023 20:47:16 +0300 Subject: [PATCH 12/12] Fix HTML MOTD (#174) --- game/client/game_controls/vguitextwindow.cpp | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/game/client/game_controls/vguitextwindow.cpp b/game/client/game_controls/vguitextwindow.cpp index 4967d74a..203f6ccd 100644 --- a/game/client/game_controls/vguitextwindow.cpp +++ b/game/client/game_controls/vguitextwindow.cpp @@ -32,7 +32,7 @@ extern INetworkStringTable *g_pStringTableInfoPanel; #define TEMP_HTML_FILE "textwindow_temp.html" -ConVar cl_disablehtmlmotd( "cl_disablehtmlmotd", "0", FCVAR_ARCHIVE, "Disable HTML motds." ); +ConVar cl_disablehtmlmotd( "cl_disablehtmlmotd", "1", FCVAR_ARCHIVE, "Disable HTML motds." ); //============================================================================= // HPE_BEGIN: @@ -129,7 +129,8 @@ void CTextWindow::ApplySchemeSettings( IScheme *pScheme ) CTextWindow::~CTextWindow() { // remove temp file again - g_pFullFileSystem->RemoveFile( TEMP_HTML_FILE, "DEFAULT_WRITE_PATH" ); + if (g_pFullFileSystem->FileExists(TEMP_HTML_FILE)) + g_pFullFileSystem->RemoveFile( TEMP_HTML_FILE, "DEFAULT_WRITE_PATH" ); } void CTextWindow::Reset( void )