[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14054] branches/soc-2007-joeedh/source/ blender: Several bugs fixed:

Joseph Eagar joeedh at gmail.com
Tue Mar 11 03:49:39 CET 2008


Revision: 14054
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14054
Author:   joeedh
Date:     2008-03-11 03:49:36 +0100 (Tue, 11 Mar 2008)

Log Message:
-----------
Several bugs fixed:

* Colored shadows weren't being accumulated correctly.
* The cache system wasn't copying compressed tile data
  to a new memory chunk after compression, which was  
  causing the cache system to fail.
* Slight problem with using -0x7FFFFFFF instead of
  -0x80000000 (forgot that it's -power_of_2 to
  power_of_2-1, not -power_of_2+1 to power_of_2 - 1).

Modified Paths:
--------------
    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/render/intern/include/zbuf.h
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/zbuf.c

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-03-11 01:17:56 UTC (rev 14053)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-03-11 02:49:36 UTC (rev 14054)
@@ -87,12 +87,18 @@
 } DSMBuffer;
 
 //32 16 8 4 2 1
-#define MAX_SAMPLELAYERS	32
-#define DSM_FINAL_TILESIZE	32
+#define MAX_SAMPLELAYERS		32
+
+#define DSM_FINAL_TILESIZE		32
+//#define DSM_FINAL_MAXSAMPLES	2000
+
 #define DSM_TILE_MEMARENASIZE	(1<<16)
-#define DSM_AASAMPLES		(shb->samp) //(G.rt>8 ? 1 : (G.rt==0 ? 1 : G.rt))
-#define DSM_AAWIDTH			(shb->soft)
+#define DSM_AASAMPLES		(shb->samp > 5? 5: shb->samp) //(G.rt>8 ? 1 : (G.rt==0 ? 1 : G.rt))
+#define DSM_AAWIDTH			(shb->soft > 3? 3: shb->soft)
+#define DSM_MAXSAMPLES		25
 
+#define DSM_SAMPLEMERGE_LIMIT	(0x7FFFFFFF) //20000000
+
 /*little bit smaller memarena buffer size for the final diced
   32x32 tiles*/
 #define DSM_TILE_FINALMEMARENASIZE (1<<16)

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h	2008-03-11 01:17:56 UTC (rev 14053)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h	2008-03-11 02:49:36 UTC (rev 14054)
@@ -65,13 +65,16 @@
 typedef struct TCS_TileType {
 	void (*loadFromCache)(struct TCS_Tile *self, TCS_File *file);
 	
-	/*should free client data after writing to disk, but not free
-	  the TCS_Tile itself.	  
+	/* 
 	  - returns length, NOTE: need to remove this particular requirement
 	 */
 	unsigned int (*saveToCache)(struct TCS_Tile *self, TCS_File *file,
 	                unsigned long current_position);
 	
+	/*frees direct data, but not the tile structure itself
+	  (obviously).*/
+	void (*freeData)(struct TCS_Tile *self);
+
 	/*returns amount size of diskspace the uncompressed tile would take, in bytes*/
 	unsigned int (*getTileLen)(struct TCS_Tile *self);
  } TCS_TileType;

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c	2008-03-11 01:17:56 UTC (rev 14053)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_bucketbuffer.c	2008-03-11 02:49:36 UTC (rev 14054)
@@ -102,11 +102,23 @@
 	self->tots = tot;
 }
 
+static void bucket_freedata(TCS_Tile *tself)
+{
+	RE_BucketTile *self = (RE_BucketTile*) tself;
+	RE_BucketEntry *entry, *enext;
 
-static unsigned int bucket_savetile(struct TCS_Tile *tself, TCS_File *file, unsigned long curpos)
+	for (entry=self->sentries; entry; entry=enext) {
+		enext = entry->next;
+		MEM_freeN(entry);
+	}
+		
+	self->ventries = self->sentries = self->lastv = self->lasts = NULL;
+}
+
+static unsigned int bucket_savetile(TCS_Tile *tself, TCS_File *file, unsigned long curpos)
 {
 	RE_BucketTile *self = (RE_BucketTile*) tself;
-	RE_BucketEntry *entry, *enext;
+	RE_BucketEntry *entry;
 	int num, tot;
 	
 	BASSERT(tself);
@@ -118,29 +130,20 @@
 	tot = self->totv;
 	TCS_fwrite(&tot, sizeof(int), 1, file);
 	
-	for (entry=self->ventries; entry; entry=enext) {
-		enext = entry->next;
+	for (entry=self->ventries; entry; entry=entry->next) {
 		TCS_fwrite(entry, sizeof(RE_BucketEntry), 1, file);
 		tot++;
-		
-		MEM_freeN(entry);
 	}
 
-	tot = self->tots;
-	TCS_fwrite(&tot, sizeof(int), 1, file);
-		
-	for (entry=self->sentries; entry; entry=enext) {
-		enext = entry->next;
+	for (entry=self->sentries; entry; entry=entry->next) {
 		TCS_fwrite(entry, sizeof(RE_BucketEntry), 1, file);
 		tot++;
-		
-		MEM_freeN(entry);
 	}
-	
+
+	tot = self->tots;
+	TCS_fwrite(&tot, sizeof(int), 1, file);
 	BASSERT(file->error_occured == 0);
 	
-	self->ventries = self->sentries = self->lastv = self->lasts = NULL;
-	
 	return TCS_ftell(file) - curpos;
 }
 
@@ -155,6 +158,7 @@
 static TCS_TileType _bucket_tile_type = {
 	bucket_loadtile,
 	bucket_savetile,
+	bucket_freedata,
 	bucket_gettilelen,
 };
 

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-11 01:17:56 UTC (rev 14053)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c	2008-03-11 02:49:36 UTC (rev 14054)
@@ -194,7 +194,10 @@
 static void TCS_CompressMemFile(TCS_File *file)
 {
 	TCS_File *memfile2 = TCS_openmemfile((float)file->length*1.1+12);
+	char *ptr;
 	int r;
+	
+	if (file->length==0) return;
 
 	r = compress2(memfile2->ptr, &memfile2->length, file->ptr, file->length, 1);
 	if (r == Z_MEM_ERROR) printf("cz mem error\n");
@@ -203,9 +206,16 @@
 	
 	if (file->ptr) MEM_freeN(file->ptr);
 	
+	/*pack compressed data in.*/
+	ptr = MEM_mallocN(memfile2->length, "compressed memfile newbuffer");
+	memcpy(ptr, memfile2->ptr, memfile2->length);
+
+	MEM_freeN(memfile2->ptr);
+	memfile2->ptr = ptr;
+
 	file->ptr = memfile2->ptr;
 	file->length = memfile2->length;
-	file->totallocated = memfile2->totallocated;
+	file->totallocated = memfile2->length;
 	file->cursor = memfile2->cursor;
 	
 	MEM_freeN(memfile2);
@@ -472,15 +482,13 @@
 		/*calculate tile filesize on disk, if its not already calculated. . .*/
 		if (tile->len == 0) tile->len = tile->type->getTileLen(tile);
 		if (tile->is_compressed) printf("YEEK! Tried to twice compress a tile! %d\n", tile->is_compressed);
-
-		/*subtract memory used for this tile*/
-		mem -= tile->mem_used;
-
 		#ifdef TCSDEBUG
 			printf("marking a tile!\n");
 		#endif
 
 		if (!tile->locked) {
+			/*subtract memory used for this tile*/
+			mem -= tile->mem_used;
 			tile->is_compressed = 1;
 		}
 		if (mem <= pool->maxmem - pool->grace_period) break;
@@ -500,6 +508,7 @@
 			tile->compressed_memfile->length = 0;
 			
 			tile->type->saveToCache(tile, tile->compressed_memfile, 0);
+			tile->type->freeData(tile);
 
 			/*paranoia check*/
 			BASSERT(tile->len == tile->compressed_memfile->length);
@@ -512,7 +521,7 @@
 			#endif
 			
 			pool->memused -= tile->mem_used;
-			pool->memused += tile->compressed_memfile->length;
+			pool->memused += tile->compressed_memfile->length + sizeof(TCS_File) + MEM_OVERHEAD;
 			
 			BLI_remlink(&pool->tiles, tile);
 			BLI_addtail(&pool->compressed_tiles, tile);
@@ -539,7 +548,7 @@
 			TCS_fwrite(tile->compressed_memfile->ptr, tile->compressed_memfile->length, 1, tile->file);
 			TCS_fflush(tile->file);
 		}
-		
+
 		/*error occured, load the tile back from the memfile.*/
 		if (tile->file->error_occured) {
 			TCS_File *f2 = tile->compressed_memfile;

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-11 01:17:56 UTC (rev 14053)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c	2008-03-11 02:49:36 UTC (rev 14054)
@@ -145,6 +145,18 @@
 	}
 }
 
+void dsm_freetiledata(struct TCS_Tile *tself)
+{
+	DSMTile *self = (DSMTile*) tself;
+
+	BLI_memarena_free(self->arena);
+
+	self->arena = NULL;
+	self->r_rect = NULL;
+	self->g_rect = NULL;
+	self->b_rect = NULL;
+}
+
 static unsigned int dsm_savetile(struct TCS_Tile *tself, TCS_File *file, unsigned long curpos)
 {
 	DSMTile *self = (DSMTile*) tself;
@@ -215,12 +227,6 @@
 	TCS_fseek(file, fend, SEEK_SET);
 	BASSERT(file->error_occured == 0);
 	
-	BLI_memarena_free(self->arena);
-	self->arena = NULL;
-	self->r_rect = NULL;
-	self->g_rect = NULL;
-	self->b_rect = NULL;
-	
 	return fend - curpos;
 }
 
@@ -266,6 +272,7 @@
 		_dsm_tile_typeptr = &_dsm_tile_type;
 		_dsm_tile_typeptr->loadFromCache = dsm_loadtile;
 		_dsm_tile_typeptr->saveToCache = dsm_savetile;
+		_dsm_tile_typeptr->freeData = dsm_freetiledata;
 		_dsm_tile_typeptr->getTileLen = dsm_gettilelen;
 	}
 

Modified: branches/soc-2007-joeedh/source/blender/render/intern/include/zbuf.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/render/intern/include/zbuf.h	2008-03-11 01:17:56 UTC (rev 14053)
+++ branches/soc-2007-joeedh/source/blender/render/intern/include/zbuf.h	2008-03-11 02:49:36 UTC (rev 14054)
@@ -108,7 +108,7 @@
 
 	int polygon_offset;						/* offset in Z */
 	float shad_alpha;						/* copy from material, used by irregular shadbuf */
-	int mask, apsmcounter;					/* in use by apixbuf */
+	unsigned int mask, apsmcounter;			/* in use by apixbuf */
 	int apstrandmcounter;
 
 	float clipcrop;							/* for shadow, was in R global before */

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-11 01:17:56 UTC (rev 14053)
+++ branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c	2008-03-11 02:49:36 UTC (rev 14054)
@@ -70,6 +70,8 @@
 #include "BIF_space.h"
 #include "BIF_editview.h"
 
+#include "PIL_time.h"
+
 extern Render R;
 static TCS_TilePool *deepbuffer_pool = NULL;
 
@@ -104,6 +106,7 @@
 	ListBase *srclist;
 	int depth;
 	int p;
+	int mask;
 	int obi;
 	int type;
 	int samplenr;
@@ -283,39 +286,50 @@
 		}
 	}
 
-	BLI_init_threads(&threads, do_dsmshadow_thread, re->r.threads);
-	
-	for (x=0; x<re->r.threads; x++) {
-		thread_data[x].tiles = &threadtiles;
-		thread_data[x].threadnr = x;
-		thread_data[x].dbuf = dbuf;
-		thread_data[x].projmat = projmat;
-		thread_data[x].bucketbuf = bucketbuf;
-		thread_data[x].re = re;
-		thread_data[x].shb = shb;
-		BLI_insert_thread(&threads, &thread_data[x]);
-	}
+	if (re->r.threads < 2) {
+		thread_data[0].tiles = &threadtiles;
+		thread_data[0].threadnr = 0;
+		thread_data[0].dbuf = dbuf;
+		thread_data[0].projmat = projmat;
+		thread_data[0].bucketbuf = bucketbuf;
+		thread_data[0].re = re;
+		thread_data[0].shb = shb;
+		do_dsmshadow_thread(thread_data);
+	} else {
+		BLI_init_threads(&threads, do_dsmshadow_thread, re->r.threads);
+		
+		for (x=0; x<re->r.threads; x++) {
+			thread_data[x].tiles = &threadtiles;
+			thread_data[x].threadnr = x;
+			thread_data[x].dbuf = dbuf;
+			thread_data[x].projmat = projmat;
+			thread_data[x].bucketbuf = bucketbuf;
+			thread_data[x].re = re;
+			thread_data[x].shb = shb;
+			BLI_insert_thread(&threads, &thread_data[x]);
+		}
 

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list