|
From: <kin...@us...> - 2004-02-29 13:52:57
|
Update of /cvsroot/teem/teem/src/mite In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv1831 Modified Files: kindnot.c mite.h ray.c renderMite.c shade.c thread.c txf.c user.c Log Message: attempt to fix and optimize computation of the miteVals per-thread Index: kindnot.c =================================================================== RCS file: /cvsroot/teem/teem/src/mite/kindnot.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** kindnot.c 26 Feb 2004 06:41:18 -0000 1.1 --- kindnot.c 29 Feb 2004 13:42:41 -0000 1.2 *************** *** 109,115 **** /* ! ** again, this is not a true gageKind- mainly because these items ** depend on items in different gageKinds (scalar and vector). So, ! ** the prerequisites here are all blank. Go look in _miteQueryAdd() ** to see these items' true prereqs */ --- 109,115 ---- /* ! ** again, this is not a true gageKind- mainly because these items may ** depend on items in different gageKinds (scalar and vector). So, ! ** the prerequisites here are all blank. Go look in miteQueryAdd() ** to see these items' true prereqs */ Index: mite.h =================================================================== RCS file: /cvsroot/teem/teem/src/mite/mite.h,v retrieving revision 1.27 retrieving revision 1.28 diff -C2 -d -r1.27 -r1.28 *** mite.h 26 Feb 2004 06:26:10 -0000 1.27 --- mite.h 29 Feb 2004 13:42:41 -0000 1.28 *************** *** 220,223 **** --- 220,226 ---- miteShadeSpec *shpec; /* information based on muu->shadeStr */ double time0; /* rendering start time */ + gageQuery queryMite; /* record of the miteVal quantities which + we'll need to compute per-sample */ + int queryMiteNonzero; /* shortcut miteVal computation if possible */ /* as long as there's no mutex around how the miteThreads are *************** *** 318,321 **** --- 321,325 ---- gageContext *gctx; /* per-thread context */ gage_t *ansScl, /* pointer to gageKindScl answer vector */ + *nPerp, *geomTens, /* convenience pointers into ansScl */ *ansVec, /* pointer to gageKindVec answer vector */ *ansTen, /* pointer to tenGageKind answer vector */ *************** *** 323,326 **** --- 327,331 ---- unlike ans{Scl,Vec,Ten} is allocated by mite instead of by gage */ + **directAnsMiteVal, /* pointers into ansMiteVal */ *shadeVec0, *shadeVec1, *shadeScl0, *shadeScl1; /* pointers into the ans* arrays above, *************** *** 359,365 **** TEEM_API void miteVariablePrint(char *buff, const gageItemSpec *isp); TEEM_API int miteNtxfCheck(const Nrrd *ntxf); ! TEEM_API void miteQueryAdd(gageQuery queryScl, ! gageQuery queryVec, ! gageQuery queryTen, gageItemSpec *isp); --- 364,370 ---- TEEM_API void miteVariablePrint(char *buff, const gageItemSpec *isp); TEEM_API int miteNtxfCheck(const Nrrd *ntxf); ! TEEM_API void miteQueryAdd(gageQuery queryScl, gageQuery queryVec, ! gageQuery queryTen, gageQuery queryMite, ! gageItemSpec *isp); *************** *** 373,379 **** TEEM_API int miteShadeSpecParse(miteShadeSpec *shpec, char *shadeStr); TEEM_API void miteShadeSpecPrint(char *buff, const miteShadeSpec *shpec); ! TEEM_API void miteShadeSpecQueryAdd(gageQuery queryScl, ! gageQuery queryVec, ! gageQuery queryTen, miteShadeSpec *shpec); /* renderMite.c */ --- 378,384 ---- TEEM_API int miteShadeSpecParse(miteShadeSpec *shpec, char *shadeStr); TEEM_API void miteShadeSpecPrint(char *buff, const miteShadeSpec *shpec); ! TEEM_API void miteShadeSpecQueryAdd(gageQuery queryScl, gageQuery queryVec, ! gageQuery queryTen, gageQuery queryMite, ! miteShadeSpec *shpec); /* renderMite.c */ Index: ray.c =================================================================== RCS file: /cvsroot/teem/teem/src/mite/ray.c,v retrieving revision 1.18 retrieving revision 1.19 diff -C2 -d -r1.18 -r1.19 *** ray.c 26 Feb 2004 06:26:10 -0000 1.18 --- ray.c 29 Feb 2004 13:42:41 -0000 1.19 *************** *** 138,146 **** } if (1-mtt->TT >= muu->opacNear1) { - /* early ray termination */ mtt->TT = 0.0; return 0.0; } mtt->samples += 1; if (gageProbe(mtt->gctx, --- 138,149 ---- } + /* early ray termination */ if (1-mtt->TT >= muu->opacNear1) { mtt->TT = 0.0; return 0.0; } + + /* do probing at this location to determine values of everything + that might appear in the txf domain */ mtt->samples += 1; if (gageProbe(mtt->gctx, *************** *** 149,186 **** biffAdd(MITE, err); return AIR_NAN; } ! /* HEY: NONE of this should be done if the txfs don't need any miteVal */ ! mtt->ansMiteVal[miteValXw] = samplePosWorld[0]; ! mtt->ansMiteVal[miteValXi] = samplePosIndex[0]; ! mtt->ansMiteVal[miteValYw] = samplePosWorld[1]; ! mtt->ansMiteVal[miteValYi] = samplePosIndex[1]; ! mtt->ansMiteVal[miteValZw] = samplePosWorld[2]; ! mtt->ansMiteVal[miteValZi] = samplePosIndex[2]; ! mtt->ansMiteVal[miteValTw] = rayT; ! mtt->ansMiteVal[miteValTi] = num; ! #if 0 ! what if shading is none? ! mtt->ansMiteVal[miteValNdotV] = ! -muu->normalSide*ELL_3V_DOT(mtt->V, mtt->shadeVec0); ! mtt->ansMiteVal[miteValNdotL] = ! -muu->normalSide*ELL_3V_DOT(mtt->shadeVec0, muu->lit->dir[0]); ! #endif ! if (!muu->normalSide) { ! mtt->ansMiteVal[miteValNdotV] = AIR_ABS(mtt->ansMiteVal[miteValNdotV]); ! mtt->ansMiteVal[miteValNdotL] = AIR_ABS(mtt->ansMiteVal[miteValNdotL]); } - - #if 0 - this is bullshit - - ELL_3MV_MUL(kn, mtt->nPerp, mtt->V); - ELL_3V_NORM(kn, kn, len); - ELL_3MV_MUL(knd, mtt->gten, kn); - mtt->ansMiteVal[miteValGTdotV] = ELL_3V_DOT(knd, kn); - #endif memcpy(mtt->range, muu->rangeInit, MITE_RANGE_NUM*sizeof(mite_t)); _miteStageRun(mtt); if (mtt->range[miteRangeAlpha]) { /* fprintf(stderr, "%s: mtt->TT = %g\n", me, mtt->TT); */ --- 152,197 ---- biffAdd(MITE, err); return AIR_NAN; } ! if (mrr->queryMiteNonzero) { ! /* There is some optimal trade-off between slowing things down ! with too many branches on all possible checks of queryMite, ! and slowing things down with doing the work of setting them all. ! This code has not been profiled whatsoever */ ! mtt->directAnsMiteVal[miteValXw][0] = samplePosWorld[0]; ! mtt->directAnsMiteVal[miteValXi][0] = samplePosIndex[0]; ! mtt->directAnsMiteVal[miteValYw][0] = samplePosWorld[1]; ! mtt->directAnsMiteVal[miteValYi][0] = samplePosIndex[1]; ! mtt->directAnsMiteVal[miteValZw][0] = samplePosWorld[2]; ! mtt->directAnsMiteVal[miteValZi][0] = samplePosIndex[2]; ! mtt->directAnsMiteVal[miteValTw][0] = rayT; ! mtt->directAnsMiteVal[miteValTi][0] = num; ! if (mtt->shadeVec0 && ! (GAGE_QUERY_ITEM_TEST(mrr->queryMite, miteValNdotV) ! || GAGE_QUERY_ITEM_TEST(mrr->queryMite, miteValNdotL))) { ! mtt->directAnsMiteVal[miteValNdotV][0] = ! -muu->normalSide*ELL_3V_DOT(mtt->shadeVec0, mtt->V); ! mtt->directAnsMiteVal[miteValNdotL][0] = ! -muu->normalSide*ELL_3V_DOT(mtt->shadeVec0, muu->lit->dir[0]); ! if (!muu->normalSide) { ! mtt->directAnsMiteVal[miteValNdotV][0] = ! AIR_ABS(mtt->directAnsMiteVal[miteValNdotV][0]); ! mtt->directAnsMiteVal[miteValNdotL][0] = ! AIR_ABS(mtt->directAnsMiteVal[miteValNdotL][0]); ! } ! } ! if (GAGE_QUERY_ITEM_TEST(mrr->queryMite, miteValGTdotV)) { ! ELL_3MV_MUL(kn, mtt->nPerp, mtt->V); ! ELL_3V_NORM(kn, kn, len); ! ELL_3MV_MUL(knd, mtt->geomTens, kn); ! mtt->ansMiteVal[miteValGTdotV] = ELL_3V_DOT(knd, kn); ! } } + /* initialize txf range quantities, and apply all txfs */ memcpy(mtt->range, muu->rangeInit, MITE_RANGE_NUM*sizeof(mite_t)); _miteStageRun(mtt); + + /* if there's opacity, do shading and compositing */ if (mtt->range[miteRangeAlpha]) { /* fprintf(stderr, "%s: mtt->TT = %g\n", me, mtt->TT); */ Index: renderMite.c =================================================================== RCS file: /cvsroot/teem/teem/src/mite/renderMite.c,v retrieving revision 1.11 retrieving revision 1.12 diff -C2 -d -r1.11 -r1.12 *** renderMite.c 26 Feb 2004 06:26:10 -0000 1.11 --- renderMite.c 29 Feb 2004 13:42:41 -0000 1.12 *************** *** 34,43 **** mrr->ntxf = NULL; mrr->ntxfNum = 0; - mrr->shpec = miteShadeSpecNew(); mrr->sclPvlIdx = -1; mrr->vecPvlIdx = -1; mrr->tenPvlIdx = -1; airMopAdd(mrr->rmop, mrr->shpec, (airMopper)miteShadeSpecNix, airMopAlways); } return mrr; --- 34,46 ---- mrr->ntxf = NULL; mrr->ntxfNum = 0; mrr->sclPvlIdx = -1; mrr->vecPvlIdx = -1; mrr->tenPvlIdx = -1; + mrr->shpec = miteShadeSpecNew(); airMopAdd(mrr->rmop, mrr->shpec, (airMopper)miteShadeSpecNix, airMopAlways); + mrr->time0 = AIR_NAN; + GAGE_QUERY_RESET(mrr->queryMite); + mrr->queryMiteNonzero = AIR_FALSE; } return mrr; *************** *** 82,93 **** GAGE_QUERY_RESET(queryVec); GAGE_QUERY_RESET(queryTen); for (T=0; T<muu->ntxfNum; T++) { for (axi=1; axi<muu->ntxf[T]->dim; axi++) { miteVariableParse(&isp, muu->ntxf[T]->axis[axi].label); ! miteQueryAdd(queryScl, queryVec, queryTen, &isp); } } miteShadeSpecParse((*mrrP)->shpec, muu->shadeStr); ! miteShadeSpecQueryAdd(queryScl, queryVec, queryTen, (*mrrP)->shpec); E = 0; --- 85,99 ---- GAGE_QUERY_RESET(queryVec); GAGE_QUERY_RESET(queryTen); + GAGE_QUERY_RESET((*mrrP)->queryMite); for (T=0; T<muu->ntxfNum; T++) { for (axi=1; axi<muu->ntxf[T]->dim; axi++) { miteVariableParse(&isp, muu->ntxf[T]->axis[axi].label); ! miteQueryAdd(queryScl, queryVec, queryTen, (*mrrP)->queryMite, &isp); } } miteShadeSpecParse((*mrrP)->shpec, muu->shadeStr); ! miteShadeSpecQueryAdd(queryScl, queryVec, queryTen, (*mrrP)->queryMite, ! (*mrrP)->shpec); ! (*mrrP)->queryMiteNonzero = GAGE_QUERY_NONZERO((*mrrP)->queryMite); E = 0; Index: shade.c =================================================================== RCS file: /cvsroot/teem/teem/src/mite/shade.c,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** shade.c 26 Feb 2004 06:41:18 -0000 1.1 --- shade.c 29 Feb 2004 13:42:41 -0000 1.2 *************** *** 193,199 **** void ! miteShadeSpecQueryAdd(gageQuery queryScl, ! gageQuery queryVec, ! gageQuery queryTen, miteShadeSpec *shpec) { if (shpec) { switch(shpec->method) { --- 193,199 ---- void ! miteShadeSpecQueryAdd(gageQuery queryScl, gageQuery queryVec, ! gageQuery queryTen, gageQuery queryMite, ! miteShadeSpec *shpec) { if (shpec) { switch(shpec->method) { *************** *** 202,212 **** break; case miteShadeMethodPhong: ! miteQueryAdd(queryScl, queryVec, queryTen, shpec->vec0); break; case miteShadeMethodLitTen: ! miteQueryAdd(queryScl, queryVec, queryTen, shpec->vec0); ! miteQueryAdd(queryScl, queryVec, queryTen, shpec->vec1); ! miteQueryAdd(queryScl, queryVec, queryTen, shpec->scl0); ! miteQueryAdd(queryScl, queryVec, queryTen, shpec->scl1); break; default: --- 202,212 ---- break; case miteShadeMethodPhong: ! miteQueryAdd(queryScl, queryVec, queryTen, queryMite, shpec->vec0); break; case miteShadeMethodLitTen: ! miteQueryAdd(queryScl, queryVec, queryTen, queryMite, shpec->vec0); ! miteQueryAdd(queryScl, queryVec, queryTen, queryMite, shpec->vec1); ! miteQueryAdd(queryScl, queryVec, queryTen, queryMite, shpec->scl0); ! miteQueryAdd(queryScl, queryVec, queryTen, queryMite, shpec->scl1); break; default: Index: thread.c =================================================================== RCS file: /cvsroot/teem/teem/src/mite/thread.c,v retrieving revision 1.10 retrieving revision 1.11 diff -C2 -d -r1.10 -r1.11 *** thread.c 26 Feb 2004 06:26:10 -0000 1.10 --- thread.c 29 Feb 2004 13:42:41 -0000 1.11 *************** *** 23,40 **** miteThread * miteThreadNew() { miteThread *mtt; mtt = (miteThread *)calloc(1, sizeof(miteThread)); if (!mtt) { ! return NULL; } mtt->gctx = NULL; mtt->ansScl = mtt->ansVec = mtt->ansTen = NULL; ! mtt->shadeVec0 = mtt->shadeVec1 = NULL; ! mtt->shadeScl0 = mtt->shadeScl1 = NULL; mtt->ansMiteVal = (gage_t *)calloc(gageKindTotalAnswerLength(miteValGageKind), sizeof(gage_t)); mtt->verbose = 0; mtt->thrid = -1; --- 23,57 ---- miteThread * miteThreadNew() { + char me[]="miteThreadNew", err[AIR_STRLEN_MED]; miteThread *mtt; + int ii; mtt = (miteThread *)calloc(1, sizeof(miteThread)); if (!mtt) { ! sprintf(err, "%s: couldn't calloc miteThread", me); ! biffAdd(MITE, err); return NULL; } mtt->gctx = NULL; mtt->ansScl = mtt->ansVec = mtt->ansTen = NULL; ! mtt->shadeVec0 = NULL; ! mtt->shadeVec1 = NULL; ! mtt->shadeScl0 = NULL; ! mtt->shadeScl1 = NULL; ! /* were miteVal a full-fledged gageKind, the following would ! be done by gagePerVolumeNew */ mtt->ansMiteVal = (gage_t *)calloc(gageKindTotalAnswerLength(miteValGageKind), sizeof(gage_t)); + mtt->directAnsMiteVal = + (gage_t **)calloc(miteValGageKind->itemMax+1, sizeof(gage_t*)); + if (!(mtt->ansMiteVal && mtt->directAnsMiteVal)) { + sprintf(err, "%s: couldn't calloc miteVal answer arrays", me); + biffAdd(MITE, err); return NULL; + } + for (ii=0; ii<=miteValGageKind->itemMax; ii++) { + mtt->directAnsMiteVal[ii] = mtt->ansMiteVal + + gageKindAnswerOffset(miteValGageKind, ii); + } mtt->verbose = 0; mtt->thrid = -1; *************** *** 81,87 **** } ! (*mttP)->ansScl = (-1 != mrr->sclPvlIdx ! ? (*mttP)->gctx->pvl[mrr->sclPvlIdx]->answer ! : NULL); (*mttP)->ansVec = (-1 != mrr->vecPvlIdx ? (*mttP)->gctx->pvl[mrr->vecPvlIdx]->answer --- 98,112 ---- } ! if (-1 != mrr->sclPvlIdx) { ! (*mttP)->ansScl = (*mttP)->gctx->pvl[mrr->sclPvlIdx]->answer; ! (*mttP)->nPerp = ((*mttP)->ansScl ! + gageKindAnswerOffset(gageKindScl, gageSclNPerp)); ! (*mttP)->geomTens = ((*mttP)->ansScl ! + gageKindAnswerOffset(gageKindScl, gageSclGeomTens)); ! } else { ! (*mttP)->ansScl = NULL; ! (*mttP)->nPerp = NULL; ! (*mttP)->geomTens = NULL; ! } (*mttP)->ansVec = (-1 != mrr->vecPvlIdx ? (*mttP)->gctx->pvl[mrr->vecPvlIdx]->answer *************** *** 90,99 **** ? (*mttP)->gctx->pvl[mrr->tenPvlIdx]->answer : NULL); - - #if 0 - (*mttP)->nPerp = (*mttP)->ans + gageKindScl->ansOffset[gageSclNPerp]; - (*mttP)->gten = (*mttP)->ans + gageKindScl->ansOffset[gageSclGeomTens]; - #endif - (*mttP)->thrid = whichThread; (*mttP)->samples = 0; --- 115,118 ---- Index: txf.c =================================================================== RCS file: /cvsroot/teem/teem/src/mite/txf.c,v retrieving revision 1.17 retrieving revision 1.18 diff -C2 -d -r1.17 -r1.18 *** txf.c 28 Feb 2004 15:11:05 -0000 1.17 --- txf.c 29 Feb 2004 13:42:42 -0000 1.18 *************** *** 270,278 **** ** up explicitly depending on the libraries supplying those gageKinds ** (like how mite now must depend on ten) */ void ! miteQueryAdd(gageQuery queryScl, ! gageQuery queryVec, ! gageQuery queryTen, gageItemSpec *isp) { char me[]="miteQueryAdd"; --- 270,282 ---- ** up explicitly depending on the libraries supplying those gageKinds ** (like how mite now must depend on ten) + ** + ** The queryMite argument is a little odd- its not a real gage kind, + ** but we use it to organize which of the miteVal quantities we take + ** the time to compute in miteSample(). */ void ! miteQueryAdd(gageQuery queryScl, gageQuery queryVec, ! gageQuery queryTen, gageQuery queryMite, ! gageItemSpec *isp) { char me[]="miteQueryAdd"; *************** *** 284,287 **** --- 288,295 ---- GAGE_QUERY_ITEM_ON(queryTen, isp->item); } else if (miteValGageKind == isp->kind) { + /* regardless of whether the mite query requires scl, vec, or ten + queries, we add it to the quantites that have to be computed + per-sample */ + GAGE_QUERY_ITEM_ON(queryMite, isp->item); /* HEY: some these have useful analogs for tensor data, but I won't be able to express them. This means that while Phong Index: user.c =================================================================== RCS file: /cvsroot/teem/teem/src/mite/user.c,v retrieving revision 1.15 retrieving revision 1.16 diff -C2 -d -r1.15 -r1.16 *** user.c 26 Feb 2004 06:26:10 -0000 1.15 --- user.c 29 Feb 2004 13:42:42 -0000 1.16 *************** *** 78,82 **** int T, axi, gotOpac; gageItemSpec isp; ! gageQuery queryScl, queryVec, queryTen; miteShadeSpec *shpec; airArray *mop; --- 78,82 ---- int T, axi, gotOpac; gageItemSpec isp; ! gageQuery queryScl, queryVec, queryTen, queryMite; miteShadeSpec *shpec; airArray *mop; *************** *** 95,98 **** --- 95,99 ---- GAGE_QUERY_RESET(queryVec); GAGE_QUERY_RESET(queryTen); + GAGE_QUERY_RESET(queryMite); /* not actually used here */ for (T=0; T<muu->ntxfNum; T++) { if (miteNtxfCheck(muu->ntxf[T])) { *************** *** 104,108 **** for (axi=1; axi<muu->ntxf[T]->dim; axi++) { miteVariableParse(&isp, muu->ntxf[T]->axis[axi].label); ! miteQueryAdd(queryScl, queryVec, queryTen, &isp); } gotOpac |= !!strchr(muu->ntxf[T]->axis[0].label, 'A'); --- 105,109 ---- for (axi=1; axi<muu->ntxf[T]->dim; axi++) { miteVariableParse(&isp, muu->ntxf[T]->axis[axi].label); ! miteQueryAdd(queryScl, queryVec, queryTen, queryMite, &isp); } gotOpac |= !!strchr(muu->ntxf[T]->axis[0].label, 'A'); *************** *** 123,127 **** biffAdd(MITE, err); airMopError(mop); return 1; } ! miteShadeSpecQueryAdd(queryScl, queryVec, queryTen, shpec); if (GAGE_QUERY_NONZERO(queryScl) && !(muu->nsin)) { sprintf(err, "%s: txf or shading require %s volume, but don't have one", --- 124,128 ---- biffAdd(MITE, err); airMopError(mop); return 1; } ! miteShadeSpecQueryAdd(queryScl, queryVec, queryTen, queryMite, shpec); if (GAGE_QUERY_NONZERO(queryScl) && !(muu->nsin)) { sprintf(err, "%s: txf or shading require %s volume, but don't have one", |