[Bf-blender-cvs] [ff9974e] master: Fix T37898: blenderplayer painfully slow in recent builds

Sergey Sharybin noreply at git.blender.org
Sun Dec 22 10:30:39 CET 2013


Commit: ff9974ed69bf2b71a569191cc06ae909217ffd2c
Author: Sergey Sharybin
Date:   Sun Dec 22 15:26:59 2013 +0600
http://developer.blender.org/rBff9974ed69bf2b71a569191cc06ae909217ffd2c

Fix T37898: blenderplayer painfully slow in recent builds

Issue was caused by recent image cache rewrite and root of
the issue goes to the fact that blender player doesn't
initialize cache limiter and it uses 32meg of memory only.

This leads to infinite image loading/freeing.

For now disabled cache limiter in game engine, this brings
back old behavior.

In theory we might be smarter here, but better caching
policy is to be discussed.

===================================================================

M	intern/memutil/MEM_CacheLimiter.h
M	intern/memutil/MEM_CacheLimiterC-Api.h
M	intern/memutil/intern/MEM_CacheLimiterC-Api.cpp
M	source/gameengine/GamePlayer/ghost/CMakeLists.txt
M	source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
M	source/gameengine/GamePlayer/ghost/SConscript

===================================================================

diff --git a/intern/memutil/MEM_CacheLimiter.h b/intern/memutil/MEM_CacheLimiter.h
index 88e0683..bbe6ace 100644
--- a/intern/memutil/MEM_CacheLimiter.h
+++ b/intern/memutil/MEM_CacheLimiter.h
@@ -69,6 +69,8 @@ class MEM_CacheLimiter;
 extern "C" {
 	void MEM_CacheLimiter_set_maximum(size_t m);
 	size_t MEM_CacheLimiter_get_maximum();
+	void MEM_CacheLimiter_set_disabled(bool disabled);
+	bool MEM_CacheLimiter_is_disabled(void);
 };
 #endif
 
@@ -177,8 +179,13 @@ public:
 
 	void enforce_limits() {
 		size_t max = MEM_CacheLimiter_get_maximum();
+		bool is_disabled = MEM_CacheLimiter_is_disabled();
 		size_t mem_in_use, cur_size;
 
+		if (is_disabled) {
+			return;
+		}
+
 		if (max == 0) {
 			return;
 		}
diff --git a/intern/memutil/MEM_CacheLimiterC-Api.h b/intern/memutil/MEM_CacheLimiterC-Api.h
index a6a3ec8..ce7782e 100644
--- a/intern/memutil/MEM_CacheLimiterC-Api.h
+++ b/intern/memutil/MEM_CacheLimiterC-Api.h
@@ -53,6 +53,8 @@ typedef bool (*MEM_CacheLimiter_ItemDestroyable_Func) (void*);
 #ifndef __MEM_CACHELIMITER_H__
 void MEM_CacheLimiter_set_maximum(size_t m);
 size_t MEM_CacheLimiter_get_maximum(void);
+void MEM_CacheLimiter_set_disabled(bool disabled);
+bool MEM_CacheLimiter_is_disabled(void);
 #endif /* __MEM_CACHELIMITER_H__ */
 
 /**
diff --git a/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp b/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp
index 6156b51..f6f1fe4 100644
--- a/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp
+++ b/intern/memutil/intern/MEM_CacheLimiterC-Api.cpp
@@ -29,6 +29,8 @@
 #include "MEM_CacheLimiter.h"
 #include "MEM_CacheLimiterC-Api.h"
 
+static bool is_disabled = false;
+
 static size_t & get_max()
 {
 	static size_t m = 32 * 1024 * 1024;
@@ -45,6 +47,16 @@ size_t MEM_CacheLimiter_get_maximum()
 	return get_max();
 }
 
+void MEM_CacheLimiter_set_disabled(bool disabled)
+{
+	is_disabled = disabled;
+}
+
+bool MEM_CacheLimiter_is_disabled(void)
+{
+	return is_disabled;
+}
+
 class MEM_CacheLimiterHandleCClass;
 class MEM_CacheLimiterCClass;
 
diff --git a/source/gameengine/GamePlayer/ghost/CMakeLists.txt b/source/gameengine/GamePlayer/ghost/CMakeLists.txt
index 6a5d97e..df75279 100644
--- a/source/gameengine/GamePlayer/ghost/CMakeLists.txt
+++ b/source/gameengine/GamePlayer/ghost/CMakeLists.txt
@@ -50,6 +50,7 @@ set(INC
 	../../../../intern/ghost
 	../../../../intern/guardedalloc
 	../../../../intern/string
+	../../../../intern/memutil
 )
 
 set(INC_SYS
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
index 14b5bca..b04dbc7 100644
--- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
+++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp
@@ -52,6 +52,8 @@ extern "C"
 {
 #endif  // __cplusplus
 #include "MEM_guardedalloc.h"
+#include "MEM_CacheLimiterC-Api.h"
+
 #include "BLI_threads.h"
 #include "BLI_mempool.h"
 #include "BLI_blenlib.h"
@@ -437,6 +439,7 @@ int main(int argc, char** argv)
 	free_main(G.main);
 	G.main = NULL;
 
+	MEM_CacheLimiter_set_disabled(true);
 	IMB_init();
 	BKE_images_init();
 	BKE_modifier_init();
diff --git a/source/gameengine/GamePlayer/ghost/SConscript b/source/gameengine/GamePlayer/ghost/SConscript
index 1b1d1fc..3e8ab3d 100644
--- a/source/gameengine/GamePlayer/ghost/SConscript
+++ b/source/gameengine/GamePlayer/ghost/SConscript
@@ -41,6 +41,7 @@ incs = [
     '#intern/string',
     '#intern/ghost',
     '#intern/guardedalloc',
+    '#intern/memutil',
     '#intern/moto/include',
     '#intern/container',
     '#intern/audaspace/intern',




More information about the Bf-blender-cvs mailing list