Carefully went over all scanline updating while rendering, to ensure only

updates are allowed to draw when a part is within a scanline rendering
loop. Might solve threads issues with opengl...
This commit is contained in:
Ton Roosendaal 2006-02-21 10:47:08 +00:00
parent 02dc8de55d
commit a2a2ad98e2
5 changed files with 29 additions and 21 deletions

@ -103,7 +103,7 @@ typedef struct RenderResult {
/* optional saved endresult on disk */ /* optional saved endresult on disk */
char exrfile[FILE_MAXDIR]; char exrfile[FILE_MAXDIR];
int filehandle; void *exrhandle;
} RenderResult; } RenderResult;

@ -283,9 +283,6 @@ static RenderResult *new_render_result(Render *re, rcti *partrct, int crop)
re->r.actlay= 0; re->r.actlay= 0;
} }
/* display active layer */
rr->renlay= render_get_active_layer(re, rr);
return rr; return rr;
} }
@ -806,7 +803,7 @@ static void threaded_tile_processor(Render *re)
{ {
ListBase threads; ListBase threads;
RenderPart *pa, *nextpa; RenderPart *pa, *nextpa;
int maxthreads, rendering=1, counter= 1, hasdrawn, drawtimer=0; int maxthreads, rendering=1, counter= 1, drawtimer=0;
if(re->result==NULL) if(re->result==NULL)
return; return;
@ -831,6 +828,7 @@ static void threaded_tile_processor(Render *re)
while(rendering) { while(rendering) {
if(nextpa && BLI_available_threads(&threads) && !re->test_break()) { if(nextpa && BLI_available_threads(&threads) && !re->test_break()) {
drawtimer= 0;
nextpa->nr= counter++; /* for nicest part, and for stats */ nextpa->nr= counter++; /* for nicest part, and for stats */
nextpa->thread= BLI_available_thread_index(&threads); /* sample index */ nextpa->thread= BLI_available_thread_index(&threads); /* sample index */
BLI_insert_thread(&threads, nextpa); BLI_insert_thread(&threads, nextpa);
@ -843,7 +841,6 @@ static void threaded_tile_processor(Render *re)
} }
/* check for ready ones to display, and if we need to continue */ /* check for ready ones to display, and if we need to continue */
hasdrawn= 0;
rendering= 0; rendering= 0;
for(pa= re->parts.first; pa; pa= pa->next) { for(pa= re->parts.first; pa; pa= pa->next) {
if(pa->ready) { if(pa->ready) {
@ -857,21 +854,18 @@ static void threaded_tile_processor(Render *re)
free_render_result(pa->result); free_render_result(pa->result);
pa->result= NULL; pa->result= NULL;
re->i.partsdone++; re->i.partsdone++;
hasdrawn= 1; drawtimer= 0;
} }
} }
else { else {
rendering= 1; rendering= 1;
if(pa->nr && pa->result && drawtimer>20) { if(pa->nr && pa->result && drawtimer>20) {
re->display_draw(pa->result, &pa->result->renrect); re->display_draw(pa->result, &pa->result->renrect);
hasdrawn= 1; drawtimer= 0;
} }
} }
} }
if(hasdrawn)
drawtimer= 0;
/* on break, wait for all slots to get freed */ /* on break, wait for all slots to get freed */
if( (g_break=re->test_break()) && BLI_available_threads(&threads)==maxthreads) if( (g_break=re->test_break()) && BLI_available_threads(&threads)==maxthreads)
rendering= 0; rendering= 0;

@ -2910,7 +2910,8 @@ static void shadeDA_tile(RenderPart *pa, RenderLayer *rl)
/* scanline updates have to be 2 lines behind */ /* scanline updates have to be 2 lines behind */
rr->renrect.ymin= 0; rr->renrect.ymin= 0;
rr->renrect.ymax= -2*crop; rr->renrect.ymax= -2*crop;
rr->renlay= rl;
for(y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) { for(y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) {
rf= rectf; rf= rectf;
rd= rectdaps; rd= rectdaps;
@ -2994,6 +2995,9 @@ static void shadeDA_tile(RenderPart *pa, RenderLayer *rl)
if(y&1) if(R.test_break()) break; if(y&1) if(R.test_break()) break;
} }
/* disable scanline updating */
rr->renlay= NULL;
if(R.do_gamma) { if(R.do_gamma) {
rectf= rl->rectf; rectf= rl->rectf;
for(y= pa->rectx*pa->recty; y>0; y--, rectf+=4) { for(y= pa->rectx*pa->recty; y>0; y--, rectf+=4) {
@ -3104,9 +3108,6 @@ void zbufshadeDA_tile(RenderPart *pa)
if(R.r.mode & R_EDGE) edgerect= MEM_callocT(sizeof(float)*pa->rectx*pa->recty, "rectedge"); 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) { for(rl= rr->layers.first; rl; rl= rl->next) {
/* indication for scanline updates */
rr->renlay= rl;
rr->renrect.ymin=rr->renrect.ymax= 0;
/* initialize pixelstructs */ /* initialize pixelstructs */
addpsmain(&psmlist); addpsmain(&psmlist);
@ -3175,6 +3176,7 @@ void zbufshadeDA_tile(RenderPart *pa)
if(edgerect) MEM_freeT(edgerect); if(edgerect) MEM_freeT(edgerect);
/* display active layer */ /* display active layer */
rr->renrect.ymin=rr->renrect.ymax= 0;
rr->renlay= render_get_active_layer(&R, rr); rr->renlay= render_get_active_layer(&R, rr);
} }
@ -3198,9 +3200,6 @@ void zbufshade_tile(RenderPart *pa)
shpi.thread= pa->thread; shpi.thread= pa->thread;
for(rl= rr->layers.first; rl; rl= rl->next) { for(rl= rr->layers.first; rl; rl= rl->next) {
/* indication for scanline updates */
rr->renlay= rl;
rr->renrect.ymin=rr->renrect.ymax= 0;
/* fill shadepixel info struct */ /* fill shadepixel info struct */
shpi.lay= rl->lay; shpi.lay= rl->lay;
@ -3218,6 +3217,10 @@ void zbufshade_tile(RenderPart *pa)
float *fcol= rl->rectf; float *fcol= rl->rectf;
int x, y, *rp= pa->rectp, *rz= pa->rectz, offs=0; int x, y, *rp= pa->rectp, *rz= pa->rectz, offs=0;
/* initialize scanline updates for main thread */
rr->renrect.ymin= 0;
rr->renlay= rl;
for(y=pa->disprect.ymin; y<pa->disprect.ymax; y++, rr->renrect.ymax++) { for(y=pa->disprect.ymin; y<pa->disprect.ymax; y++, rr->renrect.ymax++) {
for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, rz++, rp++, fcol+=4, offs++) { for(x=pa->disprect.xmin; x<pa->disprect.xmax; x++, rz++, rp++, fcol+=4, offs++) {
shadepixel_sky(&shpi, (float)x, (float)y, *rz, *rp, 0); shadepixel_sky(&shpi, (float)x, (float)y, *rz, *rp, 0);
@ -3230,6 +3233,9 @@ void zbufshade_tile(RenderPart *pa)
if(y&1) if(y&1)
if(R.test_break()) break; if(R.test_break()) break;
} }
/* disable scanline updating */
rr->renlay= NULL;
} }
} }
@ -3278,6 +3284,7 @@ void zbufshade_tile(RenderPart *pa)
} }
/* display active layer */ /* display active layer */
rr->renrect.ymin=rr->renrect.ymax= 0;
rr->renlay= render_get_active_layer(&R, rr); rr->renlay= render_get_active_layer(&R, rr);
MEM_freeT(pa->rectp); pa->rectp= NULL; MEM_freeT(pa->rectp); pa->rectp= NULL;

@ -2686,9 +2686,9 @@ void zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pass)
/* init scanline updates */ /* init scanline updates */
rr->renrect.ymin= 0; rr->renrect.ymin= 0;
rr->renrect.ymax= -pa->crop; rr->renrect.ymax= -pa->crop;
rr->renlay= rl;
/* render the tile */ /* render the tile */
for(y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) { for(y=pa->disprect.ymin+crop; y<pa->disprect.ymax-crop; y++, rr->renrect.ymax++) {
pass= passrect; pass= passrect;
ap= aprect; ap= aprect;
@ -2816,6 +2816,9 @@ void zbuffer_transp_shade(RenderPart *pa, RenderLayer *rl, float *pass)
offs+= pa->rectx; offs+= pa->rectx;
} }
/* disable scanline updating */
rr->renlay= NULL;
MEM_freeT(APixbuf); MEM_freeT(APixbuf);
freepsA(&apsmbase); freepsA(&apsmbase);

@ -761,9 +761,13 @@ static void renderwin_progress(RenderWin *rw, RenderResult *rr, rcti *renrect)
/* if renrect argument, we only display scanlines */ /* if renrect argument, we only display scanlines */
if(renrect) { if(renrect) {
/* if ymax==recty, rendering of layer is ready, we should not draw, other things happen... */
if(rr->renlay==NULL || renrect->ymax>=rr->recty)
return;
ymin= renrect->ymin; ymin= renrect->ymin;
ymax= renrect->ymax-ymin; ymax= renrect->ymax-ymin;
if(ymax<2 || renrect->ymax>=rr->recty) /* if ymax==recty, rendering of layer is ready, we should not draw, other things happen... */ if(ymax<2)
return; return;
renrect->ymin= renrect->ymax; renrect->ymin= renrect->ymax;
} }