diff options
author | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-11-15 19:59:58 +0400 |
---|---|---|
committer | Sergey Sharybin <sergey.vfx@gmail.com> | 2012-11-15 19:59:58 +0400 |
commit | 5c6f6301b02a68c6569e14a70b3968a69fa099e7 (patch) | |
tree | 2245e539979eb97feb3931639b38bf91061bc5a7 /source/gameengine | |
parent | 613cf7ae376b0994c9bd7c57b13123d72831bd3a (diff) |
Image thread safe improvements
This commit makes BKE_image_acquire_ibuf referencing result, which means once
some area requested for image buffer, it'll be guaranteed this buffer wouldn't
be freed by image signal.
To de-reference buffer BKE_image_release_ibuf should now always be used.
To make referencing working correct we can not rely on result of
image_get_ibuf_threadsafe called outside from thread lock. This is so because
we need to guarantee getting image buffer from list of loaded buffers and it's
referencing happens atomic. Without lock here it is possible that between call
of image_get_ibuf_threadsafe and referencing the buffer IMA_SIGNAL_FREE would
be called. Image signal handling too is blocking now to prevent such a
situation.
Threads are locking by spinlock, which are faster than mutexes. There were some
slowdown reports in the past about render slowdown when using OSX on Xeon CPU.
It shouldn't happen with spin locks, but more tests on different hardware would
be really welcome. So far can not see speed regressions on own computers.
This commit also removes BKE_image_get_ibuf, because it was not so intuitive
when get_ibuf and acquire_ibuf should be used.
Thanks to Ton and Brecht for discussion/review :)
Diffstat (limited to 'source/gameengine')
-rw-r--r-- | source/gameengine/GamePlayer/ghost/GPG_ghost.cpp | 3 | ||||
-rw-r--r-- | source/gameengine/Ketsji/BL_Texture.cpp | 20 |
2 files changed, 19 insertions, 4 deletions
diff --git a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp index 3e8755c41ce..4451c78b99c 100644 --- a/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp +++ b/source/gameengine/GamePlayer/ghost/GPG_ghost.cpp @@ -60,6 +60,7 @@ extern "C" #include "BKE_blender.h" #include "BKE_global.h" #include "BKE_icons.h" +#include "BKE_image.h" #include "BKE_node.h" #include "BKE_report.h" #include "BKE_library.h" @@ -446,6 +447,7 @@ int main(int argc, char** argv) G.main = NULL; IMB_init(); + BKE_images_init(); // Setup builtin font for BLF (mostly copied from creator.c, wm_init_exit.c and interface_style.c) BLF_init(11, U.dpi); @@ -1067,6 +1069,7 @@ int main(int argc, char** argv) #endif IMB_exit(); + BKE_images_exit(); free_nodesystem(); SYS_DeleteSystem(syshandle); diff --git a/source/gameengine/Ketsji/BL_Texture.cpp b/source/gameengine/Ketsji/BL_Texture.cpp index 26523df8db3..66423ed820e 100644 --- a/source/gameengine/Ketsji/BL_Texture.cpp +++ b/source/gameengine/Ketsji/BL_Texture.cpp @@ -109,7 +109,7 @@ bool BL_Texture::InitFromImage(int unit, Image *img, bool mipmap) return mOk; } - ibuf= BKE_image_get_ibuf(img, NULL); + ibuf= BKE_image_acquire_ibuf(img, NULL, NULL); if (ibuf==NULL) { img->ok = 0; @@ -128,6 +128,7 @@ bool BL_Texture::InitFromImage(int unit, Image *img, bool mipmap) if (mTexture != 0) { glBindTexture(GL_TEXTURE_2D, mTexture ); Validate(); + BKE_image_release_ibuf(img, ibuf, NULL); return mOk; } @@ -140,6 +141,7 @@ bool BL_Texture::InitFromImage(int unit, Image *img, bool mipmap) mTexture = mapLook->second.gl_texture; glBindTexture(GL_TEXTURE_2D, mTexture); mOk = IsValid(); + BKE_image_release_ibuf(img, ibuf, NULL); return mOk; } } @@ -166,6 +168,9 @@ bool BL_Texture::InitFromImage(int unit, Image *img, bool mipmap) glDisable(GL_TEXTURE_2D); ActivateUnit(0); Validate(); + + BKE_image_release_ibuf(img, ibuf, NULL); + return mOk; } @@ -251,7 +256,7 @@ bool BL_Texture::InitCubeMap(int unit, EnvMap *cubemap) return mOk; } - ImBuf *ibuf= BKE_image_get_ibuf(cubemap->ima, NULL); + ImBuf *ibuf= BKE_image_acquire_ibuf(cubemap->ima, NULL, NULL); if (ibuf==0) { cubemap->ima->ok = 0; @@ -274,6 +279,7 @@ bool BL_Texture::InitCubeMap(int unit, EnvMap *cubemap) mTexture = mapLook->second.gl_texture; glBindTexture(GL_TEXTURE_CUBE_MAP_ARB, mTexture); mOk = IsValid(); + BKE_image_release_ibuf(cubemap->ima, ibuf, NULL); return mOk; } } @@ -307,6 +313,7 @@ bool BL_Texture::InitCubeMap(int unit, EnvMap *cubemap) my_free_envmapdata(cubemap); mOk = false; + BKE_image_release_ibuf(cubemap->ima, ibuf, NULL); return mOk; } @@ -341,6 +348,9 @@ bool BL_Texture::InitCubeMap(int unit, EnvMap *cubemap) ActivateUnit(0); mOk = IsValid(); + + BKE_image_release_ibuf(cubemap->ima, ibuf, NULL); + return mOk; } @@ -646,9 +656,11 @@ int BL_Texture::GetPow2(int n) void BL_Texture::SplitEnvMap(EnvMap *map) { if (!map || !map->ima || (map->ima && !map->ima->ok)) return; - ImBuf *ibuf= BKE_image_get_ibuf(map->ima, NULL); - if (ibuf) + ImBuf *ibuf= BKE_image_acquire_ibuf(map->ima, NULL, NULL); + if (ibuf) { my_envmap_split_ima(map, ibuf); + BKE_image_release_ibuf(map->ima, ibuf, NULL); + } } unsigned int BL_Texture::mDisableState = 0; |