[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11140] branches/soc-2007-joeedh/source/ blender: This commit is because my harddrive is being a little

Joseph Eagar joeedh at gmail.com
Mon Jul 2 09:42:19 CEST 2007


Revision: 11140
          http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11140
Author:   joeedh
Date:     2007-07-02 09:42:18 +0200 (Mon, 02 Jul 2007)

Log Message:
-----------
This commit is because my harddrive is being a little
weird (or perhaps notepad2 was acting up, or window's
disk cache was being quirky, I'm not sure).

This has the initial tile cache interface.  The tile
system is fully generic, and includes an API for
manipulating both files and memory buffers.  This API
nearly completely duplicates the stdlib file library.

The tiling system does not work yet, though.  In
fact DSM in general is now broken by this.  So don't
update until I get things working again. :)

Modified Paths:
--------------
    branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h
    branches/soc-2007-joeedh/source/blender/render/intern/include/shadbuf.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

Added Paths:
-----------
    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/blenkernel/intern/tcs_image.c

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

Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h	2007-07-01 14:12:10 UTC (rev 11139)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h	2007-07-02 07:42:18 UTC (rev 11140)
@@ -71,17 +71,18 @@
 typedef struct TCS_File {
 	struct TCS_File *next, *prev;
 	int is_mem;
+	int error_occured;
 	void *ptr; /*can be either a FILE handle or a piece of memory.*/
+	char filename[256];
 	
 	/*remember to make sure these are updated, even if using
 	  a real FILE file instead of a memory block!*/
-	unsigned long length, cursor;
+	unsigned long length, cursor, totallocated;
 } TCS_File;
 
 typedef struct TCS_Tile {
 	struct TCS_Tile *next, *prev;
-	void (*loadFromCache)(struct TCS_Tile *self, TCS_File *file,
-	                      unsigned long start);
+	void (*loadFromCache)(struct TCS_Tile *self, TCS_File *file);
 	
 	/*should free client data after writing to disk, but not free
 	  the TCS_Tile itself.
@@ -91,57 +92,70 @@
 	unsigned int (*saveToCache)(struct TCS_Tile *self, TCS_File *file,
 	                unsigned long current_position);
 	
+	/*returns amount of memory the tile is using, in bytes*/
+	unsigned int (*getTileMem)(struct TCS_Tile *self);
+	void *(*getTilePixel)(struct TCS_Tile *self, int x, int y, int z);
+	
 	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;
+	TCS_File *file, *compressed_memfile;
+	
+	/*filepos is the cached tile position.  this must *never* be messed up!*/
+	int filepos, len; /*len is for caching the tile len, to avoid constantly recalculating the size*/
 
 	struct TCS_TilePool *pool;
 	struct TCS_TileBuffer *buffer; /*parent buffer*/
  } TCS_Tile;
  
-/*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;
+
+	ListBase open_files; /*open files*/
+	unsigned long long len; /*length of all files, in bytes.*/
+	int totfiles, curid; /*curid is used for naming files.*/
+	int max_file_len;
 	
 	/*tiles which have been compressed, but not written to disk yet.*/
 	ListBase compressed_tiles;
 	
-	unsigned int tottiles;
+	//unsigned int tottiles;
 	unsigned long maxmem;
 	unsigned long memused; /*total amount of memory used at the moment.*/
+	unsigned long grace_period; /*margin, used to (hopefully) cache tiles in groups instead
+								    of one at a time.*/
  } 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);
-	
+	                                     int sizex, int sizey, void *data);
 	/*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);
+	void *(*getTile)(struct TCS_TileBuffer *self, int x, int y, int z);
+	int (*getTileSizeX)(struct TCS_TileBuffer *self);
+	int (*getTileSizeY)(struct TCS_TileBuffer *self);
+	int (*getSizeX)(struct TCS_TileBuffer *self);
+	int (*getSizeY)(struct TCS_TileBuffer *self);
+	unsigned int flags;
 	
-	/*should be set by TCS_MakePool, not the newBuffer funcion*/
+	/*should be set by TCS_MakePool, not the newBuffer function*/
 	TCS_TilePool *pool;
  } TCS_TileBuffer;
 
+/*TCS_TileBuffer .flags member flags*/
+/*Read only buffer means once a tile is written once, we
+  never have to write it to disk again.*/
+#define TCS_READONLY	1
+
 /*buffer type templates*/
 
 /*I imagine these next three should each use a common set of implementation
@@ -159,11 +173,12 @@
 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);
-
+TCS_TileBuffer *TCS_MakeBuffer(TCS_TileBuffer *type, int tilesizex, int tilesizey, 
+   int sizex, int sizey, void *data);
+void TCS_InitBuffer(TCS_TileBuffer *type, void *buffer);
+void TCS_FreeBuffer(void *buf);
 /*as may dimensions can be used as needed, others can just be passed in as 0.*/
-void *TCS_GetTile(TCS_TileBuffer *type, int x, int y, int z);
+void *TCS_GetTile(void *buf, 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(), perhaps even progressively*/
@@ -174,17 +189,28 @@
 
 /*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, 
+  
+int TCS_fread(void *ptr, unsigned long size, unsigned long count, 
                TCS_File *file);
-void TCS_fwrite(void *ptr, unsigned long size, unsigned long count, 
+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);
+
+TCS_File *TCS_openmemfile(int initial_size);
 TCS_File *TCS_fopen(const char *path, const char *mode);
-TCS_File *TCS_fclose(const char *path, const char *mode);
+
+/*closes a file and frees file (and memory buffers if its a mem file)*/
+void TCS_fclose(TCS_File *file);
 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);
+void TCS_fflush(TCS_File *file);
 
- #endif /* BKE_TILE_H */
+#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 */

Deleted: branches/soc-2007-joeedh/source/blender/blenkernel/intern/cache.c
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/intern/cache.c	2007-07-01 14:12:10 UTC (rev 11139)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/cache.c	2007-07-02 07:42:18 UTC (rev 11140)
@@ -1,214 +0,0 @@
-#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,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
- *
- * The Original Code is Copyright (C) 2001-2002 by Joseph Eagar.
- *
- * Contributor(s): Joseph Eagar
- *
- * ***** END GPL/BL DUAL LICENSE BLOCK *****
- */
- 
-#include "BKE_global.h"
-#include "BKE_main.h"
-#include "BKE_tile.h"
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
- 
-/*Deep shadow buffer cache implementation*/
-typedef struct DSMBuf {
-	TCS_TileBuffer buf;
-	int tottilex, tottiley;
-	int tilesizex, tilesizey;
-	int sizex, sizey;
-	DSMTile *tiles;
-} DSMBuf;
-
-typedef struct DSMTile {
-	TCS_Tile tile;
-	void *dsmdata;
-	int x, y;
-} DSMTile;
-
-static void dsm_loadtile(TCS_Tile *self, FILE *file, unsigned long start)
-{
-}
-
-static void dsm_savetile(TCS_Tile *self, FILE *file, unsigned long curpos)
-{
-}
-
-static void dsm_maketiles(TCS_TileBuffer *self, TCS_TilePool *pool)
-{
-	DSMTile *tile;
-	DSMBuf *buf = (DSMBuf*)self;
-	int i;
-	
-	for (i=0, tile=buf->tiles; i<buf->tottilex*buf->tottiley; buf++, i++) {
-		buf->tile.loadFromCache = dsm_loadtile;
-		buf->tile.saveToCache = dsm_savetile;
-		buf->pool = pool;
-		buf->buffer = self;
-	}
-}
-
-static void dsm_freebuffer(TCS_TileBuffer *self)
-{
-	DSMBuf *buf = (DSMBuf*)self;
-	MEM_freeN(buf->tiles);
-	
-	/*FIXMEGREP: ToDo: figure out if actual deep shadow map data 
-	  should be freed here or not
-	 */
-}
-
-static void dsm_gettile(TCS_TileBuffer *self, int x, int y)
-{
-	DSMBuf *buf = (DSMBuf*)self;
-	return buf->tiles[y*buf->sizex+x];
-}
-
-static struct TCS_TileBuffer *dsm_newbuffer(int tsizex, tsizey, sizex, sizey)
-{
-	DSMBuf *buf = MEM_callocN(sizeof(DSMBuf), "DSMBuf");
-	
-	buf->tottilex = sizex / tsizex;
-	buf->tottiley = sizey / tsizey;
-	
-	buf->tilesizex = tsizex;
-	buf->tilesizey = tsizey;
-	
-	buf->sizex = sizex;
-	buf->sizey = sizey;
-	
-	buf->tiles = MEM_callocN(sizeof(DSMTile)*buf->tottilex*buf->tottiley, "DSMTile array");
-}
-
-TCS_TileBuffer TCS_DeepShadowBuffer = {
-	NULL, NULL,
-	dsm_newbuffer,
-	dsm_maketiles,
-	dsm_freebuffer,
-	dsm_gettile,
-	0
-};
-
-/*Image buffer implementation*/
-
-#define TYPE_UBYTE1	0
-#define TYPE_UBYTE3	1
-#define TYPE_UBYTE4	2
-#define TYPE_FLOAT1	3
-#define TYPE_FLOAT3	4
-#define TYPE_FLOAT4	5
-
-int type_totchannels[] = {
-	1,
-	3,
-	4,
-	1,
-	3,
-	4
-};
-
-int type_sizes[] = {
-	1,
-	3,
-	4,
-	sizeof(float),
-	sizeof(float)*3,
-	sizeof(float)*4)
-};
-
-#define GETARRAY_PIXPTR(width, x, y, arr, type, channels) ((type*)&((char*)arr)[(sizeof(type)*y*sizex+sizeof(type)*x)*sizeof(type)*channels])
-
-/*
-   Utility inline function to fetch a pixel from any image buffer type, 
-   convert it to a float if necassary, then copy the result into a float
-   array called varname.  Note that the code limits what's copied to 
-   sizeof(varname).
- 
-  heh, this would make a wonderful inline function, I'm sure, but I have no idea how

@@ Diff output truncated at 10240 characters. @@




More information about the Bf-blender-cvs mailing list