[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [17983] branches/soc-2007-joeedh/source/ blender: Significant speed and memory increases.

Joseph Eagar joeedh at gmail.com
Sun Dec 21 10:54:41 CET 2008


Revision: 17983
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=17983
Author:   joeedh
Date:     2008-12-21 10:54:41 +0100 (Sun, 21 Dec 2008)

Log Message:
-----------
Significant speed and memory increases.  Strands are now limited to 256*oversampling strand samples per pixel.  Also the system that figures out which strands are in which dsm tiles is fixed, so it isn't taking horrendous amounts of RAM anymore.  Please test.

Modified Paths:
--------------
    branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h
    branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
    branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h
    branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c
    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/blenkernel/intern/tcs_file.c
    branches/soc-2007-joeedh/source/blender/render/intern/include/dsm.h
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_func.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm_soft.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/shadbuf.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf_dsm.c

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h	2008-12-21 08:53:36 UTC (rev 17982)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_bucketbuffer.h	2008-12-21 09:54:41 UTC (rev 17983)
@@ -30,8 +30,14 @@
 #include "BKE_tile.h"
 #include "BLI_memarena.h"
 
-#define MAX_BUCKETENTRY	256
+#define MAX_BUCKETENTRY	4096
 
+//0. . .1000
+//1000.2000
+//
+/*
+ hrm, perhaps get rid of z.
+ */
 typedef struct RE_BucketEntry {
 	struct RE_BucketEntry *next;
 	int obi[MAX_BUCKETENTRY];

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-12-21 08:53:36 UTC (rev 17982)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-12-21 09:54:41 UTC (rev 17983)
@@ -51,7 +51,7 @@
 	
 	/*offsets of position of functions inside function array
 	  for pixels.*/
-	short *r_rect, *g_rect, *b_rect;
+	unsigned short *r_rect, *g_rect, *b_rect;
 	
 	/*tile coordinates inside poly_rect.
 	  Note: this is *not* in image space units!
@@ -95,7 +95,10 @@
 
 #define MAX_SAMPLELAYERS		32
 
-#define DSM_FINAL_TILESIZE		50
+/*note: making the tilesize too small can cause
+  the bucketing system to use a LOT of memory.
+  */
+#define DSM_FINAL_TILESIZE		120
 #define DSM_TILE_MEMARENASIZE	(1<<16)
 #define DSM_AASAMPLES		(shb->osasamp)
 #define DSM_AAWIDTH			1.5f;
@@ -107,6 +110,9 @@
 //code has to convert.ss
 #define DSM_STRAND_ADAPTCOS 8.0
 
+/*sentinal value, used internally*/
+#define FSENT	65535
+
 #define DSM_LINEAR	(G.rt != 102 && G.rt != 103)
 #define DSM_SOFT	0
 #define DSM_VIS		0
@@ -126,6 +132,6 @@
 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);
+DSMFunction *dsm_function_alloc(DSMTile *tile, unsigned short *offset);
 
 #endif /* BKE_DSM_H */

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h	2008-12-21 08:53:36 UTC (rev 17982)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h	2008-12-21 09:54:41 UTC (rev 17983)
@@ -44,6 +44,8 @@
    Tile caches are  grouped in "pools", which can
    contain generic tiles of any tile cache type.  Tiles are generic data
    holding structures.  Module prefix is TCS, for Tile Cache System
+
+   Things to do: Make the function pointers take a void* for self.
 */
 
 struct TCS_Tile;
@@ -89,7 +91,7 @@
 	  used by the tile.  it must always be up-to-date.  struct_overhead
 	  is the size of the tile struct plus any other noncachable memory;
 	  mem_used must *not* include this.*/
-	int mem_used, struct_overhead; 
+	unsigned int mem_used, struct_overhead; 
 	
 	/*-the rest of these members are privae variables, do not touch!-*/
 	int is_compressed, is_written;
@@ -177,11 +179,16 @@
 
  /*this macro updates a tile's memory counter,
    adding mem_to_add to both it and the tile's pool's
-   memory counter.*/
-#define TCS_AdjustTileMemSize(_tile, mem_to_add)\
+   memory counter.  also discards previous cache
+   state.*/
+/*#define TCS_AdjustTileMemSize(_tile, mem_to_add){\
 	((TCS_Tile*)(_tile))->mem_used += mem_to_add;\
 	((TCS_Tile*)(_tile))->pool->memused += mem_to_add;\
-	((TCS_Tile*)(_tile))->pool->totalsize += mem_to_add;
+	((TCS_Tile*)(_tile))->pool->totalsize += mem_to_add;\
+	((TCS_Tile*)(_tile))->file = NULL;\
+	((TCS_Tile*)(_tile))->filepos = 0;}
+*/
+void TCS_AdjustTileMemSize(void *vtile, int mem_to_add);
 
 /*buffer type templates*/
 extern TCS_TileBuffer	TCS_DeepShadowBuffer;
@@ -210,6 +217,8 @@
 /*this function removes a tile from a tile pool.
   this is automatically called by TCS_UnlinkTile.*/
 void TCS_RemFromPool(void *vtile);
+void TCS_DisablePool(TCS_TilePool *pool);
+void TCS_EnablePool(TCS_TilePool *pool);
 
 TCS_TileBuffer *TCS_MakeBuffer(TCS_TilePool *pool, TCS_TileBuffer *type, int tilesizex, int tilesizey, 
    int sizex, int sizey, void *data);
@@ -288,11 +297,19 @@
 /* TCS_TileBuffer->flag */
  /*Read only buffer means once a tile is written once, we
   never have to write it to disk again.*/
-#define TCS_READONLY	1
+#define TCS_READONLY		1
+/*no recompress means that in read only mode,
+  the system won't try to compress a tile 
+  instead of simply freeing it (resulting in
+  more disk access, but less cpu cycles dedicated
+  to compression).
+*/
+#define TCS_NORECOMPRESS	(2 | TCS_READONLY)
 
 /*TCS_TilePool>flag*/
 /*the tile size is fixed, so the pool may safely
   reuse tiles.*/
 #define TCS_POOL_TSIZEFIXED	1
+#define TCS_POOL_DISABLED	2
 
 #endif /* BKE_TILE_H */

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c	2008-12-21 08:53:36 UTC (rev 17982)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c	2008-12-21 09:54:41 UTC (rev 17983)
@@ -27,6 +27,7 @@
 #include "MEM_guardedalloc.h"
 
 #include "DNA_listBase.h"
+#include "DNA_userdef_types.h"
 
 #include "BLI_blenlib.h"
 #include "BLI_memarena.h"
@@ -41,7 +42,7 @@
 extern TCS_TileBuffer TCS_BucketBuffer;
 TCS_TilePool *re_bucket_pool = NULL;
 
-#define POOLMAXMEM	40*1024*1024
+#define POOLMAXMEM	((U.dsm_maxmem/2)*1024*1024) //150*1024*1024
 
 RE_BucketBuffer *RE_Bucket_New(int sizex, int sizey, int tsizex, int tsizey) {
 	if (re_bucket_pool == NULL) re_bucket_pool = TCS_MakePool(POOLMAXMEM, "bucketpool");
@@ -61,20 +62,26 @@
 
 static RE_BucketEntry *bucket_loadentries(TCS_File *file, int *tot, RE_BucketEntry **lastentry)
 {
-	RE_BucketEntry *firstentry = NULL, *entry = NULL;
-	int a;
-	
-	TCS_fread(tot, sizeof(int), 1, file);
+	RE_BucketEntry *firstentry = NULL, *entry = NULL, *last=NULL;
+	int a, t=0;
+
+	TCS_fread(&t, sizeof(int), 1, file);
 	for (a=0; a<*tot; a++) {
 		if (entry) {
-			entry->next = MEM_mallocN(sizeof(RE_BucketEntry), "RE_BucketEntry reloaded");
-			entry = entry->next;
-			//entry->next = NULL;
+			entry = MEM_callocN(sizeof(RE_BucketEntry), "RE_BucketEntry reloaded");
 		} else {
-			entry = firstentry = MEM_mallocN(sizeof(RE_BucketEntry), "RE_BucketEntry reloaded2");
-			//entry->next = NULL;
+			entry = firstentry = MEM_callocN(sizeof(RE_BucketEntry), "RE_BucketEntry reloaded2");
 		}
-		TCS_fread(entry, sizeof(RE_BucketEntry), 1, file);
+		if (!TCS_fread(entry, sizeof(RE_BucketEntry), 1, file)) {
+			printf("yeek tot was wrong.\n");
+			if (a != 0) entry = last;
+			*tot--;
+			break;
+		}
+
+		entry->next = NULL;
+		if (last) last->next = entry;
+		last = entry;
 	}
 	
 	*lastentry = entry;
@@ -85,7 +92,6 @@
 static void bucket_loadtile(TCS_Tile *tself, TCS_File *file)
 {
 	RE_BucketTile *self = (RE_BucketTile*) tself;
-	int tot;
 	unsigned int magic;
 	
 	TCS_fread(&magic, sizeof(int), 1, file);
@@ -96,10 +102,8 @@
 		return;
 	}
 	
-	self->ventries = bucket_loadentries(file, &tot, &self->lastv);
-	self->totv = tot;
-	self->sentries = bucket_loadentries(file, &tot, &self->lasts);
-	self->tots = tot;
+	self->ventries = bucket_loadentries(file, &self->totv, &self->lastv);
+	self->sentries = bucket_loadentries(file, &self->tots, &self->lasts);
 }
 
 static void bucket_freedata(TCS_Tile *tself)
@@ -111,6 +115,11 @@
 		enext = entry->next;
 		MEM_freeN(entry);
 	}
+
+	for (entry=self->ventries; entry; entry=enext) {
+		enext = entry->next;
+		MEM_freeN(entry);
+	}
 		
 	self->ventries = self->sentries = self->lastv = self->lasts = NULL;
 }
@@ -119,7 +128,7 @@
 {
 	RE_BucketTile *self = (RE_BucketTile*) tself;
 	RE_BucketEntry *entry;
-	int num, tot;
+	int num, tot, i;
 	
 	BASSERT(tself);
 	BASSERT(file);
@@ -130,18 +139,23 @@
 	tot = self->totv;
 	TCS_fwrite(&tot, sizeof(int), 1, file);
 	
+	i = 0;
 	for (entry=self->ventries; entry; entry=entry->next) {
-		TCS_fwrite(entry, sizeof(RE_BucketEntry), 1, file);
-		tot++;
+		if (!TCS_fwrite(entry, sizeof(RE_BucketEntry), 1, file)) break;
+		i++;
 	}
+	BASSERT(i == tot);
 
+	tot = self->tots;
+	TCS_fwrite(&tot, sizeof(int), 1, file);
+
+	i = 0;
 	for (entry=self->sentries; entry; entry=entry->next) {
-		TCS_fwrite(entry, sizeof(RE_BucketEntry), 1, file);
-		tot++;
+		if (!TCS_fwrite(entry, sizeof(RE_BucketEntry), 1, file)) break;
+		i++;
 	}
+	BASSERT(i==tot);
 
-	tot = self->tots;
-	TCS_fwrite(&tot, sizeof(int), 1, file);
 	BASSERT(file->error_occured == 0);
 	
 	return TCS_ftell(file) - curpos;
@@ -235,9 +249,9 @@
 	buf->sizey = sizey;
 	
 	/*test if we need to add extra tiles along the x axix*/
-	fac = ((float)sizex/(float)tsizex) + 0.0000001;
+	fac = ((float)sizex/(float)tsizex) + 0.0000001f;
 
-	if ((int)((fac - (int)fac)*(float)tsizex) > 0.000001) {
+	if ((int)((fac - (int)fac)*(float)tsizex) > 0.000001f) {
 		tilex += 1;
 	}
 	
@@ -292,6 +306,6 @@
 	bucket_getTileSizeY,
 	bucket_getSizeX,
 	bucket_getSizeY,
-	TCS_READONLY,
+	TCS_NORECOMPRESS,
 	NULL
 };

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-21 08:53:36 UTC (rev 17982)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c	2008-12-21 09:54:41 UTC (rev 17983)
@@ -115,10 +115,19 @@
 	tile->pool = NULL;
 }
 
+void TCS_DisablePool(TCS_TilePool *pool)
+{
+	pool->flag |= TCS_POOL_DISABLED;
+}
+
+void TCS_EnablePool(TCS_TilePool *pool)
+{
+	pool->flag &= ~TCS_POOL_DISABLED;
+}
+
 void TCS_FreePool(TCS_TilePool *pool)
 {
 	TCS_File *file, *next;
-	TCS_Tile *tile;
 	
 	BLI_freelistN(&pool->filerefs);
 	
@@ -166,6 +175,7 @@
 	void *buf = type->newBuffer(pool, tilesizex, tilesizey, sizex, sizey, data);
 	
 	TCS_InitBuffer(type, buf);
+	((TCS_TileBuffer*)buf)->pool = pool;
 	
 	return buf;
 }
@@ -173,7 +183,6 @@
 void TCS_FreeBuffer(void *vbuf)
 {
 	TCS_TileBuffer *buf = vbuf;
-	TCS_Tile *tile;
 	int tx=0, ty=0;
 	
 	BASSERT(buf);
@@ -244,15 +253,6 @@
 	
 	BASSERT(tile);
 	if (!tile) return NULL;
-
-	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;
-	}
-

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list