[Bf-blender-cvs] SVN commit: /data/svn/bf-blender [11935] branches/soc-2007-joeedh/source/ blender: Tiling cache system works again, though there may be quirks.
Joseph Eagar
joeedh at gmail.com
Tue Sep 4 06:59:13 CEST 2007
Revision: 11935
http://projects.blender.org/plugins/scmsvn/viewcvs.php?view=rev&root=bf-blender&revision=11935
Author: joeedh
Date: 2007-09-04 06:59:13 +0200 (Tue, 04 Sep 2007)
Log Message:
-----------
Tiling cache system works again, though there may be quirks.
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/blenkernel/intern/tcs_dsm.c
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
Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h 2007-09-03 20:57:12 UTC (rev 11934)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_dsm.h 2007-09-04 04:59:13 UTC (rev 11935)
@@ -10,7 +10,7 @@
int depth;
/*original number of samples between this layer and the previous one.*/
- int orig_totsamples;
+ unsigned short orig_totsamples;
} DSMLayerSample;
#define MAX_DSMLAYERS 16
@@ -74,7 +74,13 @@
} DSMBuffer;
#define MAX_SAMPLELAYERS 32
+#define DSM_FINAL_TILESIZE 25
+#define DSM_TILE_MEMARENASIZE (1<<18)
+/*little bit smaller memarena buffer size for the final diced
+ 25x25 tiles*/
+#define DSM_TILE_FINALMEMARENASIZE (1<<16)
+
/*private*/
/*ok, this was meant for using TCS_MakeBuffer, but that's kindof a bad idea really so
instead the dsm creation function uses TCS_InitBuffer*/
Modified: branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h
===================================================================
--- branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h 2007-09-03 20:57:12 UTC (rev 11934)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/BKE_tile.h 2007-09-04 04:59:13 UTC (rev 11935)
@@ -75,8 +75,6 @@
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, totallocated;
} TCS_File;
@@ -92,8 +90,11 @@
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);
+ /*returns amount size of diskspace the uncompressed tile would take, in bytes*/
+ unsigned int (*getTileLen)(struct TCS_Tile *self);
+
+ /*returns a pointer to pixel data for this tile. note that this is not
+ required to be implemented, for example dsm's don't have it.*/
void *(*getTilePixel)(struct TCS_Tile *self, int x, int y, int z);
/*length of uncompressed tile in memory.
@@ -107,8 +108,11 @@
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*/
+ int filepos;
+ /*len is for caching the tile len, to avoid constantly recalculating the size*/
+ int len;
+
struct TCS_TilePool *pool;
struct TCS_TileBuffer *buffer; /*parent buffer*/
} TCS_Tile;
@@ -221,6 +225,6 @@
#define BASSERT(eval) if (!(eval)) printf("\nassert \"%s\" in file:\n%s\n on line %d failed.\n\n", #eval, __FILE__, __LINE__)
-//#define TCSDEBUG
+#define TCSDEBUG
#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 2007-09-03 20:57:12 UTC (rev 11934)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_cache.c 2007-09-04 04:59:13 UTC (rev 11935)
@@ -341,8 +341,8 @@
TCS_Tile *tile, *prev;
unsigned long mem, memconfirm, i=0;
- /*disable cacher for now*/
- return;
+ // /*disable cacher for now*/
+ //return;
BASSERT(pool);
if (!pool) return;
@@ -374,8 +374,11 @@
printf("Eek! tile system wanted to cache the entire tile memory pool!\n");
break;
}
+
+ /*calculate tile filesize on disk, if its not already calculated. . */
+ if (tile->len == 0) tile->len = tile->getTileLen(tile);
- if (tile->len == 0) tile->len = tile->getTileMem(tile);
+ /*subtract memory used for this tile*/
mem -= tile->mem_used;
#ifdef TCSDEBUG
@@ -411,11 +414,10 @@
}
/*paranoia check*/
BASSERT(tile->len == tile->compressed_memfile->length);
- if (tile->len != tile->compressed_memfile->length) printf("dsm tile size calculation function gave bad results! %d %d\n", (int)tile->len, (int)tile->compressed_memfile->length);
- //tile->len = tile->compressed_memfile->length;
+ if (tile->len != tile->compressed_memfile->length) printf("dsm tile size calculation function gave bad results! tlen: %d memfilelen: %d\n", (int)tile->len, (int)tile->compressed_memfile->length);
TCS_CompressMemFile(tile->compressed_memfile);
- //BASSERT(tile->compressed_memfile->length != tile->len);
+
#ifdef TCSDEBUG
printf("compressed tile length: %lud, uncompressed length: %d\n", tile->compressed_memfile->length, tile->len);
#endif
@@ -446,9 +448,7 @@
TCS_fflush(tile->file);
}
- /*error occured, load the tile back from the memfile.
- NOTE: Remember to account for compression for this
- when you write the compression code!*/
+ /*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 2007-09-03 20:57:12 UTC (rev 11934)
+++ branches/soc-2007-joeedh/source/blender/blenkernel/intern/tcs_dsm.c 2007-09-04 04:59:13 UTC (rev 11935)
@@ -55,22 +55,50 @@
#define DSM_MAGICNUM ('D' | ('S' << 8) | ('H' << 16) | ('D' << 24)) //"DSHD"
+static void dsm_loadfunc(TCS_File *file, DSMTile *tile, int totsamples, int x, int y, int clr)
+{
+ DSMFunction *func;
+ DSMLayerSample *sample;
+ unsigned short value;
+ int i;
+
+ func = BLI_memarena_alloc(tile->arena, sizeof(DSMFunction));
+ func->samples = sample = BLI_memarena_alloc(tile->arena, sizeof(DSMLayerSample)*totsamples);
+ func->totsamples = totsamples;
+
+ for (i=0; i<totsamples; i++, sample++) {
+ TCS_fread(&value, sizeof(unsigned short), 1, file);
+ sample->value = ((float)value)/65535.0f;
+ TCS_fread(&sample->orig_totsamples, sizeof(unsigned short), 1, file);
+ TCS_fread(&sample->depth, sizeof(unsigned int), 1, file);
+ }
+
+ switch (clr) {
+ case 0:
+ tile->r_rect[y*tile->sizex+x] = func;
+ break;
+ case 1:
+ tile->g_rect[y*tile->sizex+x] = func;
+ break;
+ case 2:
+ tile->b_rect[y*tile->sizex+x] = func;
+ break;
+ }
+}
+
static void dsm_loadtile(TCS_Tile *tself, TCS_File *file)
{
DSMTile *self = (DSMTile*) tself;
- DSMLayerSample *sample;
- unsigned short sclr[4];
- unsigned int totdepth;
- int x, y, i, j, tot=0, magic;
+ int x, y, i, tot=0, totf, magic;
BASSERT(tself && file);
- self->arena = BLI_memarena_new(1<<18);
+ self->arena = BLI_memarena_new(DSM_TILE_MEMARENASIZE);
BLI_memarena_use_mapalloc(self->arena);
- self->layer_rect = BLI_memarena_alloc(self->arena, sizeof(void*)*self->sizex*self->sizey);
+ self->r_rect = BLI_memarena_alloc(self->arena, sizeof(void*)*self->sizex*self->sizey);
+ self->g_rect = BLI_memarena_alloc(self->arena, sizeof(void*)*self->sizex*self->sizey);
+ self->b_rect = BLI_memarena_alloc(self->arena, sizeof(void*)*self->sizex*self->sizey);
- memset(self->layer_rect, 0, sizeof(void*)*self->sizex*self->sizey);
-
TCS_fread(&magic, sizeof(int), 1, file);
if (magic != DSM_MAGICNUM) {
printf("EVIL! Corrupted DSM data! id: %c%c%c%c", ((char*)&magic)[0], ((char*)&magic)[1], ((char*)&magic)[2], ((char*)&magic)[3]);
@@ -81,54 +109,45 @@
TCS_fread(&tot, sizeof(int), 1, file);
- //printf("loading tile! tot: %d\n", tot);
-
for (i=0; i<tot; i++) {
TCS_fread(&x, sizeof(int), 1, file);
TCS_fread(&y, sizeof(int), 1, file);
- TCS_fread(&totdepth, sizeof(int), 1, file);
-
- //if (i % 50==0) {
- //printf("x: %d, y: %d, totdepth: %d, tot: %d, i %d\n, error: %d\n", x, y, totdepth, tot, i, file->error_occured);
- //fflush(stdout);
- //fflush(stderr);
- //}
-
- sample = self->layer_rect[y*self->sizex+x] = BLI_memarena_alloc(self->arena, sizeof(DSMLayerSample)*(totdepth+1));
- sample[0].depth = totdepth;
-
- sample++;
- for (j=0; j<totdepth; j++, sample++) {
- TCS_fread(&sample->depth, sizeof(int), 1, file);
-
- TCS_fread(sclr, sizeof(unsigned short), 4, file);
- /*sample->clr[0] = ((float)sclr[0]) / 65535.0f;
- sample->clr[1] = ((float)sclr[1]) / 65535.0f;
- sample->clr[2] = ((float)sclr[2]) / 65535.0f;
- sample->clr[3] = ((float)sclr[3]) / 65535.0f;*/
- }
+
+ TCS_fread(&totf, sizeof(int), 1, file);
+ if (totf) dsm_loadfunc(file, self, totf, x, y, 0);
+
+ TCS_fread(&totf, sizeof(int), 1, file);
+ if (totf) dsm_loadfunc(file, self, totf, x, y, 1);
+
+ TCS_fread(&totf, sizeof(int), 1, file);
+ if (totf) dsm_loadfunc(file, self, totf, x, y, 2);
+
}
}
-#ifdef PACK_SHORTFLOAT
-#undef PACK_SHORTFLOAT
-#endif
+static void dsm_savefunction(struct TCS_File *file, DSMFunction *func)
+{
+ int i;
+ unsigned short value;
+ DSMLayerSample *sample = func->samples;
-/*pack colors into shorts*/
-#define PACK_SHORTFLOAT(s, f) s = (f)>1.0f ? 65535 : (f)<0.0 ? 0 : (unsigned short)((f)*65535.0f)
+ for (i=0; i<func->totsamples; i++, sample++) {
+ value = sample->value * 65535.0f;
+ TCS_fwrite(&value, sizeof(unsigned short), 1, file);
+ TCS_fwrite(&sample->orig_totsamples, sizeof(signed short), 1, file);
+ TCS_fwrite(&sample->depth, sizeof(int), 1, file);
+ }
+}
static unsigned int dsm_savetile(struct TCS_Tile *tself, TCS_File *file, unsigned long curpos)
{
DSMTile *self = (DSMTile*) tself;
- DSMLayerSample *sample, *first;
- unsigned short sclr[4];
unsigned long fend;
int x, y, j, tot=0, num;
BASSERT(tself);
BASSERT(file);
- //BASSERT(tself->is_compressed==0 && tself->is_compressed==0); /*the extra && part is just to make it more visible :)*/
-
+
num = DSM_MAGICNUM;
TCS_fwrite(&num, sizeof(int), 1, file);
@@ -143,23 +162,28 @@
if (self->r_rect[y*self->sizex+x] || self->g_rect[y*self->sizex+x] || self->b_rect[y*self->sizex+x]) {
tot++;
- first = self->layer_rect[y*self->sizex+x];
- sample = first + 1;
-
+ j = 0;
+
TCS_fwrite(&x, sizeof(int), 1, file);
TCS_fwrite(&y, sizeof(int), 1, file);
- TCS_fwrite(&first->depth, sizeof(int), 1, file);
+
+ /*write each visibility function. the number of samples is
+ written first, or zero if the function has no samples.*/
+ if (self->r_rect[y*self->sizex+x]) {
+ TCS_fwrite(&self->r_rect[y*self->sizex+x]->totsamples, sizeof(int), 1, file);
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list