diff options
author | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-04 13:58:35 +0400 |
---|---|---|
committer | Brecht Van Lommel <brechtvanlommel@pandora.be> | 2012-05-04 13:58:35 +0400 |
commit | c01aa64247357570e4f469185240a416075bd971 (patch) | |
tree | 05e6f8f4fd6ee269928d101e0de1cbc9eb96c2d5 /source | |
parent | 2823a9a8090c9d063b0d35412266bac2e6cba7c8 (diff) |
Fix: issue in strand render + instancing bugfix, also optimized it a bit to avoid
unnecessary memory allocations.
Diffstat (limited to 'source')
-rw-r--r-- | source/blender/render/intern/include/strand.h | 2 | ||||
-rw-r--r-- | source/blender/render/intern/source/strand.c | 64 | ||||
-rw-r--r-- | source/blender/render/intern/source/zbuf.c | 4 |
3 files changed, 37 insertions, 33 deletions
diff --git a/source/blender/render/intern/include/strand.h b/source/blender/render/intern/include/strand.h index a343278c0ab..7482b4d10ee 100644 --- a/source/blender/render/intern/include/strand.h +++ b/source/blender/render/intern/include/strand.h @@ -101,7 +101,7 @@ void free_strand_surface(struct Render *re); struct StrandShadeCache *strand_shade_cache_create(void); void strand_shade_cache_free(struct StrandShadeCache *cache); void strand_shade_segment(struct Render *re, struct StrandShadeCache *cache, struct StrandSegment *sseg, struct ShadeSample *ssamp, float t, float s, int addpassflag); -void strand_shade_unref(struct StrandShadeCache *cache, struct ObjectInstanceRen *obi, struct StrandRen *strand, struct StrandVert *svert); +void strand_shade_unref(struct StrandShadeCache *cache, struct ObjectInstanceRen *obi, struct StrandVert *svert); #endif diff --git a/source/blender/render/intern/source/strand.c b/source/blender/render/intern/source/strand.c index 7aa114a64dc..29931e16056 100644 --- a/source/blender/render/intern/source/strand.c +++ b/source/blender/render/intern/source/strand.c @@ -323,6 +323,11 @@ struct StrandShadeCache { MemArena *memarena; }; +typedef struct StrandCacheEntry { + GHashPair pair; + ShadeResult shr; +} StrandCacheEntry; + StrandShadeCache *strand_shade_cache_create(void) { StrandShadeCache *cache; @@ -337,49 +342,49 @@ StrandShadeCache *strand_shade_cache_create(void) void strand_shade_cache_free(StrandShadeCache *cache) { - BLI_ghash_free(cache->refcounthash, (GHashKeyFreeFP)BLI_ghashutil_pairfree, NULL); - BLI_ghash_free(cache->resulthash, (GHashKeyFreeFP)BLI_ghashutil_pairfree, (GHashValFreeFP)MEM_freeN); + BLI_ghash_free(cache->refcounthash, NULL, NULL); + BLI_ghash_free(cache->resulthash, (GHashKeyFreeFP)MEM_freeN, NULL); BLI_memarena_free(cache->memarena); MEM_freeN(cache); } -static GHashPair *strand_shade_hash_pair(ObjectInstanceRen *obi, StrandRen *strand, StrandVert *svert) +static GHashPair strand_shade_hash_pair(ObjectInstanceRen *obi, StrandVert *svert) { - return BLI_ghashutil_pairalloc(obi, strand->index + (svert - strand->vert)); + GHashPair pair = {obi, svert}; + return pair; } static void strand_shade_get(Render *re, StrandShadeCache *cache, ShadeSample *ssamp, StrandSegment *sseg, StrandVert *svert) { - ShadeResult *hashshr; + StrandCacheEntry *entry; StrandPoint p; int *refcount; - GHashPair *pair = strand_shade_hash_pair(sseg->obi, sseg->strand, svert); + GHashPair pair = strand_shade_hash_pair(sseg->obi, svert); - hashshr= BLI_ghash_lookup(cache->resulthash, pair); - refcount= BLI_ghash_lookup(cache->refcounthash, pair); + entry= BLI_ghash_lookup(cache->resulthash, &pair); + refcount= BLI_ghash_lookup(cache->refcounthash, &pair); - if (!hashshr) { + if (!entry) { /* not shaded yet, shade and insert into hash */ p.t= (sseg->v[1] == svert)? 0.0f: 1.0f; strand_eval_point(sseg, &p); strand_shade_point(re, ssamp, sseg, svert, &p); - hashshr= MEM_callocN(sizeof(ShadeResult), "HashShadeResult"); - *hashshr= ssamp->shr[0]; - BLI_ghash_insert(cache->resulthash, strand_shade_hash_pair(sseg->obi, sseg->strand, svert), hashshr); + entry= MEM_callocN(sizeof(StrandCacheEntry), "StrandCacheEntry"); + entry->pair = pair; + entry->shr = ssamp->shr[0]; + BLI_ghash_insert(cache->resulthash, entry, entry); } else /* already shaded, just copy previous result from hash */ - ssamp->shr[0]= *hashshr; + ssamp->shr[0]= entry->shr; /* lower reference count and remove if not needed anymore by any samples */ (*refcount)--; if (*refcount == 0) { - BLI_ghash_remove(cache->resulthash, pair, (GHashKeyFreeFP)BLI_ghashutil_pairfree, (GHashValFreeFP)MEM_freeN); - BLI_ghash_remove(cache->refcounthash, pair, (GHashKeyFreeFP)BLI_ghashutil_pairfree, NULL); + BLI_ghash_remove(cache->resulthash, &pair, (GHashKeyFreeFP)MEM_freeN, NULL); + BLI_ghash_remove(cache->refcounthash, &pair, NULL, NULL); } - - BLI_ghashutil_pairfree(pair); } void strand_shade_segment(Render *re, StrandShadeCache *cache, StrandSegment *sseg, ShadeSample *ssamp, float t, float s, int addpassflag) @@ -402,37 +407,36 @@ void strand_shade_segment(Render *re, StrandShadeCache *cache, StrandSegment *ss } } -void strand_shade_unref(StrandShadeCache *cache, ObjectInstanceRen *obi, StrandRen *strand, StrandVert *svert) +void strand_shade_unref(StrandShadeCache *cache, ObjectInstanceRen *obi, StrandVert *svert) { - GHashPair *pair = strand_shade_hash_pair(obi, strand, svert); + GHashPair pair = strand_shade_hash_pair(obi, svert); int *refcount; /* lower reference count and remove if not needed anymore by any samples */ - refcount= BLI_ghash_lookup(cache->refcounthash, pair); + refcount= BLI_ghash_lookup(cache->refcounthash, &pair); (*refcount)--; if (*refcount == 0) { - BLI_ghash_remove(cache->resulthash, pair, (GHashKeyFreeFP)BLI_ghashutil_pairfree, (GHashValFreeFP)MEM_freeN); - BLI_ghash_remove(cache->refcounthash, pair, (GHashKeyFreeFP)BLI_ghashutil_pairfree, NULL); + BLI_ghash_remove(cache->resulthash, &pair, (GHashKeyFreeFP)MEM_freeN, NULL); + BLI_ghash_remove(cache->refcounthash, &pair, NULL, NULL); } - - BLI_ghashutil_pairfree(pair); } static void strand_shade_refcount(StrandShadeCache *cache, StrandSegment *sseg, StrandVert *svert) { - GHashPair *pair = strand_shade_hash_pair(sseg->obi, sseg->strand, svert); - int *refcount= BLI_ghash_lookup(cache->refcounthash, pair); + GHashPair pair = strand_shade_hash_pair(sseg->obi, svert); + GHashPair *key; + int *refcount= BLI_ghash_lookup(cache->refcounthash, &pair); if (!refcount) { + key= BLI_memarena_alloc(cache->memarena, sizeof(GHashPair)); + *key = pair; refcount= BLI_memarena_alloc(cache->memarena, sizeof(int)); *refcount= 1; - BLI_ghash_insert(cache->refcounthash, pair, refcount); + BLI_ghash_insert(cache->refcounthash, key, refcount); } - else { + else (*refcount)++; - BLI_ghashutil_pairfree(pair); - } } /* *************** */ diff --git a/source/blender/render/intern/source/zbuf.c b/source/blender/render/intern/source/zbuf.c index 84c5f822b53..b9e69743995 100644 --- a/source/blender/render/intern/source/zbuf.c +++ b/source/blender/render/intern/source/zbuf.c @@ -3748,8 +3748,8 @@ static void unref_strand_samples(StrandShadeCache *cache, ZTranspRow *row, int t strand= RE_findOrAddStrand(obr, row[totface].p-1); svert= strand->vert + row[totface].segment; - strand_shade_unref(cache, obi, strand, svert); - strand_shade_unref(cache, obi, strand, svert+1); + strand_shade_unref(cache, obi, svert); + strand_shade_unref(cache, obi, svert+1); } } } |