Page MenuHomec4science

pmcontribcache.c
No OneTemporary

File Metadata

Created
Tue, Sep 17, 16:36

pmcontribcache.c

#ifndef lint
static const char RCSid[] = "$Id$";
#endif
/*
=========================================================================
Routines to cache decoded bins from precomputed contribution photons.
Derived from ooccache.c
Roland Schregle (roland.schregle@{hslu.ch, gmail.com})
(c) Lucerne University of Applied Sciences and Arts,
supported by the Swiss National Science Foundation
(SNSF #179067, "Light Fields for Spatio-Temporal Glare Assessment")
=========================================================================
$Id$
*/
#include "pmapcontrib.h"
#ifdef PMAP_CONTRIB
#include "pmcontribcache.h"
OOC_Cache *initContribCache (PreComputedContrib *preCompContrib)
/* Initialise cache for precomputed contribution photons. Returns pointer to
* allocated and initialised cache in preCompContrib -> cache, or NULL if
* caching is disabled */
{
static char warn = 1;
if (!preCompContrib -> cache) {
if (pmapCacheSize > 0) {
/* Allocate cache pages for contribution bins */
const unsigned numPages = pmapCacheSize / preCompContrib -> nBins;
/* As far as the OOC_Cache is concerned, a cached "record" consists
* of a set of bins associated with a single photon */
if (!(preCompContrib -> cache = malloc(sizeof(OOC_Cache))) ||
OOC_CacheInit(preCompContrib -> cache, numPages, 1,
preCompContrib -> nBins * sizeof(DCOLOR)
)
)
error(SYSTEM, "failed to init contribution photon cache");
}
else {
if (warn) {
/* Caching disabled; issue one-shot warning */
error(WARNING, "contribution photon cache DISABLED");
warn = 0;
}
return NULL;
}
}
return preCompContrib -> cache;
}
int getContribCache (const PreComputedContrib *preCompContrib,
OOC_DataIdx idx, DCOLOR **contribBins
)
/* Retrieve cached bins for contribution photon with unique index idx.
Returns pointer contribBins to the cached bins or NULL if caching failed.
Returns 1 if the bins were already cached, else 0, indicating the bins
must be populated by the caller. */
{
OOC_Cache *cache;
unsigned long lastNumHits;
if (!contribBins || !preCompContrib ||
!(cache = preCompContrib -> cache)
) {
/* Junk params or caching disabled; return NULL pointer */
*contribBins = NULL;
return 0;
}
/* Caching enabled; retrieve (potentially new) bins from page table */
lastNumHits = cache -> numHits;
if (!(*contribBins = OOC_CacheData(cache, NULL, idx)))
return 0;
/* Check if OOC_CacheData() incremented the cache hit counter,
* indicating to caller whether the bins were already in the cache */
return cache -> numHits != lastNumHits;
}
#endif /* PMAP_CONTRIB */

Event Timeline