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,6 +916,7 @@ 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;
@ -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,7 +1638,13 @@ 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!)
extern SDL_mutex *make_table_lock; // initrender.c
if(make_table_lock) SDL_mutexP(make_table_lock);
/* 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 */
@ -1657,6 +1665,9 @@ static float *jitter_plane(LampRen *lar, int xs, int ys)
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) {
/* made it threadsafe */
if(ys & 1) {