Revision: 17942 http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17942 Author: joeedh Date: 2008-12-19 08:01:42 +0100 (Fri, 19 Dec 2008)
Log Message: ----------- more speed improvements, fixed a crash, etc. dsm now uses similar optimizations the rest of the renderer uses for OSA, which seem to work really well. also hopefully fixed why the cache system was thrashing so much, making renders slow to a crawl in certain situations. Modified Paths: -------------- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c branches/soc-2007-joeedh/source/blender/render/intern/source/strand.c Modified: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c =================================================================== --- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c 2008-12-19 06:05:00 UTC (rev 17941) +++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c 2008-12-19 07:01:42 UTC (rev 17942) @@ -245,7 +245,13 @@ BASSERT(tile); if (!tile) return NULL; - if (tile->is_compressed == 0) return tile; + if (tile->is_compressed == 0) { + /*move to head of pool list*/ + BLI_remlink(&tile->pool->tiles, tile); + BLI_addhead(&tile->pool->tiles, tile); + + return tile; + } pool = tile->pool; BASSERT(pool); @@ -348,7 +354,7 @@ { TCS_TileBuffer *buf = vbuf; TCS_Tile *tile; - + /*lock threads*/ BLI_lock_thread(LOCK_CACHER); Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c =================================================================== --- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c 2008-12-19 06:05:00 UTC (rev 17941) +++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c 2008-12-19 07:01:42 UTC (rev 17942) @@ -753,7 +753,7 @@ if (row2[totface].depth > dbuf->maxz) dbuf->maxz = row2[totface].depth; if (row2[totface].depth < dbuf->minz) dbuf->minz = row2[totface].depth; - + row2[totface].p = apn->p[a]; row2[totface].obi = apn->obi[a]; row2[totface].mask = apn->mask[a]; @@ -784,14 +784,14 @@ return totface; } - /*turns raw zbuffer data into a form the main dsm code can understand and work with. works on a pixel-by-pixel fashion.*/ int dsm_apixstr_to_row(Render *re, ShadBuf *shb, DSMBuffer *dbuf, APixstr *ap, _ClrEntry *row2, int totface) { APixstr *apn; - int a, b; + float clr[4]; + int a, b, c; apn= ap; while(apn) { @@ -828,7 +828,7 @@ if (row2[totface].depth > dbuf->maxz) dbuf->maxz = row2[totface].depth; if (row2[totface].depth < dbuf->minz) dbuf->minz = row2[totface].depth; - + row2[totface].p = apn->p[a]; row2[totface].obi = apn->obi[a]; row2[totface].mask = apn->mask[a]; @@ -843,8 +843,8 @@ row2[totface].srclist = NULL; row2[totface].value = 0.0f; + if(totface >= dbuf->max_depth/6 - DSM_AASAMPLES*DSM_AASAMPLES*2) break; totface++; - if(totface >= dbuf->max_depth/6 - DSM_AASAMPLES*DSM_AASAMPLES*2) break; } } } @@ -856,12 +856,82 @@ return totface; } +#if defined( _MSC_VER ) && !defined( __cplusplus ) +# define inline __inline +#endif // defined( _MSC_VER ) && !defined( __cplusplus + +inline static void dsm_do_shade(Render *re, ShadBuf *shb, _ClrEntry *row, + DSMTile *tile, int x, int y, float *clr, + float **pmat, StrandShadeCache *sscache, + float viewinv[4][4], ShadeSample *ssamp, + int threadnr) +{ + DSMBuffer *dbuf = shb->dsmbuffer; + Material *mat = NULL; + VlakRen *vlak; + StrandRen *strand; + + if(row->type == DSM_STRAND) { + StrandSegment sseg; + StrandVert *svert; + + strand= RE_findOrAddStrand(re->objectinstance[row->obi].obr, row->p-1); + mat= strand->buffer->ma; + + ssamp->shi[0].mat= mat; + ssamp->shi[0].har= mat->har; + + memset(&sseg, 0, sizeof(sseg)); + + sseg.obi= &re->objectinstance[row->obi]; + sseg.strand= strand; + sseg.buffer= sseg.strand->buffer; + + svert= sseg.strand->vert + row->seg; + sseg.v[0]= (row->seg > 0)? (svert-1): svert; + sseg.v[1]= svert; + sseg.v[2]= svert+1; + sseg.v[3]= (row->seg < sseg.strand->totvert-2)? svert+2: svert+1; + sseg.shadow_mode = 1; + sseg.shaded = 0; + + ssamp->shi[0].passflag = SCE_PASS_RGBA|SCE_PASS_DIFFUSE; + + strand_shade_segment(re, sscache, &sseg, ssamp, row->v, row->u, SCE_PASS_DIFFUSE); + clr[0] = ssamp->shr[0].diff[0]; + clr[1] = ssamp->shr[0].diff[1]; + clr[2] = ssamp->shr[0].diff[2]; + clr[3] = ssamp->shr[0].alpha; + + if (G.rt == 26) { + printf("clr rgba %f %f %f %f\n", clr[0], clr[1], clr[2], clr[3]); + printf("rgba %f %f %f %f\n", ssamp->shr->diff[0], ssamp->shr->diff[1], ssamp->shr->diff[2], ssamp->shr->alpha); + } + } else if (row->type == DSM_FACE) { + float sco[3]; + sco[0] = (float)(x+tile->x*dbuf->tsizex) + + shb->jit[2*row->samplenr] + * shb->soft + 0.5f; + sco[1] = (float)(y+tile->y*dbuf->tsizey) + + shb->jit[2*row->samplenr+1] + * shb->soft + 0.5f; + sco[2] = row->depth; + + vlak = RE_findOrAddVlak(re->objectinstance[row->obi].obr, (row->p-1) & RE_QUAD_MASK); + + shade_dsmsample(re, vlak, row->p, row->obi, + clr, sco, shb, vlak->mat, + viewinv, threadnr, x, y); + mat = vlak->mat; + } + *pmat = mat; +} + + /* renders a DSM tile. */ void DSM_DoTile(Render *re, float projmat[4][4], ShadBuf *shb, DSMTile *tile, DSMBuffer *dbuf, RE_BucketTile *btile, int threadnr, float viewinv[4][4]) { - VlakRen *vlak; - StrandRen *strand; RenderResult pa_res; APixstr *APixbuf; APixstrand *APixbufstrand = NULL; /* Zbuffer: linked list of face samples */ @@ -869,13 +939,13 @@ APixstrand *apstrand, *aprectstrand; ListBase transfuncs[LA_DEEPBUF_MAXSAMPLES][3], *bucket; ListBase apsmbase={NULL, NULL}; //, psm={NULL, NULL}; + StrandShadeCache *sscache; _ClrEntry *row, *row2, *lastsamples[LA_DEEPBUF_MAXSAMPLES]; + ShadeSample ssamp; + Material *mat = NULL; + Material rmat; RenderPart pa; - Material rmat; - Material *mat = NULL; // = &rmat; _ClrEntry *rowscratch = dbuf->s2[threadnr]; - StrandShadeCache *sscache; - ShadeSample ssamp; char *mergescratch = dbuf->s1[threadnr]; float accum[LA_DEEPBUF_MAXSAMPLES][3]; long *rdrect; @@ -887,6 +957,7 @@ int mergescratchlen; memset(&rmat, 0, sizeof(rmat)); + mat = &rmat; if (!dbuf) { printf("Error: no deep shadow map structure!\n"); @@ -970,9 +1041,11 @@ row2 = (_ClrEntry*) mergescratch; /* sort in z */ - totface= dsm_apixstr_to_row(re, shb, dbuf, ap, row2, 0); + totface= dsm_apixstr_to_row(re, shb, dbuf, ap, row2, + 0); if(APixbufstrand) - totface= dsm_strandstr_to_row(re, shb, dbuf, apstrand, row2, totface); + totface= dsm_strandstr_to_row(re, shb, dbuf, apstrand, + row2, totface); qsort(row2, totface, sizeof(_ClrEntry), dsmvergzvlak); @@ -1099,87 +1172,38 @@ a++; continue; } - - if(row[a].type == DSM_STRAND) { - StrandSegment sseg; - StrandVert *svert; - - strand= RE_findOrAddStrand(re->objectinstance[row[a].obi].obr, row[a].p-1); - mat= strand->buffer->ma; - - ssamp.shi[0].mat= mat; - ssamp.shi[0].har= mat->har; - - memset(&sseg, 0, sizeof(sseg)); - - sseg.obi= &re->objectinstance[row[a].obi]; - sseg.strand= strand; - sseg.buffer= sseg.strand->buffer; - - svert= sseg.strand->vert + row[a].seg; - sseg.v[0]= (row[a].seg > 0)? (svert-1): svert; - sseg.v[1]= svert; - sseg.v[2]= svert+1; - sseg.v[3]= (row[a].seg < sseg.strand->totvert-2)? svert+2: svert+1; - sseg.shadow_mode = 1; - sseg.shaded = 0; - - ssamp.shi[0].passflag = SCE_PASS_RGBA|SCE_PASS_DIFFUSE; - - strand_shade_segment(re, sscache, &sseg, &ssamp, row[a].v, row[a].u, SCE_PASS_DIFFUSE); - clr[0] = ssamp.shr[0].diff[0]; - clr[1] = ssamp.shr[0].diff[1]; - clr[2] = ssamp.shr[0].diff[2]; - clr[3] = ssamp.shr[0].alpha; - - if (G.rt == 26) { - printf("clr rgba %f %f %f %f\n", clr[0], clr[1], clr[2], clr[3]); - printf("rgba %f %f %f %f\n", ssamp.shr->diff[0], ssamp.shr->diff[1], ssamp.shr->diff[2], ssamp.shr->alpha); - } - } else if (row[a].type == DSM_FACE) { - float sco[3]; - sco[0] = (float)(x+tile->x*dbuf->tsizex) - + shb->jit[2*row[a].samplenr] - * shb->soft + 0.5f; - sco[1] = (float)(y+tile->y*dbuf->tsizey) - + shb->jit[2*row[a].samplenr+1] - * shb->soft + 0.5f; - sco[2] = row[a].depth; - - vlak = RE_findOrAddVlak(re->objectinstance[row[a].obi].obr, (row[a].p-1) & RE_QUAD_MASK); - - shade_dsmsample(re, vlak, row[a].p, row[a].obi, - clr, sco, shb, vlak->mat, - viewinv, threadnr, x, y); - mat = vlak->mat; - } - - c = 0; - for (b=0; b<DSM_AASAMPLES*DSM_AASAMPLES; b++) { - if (row[a].mask & (1<<b)) c++; - } - for (b=0; b<3; b++) { - float fac; - - BASSERT(b == row[a].index); - BASSERT(b >= 0 && b <= 3); - BLI_addtail(&transfuncs[row[a].samplenr][b], &row[a]); - row[a].srclist = &transfuncs[row[a].samplenr][b]; - - /*this stuff taken from rayshade.c code*/ - if (!ELEM(row[a].type, DSM_FACE_STEP, DSM_STRAND_STEP)) { - fac= 1.0f + mat->filter*(clr[b]-1.0f); - fac = clr[3]*clr[b] + fac*(1.0f-clr[3]); - accum[row[a].samplenr][b] *= (1.0f-clr[3])*fac; - } else { - row[a].value = row[a].prev->value; + dsm_do_shade(re, shb, &row[a], tile, x, y, clr, + &mat, sscache, viewinv, &ssamp, threadnr); + + if (!mat) mat = &rmat; + c = a; + while (a < totface && row[a].depth == row[c].depth && + row[a].p==row[c].p && row[c].obi == row[a].obi) { + for (b=0; b<3; b++) { + float fac; + + BASSERT(b == row[a].index); + BASSERT(b >= 0 && b <= 3); + BLI_addtail(&transfuncs[row[a].samplenr][b], &row[a]); + row[a].srclist = &transfuncs[row[a].samplenr][b]; + + /*this stuff taken from rayshade.c code*/ + if (!ELEM(row[a].type, DSM_FACE_STEP, DSM_STRAND_STEP)) { + fac= 1.0f + mat->filter*(clr[b]-1.0f); + fac = clr[3]*clr[b] + fac*(1.0f-clr[3]); + accum[row[a].samplenr][b] *= (1.0f-clr[3])*fac; + } else { + row[a].value = row[a].prev->value; + } + + row[a].value = accum[row[a].samplenr][b]; + + samp_totfaces[row[a].samplenr]++; + a++; } - row[a].value = accum[row[a].samplenr][b]; - - samp_totfaces[row[a].samplenr]++; - a++; + if (mat->mode & MA_FULL_OSA) break; } } else { a += 3; Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/strand.c =================================================================== @@ Diff output truncated at 10240 characters. @@ _______________________________________________ Bf-blender-cvs mailing list Bf-blender-cvs@blender.org http://lists.blender.org/mailman/listinfo/bf-blender-cvs