MaterialSystem: only update STBSP camera if we aren't GPU driven

Only update the stream camera if we aren't GPU driven to save on load in the render thread.

The camera is used to get the correct column from the STBSP file. Though, if we use the GPU feedback driven texture streaming system, it doesn't make sense to burn CPU here since the GPU system doesn't use the camera at all.
This commit is contained in:
Kawe Mazidjatari 2025-01-07 20:27:35 +01:00
parent 164c594486
commit e1f0de0089
2 changed files with 31 additions and 0 deletions

View File

@ -197,6 +197,28 @@ Vector2D CMaterialSystem::GetScreenSize(CMaterialSystem* pMatSys)
return vecScreenSize;
}
//-----------------------------------------------------------------------------
// Purpose: updates the stream camera used for getting the column from the STBSP
// Input : *pMatSys -
// *camPos -
// *camAng -
// halfFovX -
// viewWidth -
//-----------------------------------------------------------------------------
void CMaterialSystem::UpdateStreamCamera(CMaterialSystem* const pMatSys, const Vector3D* const camPos,
const QAngle* const camAng, const float halfFovX, const float viewWidth)
{
// The stream camera is only used for the STBSP. If we use the GPU feedback
// driven texture streaming system instead, do not run this code.
if (gpu_driven_tex_stream->GetBool())
return;
// NOTE: 'camAng' is set and provided to the function below, but the actual
// function that updates the global state (StreamDB_SetCameraPosition)
// isn't using it. The parameter is unused.
CMaterialSystem__UpdateStreamCamera(pMatSys, camPos, camAng, halfFovX, viewWidth);
}
#endif // !MATERIALSYSTEM_NODX
///////////////////////////////////////////////////////////////////////////////
@ -212,6 +234,8 @@ void VMaterialSystem::Detour(const bool bAttach) const
DetourSetup(&CMaterialSystem__SwapBuffers, &CMaterialSystem::SwapBuffers, bAttach);
DetourSetup(&CMaterialSystem__FindMaterialEx, &CMaterialSystem::FindMaterialEx, bAttach);
DetourSetup(&CMaterialSystem__UpdateStreamCamera, &CMaterialSystem::UpdateStreamCamera, bAttach);
DetourSetup(&v_DispatchDrawCall, &DispatchDrawCall, bAttach);
DetourSetup(&v_SpinPresent, &SpinPresent, bAttach);
#endif // !MATERIALSYSTEM_NODX

View File

@ -15,6 +15,8 @@ public:
static void* SwapBuffers(CMaterialSystem* pMatSys);
static CMaterialGlue* FindMaterialEx(CMaterialSystem* pMatSys, const char* pMaterialName, uint8_t nMaterialType, int nUnk, bool bComplain);
static Vector2D GetScreenSize(CMaterialSystem* pMatSys = nullptr);
static void UpdateStreamCamera(CMaterialSystem* const pMatSys, const Vector3D* const camPos, const QAngle* const camAng, const float halfFovX, const float viewWidth);
#endif // !MATERIALSYSTEM_NODX
// TODO: reverse the vftable!
@ -73,6 +75,8 @@ inline void*(*CMaterialSystem__SwapBuffers)(CMaterialSystem* pMatSys);
inline CMaterialGlue*(*CMaterialSystem__FindMaterialEx)(CMaterialSystem* pMatSys, const char* pMaterialName, uint8_t nMaterialType, int nUnk, bool bComplain);
inline void(*CMaterialSystem__GetScreenSize)(CMaterialSystem* pMatSys, float* outX, float* outY);
inline void(*CMaterialSystem__UpdateStreamCamera)(CMaterialSystem* const pMatSys, const Vector3D* const camPos, const QAngle* const camAng, const float halfFovX, const float viewWidth);
inline void*(*v_DispatchDrawCall)(int64_t a1, uint64_t a2, int a3, int a4, int64_t a5, int a6, uint8_t a7, int64_t a8, uint32_t a9, uint32_t a10, int a11, __m128* a12, int a13, int64_t a14);
inline ssize_t(*v_SpinPresent)(void);
#endif // !MATERIALSYSTEM_NODX
@ -102,6 +106,7 @@ class VMaterialSystem : public IDetour
LogFunAdr("CMaterialSystem::SwapBuffers", CMaterialSystem__SwapBuffers);
LogFunAdr("CMaterialSystem::FindMaterialEx", CMaterialSystem__FindMaterialEx);
LogFunAdr("CMaterialSystem::GetScreenSize", CMaterialSystem__GetScreenSize);
LogFunAdr("CMaterialSystem::UpdateStreamCamera", CMaterialSystem__UpdateStreamCamera);
LogFunAdr("DispatchDrawCall", v_DispatchDrawCall);
LogFunAdr("SpinPresent", v_SpinPresent);
#endif // !MATERIALSYSTEM_NODX
@ -125,6 +130,8 @@ class VMaterialSystem : public IDetour
g_GameDll.FindPatternSIMD("44 89 4C 24 ?? 44 88 44 24 ?? 48 89 4C 24 ??").GetPtr(CMaterialSystem__FindMaterialEx);
g_GameDll.FindPatternSIMD("8B 05 ?? ?? ?? ?? 89 02 8B 05 ?? ?? ?? ?? 41 89 ?? C3 CC CC CC CC CC CC CC CC CC CC CC CC CC CC 8B 05 ?? ?? ?? ??").GetPtr(CMaterialSystem__GetScreenSize);
g_GameDll.FindPatternSIMD("48 83 EC ?? 48 8B 05 ?? ?? ?? ?? 44 0F 29 44 24").GetPtr(CMaterialSystem__UpdateStreamCamera);
g_GameDll.FindPatternSIMD("44 89 4C 24 ?? 44 89 44 24 ?? 48 89 4C 24 ?? 55 53 56").GetPtr(v_DispatchDrawCall);
g_GameDll.FindPatternSIMD("48 89 5C 24 ?? 48 89 74 24 ?? 57 48 81 EC ?? ?? ?? ?? 8B 15 ?? ?? ?? ??").GetPtr(v_SpinPresent);
#endif // !MATERIALSYSTEM_NODX