[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [14042] branches/soc-2007-joeedh/source/ blender: commit of working copy.

Joseph Eagar joeedh at gmail.com
Mon Mar 10 16:18:41 CET 2008


Revision: 14042
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=14042
Author:   joeedh
Date:     2008-03-10 16:18:38 +0100 (Mon, 10 Mar 2008)

Log Message:
-----------
commit of working copy.  cleanup of code for serious code review and 
user testing has begun.  work is ongoing.

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_cache.c
    branches/soc-2007-joeedh/source/blender/render/intern/source/dsm.c

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-03-10 12:30:24 UTC (rev 14041)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h	2008-03-10 15:18:38 UTC (rev 14042)
@@ -29,9 +29,6 @@
 	struct DSMTile *tiles[4];
 } DSMTileQuadMap;
 
-
-/*There'll be six quadtree levels: 32, 16, 8, 4, 2, 1*/
-
 /*ok heres how it works.  A "layer"
   is the total number of samples going from light
   energy 1.0 to 0.0, then repeating.*/
@@ -44,17 +41,6 @@
 	DSMLayerSample *samples;
 } DSMFunction;
 
-/*
-typedef struct DSMFunctionArray {
-	DSMFunction *layers;
-
-	//complete total number of samples in all layers
-	int totsamples;
-	int totlayers;
-	int zmin, zmax
-} DSMFunctionArray;
-*/
-
 /*Each tile has its own memarena to work better with caching.*/
 typedef struct DSMTile {
 	TCS_Tile tile;

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h	2008-03-10 12:30:24 UTC (rev 14041)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h	2008-03-10 15:18:38 UTC (rev 14042)
@@ -38,31 +38,12 @@
  
 #include "DNA_listBase.h"
  
-#include <stdio.h> /* needed for FILE typedef */
-
- /*Tile caching interface.  Tile caches are  grouped in "pools", which can
+/*
+   Tile caching interface.  
+   
+   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*/
- 
- 
-/*
-  -- Implementation Ideas--
-  
-  - Tiles can be held in a single linked-list stack (TCS_TilePool), 
-    for convienence.  If the stack grows too big, a necassary number of tiles
-    can be removed from the stack, compressed via level-1 or level-2 zlib 
-    zip, then written to disk (if necessary).
-
-	NOTE: never insert tiles into any ListBase list yourself!
-  
-  - Tiles are never written to disk more then once.
-  
-  - For image types, the tile sizes should be limited to powers of 2.  This 
-    should allow easier generation of mipmaps for gigantic images.
-  
-  - I wonder if it'd work to only store the first or second mipmap as a
-    fully-tilable cache, then store the rest as contiguous image buffers?
-    Hrm.  Sounds hackish and potentially stupid. . .
+   holding structures.  Module prefix is TCS, for Tile Cache System
 */
 
 struct TCS_Tile;
@@ -85,9 +66,8 @@
 	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
+	  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);
@@ -125,6 +105,12 @@
 	struct TCS_TileBuffer *buffer; /*parent buffer*/
 } TCS_Tile;
 
+typedef struct TCS_FileTileRef {
+	struct TCS_FileTileRef *next, *prev;
+	TCS_File *file;
+	unsigned long filepos;
+} TCS_FileTileRef;
+
 /*pools manage tiles, but the the tiles themselves belong to TCS_TileBuffers.
   This is a generic container structure, so it can hold any tile from
   any buffer, of any buffer type.*/
@@ -144,7 +130,15 @@
 	
 	/*tiles which have been written to disk.*/
 	ListBase saved_tiles;
-
+	
+	/*if TCS_POOL_TSIZEFIXED flag is set, then this is a
+	  linked list of TCS_FileTileRefs,
+	  basically available disk positions to use.*/
+	ListBase filerefs;
+	
+	int flag;
+	int tilesize; /*if flag->TCS_POOL_TSIZEFIXED is set*/
+	
 	//unsigned int tottiles;
 	unsigned long maxmem;
 	unsigned long memused; /*total amount of memory used at the moment.*/
@@ -152,6 +146,12 @@
 								    of one at a time.*/
  } TCS_TilePool;
  
+ /*TCS_TilePool->flag*/
+ 
+ /*the tile size is fixed, so the pool may safely
+   reuse tiles.*/
+ #define TCS_POOL_TSIZEFIXED	1
+ 
  typedef struct TCS_TileBuffer {
 	struct TCS_TileBuffer *next, *prev;
 	struct TCS_TileBuffer *(*newBuffer)(TCS_TilePool *pool, int tilesizex, int tilesizey, 
@@ -172,8 +172,7 @@
 	TCS_TilePool *pool;
  } TCS_TileBuffer;
 
-/*TCS_TileBuffer .flags member flags*/
-
+/* TCS_TileBuffer->flags */
  /*Read only buffer means once a tile is written once, we
   never have to write it to disk again.*/
 #define TCS_READONLY	1
@@ -191,18 +190,38 @@
 /*buffer type templates*/
 extern TCS_TileBuffer	TCS_DeepShadowBuffer;
 
+/* Create a new tile pool.  
+  
+   note that this pool will support variable-length
+   tiles, however this does means that no reuse of disk cache space will be
+   done.  there is experimental support for fixed-size tile pools that would
+   reuse disk space, but it has not been tested yet.
+
+ */
+
 TCS_TilePool *TCS_MakePool(unsigned long max_mem_bytes, char *name);
+
+/*free a tile pool*/
 void TCS_FreePool(TCS_TilePool *pool);
-/*note: the tile's TCS_Tile header's mem_used and struct_overhead members
+
+/*adds a tile to a pool
+
+  note: the tile's TCS_Tile header's mem_used and struct_overhead members
   must both be valid.  To increase a tile's memory usage after calling this,
   use TCS_AdjustTileMemSize (which is currently a macro).*/
 void TCS_AddToPool(TCS_TilePool *pool, void *vtile);
-/*this is automatically called by TCS_FreeTile*/
+
+/*this function removes a tile from a tile pool.
+  this is automatically called by TCS_FreeTile.*/
 void TCS_RemFromPool(void *vtile);
 
 TCS_TileBuffer *TCS_MakeBuffer(TCS_TilePool *pool, TCS_TileBuffer *type, int tilesizex, int tilesizey, 
    int sizex, int sizey, void *data);
+
+/*init a buffer using another as a template*/
 void TCS_InitBuffer(TCS_TileBuffer *type, void *buffer);
+
+/*free a buffer using the tcs api.*/
 void TCS_FreeBuffer(void *buf);
 
 /*get a tile from the buffer.
@@ -235,18 +254,16 @@
 void TCS_RunCacher(TCS_TilePool *pool);
 void TCS_SetCacheLimit(TCS_TilePool *pool, unsigned long max_mem_bytes);
 
-/* *** File wrapper to support both memory and real files. *** */
+/******************* File wrapper to support both memory and real files. ************************/
+/*this should all probably become part of blenlib*/
 
 /*all these file functions (other then TCS_wrapmem) have the same interface
-  as their stdlib stdio counterparts.*/
-  
+  as their stdlib stdio counterparts.*/  
 int TCS_fread(void *ptr, unsigned long size, unsigned long count, 
                TCS_File *file);
 int TCS_fwrite(void *ptr, unsigned long size, unsigned long count, 
                  TCS_File *file);
 
-/*these are actually private functions, never use them in cache implementations!*/
-
 /*closes a file, then deletes it if its a disk file.  like TCS_fclose it frees file*/
 void TCS_fdelete(TCS_File *file);
 
@@ -261,12 +278,10 @@
 void TCS_fseek(TCS_File *file, unsigned long offset, int origin);
 void TCS_fflush(TCS_File *file);
 
-#define TCSDEBUG
+/*define TCSDEBUG to enable extra debug printf's*/
+//#define TCSDEBUG
 
-#ifdef TCSDEBUG
-	#define BASSERT(eval)	if (!(eval)) printf("\nassert \"%s\" in file:\n%s\n on line %d failed.\n\n", #eval, __FILE__, __LINE__)
-#else
-	#define BASSERT(eval)
-#endif
+/*a non-fatal warning assertion.  it just prints into the console.*/
+#define BASSERT(eval)	if (!(eval)) printf("\nassert \"%s\" in file:\n%s\n on line %d failed.\n\n", #eval, __FILE__, __LINE__)
 
 #endif /* BKE_TILE_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-10 12:30:24 UTC (rev 14041)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c	2008-03-10 15:18:38 UTC (rev 14042)
@@ -64,6 +64,15 @@
 	return pool;
 }
 
+TCS_TilePool *TCS_MakeFixedPool(unsigned long max_mem_bytes, char *name, int tilesize)
+{
+	TCS_TilePool *pool = TCS_MakePool(max_mem_bytes, name);
+	pool->tilesize = tilesize;
+	pool->flag |= TCS_POOL_TSIZEFIXED;
+	
+	return pool;
+}
+
 void TCS_AddToPool(TCS_TilePool *pool, void *vtile)
 {
 	TCS_Tile *tile = vtile;
@@ -90,6 +99,15 @@
 	}
 	
 	tile->pool->memused -= tile->struct_overhead;
+	
+	/*add tile's file position to tile if in fixed tilesize mode.*/
+	if (tile->pool->flag & TCS_POOL_TSIZEFIXED) {
+		TCS_FileTileRef *ref = MEM_callocN(sizeof(TCS_POOL_TSIZEFIXED), "TCS_POOL_TSIZEFIXED");
+		ref->file = tile->file;
+		ref->filepos = tile->filepos;
+		BLI_addtail(&tile->pool->filerefs, ref);
+	}
+	
 	tile->pool = NULL;
 }
 
@@ -98,6 +116,8 @@
 	TCS_File *file, *next;
 	TCS_Tile *tile;
 	
+	BLI_freelistN(&pool->filerefs);
+	
 	for (file=pool->open_files.first; file; file=next) {
 		next=file->next;
 		TCS_fdelete(file);
@@ -169,22 +189,6 @@
 	MEM_freeN(buf);
 }
 
-/*
-void *TCS_GetPixel(TCS_TileBuffer *buf, int x, int y)
-{
-	TCS_Tile *tile;
-	BASSERT(buf);
-	tile = TCS_GetTile(buf, x/buf->getTileSizeX(buf), y/buf->getTileSizeY(buf), 0);
-	BASSERT(tile);
-	
-	if (!tile) return NULL;
-	return tile->type->getTilePixel(tile, x%buf->getTileSizeX(buf), y%buf->getTileSizeY(buf), 0);
-}
-*/
-
-//static int TCS_deflate(TCS_File *source, TCS_File *dest, int level);
-//static int TCS_inflate(TCS_File *source, TCS_File *dest, int len);
-
 #define USECOMPRESSION
 
 static void TCS_CompressMemFile(TCS_File *file)
@@ -258,7 +262,6 @@
 	tile->locked = olock;
 
 	if (tile->is_compressed != 0) {
-		//printf("comp: %p, file: %p, tile->compressed_memfile, tile->file);
 		
 		if (tile->is_written) {
 			TCS_File *memfile;
@@ -268,9 +271,6 @@
 			TCS_fseek(tile->file, tile->filepos, SEEK_SET);
 			TCS_fread(&len, sizeof(unsigned long), 1, tile->file);
 			
-			#ifdef TCSDEBUG
-				printf("gettile len: %lud\n", len);
-			#endif
 			mem = MEM_callocN(len, "temp array for tcs");
 			
 			TCS_fread(mem, len, 1, tile->file);
@@ -385,7 +385,7 @@
 	int i;
 	char str1[64];
 	
-	if (tile->file == NULL) {
+	if (tile->file == NULL && pool->filerefs.first == NULL) {
 		file=pool->open_files.last;
 		if (!file || file->length >= pool->max_file_len) {
 			/*tries 512 times to open a file.  this is done
@@ -405,10 +405,7 @@
 			}
 			BASSERT(file);
 			
-			BLI_addtail(&pool->open_files, file);
-			#ifdef TCSDEBUG
-				printf("new file->length: %lud\n", file->length);
-			#endif
+			if (file) BLI_addtail(&pool->open_files, file);
 		}
 		BASSERT(file);
 		if (file == NULL) return;

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list