diff options
Diffstat (limited to 'intern')
-rw-r--r-- | intern/cycles/bvh/bvh_build.cpp | 5 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_bake.h | 3 | ||||
-rw-r--r-- | intern/cycles/kernel/kernel_shader.h | 12 | ||||
-rw-r--r-- | intern/cycles/render/session.cpp | 8 | ||||
-rw-r--r-- | intern/cycles/util/util_half.h | 23 | ||||
-rw-r--r-- | intern/cycles/util/util_image_impl.h | 62 | ||||
-rw-r--r-- | intern/cycles/util/util_static_assert.h | 4 |
7 files changed, 107 insertions, 10 deletions
diff --git a/intern/cycles/bvh/bvh_build.cpp b/intern/cycles/bvh/bvh_build.cpp index fcbc50f4f6f..517afc75641 100644 --- a/intern/cycles/bvh/bvh_build.cpp +++ b/intern/cycles/bvh/bvh_build.cpp @@ -905,12 +905,13 @@ BVHNode* BVHBuild::create_leaf_node(const BVHRange& range, * can not control. */ typedef StackAllocator<256, int> LeafStackAllocator; + typedef StackAllocator<256, float2> LeafTimeStackAllocator; typedef StackAllocator<256, BVHReference> LeafReferenceStackAllocator; vector<int, LeafStackAllocator> p_type[PRIMITIVE_NUM_TOTAL]; vector<int, LeafStackAllocator> p_index[PRIMITIVE_NUM_TOTAL]; vector<int, LeafStackAllocator> p_object[PRIMITIVE_NUM_TOTAL]; - vector<float2, LeafStackAllocator> p_time[PRIMITIVE_NUM_TOTAL]; + vector<float2, LeafTimeStackAllocator> p_time[PRIMITIVE_NUM_TOTAL]; vector<BVHReference, LeafReferenceStackAllocator> p_ref[PRIMITIVE_NUM_TOTAL]; /* TODO(sergey): In theory we should be able to store references. */ @@ -964,7 +965,7 @@ BVHNode* BVHBuild::create_leaf_node(const BVHRange& range, vector<int, LeafStackAllocator> local_prim_type, local_prim_index, local_prim_object; - vector<float2, LeafStackAllocator> local_prim_time; + vector<float2, LeafTimeStackAllocator> local_prim_time; local_prim_type.resize(num_new_prims); local_prim_index.resize(num_new_prims); local_prim_object.resize(num_new_prims); diff --git a/intern/cycles/kernel/kernel_bake.h b/intern/cycles/kernel/kernel_bake.h index 5bcc57cdcdf..f18d145f7cf 100644 --- a/intern/cycles/kernel/kernel_bake.h +++ b/intern/cycles/kernel/kernel_bake.h @@ -54,7 +54,8 @@ ccl_device_inline void compute_light_pass(KernelGlobals *kg, float rbsdf = path_state_rng_1D(kg, &rng, &state, PRNG_BSDF); shader_eval_surface(kg, sd, &rng, &state, rbsdf, state.flag, SHADER_CONTEXT_MAIN); - /* TODO, disable the closures we won't need */ + /* TODO, disable more closures we don't need besides transparent */ + shader_bsdf_disable_transparency(kg, sd); #ifdef __BRANCHED_PATH__ if(!kernel_data.integrator.branched) { diff --git a/intern/cycles/kernel/kernel_shader.h b/intern/cycles/kernel/kernel_shader.h index 635365b5702..a2ab96b35e2 100644 --- a/intern/cycles/kernel/kernel_shader.h +++ b/intern/cycles/kernel/kernel_shader.h @@ -685,6 +685,18 @@ ccl_device float3 shader_bsdf_transparency(KernelGlobals *kg, ShaderData *sd) return eval; } +ccl_device void shader_bsdf_disable_transparency(KernelGlobals *kg, ShaderData *sd) +{ + for(int i = 0; i < sd->num_closure; i++) { + ShaderClosure *sc = &sd->closure[i]; + + if(sc->type == CLOSURE_BSDF_TRANSPARENT_ID) { + sc->sample_weight = 0.0f; + sc->weight = make_float3(0.0f, 0.0f, 0.0f); + } + } +} + ccl_device float3 shader_bsdf_alpha(KernelGlobals *kg, ShaderData *sd) { float3 alpha = make_float3(1.0f, 1.0f, 1.0f) - shader_bsdf_transparency(kg, sd); diff --git a/intern/cycles/render/session.cpp b/intern/cycles/render/session.cpp index 91a0ff08f3b..0c7bd271371 100644 --- a/intern/cycles/render/session.cpp +++ b/intern/cycles/render/session.cpp @@ -230,7 +230,9 @@ void Session::run_gpu() while(1) { scoped_timer pause_timer; pause_cond.wait(pause_lock); - progress.add_skip_time(pause_timer, params.background); + if(pause) { + progress.add_skip_time(pause_timer, params.background); + } update_status_time(pause, no_tiles); progress.set_update(); @@ -520,7 +522,9 @@ void Session::run_cpu() while(1) { scoped_timer pause_timer; pause_cond.wait(pause_lock); - progress.add_skip_time(pause_timer, params.background); + if(pause) { + progress.add_skip_time(pause_timer, params.background); + } update_status_time(pause, no_tiles); progress.set_update(); diff --git a/intern/cycles/util/util_half.h b/intern/cycles/util/util_half.h index 5db3384cda4..c1a47d58c55 100644 --- a/intern/cycles/util/util_half.h +++ b/intern/cycles/util/util_half.h @@ -18,6 +18,7 @@ #define __UTIL_HALF_H__ #include "util_types.h" +#include "util_math.h" #ifdef __KERNEL_SSE2__ #include "util_simd.h" @@ -110,6 +111,28 @@ ccl_device_inline float4 half4_to_float4(half4 h) return f; } +ccl_device_inline half float_to_half(float f) +{ + const uint u = __float_as_uint(f); + /* Sign bit, shifted to it's position. */ + uint sign_bit = u & 0x80000000; + sign_bit >>= 16; + /* Exponent. */ + uint exponent_bits = u & 0x7f800000; + /* Non-sign bits. */ + uint value_bits = u & 0x7fffffff; + value_bits >>= 13; /* Align mantissa on MSB. */ + value_bits -= 0x1c000; /* Adjust bias. */ + /* Flush-to-zero. */ + value_bits = (exponent_bits < 0x38800000) ? 0 : value_bits; + /* Clamp-to-max. */ + value_bits = (exponent_bits > 0x47000000) ? 0x7bff : value_bits; + /* Denormals-as-zero. */ + value_bits = (exponent_bits == 0 ? 0 : value_bits); + /* Re-insert sign bit and return. */ + return (value_bits | sign_bit); +} + #endif #endif diff --git a/intern/cycles/util/util_image_impl.h b/intern/cycles/util/util_image_impl.h index 73ecfda0855..4daf1eaac22 100644 --- a/intern/cycles/util/util_image_impl.h +++ b/intern/cycles/util/util_image_impl.h @@ -19,6 +19,7 @@ #include "util_algorithm.h" #include "util_debug.h" +#include "util_half.h" #include "util_image.h" CCL_NAMESPACE_BEGIN @@ -38,6 +39,52 @@ const T *util_image_read(const vector<T>& pixels, return &pixels[index]; } +/* Cast input pixel from unknown storage to float. */ +template<typename T> +inline float cast_to_float(T value); + +template<> +inline float cast_to_float(float value) +{ + return value; +} +template<> +inline float cast_to_float(uchar value) +{ + return (float)value / 255.0f; +} +template<> +inline float cast_to_float(half value) +{ + return half_to_float(value); +} + +/* Cast float value to output pixel type. */ +template<typename T> +inline T cast_from_float(float value); + +template<> +inline float cast_from_float(float value) +{ + return value; +} +template<> +inline uchar cast_from_float(float value) +{ + if(value < 0.0f) { + return 0; + } + else if(value > (1.0f - 0.5f / 255.0f)) { + return 255; + } + return (uchar)((255.0f * value) + 0.5f); +} +template<> +inline half cast_from_float(float value) +{ + return float_to_half(value); +} + template<typename T> void util_image_downscale_sample(const vector<T>& pixels, const size_t width, @@ -71,15 +118,22 @@ void util_image_downscale_sample(const vector<T>& pixels, components, nx, ny, nz); for(size_t k = 0; k < components; ++k) { - accum[k] += pixel[k]; + accum[k] += cast_to_float(pixel[k]); } ++count; } } } - const float inv_count = 1.0f / (float)count; - for(size_t k = 0; k < components; ++k) { - result[k] = T(accum[k] * inv_count); + if(count != 0) { + const float inv_count = 1.0f / (float)count; + for(size_t k = 0; k < components; ++k) { + result[k] = cast_from_float<T>(accum[k] * inv_count); + } + } + else { + for(size_t k = 0; k < components; ++k) { + result[k] = T(0.0f); + } } } diff --git a/intern/cycles/util/util_static_assert.h b/intern/cycles/util/util_static_assert.h index 033d85e8ec6..e90049254de 100644 --- a/intern/cycles/util/util_static_assert.h +++ b/intern/cycles/util/util_static_assert.h @@ -43,7 +43,9 @@ template <> class StaticAssertFailure<true> {}; # endif /* __COUNTER__ */ # endif /* C++11 or MSVC2015 */ #else /* __KERNEL_GPU__ */ -# define static_assert(statement, message) +# ifndef static_assert +# define static_assert(statement, message) +# endif #endif /* __KERNEL_GPU__ */ /* TODO(sergey): For until C++11 is a bare minimum for us, |