Thread rendering stability commit.
authorTon Roosendaal <ton@blender.org>
Sat, 11 Feb 2006 15:55:00 +0000 (15:55 +0000)
committerTon Roosendaal <ton@blender.org>
Sat, 11 Feb 2006 15:55:00 +0000 (15:55 +0000)
I noticed still several cases where the Imbuf library was called within a
thread... and that whilst the Imbuf itself isn't threadsafe. Also the
thread lock I added in rendering for loading images actually didn't
work, because then it was still possible both threads were accessing the
MEM_malloc function at same time.

This commit nearly fully replaces ImBuf calls in compositor (giving another
nice speedup btw, the way preview images in Nodes were calculated used
clumsy imbuf scaling code).

I've also centralized the 'mutex' locking for threading, which now only
resides in BLI_threads.h. This is used to secure the last ImBuf calls
I cannot replace, which is loading images and creating mipmaps.

Really hope we get something more stable now!

source/blender/blenkernel/intern/image.c
source/blender/blenkernel/intern/node_composite.c
source/blender/blenlib/BLI_threads.h
source/blender/blenlib/intern/threads.c
source/blender/render/intern/include/renderpipeline.h
source/blender/render/intern/source/envmap.c
source/blender/render/intern/source/imagetexture.c
source/blender/render/intern/source/pipeline.c
source/blender/render/intern/source/rendercore.c
source/blender/render/intern/source/zbuf.c

index 4a2f87cf820b61a9539018bbc9b7aa3bbe8d70e9..a4dfa9b93feb1811d964a3c6916682318b19884f 100644 (file)
@@ -572,7 +572,8 @@ static void de_interlace_st(struct ImBuf *ibuf)     /* standard fields */
        ibuf->y /= 2;
 }
 
-
+/* important note: all calls here and calls inside can NOT use threadsafe malloc! */
+/* this entire function is mutex'ed with the same lock as for mallocs */
 void ima_ibuf_is_nul(Tex *tex, Image *ima)
 {
        void (*de_interlacefunc)(struct ImBuf *ibuf);
index d90226711333229dfed1ebab4365f767236dd93c..1eabc068daa4d54016933d93bb2899355825d37c 100644 (file)
@@ -52,7 +52,7 @@
 #include "BLI_blenlib.h"
 #include "BLI_threads.h"
 
-#include "IMB_imbuf.h"
+/* NOTE: no imbuf calls allowed in composit, we need threadsafe malloc! */
 #include "IMB_imbuf_types.h"
 
 #include "RE_pipeline.h"
@@ -143,6 +143,48 @@ static CompBuf *get_cropped_compbuf(rcti *drect, float *rectf, int rectx, int re
        return cbuf;
 }
 
+static CompBuf *scalefast_compbuf(CompBuf *inbuf, int newx, int newy)
+{
+       CompBuf *outbuf; 
+       float *rectf, *newrectf, *rf;
+       int x, y, c, pixsize= inbuf->type;
+       int ofsx, ofsy, stepx, stepy;
+       
+       if(inbuf->x==newx && inbuf->y==newy)
+               return dupalloc_compbuf(inbuf);
+       
+       outbuf= alloc_compbuf(newx, newy, inbuf->type, 1);
+       newrectf= outbuf->rect;
+       
+       stepx = (65536.0 * (inbuf->x - 1.0) / (newx - 1.0)) + 0.5;
+       stepy = (65536.0 * (inbuf->y - 1.0) / (newy - 1.0)) + 0.5;
+       ofsy = 32768;
+       
+       for (y = newy; y > 0 ; y--){
+               rectf = inbuf->rect;
+               rectf += pixsize * (ofsy >> 16) * inbuf->x;
+
+               ofsy += stepy;
+               ofsx = 32768;
+               
+               for (x = newx ; x>0 ; x--) {
+                       
+                       rf= rectf + pixsize*(ofsx >> 16);
+                       for(c=0; c<pixsize; c++)
+                               newrectf[c] = rf[c];
+                       
+                       newrectf+= pixsize;
+                       
+                       ofsx += stepx;
+               }
+       }
+       
+       return outbuf;
+}
+
+
+
+/* **************************************************** */
 
 #if 0
 /* on first call, disprect should be initialized to 'out', then you can call this on all 'src' images */
@@ -418,7 +460,7 @@ static void generate_preview(bNode *node, CompBuf *stackbuf)
        bNodePreview *preview= node->preview;
        
        if(preview) {
-               ImBuf *ibuf= IMB_allocImBuf(stackbuf->x, stackbuf->y, 32, 0, 0);        /* empty */
+               CompBuf *cbuf;
                
                if(stackbuf->x > stackbuf->y) {
                        preview->xsize= 140;
@@ -428,13 +470,13 @@ static void generate_preview(bNode *node, CompBuf *stackbuf)
                        preview->ysize= 140;
                        preview->xsize= (140*stackbuf->x)/stackbuf->y;
                }
-               ibuf->rect_float= stackbuf->rect;
-               ibuf= IMB_scalefastImBuf(ibuf, preview->xsize, preview->ysize);
                
-               /* this ensures free-imbuf does the right stuff */
-               SWAP(float *, ibuf->rect_float, node->preview->rect);
+               cbuf= scalefast_compbuf(stackbuf, preview->xsize, preview->ysize);
                
-               IMB_freeImBuf(ibuf);
+               /* this ensures free-compbuf does the right stuff */
+               SWAP(float *, cbuf->rect, node->preview->rect);
+               
+               free_compbuf(cbuf);
        }
 }
 
@@ -490,7 +532,7 @@ static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in,
                Image *ima= (Image *)node->id;
                CompBuf *cbuf, *inbuf= in[0]->data;
                int rectx, recty;
-
+               
                if(inbuf==NULL) {
                        rectx= 320; recty= 256;
                }
@@ -499,9 +541,33 @@ static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in,
                        recty= inbuf->y;
                }
                
-               if(ima->ibuf) IMB_freeImBuf(ima->ibuf);
-               ima->ibuf= IMB_allocImBuf(rectx, recty, 32, IB_rectfloat, 0); // do alloc
+               /* full copy of imbuf, but threadsafe... */
+               if(ima->ibuf==NULL) {
+                       ima->ibuf = MEM_callocT(sizeof(struct ImBuf), "ImBuf_struct");
+                       ima->ibuf->depth= 32;
+                       ima->ibuf->ftype= TGA;
+               }
                
+               /* cleanup of composit image */
+               if(ima->ibuf->rect) {
+                       MEM_freeT(ima->ibuf->rect);
+                       ima->ibuf->rect= NULL;
+                       ima->ibuf->mall &= ~IB_rect;
+               }
+               if(ima->ibuf->zbuf_float) {
+                       MEM_freeT(ima->ibuf->zbuf_float);
+                       ima->ibuf->zbuf_float= NULL;
+                       ima->ibuf->mall &= ~IB_zbuffloat;
+               }
+               if(ima->ibuf->rect_float)
+                       MEM_freeT(ima->ibuf->rect_float);
+               
+               ima->ibuf->x= rectx;
+               ima->ibuf->y= recty;
+               ima->ibuf->mall |= IB_rectfloat;
+               ima->ibuf->rect_float= MEM_mallocT(4*rectx*recty*sizeof(float), "viewer rect");
+               
+               /* now we combine the input with ibuf */
                cbuf= alloc_compbuf(rectx, recty, CB_RGBA, 0);  // no alloc
                cbuf->rect= ima->ibuf->rect_float;
                
@@ -520,10 +586,14 @@ static void node_composit_exec_viewer(void *data, bNode *node, bNodeStack **in,
                        composit2_pixel_processor(node, cbuf, inbuf, in[0]->vec, in[1]->data, in[1]->vec, do_copy_a_rgba);
                
                if(in[2]->data) {
-                       CompBuf *zbuf= alloc_compbuf(rectx, recty, CB_VAL, 0);
-                       addzbuffloatImBuf(ima->ibuf);
-                       zbuf->rect= ima->ibuf->zbuf_float;
+                       CompBuf *zbuf= alloc_compbuf(rectx, recty, CB_VAL, 1);
+                       ima->ibuf->zbuf_float= zbuf->rect;
+                       ima->ibuf->mall |= IB_zbuffloat;
+                       
                        composit1_pixel_processor(node, zbuf, in[2]->data, in[2]->vec, do_copy_value);
+                       
+                       /* free compbuf, but not the rect */
+                       zbuf->malloc= 0;
                        free_compbuf(zbuf);
                }
 
@@ -725,6 +795,26 @@ static void animated_image(bNode *node, int cfra)
        }
 }
 
+static float *float_from_byte_rect(int rectx, int recty, char *rect)
+{
+       /* quick method to convert byte to floatbuf */
+       float *rect_float= MEM_mallocT(4*sizeof(float)*rectx*recty, "float rect");
+       float *tof = rect_float;
+       int i;
+       
+       for (i = rectx*recty; i > 0; i--) {
+               tof[0] = ((float)rect[0])*(1.0f/255.0f);
+               tof[1] = ((float)rect[1])*(1.0f/255.0f);
+               tof[2] = ((float)rect[2])*(1.0f/255.0f);
+               tof[3] = ((float)rect[3])*(1.0f/255.0f);
+               rect += 4; 
+               tof += 4;
+       }
+       return rect_float;
+}
+
+
+
 static CompBuf *node_composit_get_image(bNode *node, RenderData *rd)
 {
        Image *ima;
@@ -740,15 +830,19 @@ static CompBuf *node_composit_get_image(bNode *node, RenderData *rd)
        if(ima->ok==0) return NULL;
        
        if(ima->ibuf==NULL) {
-               
+               BLI_lock_thread();
                load_image(ima, IB_rect, G.sce, rd->cfra);      /* G.sce is current .blend path */
+               BLI_unlock_thread();
                if(ima->ibuf==NULL) {
                        ima->ok= 0;
                        return NULL;
                }
        }
-       if(ima->ibuf->rect_float==NULL)
-               IMB_float_from_rect(ima->ibuf);
+       if(ima->ibuf->rect_float==NULL) {
+               /* can't use imbuf module, we need secure malloc */
+               ima->ibuf->rect_float= float_from_byte_rect(ima->ibuf->x, ima->ibuf->y, (char *)ima->ibuf->rect);
+               ima->ibuf->mall |= IB_rectfloat;
+       }
        
        if(rd->scemode & R_COMP_CROP) {
                stackbuf= get_cropped_compbuf(&rd->disprect, ima->ibuf->rect_float, ima->ibuf->x, ima->ibuf->y, CB_RGBA);
index a9927fa08ef811a836255c1aef54e8b9c753f775..3791d92d6fce80812ac0450b5ac3f4e6115bc03a 100644 (file)
@@ -38,7 +38,10 @@ int          BLI_available_thread_index(ListBase *threadbase);
 void   BLI_insert_thread       (ListBase *threadbase, void *callerdata);
 void   BLI_remove_thread       (ListBase *threadbase, void *callerdata);
 void   BLI_end_threads         (ListBase *threadbase);
-               
+
+void   BLI_lock_thread         (void);
+void   BLI_unlock_thread       (void);
+
                /* threadsafe version of MEM_malloc and friends */
 void   *MEM_mallocT(int len, char *name);
 void   *MEM_callocT(int len, char *name);
index 19dadd211db0445defc8c237cc3e822d902db167..d1a9183518e88b969909512994310d26aa47ce6a 100644 (file)
@@ -191,6 +191,17 @@ void BLI_end_threads(ListBase *threadbase)
        _malloc_lock= NULL;
 }
 
+void BLI_lock_thread(void)
+{
+       if(_malloc_lock) SDL_mutexP(_malloc_lock);
+}
+
+void BLI_unlock_thread(void)
+{
+       if(_malloc_lock) SDL_mutexV(_malloc_lock);
+}
+
+
 /* ***************** Thread safe MEM_malloc/calloc/free ************************** */
 
 void *MEM_mallocT(int len, char *name)
index 400420c70818dfa54949a902861f5089952201db..b6fc3b4170375265aefa8b13923bf6f9f1a98ddc 100644 (file)
 
 struct Render;
 
-void *RE_mallocN(int len, char *name);
-void *RE_callocN(int len, char *name);
-void RE_freeN(void *poin);
-
 #define PASS_VECTOR_MAX        10000.0f
 
 #endif /* PIPELINE_H */
index 80e902e2a453eafafa5ae607c2698766aa607602..65ec49e58737a264082bcca0a8a3c6bfc7ab6599 100644 (file)
 
 /* external modules: */
 #include "MEM_guardedalloc.h"
+
 #include "BLI_arithb.h"
 #include "BLI_blenlib.h"
-#include "BKE_utildefines.h"
+#include "BLI_threads.h"
 
 #include "IMB_imbuf_types.h"
 #include "IMB_imbuf.h"        /* for rectcpy */
 #include "BKE_global.h"
 #include "BKE_image.h"   // BKE_write_ibuf 
 #include "BKE_texture.h"
+#include "BKE_utildefines.h"
 
 #include "MTC_matrixops.h"
 
-#include "SDL_thread.h"
-#undef main 
-#define main main /* stupid SDL_main redefines main as SDL_main */
-
 /* this module */
 #include "render_types.h"
 #include "renderpipeline.h"
@@ -574,7 +572,6 @@ static void set_dxtdyt(float *dxts, float *dyts, float *dxt, float *dyt, int fac
 
 int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexResult *texres)
 {
-       extern SDL_mutex *load_ibuf_lock; // initrender.c
        extern Render R;                                /* only in this call */
        /* texvec should be the already reflected normal */
        EnvMap *env;
@@ -591,10 +588,10 @@ int envmaptex(Tex *tex, float *texvec, float *dxt, float *dyt, int osatex, TexRe
                env->ima= tex->ima;
                if(env->ima && env->ima->ok) {
                        // Now thread safe
-                       if(load_ibuf_lock) SDL_mutexP(load_ibuf_lock);
+                       BLI_lock_thread();
                        if(env->ima->ibuf==NULL) ima_ibuf_is_nul(tex, tex->ima);
                        if(env->ima->ok && env->ok==0) envmap_split_ima(env);
-                       if(load_ibuf_lock) SDL_mutexV(load_ibuf_lock);
+                       BLI_unlock_thread();
                }
        }
 
index e1868eda917b36ddc35f915ce9a440c18ba080c7..4552aba421a464a2839b6d363d03e6ac835c155a 100644 (file)
@@ -48,6 +48,7 @@
 #include "DNA_texture_types.h"
 
 #include "BLI_blenlib.h"
+#include "BLI_threads.h"
 
 #include "BKE_utildefines.h"
 #include "BKE_global.h"
@@ -56,8 +57,6 @@
 #include "BKE_texture.h"
 #include "BKE_library.h"
 
-#include "SDL_thread.h"
-
 #include "renderpipeline.h"
 #include "render_types.h"
 #include "texture.h"
@@ -106,10 +105,9 @@ int imagewrap(Tex *tex, Image *ima, float *texvec, TexResult *texres)
        }
        
        if(ima->ibuf==NULL) {
-               extern SDL_mutex *load_ibuf_lock; // initrender.c
-               if(load_ibuf_lock) SDL_mutexP(load_ibuf_lock);
+               BLI_lock_thread();
                if(ima->ibuf==NULL) ima_ibuf_is_nul(tex, ima);
-               if(load_ibuf_lock) SDL_mutexV(load_ibuf_lock);
+               BLI_unlock_thread();
        }
 
        if (ima->ok) {
@@ -594,7 +592,6 @@ static void makemipmap(Tex *tex, Image *ima)
 
 int imagewraposa(Tex *tex, Image *ima, float *texvec, float *dxt, float *dyt, TexResult *texres)
 {
-       extern SDL_mutex *load_ibuf_lock; // initrender.c
        TexResult texr;
        ImBuf *ibuf, *previbuf;
        float fx, fy, minx, maxx, miny, maxy, dx, dy;
@@ -611,18 +608,18 @@ int imagewraposa(Tex *tex, Image *ima, float *texvec, float *dxt, float *dyt, Te
        }
        
        if(ima->ibuf==NULL) {
-               if(load_ibuf_lock) SDL_mutexP(load_ibuf_lock);
+               BLI_lock_thread();
                if(ima->ibuf==NULL) ima_ibuf_is_nul(tex, ima);
-               if(load_ibuf_lock) SDL_mutexV(load_ibuf_lock);
+               BLI_unlock_thread();
        }
        
        if (ima->ok) {
        
                if(tex->imaflag & TEX_MIPMAP) {
                        if(ima->mipmap[0]==NULL) {
-                               if(load_ibuf_lock) SDL_mutexP(load_ibuf_lock);
+                               BLI_lock_thread();
                                if(ima->mipmap[0]==NULL) makemipmap(tex, ima);
-                               if(load_ibuf_lock) SDL_mutexV(load_ibuf_lock);
+                               BLI_unlock_thread();
                        }
                }
        
index 2d14c15c6c82161ccbb7dea74eba4f4d2ca98838..43ca42a390b98611dac204cfa9ed8d11482b4d08 100644 (file)
@@ -107,33 +107,6 @@ Render R;
 /* ********* alloc and free ******** */
 
 
-SDL_mutex *malloc_lock= NULL, *load_ibuf_lock=NULL;
-
-void *RE_mallocN(int len, char *name)
-{
-       void *mem;
-       if(malloc_lock) SDL_mutexP(malloc_lock);
-       mem= MEM_mallocN(len, name);
-       if(malloc_lock) SDL_mutexV(malloc_lock);
-       return mem;
-}
-void *RE_callocN(int len, char *name)
-{
-       void *mem;
-       if(malloc_lock) SDL_mutexP(malloc_lock);
-       mem= MEM_callocN(len, name);
-       if(malloc_lock) SDL_mutexV(malloc_lock);
-       return mem;
-}
-void RE_freeN(void *poin)
-{
-       if(malloc_lock) SDL_mutexP(malloc_lock);
-       MEM_freeN(poin);
-       if(malloc_lock) SDL_mutexV(malloc_lock);
-}
-
-/* ********************** */
-
 static int g_break= 0;
 static int thread_break(void)
 {
@@ -155,30 +128,30 @@ static void free_render_result(RenderResult *res)
        while(res->layers.first) {
                RenderLayer *rl= res->layers.first;
                
-               if(rl->rectf) RE_freeN(rl->rectf);
+               if(rl->rectf) MEM_freeT(rl->rectf);
                while(rl->passes.first) {
                        RenderPass *rpass= rl->passes.first;
-                       RE_freeN(rpass->rect);
+                       MEM_freeT(rpass->rect);
                        BLI_remlink(&rl->passes, rpass);
-                       RE_freeN(rpass);
+                       MEM_freeT(rpass);
                }
                BLI_remlink(&res->layers, rl);
-               RE_freeN(rl);
+               MEM_freeT(rl);
        }
        
        if(res->rect32)
-               RE_freeN(res->rect32);
+               MEM_freeT(res->rect32);
        if(res->rectz)
-               RE_freeN(res->rectz);
+               MEM_freeT(res->rectz);
        if(res->rectf)
-               RE_freeN(res->rectf);
+               MEM_freeT(res->rectf);
        
-       RE_freeN(res);
+       MEM_freeT(res);
 }
 
 static void render_layer_add_pass(RenderLayer *rl, int rectsize, int passtype, char *mallocstr)
 {
-       RenderPass *rpass= RE_mallocN(sizeof(RenderPass), mallocstr);
+       RenderPass *rpass= MEM_mallocT(sizeof(RenderPass), mallocstr);
        
        BLI_addtail(&rl->passes, rpass);
        rpass->passtype= passtype;
@@ -187,12 +160,12 @@ static void render_layer_add_pass(RenderLayer *rl, int rectsize, int passtype, c
                int x;
                
                /* initialize to max speed */
-               rect= rpass->rect= RE_mallocN(sizeof(float)*rectsize, mallocstr);
+               rect= rpass->rect= MEM_mallocT(sizeof(float)*rectsize, mallocstr);
                for(x= rectsize-1; x>=0; x--)
                        rect[x]= PASS_VECTOR_MAX;
        }
        else
-               rpass->rect= RE_callocN(sizeof(float)*rectsize, mallocstr);
+               rpass->rect= MEM_callocT(sizeof(float)*rectsize, mallocstr);
 }
 
 float *RE_RenderLayerGetPass(RenderLayer *rl, int passtype)
@@ -222,7 +195,7 @@ static RenderResult *new_render_result(Render *re, rcti *partrct, int crop)
        if(rectx<=0 || recty<=0)
                return NULL;
        
-       rr= RE_callocN(sizeof(RenderResult), "new render result");
+       rr= MEM_callocT(sizeof(RenderResult), "new render result");
        rr->rectx= rectx;
        rr->recty= recty;
        /* crop is one or two extra pixels rendered for filtering, is used for merging and display too */
@@ -237,7 +210,7 @@ static RenderResult *new_render_result(Render *re, rcti *partrct, int crop)
        /* check renderdata for amount of layers */
        for(srl= re->r.layers.first; srl; srl= srl->next) {
 
-               rl= RE_callocN(sizeof(RenderLayer), "new render layer");
+               rl= MEM_callocT(sizeof(RenderLayer), "new render layer");
                BLI_addtail(&rr->layers, rl);
                
                strcpy(rl->name, srl->name);
@@ -245,7 +218,7 @@ static RenderResult *new_render_result(Render *re, rcti *partrct, int crop)
                rl->layflag= srl->layflag;
                rl->passflag= srl->passflag;
                
-               rl->rectf= RE_callocN(rectx*recty*sizeof(float)*4, "layer float rgba");
+               rl->rectf= MEM_callocT(rectx*recty*sizeof(float)*4, "layer float rgba");
                
                if(srl->passflag  & SCE_PASS_Z)
                        render_layer_add_pass(rl, rectx*recty, SCE_PASS_Z, "Layer float Z");
@@ -269,10 +242,10 @@ static RenderResult *new_render_result(Render *re, rcti *partrct, int crop)
        }
        /* previewrender and envmap don't do layers, so we make a default one */
        if(rr->layers.first==NULL) {
-               rl= RE_callocN(sizeof(RenderLayer), "new render layer");
+               rl= MEM_callocT(sizeof(RenderLayer), "new render layer");
                BLI_addtail(&rr->layers, rl);
                
-               rl->rectf= RE_callocN(rectx*recty*sizeof(float)*4, "prev/env float rgba");
+               rl->rectf= MEM_callocT(rectx*recty*sizeof(float)*4, "prev/env float rgba");
                
                /* note, this has to be in sync with scene.c */
                rl->lay= (1<<20) -1;
@@ -457,7 +430,7 @@ Render *RE_NewRender(const char *name)
        }
        
        /* new render data struct */
-       re= RE_callocN(sizeof(Render), "new render");
+       re= MEM_callocT(sizeof(Render), "new render");
        BLI_addtail(&RenderList, re);
        strncpy(re->name, name, RE_MAXNAME);
        
@@ -487,7 +460,7 @@ void RE_FreeRender(Render *re)
        free_render_result(re->result);
        
        BLI_remlink(&RenderList, re);
-       RE_freeN(re);
+       MEM_freeT(re);
 }
 
 /* exit blender */
@@ -754,10 +727,8 @@ static void threaded_tile_processor(Render *re)
        /* assuming no new data gets added to dbase... */
        R= *re;
        
-       /* set threadsafety */
+       /* set threadsafe break */
        R.test_break= thread_break;
-       malloc_lock= SDL_CreateMutex();
-       load_ibuf_lock= SDL_CreateMutex();
        
        /* timer loop demands to sleep when no parts are left */
        nextpa= find_next_part(re);
@@ -809,8 +780,6 @@ static void threaded_tile_processor(Render *re)
        }
        
        /* restore threadsafety */
-       if(malloc_lock) SDL_DestroyMutex(malloc_lock); malloc_lock= NULL;
-       if(load_ibuf_lock) SDL_DestroyMutex(load_ibuf_lock); load_ibuf_lock= NULL;
        g_break= 0;
        
        BLI_end_threads(&threads);
@@ -948,7 +917,7 @@ static void do_render_final(Render *re)
 
        if(re->r.scemode & R_DOSEQ) {
                if (!re->result->rect32) {
-                       re->result->rect32= RE_callocN(sizeof(int)*re->rectx*re->recty, "do_render_final rectot");
+                       re->result->rect32= MEM_callocT(sizeof(int)*re->rectx*re->recty, "do_render_final rectot");
                }
                if(!re->test_break()) 
                        do_render_seq(re->result, re->r.cfra);
@@ -1110,13 +1079,13 @@ static void do_write_image_or_movie(Render *re, Scene *scene, bMovieHandle *mh)
                int dofree = 0;
                /* note; the way it gets 32 bits rects is weak... */
                if(rres.rect32==NULL) {
-                       rres.rect32= RE_mallocN(sizeof(int)*rres.rectx*rres.recty, "temp 32 bits rect");
+                       rres.rect32= MEM_mallocT(sizeof(int)*rres.rectx*rres.recty, "temp 32 bits rect");
                        dofree = 1;
                }
                RE_ResultGet32(re, rres.rect32);
                mh->append_movie(scene->r.cfra, rres.rect32, rres.rectx, rres.recty);
                if(dofree) {
-                       RE_freeN(rres.rect32);
+                       MEM_freeT(rres.rect32);
                }
                printf("Append frame %d", scene->r.cfra);
        } else {
index 65447aca4b462dc94e721d0b75cdc0d2fd95c856..063e225d08fa6ea23b970dfc733a7636284763e5 100644 (file)
 
 /* External modules: */
 #include "MTC_matrixops.h"
+
 #include "BLI_arithb.h"
 #include "BLI_blenlib.h"
-#include "BLI_rand.h"
 #include "BLI_jitter.h"
+#include "BLI_rand.h"
+#include "BLI_threads.h"
 
 #include "BKE_utildefines.h"
 
@@ -3010,10 +3012,10 @@ static PixStrMain *addpsmain(ListBase *lb)
 {
        PixStrMain *psm;
        
-       psm= (PixStrMain *)RE_mallocN(sizeof(PixStrMain),"pixstrMain");
+       psm= (PixStrMain *)MEM_mallocT(sizeof(PixStrMain),"pixstrMain");
        BLI_addtail(lb, psm);
        
-       psm->ps= (PixStr *)RE_mallocN(4096*sizeof(PixStr),"pixstr");
+       psm->ps= (PixStr *)MEM_mallocT(4096*sizeof(PixStr),"pixstr");
        psm->counter= 0;
        
        return psm;
@@ -3026,8 +3028,8 @@ static void freeps(ListBase *lb)
        for(psm= lb->first; psm; psm= psmnext) {
                psmnext= psm->next;
                if(psm->ps)
-                       RE_freeN(psm->ps);
-               RE_freeN(psm);
+                       MEM_freeT(psm->ps);
+               MEM_freeT(psm);
        }
        lb->first= lb->last= NULL;
 }
@@ -3097,9 +3099,9 @@ void zbufshadeDA_tile(RenderPart *pa)
        
        /* allocate the necessary buffers */
                                /* zbuffer inits these rects */
-       pa->rectp= RE_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp");
-       pa->rectz= RE_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
-       if(R.r.mode & R_EDGE) edgerect= RE_callocN(sizeof(float)*pa->rectx*pa->recty, "rectedge");
+       pa->rectp= MEM_mallocT(sizeof(int)*pa->rectx*pa->recty, "rectp");
+       pa->rectz= MEM_mallocT(sizeof(int)*pa->rectx*pa->recty, "rectz");
+       if(R.r.mode & R_EDGE) edgerect= MEM_callocT(sizeof(float)*pa->rectx*pa->recty, "rectedge");
        
        for(rl= rr->layers.first; rl; rl= rl->next) {
                /* indication for scanline updates */
@@ -3107,7 +3109,7 @@ void zbufshadeDA_tile(RenderPart *pa)
 
                /* initialize pixelstructs */
                addpsmain(&psmlist);
-               pa->rectdaps= RE_callocN(sizeof(long)*pa->rectx*pa->recty+4, "zbufDArectd");
+               pa->rectdaps= MEM_callocT(sizeof(long)*pa->rectx*pa->recty+4, "zbufDArectd");
                
                /* always fill visibility */
                for(pa->sample=0; pa->sample<R.osa; pa->sample++) {
@@ -3131,7 +3133,7 @@ void zbufshadeDA_tile(RenderPart *pa)
                /* transp layer */
                if(R.flag & R_ZTRA) {
                        if(rl->layflag & SCE_LAY_ZTRA) {
-                               float *acolrect= RE_callocN(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
+                               float *acolrect= MEM_callocT(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
                                float *fcol= rl->rectf, *acol= acolrect;
                                int x;
                                
@@ -3146,7 +3148,7 @@ void zbufshadeDA_tile(RenderPart *pa)
                                for(x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) {
                                        addAlphaOverFloat(fcol, acol);
                                }
-                               RE_freeN(acolrect);
+                               MEM_freeT(acolrect);
                        }
                }
                
@@ -3161,15 +3163,15 @@ void zbufshadeDA_tile(RenderPart *pa)
                        convert_zbuf_to_distbuf(pa, rl);
                
                /* free stuff within loop! */
-               RE_freeN(pa->rectdaps); pa->rectdaps= NULL;
+               MEM_freeT(pa->rectdaps); pa->rectdaps= NULL;
                freeps(&psmlist);
        }
        
        /* free all */
-       RE_freeN(pa->rectp); pa->rectp= NULL;
-       RE_freeN(pa->rectz); pa->rectz= NULL;
+       MEM_freeT(pa->rectp); pa->rectp= NULL;
+       MEM_freeT(pa->rectz); pa->rectz= NULL;
        
-       if(edgerect) RE_freeN(edgerect);
+       if(edgerect) MEM_freeT(edgerect);
        
        /* display active layer */
        rr->renlay= BLI_findlink(&rr->layers, R.r.actlay);
@@ -3190,8 +3192,8 @@ void zbufshade_tile(RenderPart *pa)
        set_part_zbuf_clipflag(pa);
        
        /* zbuffer code clears/inits rects */
-       pa->rectp= RE_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectp");
-       pa->rectz= RE_mallocN(sizeof(int)*pa->rectx*pa->recty, "rectz");
+       pa->rectp= MEM_mallocT(sizeof(int)*pa->rectx*pa->recty, "rectp");
+       pa->rectz= MEM_mallocT(sizeof(int)*pa->rectx*pa->recty, "rectz");
        
        shpi.thread= pa->thread;
        
@@ -3241,7 +3243,7 @@ void zbufshade_tile(RenderPart *pa)
                
                if(R.flag & R_ZTRA) {
                        if(rl->layflag & SCE_LAY_ZTRA) {
-                               float *acolrect= RE_callocN(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
+                               float *acolrect= MEM_callocT(4*sizeof(float)*pa->rectx*pa->recty, "alpha layer");
                                float *fcol= rl->rectf, *acol= acolrect;
                                int x;
                                
@@ -3256,7 +3258,7 @@ void zbufshade_tile(RenderPart *pa)
                                for(x=pa->rectx*pa->recty; x>0; x--, acol+=4, fcol+=4) {
                                        addAlphaOverFloat(fcol, acol);
                                }
-                               RE_freeN(acolrect);
+                               MEM_freeT(acolrect);
                        }
                }
                
@@ -3280,8 +3282,8 @@ void zbufshade_tile(RenderPart *pa)
        /* display active layer */
        rr->renlay= BLI_findlink(&rr->layers, R.r.actlay);
        
-       RE_freeN(pa->rectp); pa->rectp= NULL;
-       RE_freeN(pa->rectz); pa->rectz= NULL;
+       MEM_freeT(pa->rectp); pa->rectp= NULL;
+       MEM_freeT(pa->rectz); pa->rectz= NULL;
 }
 
 /* ------------------------------------------------------------------------ */
index 7bbbd7fc3ef1a8cb6bd57b079ecedfb03e4c030d..0b813d90df7b8541066ca92ece50972e1ccf0923 100644 (file)
@@ -55,8 +55,6 @@
 #include "radio_types.h"
 #include "radio.h"  /* needs RG, some root data for radiosity */
 
-#include "SDL_thread.h"
-
 #include "RE_render_ext.h"
 
 /* local includes */
@@ -87,15 +85,15 @@ void zbuf_alloc_span(ZSpan *zspan, int rectx, int recty)
        zspan->rectx= rectx;
        zspan->recty= recty;
        
-       zspan->span1= RE_mallocN(recty*sizeof(float), "zspan");
-       zspan->span2= RE_mallocN(recty*sizeof(float), "zspan");
+       zspan->span1= MEM_mallocT(recty*sizeof(float), "zspan");
+       zspan->span2= MEM_mallocT(recty*sizeof(float), "zspan");
 }
 
 static void zbuf_free_span(ZSpan *zspan)
 {
        if(zspan) {
-               if(zspan->span1) RE_freeN(zspan->span1);
-               if(zspan->span2) RE_freeN(zspan->span2);
+               if(zspan->span1) MEM_freeT(zspan->span1);
+               if(zspan->span2) MEM_freeT(zspan->span2);
                zspan->span1= zspan->span2= NULL;
        }
 }
@@ -261,9 +259,9 @@ static APixstr *addpsmainA(ListBase *lb)
 {
        APixstrMain *psm;
 
-       psm= RE_mallocN(sizeof(APixstrMain), "addpsmainA");
+       psm= MEM_mallocT(sizeof(APixstrMain), "addpsmainA");
        BLI_addtail(lb, psm);
-       psm->ps= RE_callocN(4096*sizeof(APixstr),"pixstr");
+       psm->ps= MEM_callocT(4096*sizeof(APixstr),"pixstr");
 
        return psm->ps;
 }
@@ -275,8 +273,8 @@ static void freepsA(ListBase *lb)
        for(psm= lb->first; psm; psm= psmnext) {
                psmnext= psm->next;
                if(psm->ps)
-                       RE_freeN(psm->ps);
-               RE_freeN(psm);
+                       MEM_freeT(psm->ps);
+               MEM_freeT(psm);
        }
 }
 
@@ -2398,7 +2396,7 @@ static void zbuffer_abuf(RenderPart *pa, APixstr *APixbuf, ListBase *apsmbase, u
        zspan.zofsy= -pa->disprect.ymin;
        
        /* the buffers */
-       zspan.arectz= RE_mallocN(sizeof(int)*pa->rectx*pa->recty, "Arectz");
+       zspan.arectz= MEM_mallocT(sizeof(int)*pa->rectx*pa->recty, "Arectz");
        zspan.apixbuf= APixbuf;
        zspan.apsmbase= apsmbase;
        
@@ -2480,7 +2478,7 @@ static void zbuffer_abuf(RenderPart *pa, APixstr *APixbuf, ListBase *apsmbase, u
                if(R.test_break()) break;
        }
        
-       RE_freeN(zspan.arectz);
+       MEM_freeT(zspan.arectz);
        zbuf_free_span(&zspan);
 
 }
@@ -2646,7 +2644,7 @@ void zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pass)
        if(R.test_break())
                return;
        
-       APixbuf= RE_callocN(pa->rectx*pa->recty*sizeof(APixstr), "APixbuf");
+       APixbuf= MEM_callocT(pa->rectx*pa->recty*sizeof(APixstr), "APixbuf");
        
        if(R.osa>16) {
                printf("abufsetrow: osa too large\n");
@@ -2818,7 +2816,7 @@ void zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pass)
                offs+= pa->rectx;
        }
 
-       RE_freeN(APixbuf);
+       MEM_freeT(APixbuf);
        freepsA(&apsmbase);     
 
 }