diff options
author | Jacques Lucke <jacques@blender.org> | 2021-06-14 13:44:13 +0300 |
---|---|---|
committer | Jacques Lucke <jacques@blender.org> | 2021-06-14 13:44:13 +0300 |
commit | dddcf1e9bbf4a6d1f4ff03eaf0cb7e9228b18ec5 (patch) | |
tree | c20defa7efd54c933d20a296abefe567909bb6c0 /intern/cycles/kernel/closure/alloc.h | |
parent | 3b162b7c185d089e93d892169a458d552196b7b6 (diff) | |
parent | c9dc55301cd7903b7ef7c045d337ada29aa809a1 (diff) |
Merge branch 'master' into temp-compact-node-prototypetemp-compact-node-prototype
Diffstat (limited to 'intern/cycles/kernel/closure/alloc.h')
-rw-r--r-- | intern/cycles/kernel/closure/alloc.h | 48 |
1 files changed, 34 insertions, 14 deletions
diff --git a/intern/cycles/kernel/closure/alloc.h b/intern/cycles/kernel/closure/alloc.h index 341d1e16eb1..99a5a675976 100644 --- a/intern/cycles/kernel/closure/alloc.h +++ b/intern/cycles/kernel/closure/alloc.h @@ -57,14 +57,24 @@ ccl_device ccl_addr_space void *closure_alloc_extra(ShaderData *sd, int size) ccl_device_inline ShaderClosure *bsdf_alloc(ShaderData *sd, int size, float3 weight) { - ShaderClosure *sc = closure_alloc(sd, size, CLOSURE_NONE_ID, weight); + kernel_assert(isfinite3_safe(weight)); - if (sc == NULL) - return NULL; + const float sample_weight = fabsf(average(weight)); + + /* Use comparison this way to help dealing with non-finite weight: if the average is not finite + * we will not allocate new closure. */ + if (sample_weight >= CLOSURE_WEIGHT_CUTOFF) { + ShaderClosure *sc = closure_alloc(sd, size, CLOSURE_NONE_ID, weight); + if (sc == NULL) { + return NULL; + } + + sc->sample_weight = sample_weight; - float sample_weight = fabsf(average(weight)); - sc->sample_weight = sample_weight; - return (sample_weight >= CLOSURE_WEIGHT_CUTOFF) ? sc : NULL; + return sc; + } + + return NULL; } #ifdef __OSL__ @@ -73,17 +83,27 @@ ccl_device_inline ShaderClosure *bsdf_alloc_osl(ShaderData *sd, float3 weight, void *data) { - ShaderClosure *sc = closure_alloc(sd, size, CLOSURE_NONE_ID, weight); + kernel_assert(isfinite3_safe(weight)); - if (!sc) - return NULL; + const float sample_weight = fabsf(average(weight)); - memcpy((void *)sc, data, size); + /* Use comparison this way to help dealing with non-finite weight: if the average is not finite + * we will not allocate new closure. */ + if (sample_weight >= CLOSURE_WEIGHT_CUTOFF) { + ShaderClosure *sc = closure_alloc(sd, size, CLOSURE_NONE_ID, weight); + if (!sc) { + return NULL; + } - float sample_weight = fabsf(average(weight)); - sc->weight = weight; - sc->sample_weight = sample_weight; - return (sample_weight >= CLOSURE_WEIGHT_CUTOFF) ? sc : NULL; + memcpy((void *)sc, data, size); + + sc->weight = weight; + sc->sample_weight = sample_weight; + + return sc; + } + + return NULL; } #endif |