Streamer memory management bug fixes and experimental low memory warning handler in progress.

This commit is contained in:
2014-06-03 02:40:56 -07:00
parent 9501c29ec5
commit 67ccdf4471
4 changed files with 52 additions and 17 deletions

View File

@@ -322,7 +322,7 @@ void KRContext::getMemoryStats(long &free_memory)
} else { } else {
total_ram = (vm_stat.wire_count + vm_stat.active_count + vm_stat.inactive_count + vm_stat.free_count) * pagesize; total_ram = (vm_stat.wire_count + vm_stat.active_count + vm_stat.inactive_count + vm_stat.free_count) * pagesize;
free_memory = vm_stat.free_count * pagesize; free_memory = (vm_stat.free_count + vm_stat.inactive_count) * pagesize;
} }
#else #else
#error Unsupported Platform #error Unsupported Platform
@@ -332,17 +332,52 @@ void KRContext::getMemoryStats(long &free_memory)
void KRContext::doStreaming() void KRContext::doStreaming()
{ {
if(m_streamingEnabled) { if(m_streamingEnabled) {
const long MEMORY_WARNING_THROTTLE_FRAMES = 15; /*
long free_memory = KRENGINE_GPU_MEM_TARGET;
long total_memory = KRENGINE_GPU_MEM_MAX;
*/
/*
#if TARGET_OS_IPHONE
// FINDME, TODO, HACK! - Experimental code, need to expose through engine parameters
const long KRENGINE_RESERVE_MEMORY = 0x4000000; // 64MB
getMemoryStats(free_memory);
free_memory = KRCLAMP(free_memory - KRENGINE_RESERVE_MEMORY, 0, KRENGINE_GPU_MEM_TARGET);
total_memory = KRMIN(KRENGINE_GPU_MEM_MAX, free_memory * 3 / 4 + m_pTextureManager->getMemUsed() + m_pMeshManager->getMemUsed());
#endif
*/
/*
// FINDME, TODO - Experimental code, need to expose through engine parameters
const long MEMORY_WARNING_THROTTLE_FRAMES = 5;
bool memory_warning_throttle = m_last_memory_warning_frame != 0 && m_current_frame - m_last_memory_warning_frame < MEMORY_WARNING_THROTTLE_FRAMES; bool memory_warning_throttle = m_last_memory_warning_frame != 0 && m_current_frame - m_last_memory_warning_frame < MEMORY_WARNING_THROTTLE_FRAMES;
if(memory_warning_throttle) {
free_memory = 0;
}
*/
/*
// FINDME, TODO - Experimental code, need to expose through engine parameters
const long MEMORY_WARNING_THROTTLE2_FRAMES = 30;
bool memory_warning_throttle2 = m_last_memory_warning_frame != 0 && m_current_frame - m_last_memory_warning_frame < MEMORY_WARNING_THROTTLE2_FRAMES;
if(memory_warning_throttle2) {
total_memory /= 2;
free_memory /= 2;
}
*/
/*
m_pMeshManager->doStreaming(total_memory, free_memory);
m_pTextureManager->doStreaming(total_memory, free_memory);
*/
long memoryRemaining = KRENGINE_GPU_MEM_TARGET; long memoryRemaining = KRENGINE_GPU_MEM_TARGET;
long memoryRemainingThisFrame = KRENGINE_GPU_MEM_MAX - m_pTextureManager->getMemUsed() - m_pMeshManager->getMemUsed(); long memoryRemainingThisFrame = KRENGINE_GPU_MEM_MAX - m_pTextureManager->getMemUsed() - m_pMeshManager->getMemUsed();
if(!memory_warning_throttle) { m_pMeshManager->doStreaming(memoryRemaining, memoryRemainingThisFrame);
m_pMeshManager->doStreaming(memoryRemaining, memoryRemainingThisFrame); m_pTextureManager->doStreaming(memoryRemaining, memoryRemainingThisFrame);
m_pTextureManager->doStreaming(memoryRemaining, memoryRemainingThisFrame);
}
} }
} }

View File

@@ -89,7 +89,7 @@ void kraken::set_debug_text(const std::string &print_text)
} }
KRContext::KRENGINE_MAX_SHADER_HANDLES = 4000; KRContext::KRENGINE_MAX_SHADER_HANDLES = 1000;
KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048; KRContext::KRENGINE_MAX_TEXTURE_DIM = 2048;
KRContext::KRENGINE_MIN_TEXTURE_DIM = 64; KRContext::KRENGINE_MIN_TEXTURE_DIM = 64;
KRContext::KRENGINE_PRESTREAM_DISTANCE = 1000.0f; KRContext::KRENGINE_PRESTREAM_DISTANCE = 1000.0f;

View File

@@ -217,17 +217,9 @@ void KRMeshManager::startFrame(float deltaTime)
switch(activeVBO->getType()) { switch(activeVBO->getType()) {
case KRVBOData::STREAMING: case KRVBOData::STREAMING:
// TODO - Move to KRVBOData::unload()
if(activeVBO->isVBOLoaded()) {
m_vboMemUsed -= activeVBO->getSize();
}
activeVBO->unload(); activeVBO->unload();
break; break;
case KRVBOData::TEMPORARY: case KRVBOData::TEMPORARY:
// TODO - Move to KRVBOData::unload()
if(activeVBO->isVBOLoaded()) {
m_vboMemUsed -= activeVBO->getSize();
}
delete activeVBO; delete activeVBO;
break; break;
case KRVBOData::CONSTANT: case KRVBOData::CONSTANT:
@@ -299,8 +291,8 @@ void KRMeshManager::balanceVBOMemory(long &memoryRemaining, long &memoryRemainin
if(memoryRemainingThisFrame > vbo_size) { if(memoryRemainingThisFrame > vbo_size) {
vbo_data->load(); vbo_data->load();
memoryRemainingThisFrame -= vbo_size; memoryRemainingThisFrame -= vbo_size;
memoryRemaining -= vbo_size;
} }
memoryRemaining -= vbo_size;
} }
} }
@@ -622,6 +614,10 @@ void KRMeshManager::KRVBOData::load()
} }
m_is_vbo_loaded = true; m_is_vbo_loaded = true;
m_manager->m_vboMemUsed += getSize();
m_manager->m_memoryTransferredThisFrame += getSize();
if(m_type == CONSTANT) { if(m_type == CONSTANT) {
_swapHandles(); _swapHandles();
} }
@@ -629,6 +625,10 @@ void KRMeshManager::KRVBOData::load()
void KRMeshManager::KRVBOData::unload() void KRMeshManager::KRVBOData::unload()
{ {
if(isVBOLoaded()) {
m_manager->m_vboMemUsed -= getSize();
}
#if GL_OES_vertex_array_object #if GL_OES_vertex_array_object
if(m_vao_handle != -1) { if(m_vao_handle != -1) {
GLDEBUG(glDeleteVertexArraysOES(1, &m_vao_handle)); GLDEBUG(glDeleteVertexArraysOES(1, &m_vao_handle));

View File

@@ -88,7 +88,7 @@ public:
KRVBOData(const KRVBOData& o) = delete; KRVBOData(const KRVBOData& o) = delete;
KRVBOData(KRVBOData& o) = delete; KRVBOData(KRVBOData& o) = delete;
bool getSize() { return m_size; } long getSize() { return m_size; }
void resetPoolExpiry(float lodCoverage); void resetPoolExpiry(float lodCoverage);
long getLastFrameUsed() { return m_last_frame_used; } long getLastFrameUsed() { return m_last_frame_used; }