[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11121] branches/soc-2007-joeedh: Wahoo! DSM buffers actually work! Well, sortof.

Joseph Eagar joeedh at gmail.com
Fri Jun 29 09:10:00 CEST 2007


Revision: 11121
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11121
Author:   joeedh
Date:     2007-06-29 09:10:00 +0200 (Fri, 29 Jun 2007)

Log Message:
-----------
Wahoo! DSM buffers actually work! Well, sortof.  The idiotic bug where DSM maps can only be initialized in the ztransp pass function is still there, so you have to a) have all the objects in your scene be ztransp with an alpha less then 1.0 (0.999 will do), and b) only render in one big tile, e.g. with x/yparts = 1.

Test renders:

With DSM:
http://img.photobucket.com/albums/v287/joeedh/deepstrandtest.png

Comparison with irregular:
http://img.photobucket.com/albums/v287/joeedh/deepstrandtest_irregular.png

Another DSM test:

http://img.photobucket.com/albums/v287/joeedh/deepstrandtest2.png

Compare with classical-halfway buffers:

http://img.photobucket.com/albums/v287/joeedh/deepstrandtest2classical-halfway.png

And compare with no shadows at all:

http://img.photobucket.com/albums/v287/joeedh/deepstrandtest2noshad.png

Also this commit includes some debugging modifications to guardedalloc.  Basically MEM_freeN is now a macro, to allow passing in file/line number info.  This way MEM_freeN can give traceback in error messages.

And, last but not least, I am not going to manually wrap the lines in this commit, instead I'm going to see what tortoisesvn does.  If it doesn't wrap them, I'll commit a dummy commit with the lines wrapped to play nice with reads and web archives and stuff.

Modified Paths:
--------------
    branches/soc-2007-joeedh/intern/guardedalloc/MEM_guardedalloc.h
    branches/soc-2007-joeedh/intern/guardedalloc/intern/mallocn.c
    branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h
    branches/soc-2007-joeedh/source/blender/blenlib/intern/BLI_memarena.c
    branches/soc-2007-joeedh/source/blender/blenlib/intern/arithb.c
    branches/soc-2007-joeedh/source/blender/blenlib/intern/storage.c
    branches/soc-2007-joeedh/source/blender/render/intern/include/render_types.h
    branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.h
    branches/soc-2007-joeedh/source/blender/render/intern/include/zbuf.h
    branches/soc-2007-joeedh/source/blender/render/intern/source/convertblender.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/src/buttons_shading.c
    branches/soc-2007-joeedh/source/blender/src/editmesh_loop.c
    branches/soc-2007-joeedh/source/blender/src/editmesh_tools.c

Added Paths:
-----------
    branches/soc-2007-joeedh/source/blender/blenkernel/intern/cache.c

Modified: branches/soc-2007-joeedh/intern/guardedalloc/MEM_guardedalloc.h
===================================================================
--- branches/soc-2007-joeedh/intern/guardedalloc/MEM_guardedalloc.h	2007-06-29 05:33:43 UTC (rev 11120)
+++ branches/soc-2007-joeedh/intern/guardedalloc/MEM_guardedalloc.h	2007-06-29 07:10:00 UTC (rev 11121)
@@ -76,8 +76,9 @@
 	/**
 	 * Release memory previously allocatred by this module. 
 	 */
-	short MEM_freeN(void *vmemh);
-
+	short WMEM_freeN(void *vmemh);
+	short _MEM_freeN(void *vmemh, char *file, int line);
+	#define MEM_freeN(vmemh)	_MEM_freeN(vmemh, __FILE__, __LINE__)
 	/**
 	 * Duplicates a block of memory, and returns a pointer to the
 	 * newly allocated block.  */

Modified: branches/soc-2007-joeedh/intern/guardedalloc/intern/mallocn.c
===================================================================
--- branches/soc-2007-joeedh/intern/guardedalloc/intern/mallocn.c	2007-06-29 05:33:43 UTC (rev 11120)
+++ branches/soc-2007-joeedh/intern/guardedalloc/intern/mallocn.c	2007-06-29 07:10:00 UTC (rev 11121)
@@ -351,35 +351,46 @@
 	mem_unlock_thread();
 }
 
-short MEM_freeN(void *vmemh)		/* anders compileertie niet meer */
+short WMEM_freeN(void *vmemh)
 {
+	return _MEM_freeN(vmemh, "(called through C stub function)", -1);
+}
+
+/*special macro-wrapped MEM_freeN that keeps track of where MEM_freeN is called.*/
+short _MEM_freeN(void *vmemh, char *file, int line)		/* anders compileertie niet meer */
+{
 	short error = 0;
 	MemTail *memt;
 	MemHead *memh= vmemh;
 	const char *name;
-
+	char str1[90];
+	
 	if (memh == NULL){
-		MemorY_ErroR("free","attempt to free NULL pointer");
+		sprintf(str1, "Error in %s on line %d: attempt to free NULL pointer", file, line);
+		MemorY_ErroR("free", str1);
 		/* print_error(err_stream, "%d\n", (memh+4000)->tag1); */
 		return(-1);
 	}
 
 	if(sizeof(long)==8) {
 		if (((long) memh) & 0x7) {
-			MemorY_ErroR("free","attempt to free illegal pointer");
+			sprintf(str1, "Error in %s on line %d: attempt to free illegal pointer", file, line);
+			MemorY_ErroR("free", str1);
 			return(-1);
 		}
 	}
 	else {
 		if (((long) memh) & 0x3) {
-			MemorY_ErroR("free","attempt to free illegal pointer");
+			sprintf(str1, "Error in %s on line %d: attempt to free illegal pointer", file, line);
+			MemorY_ErroR("free", str1);
 			return(-1);
 		}
 	}
 	
 	memh--;
 	if(memh->tag1 == MEMFREE && memh->tag2 == MEMFREE) {
-		MemorY_ErroR(memh->name,"double free");
+		sprintf(str1, "Error in %s on line %d: double free", file, line);
+		MemorY_ErroR(memh->name, str1);
 		return(-1);
 	}
 
@@ -403,13 +414,19 @@
 		MemorY_ErroR(memh->name,"end corrupt");
 		name = check_memlist(memh);
 		if (name != 0){
-			if (name != memh->name) MemorY_ErroR(name,"is also corrupt");
+			sprintf(str1, "Error in %s on line %d: %s is also corrupt", file, line, name);
+			if (name != memh->name) MemorY_ErroR(name, str1);
 		}
 	} else{
 		error = -1;
 		name = check_memlist(memh);
-		if (name == 0) MemorY_ErroR("free","pointer not in memlist");
-		else MemorY_ErroR(name,"error in header");
+		if (name == 0) {
+			sprintf(str1, "Error in %s on line %d: pointer not in memlist", file, line);
+			MemorY_ErroR("free", str1);
+		} else {
+			sprintf(str1, "Error in %s on line %d: error in header", file, line);
+			MemorY_ErroR(name, str1);
+		}
 	}
 
 	totblock--;

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h	2007-06-29 05:33:43 UTC (rev 11120)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h	2007-06-29 07:10:00 UTC (rev 11121)
@@ -43,51 +43,122 @@
    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).
+  
+  - 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. . .
+*/
+
 struct TCS_Tile;
 struct TCS_TilePool;
 struct TCS_TileBuffer;
+struct TCS_File;
 
+/*Wrapped file interface, for working with both real and memory files.*/
+typedef struct TCS_File {
+	struct TCS_File *next, *prev;
+	int is_mem;
+	void *ptr; /*can be either a FILE handle or a piece of memory.*/
+	
+	/*remember to make sure these are updated, even if using
+	  a real FILE file instead of a memory block!*/
+	unsigned long length, cursor;
+} TCS_File;
+
 typedef struct TCS_Tile {
 	struct TCS_Tile *next, *prev;
-	void (*loadFromCache)(struct TCS_Tile *self, FILE *file, unsigned long start);
+	void (*loadFromCache)(struct TCS_Tile *self, TCS_File *file,
+	                      unsigned long start);
 	
-	/*returns length*/
-	unsigned int (*saveToCache)(struct TCS_Tile *self, FILE *file, unsigned long current_position);
-	int is_cached;
+	/*should free client data after writing to disk, but not free
+	  the TCS_Tile itself.
+	  
+	  - returns length
+	 */
+	unsigned int (*saveToCache)(struct TCS_Tile *self, TCS_File *file,
+	                unsigned long current_position);
+	
+	int is_cached; /*is 1 if either (or both) is_compressed or is_written is 1.*/
+	
+	/*-privae variables, do not touch!-*/
+	int is_compressed, is_written, mem_used;
+	TCS_File *file;
+	int filepos;
+
 	struct TCS_TilePool *pool;
 	struct TCS_TileBuffer *buffer; /*parent buffer*/
  } TCS_Tile;
  
- /*pools manage tiles, but the the tiles themselves belong to TCS_TileBuffers
-   this is a generic container structure.*/
- typedef struct TCS_TilePool {
+/*List of files used by a tile pool*/
+typedef struct TCS_FileList {
+	ListBase open_files; /*open files*/
+	unsigned long long len; /*length of all files, in bytes.*/
+} TCS_FileList;
+
+/*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.*/
+typedef struct TCS_TilePool {
 	struct TCS_TilePool *next, *prev;
 	ListBase tiles;
 	
+	/*tiles which have been compressed, but not written to disk yet.*/
+	ListBase compressed_tiles;
+	
 	unsigned int tottiles;
 	unsigned long maxmem;
+	unsigned long memused; /*total amount of memory used at the moment.*/
  } TCS_TilePool;
  
  typedef struct TCS_TileBuffer {
 	struct TCS_TileBuffer *next, *prev;
+	struct TCS_TileBuffer *(*newBuffer)(int tilesizex, int tilesizey, 
+	                                     int sizex, int sizey);
+	
+	/*should make sure tiles reference cachepool.*/
 	void (*makeTiles)(struct TCS_TileBuffer *self, TCS_TilePool *cachepool);
+	
+	/*only frees direct data*/
 	void (*freeBuffer)(struct TCS_TileBuffer *self);
 
-	/*as may dimensions can be used as needed, others can just be passed in as 0.*/
-	void (*getTile)(struct TCS_TileBuffer *self, int x, int y, int z);
-	void (*getTileMemUsage)(struct TCS_TileBuffer *self, int x, int y, int z);
+	/*as may dimensions can be used as needed, others can just be passed in 
+	   as 0.*/
+	void (*getTile)(struct TCS_TileBuffer *self, int x, int y);
+	
+	/*should be set by TCS_MakePool, not the newBuffer funcion*/
 	TCS_TilePool *pool;
  } TCS_TileBuffer;
 
 /*buffer type templates*/
-extern TCS_TileBuffer	TCS_FloatImageBuffer;
-extern TCS_TileBuffer	TCS_UByteImageBuffer;
 
+/*I imagine these next three should each use a common set of implementation
+  functions.*/
+extern TCS_TileBuffer	TCS_Float3ImageBuffer;
+extern TCS_TileBuffer	TCS_Float4ImageBuffer;
+extern TCS_TileBuffer	TCS_Float1ImageBuffer;
+
+extern TCS_TileBuffer	TCS_UByte4ImageBuffer;
+extern TCS_TileBuffer	TCS_UByte3ImageBuffer;
+
 /*remember to use this name!*/
 extern TCS_TileBuffer	TCS_DeepShadowBuffer;
 
 TCS_TilePool *TCS_MakePool(unsigned long max_mem_bytes);
 void TCS_FreePool(TCS_TilePool *pool);
+
 TCS_TileBuffer *TCS_MakeBuffer(TCS_TileBuffer *type, void *data);
 void TCS_FreeBuffer(TCS_TileBuffer *type);
 
@@ -95,9 +166,25 @@
 void *TCS_GetTile(TCS_TileBuffer *type, int x, int y, int z);
 
 /*hrm, not sure if this next one will be needed, its possible it can
-  all be done from within TCS_GetTile()*/
+  all be done from within TCS_GetTile(), perhaps even progressively*/
 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. *** */
 
+/*all these file functions (other then TCS_wrapmem) have the same interface
+  as their stdlib stdio counterparts.*/
+void TCS_fread(void *ptr, unsigned long size, unsigned long count, 
+               TCS_File *file);
+void TCS_fwrite(void *ptr, unsigned long size, unsigned long count, 
+                 TCS_File *file);
+
+/*these are actually private functions, never use them in cache implementations!*/
+TCS_File *TCS_fopen(const char *path, const char *mode);
+TCS_File *TCS_fclose(const char *path, const char *mode);
+TCS_File *TCS_wrapmem(void *mem, int len);
+unsigned int TCS_ftell(TCS_File *file);
+void TCS_rewind(TCS_File *file);
+void TCS_fseek(TCS_File *file, unsigned long offset, int origin);
+
  #endif /* BKE_TILE_H */

Added: branches/soc-2007-joeedh/source/blender/blenkernel/intern/cache.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/cache.c	                        (rev 0)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/cache.c	2007-06-29 07:10:00 UTC (rev 11121)
@@ -0,0 +1,214 @@
+#if 0
+/**
+ * $Id: cache.c 10648 2007-05-03 21:37:52Z blendix $
+ *
+ * ***** BEGIN GPL LICENSE BLOCK *****
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version. 
+ *
+ * This program is distributed in the hope that it will be useful,

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list