From 36d2b3534accaba75082701177033e1a1d9a721c Mon Sep 17 00:00:00 2001 From: Kawe Mazidjatari <48657826+Mauler125@users.noreply.github.com> Date: Fri, 3 Jan 2025 15:19:48 +0100 Subject: [PATCH] MaterialSystem: properly switch between static and dynamic texture streaming systems The engine has a bug where it would use GPU feedback even when a static precomputed texture streaming database file exists. If we have an STBSP file for the given level or override, load that in and disable GPU feedback so proper use of the static file could be made. Else we load gpu_driven.stbsp which is a dummy to enable the dynamic, GPU based texture streaming system. --- src/materialsystem/cmaterialsystem.cpp | 35 +++++++++++++++++--------- 1 file changed, 23 insertions(+), 12 deletions(-) diff --git a/src/materialsystem/cmaterialsystem.cpp b/src/materialsystem/cmaterialsystem.cpp index 27b62eca..e6f15c6a 100644 --- a/src/materialsystem/cmaterialsystem.cpp +++ b/src/materialsystem/cmaterialsystem.cpp @@ -99,26 +99,37 @@ int CMaterialSystem::Shutdown(CMaterialSystem* thisptr) // (overrides level name if stbsp field has value in prerequisites file) // Input : *pszLevelName - //--------------------------------------------------------------------------------- -void StreamDB_Init(const char* pszLevelName) +static void StreamDB_Init(const char* const pszLevelName) { - KeyValues* pSettingsKV = Mod_GetLevelSettings(pszLevelName); + KeyValues* const pSettingsKV = Mod_GetLevelSettings(pszLevelName); + const char* targetStreamDB = pszLevelName; if (pSettingsKV) { - KeyValues* pStreamKV = pSettingsKV->FindKey("StreamDB"); + KeyValues* const pStreamKV = pSettingsKV->FindKey("StreamDB"); if (pStreamKV) - { - const char* pszColumnName = pStreamKV->GetString(); - Msg(eDLL_T::MS, "StreamDB_Init: Loading override STBSP file '%s.stbsp'\n", pszColumnName); - - v_StreamDB_Init(pszColumnName); - return; - } + targetStreamDB = pStreamKV->GetString(); } - Msg(eDLL_T::MS, "StreamDB_Init: Loading STBSP file '%s.stbsp'\n", pszLevelName); - v_StreamDB_Init(pszLevelName); + v_StreamDB_Init(targetStreamDB); + + // If the requested STBSP file doesn't exist, load the dummy file to enable + // GPU driven texture streaming. + if (s_streamDataBase->fileHandle == FS_ASYNC_FILE_INVALID) + { + targetStreamDB = STBSP_GPU_DRIVEN_FILE; + v_StreamDB_Init(targetStreamDB); + + gpu_driven_tex_stream->SetValue(true); + } + else + gpu_driven_tex_stream->SetValue(false); + + if (s_streamDataBase->fileHandle != FS_ASYNC_FILE_INVALID) + Msg(eDLL_T::MS, "StreamDB_Init: Loaded STBSP file '%s.stbsp'\n", targetStreamDB); + else + Error(eDLL_T::MS, 0, "StreamDB_Init: STBSP file '%s.stbsp' not found; texture streaming unavailable\n", pszLevelName, STBSP_GPU_DRIVEN_FILE); } static ConVar stream_overlay_memory("stream_overlay_memory", "524288", FCVAR_DEVELOPMENTONLY, "Total string memory to allocate for the texture streaming debug overlay.");