[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14126] branches/soc-2007-joeedh/source/ blender: User testing shall begin now!

Joseph Eagar joeedh at gmail.com
Sat Mar 15 22:32:53 CET 2008


Revision: 14126
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14126
Author:   joeedh
Date:     2008-03-15 22:32:52 +0100 (Sat, 15 Mar 2008)

Log Message:
-----------
User testing shall  begin now!

Fixed a bug with dsm compression that was causing it to be way less effective.
Interestingly enough, the tile cache compression was effectively compensating
for this (with a cache limit of 75, a 1 gig map was only taking ~40 megs of swap space),
however there was of course still a significant slowdown due to this.

Also changed the compression function to assume (2.0/sqrt(maxsamples))/2, instead of
2.0/sqrt(maxsamples) (the diameter-vs-radius issue); this seems to correct the visual
glitches with compression.

Also, rearranged the user prefs a little bit, both the DSM cache limit and the sequencer
cache limit are in their own little section now in System and OpenGL.

Modified Paths:
--------------
    branches/soc-2007-joeedh/source/blender/blenkernel/BKE_blender.h
    branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
    branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c
    branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
    branches/soc-2007-joeedh/source/blender/src/space.c
    branches/soc-2007-joeedh/source/blender/src/usiblender.c

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_blender.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_blender.h	2008-03-15 20:59:26 UTC (rev 14125)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_blender.h	2008-03-15 21:32:52 UTC (rev 14126)
@@ -44,7 +44,7 @@
 struct MemFile;
 
 #define BLENDER_VERSION			245
-#define BLENDER_SUBVERSION		14
+#define BLENDER_SUBVERSION		20
 
 #define BLENDER_MINVERSION		240
 #define BLENDER_MINSUBVERSION	0

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-03-15 20:59:26 UTC (rev 14125)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-03-15 21:32:52 UTC (rev 14126)
@@ -44,18 +44,24 @@
 /*Each tile has its own memarena to work better with caching.*/
 typedef struct DSMTile {
 	TCS_Tile tile;
-
-	DSMFunction **r_rect;
-	DSMFunction **g_rect;
-	DSMFunction **b_rect;
 	
-	DSMFuncQuadTree tree;
-	//DSMLayerSample **sample_rect; /*first entry's depth is the length of the pixel array*/
+	DSMFunction *funcarray;
+	int funcarray_len; /*logical length of function array*/
+	int funcarray_buffer; /*total length of function array*/
 	
+	/*offsets of position of functions inside function array
+	  for pixels.*/
+	short *r_rect, *g_rect, *b_rect;
+	
 	/*tile coordinates inside poly_rect.
 	  Note: this is *not* in image space units!
 	  Multiple by the parent buffer's tsizex/y
-	  to get the tile position in image space.*/
+	  to get the tile position in image space.
+	  
+	  (note that multiplying by the tile's actual
+	   size will not work, as the tile might've
+	   been clipped to fit within the parent
+	   buffer's image size.)*/
 	int x, y;
 	int sizex, sizey;
 	struct MemArena *arena;
@@ -112,4 +118,7 @@
 struct ShadBuf;
 void DSM_CreateBuffer(struct Render *re, float projmat[4][4], struct ShadBuf *buf, int tilesize);
 
+/*private, internal only to dsm and it's caching code*/
+DSMFunction *dsm_function_alloc(DSMTile *tile, short *offset);
+
 #endif /* BKE_DSM_H */

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c	2008-03-15 20:59:26 UTC (rev 14125)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c	2008-03-15 21:32:52 UTC (rev 14126)
@@ -365,7 +365,7 @@
 
 	BASSERT(vbuf);
 	tile = buf->getTile(buf, x, y, z);
-	tile->locked = 1;
+	tile->locked++;
 	_TCS_UncacheTile(vbuf, tile);
 	
 	/*unlock threads*/
@@ -379,7 +379,15 @@
 	TCS_Tile *tile = vtile;
 	
 	BLI_lock_thread(LOCK_CACHER);
-	tile->locked = 1;
+
+	/*rather then setting locked to 1, instead increment it.
+	  this is to handle nested calles to TCS_LockTile
+	  (for example, if two threads lock a tile at once).
+
+	  remember that locking a tile only means it isn't
+	  cached, not that it's read- or write-limited to whoever
+	  locked it.*/
+	tile->locked++;
 	if (uncache) _TCS_UncacheTile(tile->buffer, tile);
 	BLI_unlock_thread(LOCK_CACHER);
 }
@@ -389,7 +397,13 @@
 	TCS_Tile *tile = vtile;
 
 	BLI_lock_thread(LOCK_CACHER);
-	tile->locked = 0;
+	tile->locked--;
+
+	if (tile->locked < 0) {
+		printf("Error! TCS_UnlockTile called on an already unlocked tile!\n");
+		tile->locked = 0;
+	}
+
 	BLI_unlock_thread(LOCK_CACHER);
 }
 

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c	2008-03-15 20:59:26 UTC (rev 14125)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c	2008-03-15 21:32:52 UTC (rev 14126)
@@ -59,10 +59,20 @@
 {
 	DSMFunction *func;
 	DSMLayerSample *sample;
-	unsigned short value;
 	int i;
 
-	func = BLI_memarena_alloc(tile->arena, sizeof(DSMFunction));
+	switch (clr) {
+		case 0:
+			func = dsm_function_alloc(tile, &tile->r_rect[y*tile->sizex+x]);
+			break;
+		case 1:
+			func = dsm_function_alloc(tile, &tile->g_rect[y*tile->sizex+x]);
+			break;
+		case 2:
+			func = dsm_function_alloc(tile, &tile->b_rect[y*tile->sizex+x]);
+			break;
+	}
+
 	func->samples = sample = BLI_memarena_alloc(tile->arena, sizeof(DSMLayerSample)*totsamples);
 	func->totsamples = totsamples;
 	
@@ -74,18 +84,6 @@
 		TCS_fread(&sample->orig_totsamples, sizeof(unsigned short), 1, file);
 		TCS_fread(&sample->depth, sizeof(unsigned int), 1, file);
 	}
-
-	switch (clr) {
-		case 0:
-			tile->r_rect[y*tile->sizex+x] = func;
-			break;
-		case 1:
-			tile->g_rect[y*tile->sizex+x] = func;
-			break;
-		case 2:
-			tile->b_rect[y*tile->sizex+x] = func;
-			break;
-	}
 }
 
 static void dsm_loadtile(TCS_Tile *tself, TCS_File *file)
@@ -97,10 +95,14 @@
 
 	self->arena = BLI_memarena_new(DSM_TILE_FINALMEMARENASIZE);
 	BLI_memarena_use_mapalloc(self->arena);
-	self->r_rect = BLI_memarena_alloc(self->arena, sizeof(void*)*self->sizex*self->sizey);
-	self->g_rect = BLI_memarena_alloc(self->arena, sizeof(void*)*self->sizex*self->sizey);
-	self->b_rect = BLI_memarena_alloc(self->arena, sizeof(void*)*self->sizex*self->sizey);
+	self->r_rect = BLI_memarena_alloc(self->arena, sizeof(short)*self->sizex*self->sizey);
+	self->g_rect = BLI_memarena_alloc(self->arena, sizeof(short)*self->sizex*self->sizey);
+	self->b_rect = BLI_memarena_alloc(self->arena, sizeof(short)*self->sizex*self->sizey);
+	self->funcarray = MEM_mallocN(sizeof(DSMFunction)*self->funcarray_len, "new tile func array after decaching");
 	
+	self->funcarray_buffer = self->funcarray_len;
+	self->funcarray_len = 0;
+
 	TCS_fread(&magic, sizeof(int), 1, file);
 	if (magic != DSM_MAGICNUM) {
 		printf("EVIL! Corrupted DSM data!  id: %c%c%c%c", ((char*)&magic)[0], ((char*)&magic)[1], ((char*)&magic)[2], ((char*)&magic)[3]);
@@ -130,7 +132,6 @@
 static void dsm_savefunction(struct TCS_File *file, DSMFunction *func)
 {
 	int i;
-	unsigned short value;
 	DSMLayerSample *sample = func->samples;
 	
 	TCS_fwrite(&func->zmin, sizeof(int), 1, file);
@@ -150,7 +151,12 @@
 	DSMTile *self = (DSMTile*) tself;
 
 	BLI_memarena_free(self->arena);
-
+	if (self->funcarray) MEM_freeN(self->funcarray);
+	
+	/*tile->funcarray_len is left intact so
+	  we can know how much to allocate
+	  when decaching.*/
+	self->funcarray = NULL;
 	self->arena = NULL;
 	self->r_rect = NULL;
 	self->g_rect = NULL;
@@ -178,7 +184,7 @@
 
 	for (y=0; y<self->sizey; y++) {
 		for (x=0; x<self->sizex; x++) {
-			if (self->r_rect[y*self->sizex+x] || self->g_rect[y*self->sizex+x] || self->b_rect[y*self->sizex+x]) {
+			if (self->r_rect[y*self->sizex+x] != -1 || self->g_rect[y*self->sizex+x] != -1 || self->b_rect[y*self->sizex+x] != -1) {
 				tot++;
 				
 				TCS_fwrite(&x, sizeof(int), 1, file);
@@ -186,19 +192,19 @@
 
 				/*write each visibility function.  the number of samples is
 				  written first, or zero if the function has no samples.*/
-				if (self->r_rect[y*self->sizex+x]) {
-					TCS_fwrite(&self->r_rect[y*self->sizex+x]->totsamples, sizeof(int), 1, file);
-					dsm_savefunction(file, self->r_rect[y*self->sizex+x]);
+				if (self->r_rect[y*self->sizex+x] != -1) {
+					TCS_fwrite(&self->funcarray[self->r_rect[y*self->sizex+x]].totsamples, sizeof(int), 1, file);
+					dsm_savefunction(file, &self->funcarray[self->r_rect[y*self->sizex+x]]);
 				} else TCS_fwrite(&zero, sizeof(int), 1, file);
 
-				if (self->g_rect[y*self->sizex+x]) {
-					TCS_fwrite(&self->g_rect[y*self->sizex+x]->totsamples, sizeof(int), 1, file);
-					dsm_savefunction(file, self->g_rect[y*self->sizex+x]);
+				if (self->g_rect[y*self->sizex+x] != -1) {
+					TCS_fwrite(&self->funcarray[self->g_rect[y*self->sizex+x]].totsamples, sizeof(int), 1, file);
+					dsm_savefunction(file, &self->funcarray[self->g_rect[y*self->sizex+x]]);
 				} else TCS_fwrite(&zero, sizeof(int), 1, file);
 
-				if (self->b_rect[y*self->sizex+x]) {
-					TCS_fwrite(&self->b_rect[y*self->sizex+x]->totsamples, sizeof(int), 1, file);
-					dsm_savefunction(file, self->b_rect[y*self->sizex+x]);
+				if (self->b_rect[y*self->sizex+x] != -1) {
+					TCS_fwrite(&self->funcarray[self->b_rect[y*self->sizex+x]].totsamples, sizeof(int), 1, file);
+					dsm_savefunction(file, &self->funcarray[self->b_rect[y*self->sizex+x]]);
 				} else TCS_fwrite(&zero, sizeof(int), 1, file);
 				
 				BASSERT(0 == file->error_occured);
@@ -233,7 +239,6 @@
 unsigned int dsm_gettilelen(TCS_Tile *tself)
 {
 	DSMTile *tile = (DSMTile*)tself;
-	DSMLayerSample *sample;
 	unsigned int len = 0, x, y, found;
 	
 	len += sizeof(int)*2;
@@ -241,16 +246,16 @@
 	for (x=0; x<tile->sizex; x++) {
 		for (y=0; y<tile->sizey; y++) {
 			found = 0;
-			if (tile->r_rect[y*tile->sizex+x]) {
-				len += sizeof(int)*3 + (sizeof(short)+sizeof(float)+sizeof(int))*tile->r_rect[y*tile->sizex+x]->totsamples;
+			if (tile->r_rect[y*tile->sizex+x] != -1) {
+				len += sizeof(int)*3 + (sizeof(short)+sizeof(float)+sizeof(int))*tile->funcarray[tile->r_rect[y*tile->sizex+x]].totsamples;
 				found++;
 			}
-			if (tile->g_rect[y*tile->sizex+x]) {
-				len += sizeof(int)*3 + (sizeof(short)+sizeof(float)+sizeof(int))*tile->g_rect[y*tile->sizex+x]->totsamples;
+			if (tile->g_rect[y*tile->sizex+x] != -1) {
+				len += sizeof(int)*3 + (sizeof(short)+sizeof(float)+sizeof(int))*tile->funcarray[tile->g_rect[y*tile->sizex+x]].totsamples;
 				found++;
 			}
-			if (tile->b_rect[y*tile->sizex+x]) {
-				len += sizeof(int)*3 + (sizeof(short)+sizeof(float)+sizeof(int))*tile->b_rect[y*tile->sizex+x]->totsamples;
+			if (tile->b_rect[y*tile->sizex+x] != -1) {
+				len += sizeof(int)*3 + (sizeof(short)+sizeof(float)+sizeof(int))*tile->funcarray[tile->b_rect[y*tile->sizex+x]].totsamples;
 				found++;
 			}
 

Modified: branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2008-03-15 20:59:26 UTC (rev 14125)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2008-03-15 21:32:52 UTC (rev 14126)
@@ -133,6 +133,7 @@
 	for (i=0; i<dbuf->tilex*dbuf->tiley; i++) {
 		TCS_FreeTile(&dbuf->vfunc_rect[i]);
 		if (dbuf->vfunc_rect[i].arena) BLI_memarena_free(dbuf->vfunc_rect[i].arena);

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list