]> git.rm.cloudns.org Git - xonotic/darkplaces.git/commitdiff
Add support for barriers to the threading interface; fix skeletal animation appearing...
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 16 Feb 2012 21:04:22 +0000 (21:04 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Thu, 16 Feb 2012 21:04:22 +0000 (21:04 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@11692 d7cf8633-e32d-0410-b094-e92efae38249

gl_rmain.c
thread.h
thread_null.c
thread_pthread.c
thread_sdl.c
thread_win.c

index 6b5095cff96650c837a9b808e1232b4734e05ddf..c425e06fef8d0788d7168d1baf900dec3fc1c917 100644 (file)
@@ -5293,7 +5293,6 @@ static void R_View_UpdateWithScissor(const int *myscissor)
        R_View_WorldVisibility(r_refdef.view.useclipplane);
        R_View_UpdateEntityVisible();
        R_View_UpdateEntityLighting();
-       R_AnimCache_CacheVisibleEntities();
 }
 
 static void R_View_Update(void)
@@ -5303,7 +5302,6 @@ static void R_View_Update(void)
        R_View_WorldVisibility(r_refdef.view.useclipplane);
        R_View_UpdateEntityVisible();
        R_View_UpdateEntityLighting();
-       R_AnimCache_CacheVisibleEntities();
 }
 
 float viewscalefpsadjusted = 1.0f;
@@ -5847,6 +5845,7 @@ static void R_Water_ProcessPlanes(int fbo, rtexture_t *depthtexture, rtexture_t
                                R_View_UpdateWithScissor(myscissor);
                        else
                                R_View_Update();
+                       R_AnimCache_CacheVisibleEntities();
                        if(r_water_scissormode.integer & 1)
                                GL_Scissor(myscissor[0], myscissor[1], myscissor[2], myscissor[3]);
                        R_RenderScene(p->fbo_reflection, r_fb.water.depthtexture, p->texture_reflection);
@@ -5895,6 +5894,7 @@ static void R_Water_ProcessPlanes(int fbo, rtexture_t *depthtexture, rtexture_t
                                R_View_UpdateWithScissor(myscissor);
                        else
                                R_View_Update();
+                       R_AnimCache_CacheVisibleEntities();
                        if(r_water_scissormode.integer & 1)
                                GL_Scissor(myscissor[0], myscissor[1], myscissor[2], myscissor[3]);
                        R_RenderScene(p->fbo_refraction, r_fb.water.depthtexture, p->texture_refraction);
@@ -5949,6 +5949,7 @@ static void R_Water_ProcessPlanes(int fbo, rtexture_t *depthtexture, rtexture_t
                        R_ResetViewRendering3D(p->fbo_camera, r_fb.water.depthtexture, p->texture_camera);
                        R_ClearScreen(r_refdef.fogenabled);
                        R_View_Update();
+                       R_AnimCache_CacheVisibleEntities();
                        R_RenderScene(p->fbo_camera, r_fb.water.depthtexture, p->texture_camera);
 
                        if (!p->fbo_camera)
@@ -5964,6 +5965,7 @@ static void R_Water_ProcessPlanes(int fbo, rtexture_t *depthtexture, rtexture_t
        if (!r_fb.water.depthtexture)
                R_ClearScreen(r_refdef.fogenabled);
        R_View_Update();
+       R_AnimCache_CacheVisibleEntities();
        goto finish;
 error:
        r_refdef.view = originalview;
@@ -6943,6 +6945,10 @@ void R_RenderView(void)
        if (r_timereport_active)
                R_TimeReport("visibility");
 
+       R_AnimCache_CacheVisibleEntities();
+       if (r_timereport_active)
+               R_TimeReport("animcache");
+
        R_Shadow_UpdateBounceGridTexture();
        if (r_timereport_active && r_shadow_bouncegrid.integer)
                R_TimeReport("bouncegrid");
index 7f88d8b4324adf5fc722681b9de03412ecdb46f2..7f590a47dd62f355e89be3435adb4da0ea33540d 100644 (file)
--- a/thread.h
+++ b/thread.h
@@ -17,6 +17,9 @@
 #define Thread_CondWait(cond, mutex)      (_Thread_CondWait(cond, mutex, __FILE__, __LINE__))
 #define Thread_CreateThread(fn, data)     (_Thread_CreateThread(fn, data, __FILE__, __LINE__))
 #define Thread_WaitThread(thread, retval) (_Thread_WaitThread(thread, retval, __FILE__, __LINE__))
+#define Thread_CreateBarrier(count)       (_Thread_CreateBarrier(count, __FILE__, __LINE__))
+#define Thread_DestroyBarrier(barrier)    (_Thread_DestroyBarrier(barrier, __FILE__, __LINE__))
+#define Thread_WaitBarrier(barrier)       (_Thread_WaitBarrier(barrier, __FILE__, __LINE__))
 
 int Thread_Init(void);
 void Thread_Shutdown(void);
@@ -32,6 +35,8 @@ int _Thread_CondBroadcast(void *cond, const char *filename, int fileline);
 int _Thread_CondWait(void *cond, void *mutex, const char *filename, int fileline);
 void *_Thread_CreateThread(int (*fn)(void *), void *data, const char *filename, int fileline);
 int _Thread_WaitThread(void *thread, int retval, const char *filename, int fileline);
+void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline);
+void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline);
+void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline);
 
 #endif
-
index c7d439c90cf2538b5f533e13a6ab68eeb992dd69..35c4e4b5f4cf319a3d285b8d8a60504c46144d81 100644 (file)
@@ -67,3 +67,16 @@ int _Thread_WaitThread(void *thread, int retval, const char *filename, int filel
 {
        return retval;
 }
+
+void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline)
+{
+       return NULL;
+}
+
+void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline)
+{
+}
+
+void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline)
+{
+}
index 9340403ebb91cbc39a992401004a9de8bb1e7fe6..27ccf5fbd8cd5a46226627a5a63bf7b28c527857 100644 (file)
@@ -142,4 +142,83 @@ int _Thread_WaitThread(void *thread, int retval, const char *filename, int filel
        return (int) (intptr_t) status;
 }
 
+#ifdef PTHREAD_BARRIER_SERIAL_THREAD
+void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline)
+{
+       pthread_barrier_t *b = (pthread_barrier_t *) Z_Malloc(sizeof(pthread_barrier_t));
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier create(%d) %s:%i\n", b, count, filename, fileline);
+#endif
+       pthread_barrier_init(b, NULL, count);
+       return (void *) b;
+}
+
+void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline)
+{
+       pthread_barrier_t *b = (pthread_barrier_t *) barrier;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier destroy %s:%i\n", b, filename, fileline);
+#endif
+       pthread_barrier_destroy(b);
+}
+
+void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline)
+{
+       pthread_barrier_t *b = (pthread_barrier_t *) barrier;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier wait %s:%i\n", b, filename, fileline);
+#endif
+       pthread_barrier_wait(b);
+}
+#else
+// standard barrier implementation using conds and mutexes
+// see: http://www.howforge.com/implementing-barrier-in-pthreads
+typedef struct {
+       unsigned int needed;
+       unsigned int called;
+       void *mutex;
+       void *cond;
+} barrier_t;
+
+void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline)
+{
+       barrier_t *b = Z_Malloc(sizeof(barrier_t));
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier create(%d) %s:%i\n", b, count, filename, fileline);
+#endif
+       b->needed = count;
+       b->called = 0;
+       b->mutex = Thread_CreateMutex();
+       b->cond = Thread_CreateCond();
+       return (void *) b;
+}
 
+void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline)
+{
+       barrier_t *b = (barrier_t *) barrier;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier destroy %s:%i\n", b, filename, fileline);
+#endif
+       Thread_DestroyMutex(b->mutex);
+       Thread_DestroyCond(b->cond);
+}
+
+void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline)
+{
+       barrier_t *b = (barrier_t *) barrier;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier wait %s:%i\n", b, filename, fileline);
+#endif
+       Thread_LockMutex(b->mutex);
+       b->called++;
+       if (b->called == b->needed) {
+               b->called = 0;
+               Thread_CondBroadcast(b->cond);
+       } else {
+               do {
+                       Thread_CondWait(b->cond, b->mutex);
+               } while(b->called);
+       }
+       Thread_UnlockMutex(b->mutex);
+}
+#endif
index b49069c3d55d36bb4e544b995042fb2257391374..9df9ffc9ebfeac7c37677bb70717c717f3e63be3 100644 (file)
@@ -117,4 +117,54 @@ int _Thread_WaitThread(void *thread, int retval, const char *filename, int filel
        return status;
 }
 
+// standard barrier implementation using conds and mutexes
+// see: http://www.howforge.com/implementing-barrier-in-pthreads
+typedef struct {
+       unsigned int needed;
+       unsigned int called;
+       void *mutex;
+       void *cond;
+} barrier_t;
+
+void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline)
+{
+       barrier_t *b = Z_Malloc(sizeof(barrier_t));
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier create(%d) %s:%i\n", b, count, filename, fileline);
+#endif
+       b->needed = count;
+       b->called = 0;
+       b->mutex = Thread_CreateMutex();
+       b->cond = Thread_CreateCond();
+       return (void *) b;
+}
+
+void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline)
+{
+       barrier_t *b = (barrier_t *) barrier;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier destroy %s:%i\n", b, filename, fileline);
+#endif
+       Thread_DestroyMutex(b->mutex);
+       Thread_DestroyCond(b->cond);
+}
+
+void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline)
+{
+       barrier_t *b = (barrier_t *) barrier;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier wait %s:%i\n", b, filename, fileline);
+#endif
+       Thread_LockMutex(b->mutex);
+       b->called++;
+       if (b->called == b->needed) {
+               b->called = 0;
+               Thread_CondBroadcast(b->cond);
+       } else {
+               do {
+                       Thread_CondWait(b->cond, b->mutex);
+               } while(b->called);
+       }
+       Thread_UnlockMutex(b->mutex);
+}
        
index 77fe939cd291de9f017daf5ccf3d4c615aea3b19..692a6f11735880c18fdccd1c48c5f5c22fbfe77a 100644 (file)
@@ -250,3 +250,54 @@ int _Thread_WaitThread(void *d, int retval, const char *filename, int fileline)
        free(w);
        return retval;
 }
+
+// standard barrier implementation using conds and mutexes
+// see: http://www.howforge.com/implementing-barrier-in-pthreads
+typedef struct {
+       unsigned int needed;
+       unsigned int called;
+       void *mutex;
+       void *cond;
+} barrier_t;
+
+void *_Thread_CreateBarrier(unsigned int count, const char *filename, int fileline)
+{
+       barrier_t *b = Z_Malloc(sizeof(barrier_t));
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier create(%d) %s:%i\n", b, count, filename, fileline);
+#endif
+       b->needed = count;
+       b->called = 0;
+       b->mutex = Thread_CreateMutex();
+       b->cond = Thread_CreateCond();
+       return (void *) b;
+}
+
+void _Thread_DestroyBarrier(void *barrier, const char *filename, int fileline)
+{
+       barrier_t *b = (barrier_t *) barrier;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier destroy %s:%i\n", b, filename, fileline);
+#endif
+       Thread_DestroyMutex(b->mutex);
+       Thread_DestroyCond(b->cond);
+}
+
+void _Thread_WaitBarrier(void *barrier, const char *filename, int fileline)
+{
+       barrier_t *b = (barrier_t *) barrier;
+#ifdef THREADDEBUG
+       Sys_PrintfToTerminal("%p barrier wait %s:%i\n", b, filename, fileline);
+#endif
+       Thread_LockMutex(b->mutex);
+       b->called++;
+       if (b->called == b->needed) {
+               b->called = 0;
+               Thread_CondBroadcast(b->cond);
+       } else {
+               do {
+                       Thread_CondWait(b->cond, b->mutex);
+               } while(b->called);
+       }
+       Thread_UnlockMutex(b->mutex);
+}