Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions indra/newview/llviewermessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
26 changes: 19 additions & 7 deletions indra/newview/llviewertexture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
1 change: 1 addition & 0 deletions indra/newview/llviewertexture.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,7 @@ class LLViewerTexture : public LLGLTexture
static void initClass();
static void updateClass();
static bool isSystemMemoryLow();
static bool isSystemMemoryCritical();
static F32 getSystemMemoryBudgetFactor();

LLViewerTexture(bool usemipmaps = true);
Expand Down
6 changes: 2 additions & 4 deletions indra/newview/llvocache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Loading