Page Menu
Home
c4science
Search
Configure Global Search
Log In
Files
F83536917
pmcontribcache.c
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Subscribers
None
File Metadata
Details
File Info
Storage
Attached
Created
Tue, Sep 17, 16:36
Size
2 KB
Mime Type
text/x-c
Expires
Thu, Sep 19, 16:36 (2 d)
Engine
blob
Format
Raw Data
Handle
20853927
Attached To
R10977 RADIANCE Photon Map
pmcontribcache.c
View Options
#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
Log In to Comment