diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-04-25 14:49:13 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2010-04-25 14:49:13 +0400 |
commit | 3f12beb4d0440da93ccbe67c76f23a2f15452aac (patch) | |
tree | 3e3d34d0396a598abd4b40f8cc4de8d450d08d2c /source/blender/gpu | |
parent | 6c3317612edce15095e3868e0cb3135e19eb77f2 (diff) |
Fix #22123 and #22124: some problems with mutex locks, also tweak to
how removing opengl textures from outside main thread is done so it
happens as part of the main loop.
Diffstat (limited to 'source/blender/gpu')
-rw-r--r-- | source/blender/gpu/GPU_draw.h | 3 | ||||
-rw-r--r-- | source/blender/gpu/intern/gpu_draw.c | 42 |
2 files changed, 21 insertions, 24 deletions
diff --git a/source/blender/gpu/GPU_draw.h b/source/blender/gpu/GPU_draw.h index d602d75bb35..e233a3f3d94 100644 --- a/source/blender/gpu/GPU_draw.h +++ b/source/blender/gpu/GPU_draw.h @@ -122,6 +122,9 @@ void GPU_free_images(void); void GPU_free_smoke(struct SmokeModifierData *smd); void GPU_create_smoke(struct SmokeModifierData *smd, int highres); +/* Delayed free of OpenGL buffers by main thread */ +void GPU_free_unused_buffers(void); + #ifdef __cplusplus } #endif diff --git a/source/blender/gpu/intern/gpu_draw.c b/source/blender/gpu/intern/gpu_draw.c index 4ded9dc6162..5c85abef581 100644 --- a/source/blender/gpu/intern/gpu_draw.c +++ b/source/blender/gpu/intern/gpu_draw.c @@ -784,42 +784,36 @@ void GPU_create_smoke(SmokeModifierData *smd, int highres) smd->domain->tex_shadow = GPU_texture_create_3D(smd->domain->res[0], smd->domain->res[1], smd->domain->res[2], smd->domain->shadow); } -ListBase image_free_queue = {NULL, NULL}; -static ThreadMutex queuelock = BLI_MUTEX_INITIALIZER; +static ListBase image_free_queue = {NULL, NULL}; -static void flush_queued_free(void) +static void gpu_queue_image_for_free(Image *ima) { - Image *ima, *imanext; - - BLI_mutex_lock(&queuelock); - - ima = image_free_queue.first; - image_free_queue.first = image_free_queue.last = NULL; - for (; ima; ima=imanext) { - imanext = (Image*)ima->id.next; - GPU_free_image(ima); - MEM_freeN(ima); - } + Image *cpy = MEM_dupallocN(ima); - BLI_mutex_unlock(&queuelock); + BLI_lock_thread(LOCK_OPENGL); + BLI_addtail(&image_free_queue, cpy); + BLI_unlock_thread(LOCK_OPENGL); } -static void queue_image_for_free(Image *ima) +void GPU_free_unused_buffers(void) { - Image *cpy = MEM_dupallocN(ima); + Image *ima; - BLI_mutex_lock(&queuelock); - BLI_addtail(&image_free_queue, cpy); - BLI_mutex_unlock(&queuelock); + BLI_lock_thread(LOCK_OPENGL); + + for(ima=image_free_queue.first; ima; ima=ima->id.next) + GPU_free_image(ima); + + BLI_freelistN(&image_free_queue); + + BLI_unlock_thread(LOCK_OPENGL); } void GPU_free_image(Image *ima) { - if (!BLI_thread_is_main()) { - queue_image_for_free(ima); + if(!BLI_thread_is_main()) { + gpu_queue_image_for_free(ima); return; - } else if (image_free_queue.first) { - flush_queued_free(); } /* free regular image binding */ |