[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [28707] branches/render25/source/blender/ render/intern: Deep shadow buffers are now created and stored tiled, this helps avoid a

Brecht Van Lommel brecht at blender.org
Mon May 10 12:21:38 CEST 2010


Revision: 28707
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=28707
Author:   blendix
Date:     2010-05-10 12:21:38 +0200 (Mon, 10 May 2010)

Log Message:
-----------
Deep shadow buffers are now created and stored tiled, this helps avoid a
memory peak when creating them, and also can save some memory afterwards
by not storing empty tiles. Threading code here was also changed so that
each tile can be rendered by it's own thread, and memarena is now used
to avoid slowness due to malloc mutex locks. There's no setting at the
moment to configure the tile size, fixed to 256x256 currently to avoid
performance problems.

Modified Paths:
--------------
    branches/render25/source/blender/render/intern/include/lamp.h
    branches/render25/source/blender/render/intern/include/part.h
    branches/render25/source/blender/render/intern/include/zbuf.h
    branches/render25/source/blender/render/intern/source/part.c
    branches/render25/source/blender/render/intern/source/shadowbuf.c
    branches/render25/source/blender/render/intern/source/zbuf.c

Modified: branches/render25/source/blender/render/intern/include/lamp.h
===================================================================
--- branches/render25/source/blender/render/intern/include/lamp.h	2010-05-10 09:22:29 UTC (rev 28706)
+++ branches/render25/source/blender/render/intern/include/lamp.h	2010-05-10 10:21:38 UTC (rev 28707)
@@ -163,9 +163,7 @@
 	
 	struct MTex *mtex[MAX_MTEX];
 
-	/* threading */
-	int thread_assigned;
-	int thread_ready;
+	float (*jitbuf)[2];
 } LampRen;
 
 #endif /* __RENDER_LAMP_H__ */

Modified: branches/render25/source/blender/render/intern/include/part.h
===================================================================
--- branches/render25/source/blender/render/intern/include/part.h	2010-05-10 09:22:29 UTC (rev 28706)
+++ branches/render25/source/blender/render/intern/include/part.h	2010-05-10 10:21:38 UTC (rev 28707)
@@ -33,11 +33,13 @@
 struct APixstr;
 struct APixstrand;
 struct GHash;
+struct ListBase;
 struct PixStr;
 struct Render;
 struct RenderPart;
 struct RenderResult;
 struct StrandShadeCache;
+struct rcti;
 struct rctf;
 
 /* Create/Free */
@@ -45,6 +47,9 @@
 void parts_create(struct Render *re);
 void parts_free(struct Render *re);
 
+void parts_list_create(struct ListBase *list, int *partx, int *party,
+	struct rcti *rect, int xparts, int yparts, int padding);
+
 /* Find/Next */
 
 int parts_find_next_slice(struct Render *re, int *slice, int *minx,

Modified: branches/render25/source/blender/render/intern/include/zbuf.h
===================================================================
--- branches/render25/source/blender/render/intern/include/zbuf.h	2010-05-10 09:22:29 UTC (rev 28706)
+++ branches/render25/source/blender/render/intern/include/zbuf.h	2010-05-10 10:21:38 UTC (rev 28707)
@@ -53,9 +53,9 @@
 
 void zbuffer_shadow(struct Render *re, float winmat[][4], struct LampRen *lar,
 	int *rectz, int size, float jitx, float jity);
-void zbuffer_abuf_shadow(struct Render *re, struct LampRen *lar, float winmat[][4],
-	struct APixstr *APixbuf, struct APixstrand *apixbuf, struct ListBase *apsmbase,
-	int size, int samples, float (*jit)[2]);
+void zbuffer_abuf_shadow(struct Render *re, struct RenderPart *pa, struct LampRen *lar,
+	float winmat[][4], struct APixstr *APixbuf, struct APixstrand *apixbuf,
+	struct ListBase *apsmbase, int size, int samples, float (*jit)[2]);
 
 /* SSS Rasterization */
 

Modified: branches/render25/source/blender/render/intern/source/part.c
===================================================================
--- branches/render25/source/blender/render/intern/source/part.c	2010-05-10 09:22:29 UTC (rev 28706)
+++ branches/render25/source/blender/render/intern/source/part.c	2010-05-10 10:21:38 UTC (rev 28707)
@@ -37,54 +37,21 @@
 
 /******************************* Create/Free *********************************/
 
-void parts_create(Render *re)
+void parts_list_create(ListBase *list, int *partx, int *party, rcti *rect, int xparts, int yparts, int padding)
 {
-	int nr, xd, yd, partx, party, xparts, yparts;
-	int xminb, xmaxb, yminb, ymaxb;
-	
-	parts_free(re);
-	
-	/* this is render info for caller, is not reset when parts are freed! */
-	re->cb.i.totpart= 0;
-	re->cb.i.curpart= 0;
-	re->cb.i.partsdone= 0;
-	
-	/* just for readable code.. */
-	xminb= re->disprect.xmin;
-	yminb= re->disprect.ymin;
-	xmaxb= re->disprect.xmax;
-	ymaxb= re->disprect.ymax;
-	
-	xparts= re->params.r.xparts;
-	yparts= re->params.r.yparts;
-	
-	/* mininum part size, but for exr tile saving it was checked already */
-	if(!(re->params.r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE))) {
-		if(re->cam.type == CAM_PANORAMA) {
-			if(ceil(re->rectx/(float)xparts) < 8) 
-				xparts= 1 + re->rectx/8;
-		}
-		else
-			if(ceil(re->rectx/(float)xparts) < 64) 
-				xparts= 1 + re->rectx/64;
-		
-		if(ceil(re->recty/(float)yparts) < 64) 
-			yparts= 1 + re->recty/64;
-	}
-	
+	int xminb, xmaxb, yminb, ymaxb, nr, xd, yd;
+
+	list->first= list->last= NULL;
+
 	/* part size */
-	partx= ceil(re->rectx/(float)xparts);
-	party= ceil(re->recty/(float)yparts);
-	
-	re->xparts= xparts;
-	re->yparts= yparts;
-	re->partx= partx;
-	re->party= party;
-	
-	/* calculate rotation factor of 1 pixel */
-	if(re->cam.type == CAM_PANORAMA)
-		re->cam.panophi= panorama_pixel_rot(re);
-	
+	xminb= rect->xmin;
+	yminb= rect->ymin;
+	xmaxb= rect->xmax;
+	ymaxb= rect->ymax;
+
+	*partx= ceil((xmaxb-xminb)/(float)xparts);
+	*party= ceil((ymaxb-yminb)/(float)yparts);
+
 	for(nr=0; nr<xparts*yparts; nr++) {
 		rcti disprect;
 		int rectx, recty;
@@ -92,19 +59,19 @@
 		xd= (nr % xparts);
 		yd= (nr-xd)/xparts;
 		
-		disprect.xmin= xminb+ xd*partx;
-		disprect.ymin= yminb+ yd*party;
+		disprect.xmin= xminb+ xd*(*partx);
+		disprect.ymin= yminb+ yd*(*party);
 		
 		/* ensure we cover the entire picture, so last parts go to end */
 		if(xd<xparts-1) {
-			disprect.xmax= disprect.xmin + partx;
+			disprect.xmax= disprect.xmin + *partx;
 			if(disprect.xmax > xmaxb)
 				disprect.xmax = xmaxb;
 		}
 		else disprect.xmax= xmaxb;
 		
 		if(yd<yparts-1) {
-			disprect.ymax= disprect.ymin + party;
+			disprect.ymax= disprect.ymin + *party;
 			if(disprect.ymax > ymaxb)
 				disprect.ymax = ymaxb;
 		}
@@ -116,11 +83,9 @@
 		/* so, now can we add this part? */
 		if(rectx>0 && recty>0) {
 			RenderPart *pa= MEM_callocN(sizeof(RenderPart), "new part");
-
-			pa->re= re;
 			
 			/* Non-box filters need 2 pixels extra to work */
-			if((re->params.r.filtertype || (re->params.r.mode & R_EDGE))) {
+			if(padding) {
 				pa->crop= 2;
 				disprect.xmin -= pa->crop;
 				disprect.ymin -= pa->crop;
@@ -133,12 +98,62 @@
 			pa->rectx= rectx;
 			pa->recty= recty;
 
-			BLI_addtail(&re->parts, pa);
-			re->cb.i.totpart++;
+			BLI_addtail(list, pa);
 		}
 	}
+
 }
 
+void parts_create(Render *re)
+{
+	RenderPart *pa;
+	int padding, partx, party, xparts, yparts;
+	
+	parts_free(re);
+	
+	/* this is render info for caller, is not reset when parts are freed! */
+	re->cb.i.totpart= 0;
+	re->cb.i.curpart= 0;
+	re->cb.i.partsdone= 0;
+	
+	xparts= re->params.r.xparts;
+	yparts= re->params.r.yparts;
+	
+	/* mininum part size, but for exr tile saving it was checked already */
+	if(!(re->params.r.scemode & (R_EXR_TILE_FILE|R_FULL_SAMPLE))) {
+		if(re->cam.type == CAM_PANORAMA) {
+			if(ceil(re->rectx/(float)xparts) < 8) 
+				xparts= 1 + re->rectx/8;
+		}
+		else
+			if(ceil(re->rectx/(float)xparts) < 64) 
+				xparts= 1 + re->rectx/64;
+		
+		if(ceil(re->recty/(float)yparts) < 64) 
+			yparts= 1 + re->recty/64;
+	}
+	
+	/* part size */
+	
+	/* calculate rotation factor of 1 pixel */
+	if(re->cam.type == CAM_PANORAMA)
+		re->cam.panophi= panorama_pixel_rot(re);
+	
+	padding= (re->params.r.filtertype || (re->params.r.mode & R_EDGE))? 2: 0;
+
+	parts_list_create(&re->parts, &partx, &party, &re->disprect, xparts, yparts, padding);
+
+	re->xparts= xparts;
+	re->yparts= yparts;
+	re->partx= partx;
+	re->party= party;
+
+	for(pa=re->parts.first; pa; pa=pa->next) {
+		pa->re= re;
+		re->cb.i.totpart++;
+	}
+}
+
 void parts_free(Render *re)
 {
 	RenderPart *part;

Modified: branches/render25/source/blender/render/intern/source/shadowbuf.c
===================================================================
--- branches/render25/source/blender/render/intern/source/shadowbuf.c	2010-05-10 09:22:29 UTC (rev 28706)
+++ branches/render25/source/blender/render/intern/source/shadowbuf.c	2010-05-10 10:21:38 UTC (rev 28707)
@@ -80,13 +80,21 @@
 	int z;
 	float v;
 } DeepSample;
+
+typedef struct DeepTile {
+	DeepSample **deepbuf;
+	int *totbuf;
+	MemArena *arena;
+} DeepTile;
  
 typedef struct ShadSampleBuf {
 	struct ShadSampleBuf *next, *prev;
+
 	intptr_t *zbuf;
 	char *cbuf;
-	DeepSample **deepbuf;
-	int *totbuf;
+
+	DeepTile *deeptile;
+	int tilex, tiley, xtiles, ytiles;
 } ShadSampleBuf;
 
 typedef struct ShadBuf {
@@ -236,7 +244,6 @@
 		first= 1;
 
 		for(; a<tot; a++, ds++) {
-			//dz= ds->z - newds->z;
 			if(ds->z == newds->z) {
 				/* still in same z position, simply check
 				   visibility difference against epsilon */
@@ -327,199 +334,216 @@
 	return ma->shad_alpha;
 }
 
-static void compress_deepshadowbuf(Render *re, ShadBuf *shb, APixstr *apixbuf, APixstrand *apixbufstrand)
+static int compress_deepshadowbuf(Render *re, LampRen *lar, DeepTile *tile, RenderPart *pa, APixstr *apixbuf, APixstrand *apixbufstrand)
 {
-	ShadSampleBuf *shsample;
+	ShadBuf *shb= lar->shb;
+	ShadSampleBuf *shsample= shb->buffers.first;
 	DeepSample *ds[RE_MAX_OSA], *sampleds[RE_MAX_OSA], *dsb, *newbuf;
+	DeepSample *dsbuf1= NULL, *dsbuf2= NULL;
 	APixstr *ap, *apn;
 	APixstrand *aps, *apns;
-	float visibility, totbuf= shb->totbuf;
-	int a, b, c, tot, minz, found, size= shb->size, prevtot, newtot;
-	int sampletot[RE_MAX_OSA], totsample = 0, totsamplec = 0;
+	float visibility, totbuf= lar->buffers;
+	int x, y, offset, b, c, tot, minz, found, prevtot, newtot;
+	int sampletot[RE_MAX_OSA], totsample = 0, totsamplec = 0, dsbufsize= 0;
 	
-	shsample= MEM_callocN( sizeof(ShadSampleBuf), "shad sample buf");
-	BLI_addtail(&shb->buffers, shsample);
-
-	shsample->totbuf= MEM_callocN(sizeof(int)*size*size, "deeptotbuf");
-	shsample->deepbuf= MEM_callocN(sizeof(DeepSample*)*size*size, "deepbuf");
-
 	ap= apixbuf;
 	aps= apixbufstrand;
-	for(a=0; a<size*size; a++, ap++, aps++) {
-		/* count number of samples */
-		for(c=0; c<totbuf; c++)
-			sampletot[c]= 0;
+	for(y=0; y<pa->recty; y++) {
+		offset= y*shsample->tilex;
 
-		tot= 0;
-		for(apn=ap; apn; apn=apn->next)
-			for(b=0; b<4; b++)
-				if(apn->p[b])
-					for(c=0; c<totbuf; c++)
-						if(apn->mask[b] & (1<<c))
-							sampletot[c]++;
+		for(x=0; x<pa->rectx; x++, ap++, aps++, offset++) {
+			/* count number of samples */
+			for(c=0; c<totbuf; c++)
+				sampletot[c]= 0;
 
-		if(apixbufstrand) {
-			for(apns=aps; apns; apns=apns->next)
+			tot= 0;
+			for(apn=ap; apn; apn=apn->next)
 				for(b=0; b<4; b++)
-					if(apns->p[b])
+					if(apn->p[b])
 						for(c=0; c<totbuf; c++)
-							if(apns->mask[b] & (1<<c))
+							if(apn->mask[b] & (1<<c))
 								sampletot[c]++;
-		}
 
-		for(c=0; c<totbuf; c++)
-			tot += sampletot[c];
+			if(apixbufstrand) {
+				for(apns=aps; apns; apns=apns->next)
+					for(b=0; b<4; b++)
+						if(apns->p[b])
+							for(c=0; c<totbuf; c++)
+								if(apns->mask[b] & (1<<c))
+									sampletot[c]++;
+			}
 
-		if(tot == 0) {
-			shsample->deepbuf[a]= NULL;
-			shsample->totbuf[a]= 0;
-			continue;
-		}
+			for(c=0; c<totbuf; c++)
+				tot += sampletot[c];
 
-		/* fill samples */
-		ds[0]= sampleds[0]= MEM_callocN(sizeof(DeepSample)*tot*2, "deepsample");

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list