--- ray/src/rt/preload.c 2013/11/08 17:11:42 2.13 +++ ray/src/rt/preload.c 2024/08/21 20:42:20 2.18 @@ -1,5 +1,5 @@ #ifndef lint -static const char RCSid[] = "$Id: preload.c,v 2.13 2013/11/08 17:11:42 greg Exp $"; +static const char RCSid[] = "$Id: preload.c,v 2.18 2024/08/21 20:42:20 greg Exp $"; #endif /* * Preload associated object structures to maximize memory sharing. @@ -19,7 +19,9 @@ static const char RCSid[] = "$Id: preload.c,v 2.13 201 #include "func.h" #include "bsdf.h" +char *shm_boundary = NULL; /* boundary of shared memory */ + /* KEEP THIS ROUTINE CONSISTENT WITH THE DIFFERENT OBJECT FUNCTIONS! */ @@ -28,8 +30,11 @@ load_os( /* load associated data for object */ OBJREC *op ) { - DATARRAY *dp; + DATARRAY *dp; + SDData *sd; + SDretainSet = SDretainAll; + switch (op->otype) { case OBJ_FACE: /* polygon */ getface(op); @@ -54,6 +59,8 @@ load_os( /* load associated data for object */ getfunc(op, 4, 0x3<<5, 0); return(1); case PAT_CDATA: /* color data */ + if (op->oargs.nsargs < 4) + goto sargerr; dp = getdata(op->oargs.sarg[3]); getdata(op->oargs.sarg[4]); getdata(op->oargs.sarg[5]); @@ -71,6 +78,26 @@ load_os( /* load associated data for object */ case PAT_CFUNC: /* color function */ getfunc(op, 3, 0x7, 0); return(1); + case PAT_SPECFUNC: /* spectral function */ + getfunc(op, 1, 0, 0); + return(1); + case PAT_SPECFILE: /* spectrum file */ + if (op->oargs.nsargs < 1) + goto sargerr; + getdata(op->oargs.sarg[0]); + return(1); + case PAT_SPECDATA: /* spectral data file */ + if (op->oargs.nsargs < 2) + goto sargerr; + dp = getdata(op->oargs.sarg[1]); + getfunc(op, 2, ((1<<(dp->nd-1)) - 1)<<3, 0); + return(1); + case PAT_SPECPICT: /* spectral picture */ + if (op->oargs.nsargs < 2) + goto sargerr; + getspec(op->oargs.sarg[1]); + getfunc(op, 2, 0x3<<3, 0); + return(1); case TEX_DATA: /* texture data */ if (op->oargs.nsargs < 6) goto sargerr; @@ -104,8 +131,16 @@ load_os( /* load associated data for object */ if (op->oargs.nsargs < 6) goto sargerr; getfunc(op, 5, 0x1d, 1); - loadBSDF(op->oargs.sarg[1]); + sd = loadBSDF(op->oargs.sarg[1]); + if (sd != NULL) SDfreeCache(sd); return(1); + case MAT_ABSDF: /* aBSDF material */ + if (op->oargs.nsargs < 5) + goto sargerr; + getfunc(op, 4, 0xe, 1); + sd = loadBSDF(op->oargs.sarg[0]); + if (sd != NULL) SDfreeCache(sd); + return(1); case MAT_PDATA: /* plastic BRDF data */ case MAT_MDATA: /* metal BRDF data */ case MAT_TDATA: /* trans BRDF data */ @@ -141,4 +176,28 @@ preload_objs(void) /* preload object data structures /* note that nobjects may change during loop */ for (on = 0; on < nobjects; on++) load_os(objptr(on)); +} + + +void +cow_memshare(void) /* set up copy-on-write memory sharing */ +{ + if (shm_boundary != NULL) + return; /* assume we're good */ + + preload_objs(); /* preload auxiliary data */ + /* set shared memory boundary */ + shm_boundary = (char *)malloc(16); + strcpy(shm_boundary, "SHM_BOUNDARY"); +} + + +void +cow_doneshare(void) /* clear memory sharing boundary */ +{ + if (shm_boundary == NULL) + return; + /* clear shared memory boundary */ + free((void *)shm_boundary); + shm_boundary = NULL; }