Thread render with  using Area lights was not fully thread safe yet. I
thought I had a smart method to trick threads, but apparently it can best
(and only) be done with Mutexes...
This commit is contained in:
Ton Roosendaal 2005-06-02 09:53:53 +00:00
parent 9c869b1237
commit e0bc635743
2 changed files with 31 additions and 17 deletions

@ -872,7 +872,7 @@ static void yafrayRender(void)
/* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ */
// exported to other files, belongs in include... later
SDL_mutex *render_abuf_lock=NULL, *load_ibuf_lock=NULL;
SDL_mutex *render_abuf_lock=NULL, *load_ibuf_lock=NULL, *make_table_lock= NULL;
static void renderloop_setblending(void)
@ -916,7 +916,8 @@ static void mainRenderLoop(void) /* here the PART and FIELD loops */
/* create mutexes for threaded render */
render_abuf_lock = SDL_CreateMutex();
load_ibuf_lock = SDL_CreateMutex();
make_table_lock = SDL_CreateMutex();
if(R.rectz) MEM_freeN(R.rectz);
R.rectz = NULL;
if(R.rectftot) MEM_freeN(R.rectftot);
@ -1170,8 +1171,10 @@ static void mainRenderLoop(void) /* here the PART and FIELD loops */
/* mutexes free */
SDL_DestroyMutex(load_ibuf_lock);
SDL_DestroyMutex(render_abuf_lock);
SDL_DestroyMutex(make_table_lock);
load_ibuf_lock= NULL;
render_abuf_lock= NULL;
make_table_lock= NULL;
}
void render() {

@ -51,6 +51,8 @@
#include "jitter.h"
#include "texture.h"
#include "SDL_thread.h"
#define DDA_SHADOW 0
#define DDA_MIRROR 1
#define DDA_SHADOW_TRA 2
@ -1636,25 +1638,34 @@ static float *jitter_plane(LampRen *lar, int xs, int ys)
tot= lar->ray_totsamp;
if(lar->jitter==NULL) {
lar->jitter= (float *)4; // mislead thread quickly (tsk!)
fp=lar->jitter= MEM_mallocN(4*tot*2*sizeof(float), "lamp jitter tab");
extern SDL_mutex *make_table_lock; // initrender.c
if(make_table_lock) SDL_mutexP(make_table_lock);
/* fill table with random locations, area_size large */
for(x=0; x<tot; x++, fp+=2) {
fp[0]= (BLI_frand()-0.5)*lar->area_size;
fp[1]= (BLI_frand()-0.5)*lar->area_sizey;
}
while(iter--) {
fp= lar->jitter;
for(x=tot; x>0; x--, fp+=2) {
DP_energy(lar->jitter, fp, tot, lar->area_size, lar->area_sizey);
/* check again, since other thread could have entered */
if(lar->jitter==NULL) {
fp=lar->jitter= MEM_mallocN(4*tot*2*sizeof(float), "lamp jitter tab");
/* fill table with random locations, area_size large */
for(x=0; x<tot; x++, fp+=2) {
fp[0]= (BLI_frand()-0.5)*lar->area_size;
fp[1]= (BLI_frand()-0.5)*lar->area_sizey;
}
while(iter--) {
fp= lar->jitter;
for(x=tot; x>0; x--, fp+=2) {
DP_energy(lar->jitter, fp, tot, lar->area_size, lar->area_sizey);
}
}
jitter_plane_offset(lar->jitter, lar->jitter+2*tot, tot, lar->area_size, lar->area_sizey, 0.5, 0.0);
jitter_plane_offset(lar->jitter, lar->jitter+4*tot, tot, lar->area_size, lar->area_sizey, 0.5, 0.5);
jitter_plane_offset(lar->jitter, lar->jitter+6*tot, tot, lar->area_size, lar->area_sizey, 0.0, 0.5);
}
jitter_plane_offset(lar->jitter, lar->jitter+2*tot, tot, lar->area_size, lar->area_sizey, 0.5, 0.0);
jitter_plane_offset(lar->jitter, lar->jitter+4*tot, tot, lar->area_size, lar->area_sizey, 0.5, 0.5);
jitter_plane_offset(lar->jitter, lar->jitter+6*tot, tot, lar->area_size, lar->area_sizey, 0.0, 0.5);
if(make_table_lock) SDL_mutexV(make_table_lock);
}
if(lar->ray_samp_type & LA_SAMP_JITTER) {