#4604 Tweak range decrease

isSystemMemoryLow() and factor check were too agressive for draw range.
master
Andrey Kleshchev 2025-09-12 23:07:47 +03:00
parent a6d4c1d394
commit 5c69ae1d66
4 changed files with 24 additions and 16 deletions

View File

@ -3366,13 +3366,10 @@ void send_agent_update(bool force_send, bool send_reliable)
static F32 last_draw_disatance_step = 1024;
F32 memory_limited_draw_distance = gAgentCamera.mDrawDistance;
if (LLViewerTexture::sDesiredDiscardBias > 2.f && LLViewerTexture::isSystemMemoryLow())
if (LLViewerTexture::isSystemMemoryCritical())
{
// If we are low on memory, reduce requested draw distance
// Discard's bias is clamped to 4 so we need to check 2 to 4 range
// Factor is intended to go from 1.0 to 2.0
F32 factor = 1.f + (LLViewerTexture::sDesiredDiscardBias - 2.f) / 2.f;
memory_limited_draw_distance = llmax(gAgentCamera.mDrawDistance / factor, gAgentCamera.mDrawDistance / 2.f);
memory_limited_draw_distance = llmax(gAgentCamera.mDrawDistance / LLViewerTexture::getSystemMemoryBudgetFactor(), gAgentCamera.mDrawDistance / 2.f);
}
if (tp_state == LLAgent::TELEPORT_ARRIVING || LLStartUp::getStartupState() < STATE_MISC)

View File

@ -657,23 +657,35 @@ U32Megabytes LLViewerTexture::getFreeSystemMemory()
return physical_res;
}
//static
bool LLViewerTexture::isSystemMemoryLow()
S32Megabytes get_render_free_main_memory_treshold()
{
static LLCachedControl<U32> min_free_main_memory(gSavedSettings, "RenderMinFreeMainMemoryThreshold", 512);
const U32Megabytes MIN_FREE_MAIN_MEMORY(min_free_main_memory);
return getFreeSystemMemory() < MIN_FREE_MAIN_MEMORY;
return MIN_FREE_MAIN_MEMORY;
}
//static
bool LLViewerTexture::isSystemMemoryLow()
{
return getFreeSystemMemory() < get_render_free_main_memory_treshold();
}
//static
bool LLViewerTexture::isSystemMemoryCritical()
{
return getFreeSystemMemory() < get_render_free_main_memory_treshold() / 2;
}
F32 LLViewerTexture::getSystemMemoryBudgetFactor()
{
static LLCachedControl<U32> min_free_main_memory(gSavedSettings, "RenderMinFreeMainMemoryThreshold", 512);
const S32Megabytes MIN_FREE_MAIN_MEMORY(min_free_main_memory);
const S32Megabytes MIN_FREE_MAIN_MEMORY(get_render_free_main_memory_treshold() / 2);
S32 free_budget = (S32Megabytes)getFreeSystemMemory() - MIN_FREE_MAIN_MEMORY;
if (free_budget < 0)
{
// Result should range from 1 (0 free budget) to 2 (-512 free budget)
return 1.f - free_budget / MIN_FREE_MAIN_MEMORY;
// Leave some padding, otherwise we will crash out of memory before hitting factor 2.
const S32Megabytes PAD_BUFFER(32);
// Result should range from 1 at 0 free budget to 2 at -224 free budget, 2.14 at -256MB
return 1.f - free_budget / (MIN_FREE_MAIN_MEMORY - PAD_BUFFER);
}
return 1.f;
}

View File

@ -115,6 +115,7 @@ public:
static void initClass();
static void updateClass();
static bool isSystemMemoryLow();
static bool isSystemMemoryCritical();
static F32 getSystemMemoryBudgetFactor();
LLViewerTexture(bool usemipmaps = true);

View File

@ -488,13 +488,11 @@ void LLVOCacheEntry::updateDebugSettings()
static const F32 MIN_RADIUS = 1.0f;
F32 draw_radius = gAgentCamera.mDrawDistance;
if (LLViewerTexture::sDesiredDiscardBias > 2.f && LLViewerTexture::isSystemMemoryLow())
if (LLViewerTexture::isSystemMemoryCritical())
{
// Discard's bias maximum is 4 so we need to check 2 to 4 range
// Factor is intended to go from 1.0 to 2.0
F32 factor = 1.f + (LLViewerTexture::sDesiredDiscardBias - 2.f) / 2.f;
// For safety cap reduction at 50%, we don't want to go below half of draw distance
draw_radius = llmax(draw_radius / factor, draw_radius / 2.f);
draw_radius = llmax(draw_radius / LLViewerTexture::getSystemMemoryBudgetFactor(), draw_radius / 2.f);
}
const F32 clamped_min_radius = llclamp((F32) min_radius, MIN_RADIUS, draw_radius); // [1, mDrawDistance]
sNearRadius = MIN_RADIUS + ((clamped_min_radius - MIN_RADIUS) * adjust_factor);