From bbe6d44928235cd4a5cfbeaf1a1de78ed861bb92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?K=C3=A9vin=20Dietrich?= Date: Fri, 22 Jan 2021 15:01:26 +0100 Subject: Cycles: optimize device updates This optimizes device updates (during user edits or frame changes in the viewport) by avoiding unnecessary computations. To achieve this, we use a combination of the sockets' update flags as well as some new flags passed to the various managers when tagging for an update to tell exactly what the tagging is for (e.g. shader was modified, object was removed, etc.). Besides avoiding recomputations, we also avoid resending to the devices unmodified data arrays, thus reducing bandwidth usage. For OptiX and Embree, BVH packing was also multithreaded. The performance improvements may vary depending on the used device (CPU or GPU), and the content of the scene. Simple scenes (e.g. with no adaptive subdivision or volumes) rendered using OptiX will benefit from this work the most. On average, for a variety of animated scenes, this gives a 3x speedup. Reviewed By: #cycles, brecht Maniphest Tasks: T79174 Differential Revision: https://developer.blender.org/D9555 --- intern/cycles/render/hair.cpp | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) (limited to 'intern/cycles/render/hair.cpp') diff --git a/intern/cycles/render/hair.cpp b/intern/cycles/render/hair.cpp index 896e798b6f9..e94cad6b32e 100644 --- a/intern/cycles/render/hair.cpp +++ b/intern/cycles/render/hair.cpp @@ -494,33 +494,38 @@ void Hair::pack_curves(Scene *scene, } } -void Hair::pack_primitives(PackedBVH &pack, int object, uint visibility) +void Hair::pack_primitives(PackedBVH *pack, int object, uint visibility, bool pack_all) { if (curve_first_key.empty()) return; - const size_t num_prims = num_segments(); - pack.prim_tri_index.reserve(pack.prim_tri_index.size() + num_prims); - pack.prim_type.reserve(pack.prim_type.size() + num_prims); - pack.prim_visibility.reserve(pack.prim_visibility.size() + num_prims); - pack.prim_index.reserve(pack.prim_index.size() + num_prims); - pack.prim_object.reserve(pack.prim_object.size() + num_prims); - // 'pack.prim_time' is unused by Embree and OptiX + /* If the BVH does not have to be recreated, we can bail out. */ + if (!pack_all) { + return; + } + + unsigned int *prim_tri_index = &pack->prim_tri_index[optix_prim_offset]; + int *prim_type = &pack->prim_type[optix_prim_offset]; + unsigned int *prim_visibility = &pack->prim_visibility[optix_prim_offset]; + int *prim_index = &pack->prim_index[optix_prim_offset]; + int *prim_object = &pack->prim_object[optix_prim_offset]; + // 'pack->prim_time' is unused by Embree and OptiX uint type = has_motion_blur() ? ((curve_shape == CURVE_RIBBON) ? PRIMITIVE_MOTION_CURVE_RIBBON : PRIMITIVE_MOTION_CURVE_THICK) : ((curve_shape == CURVE_RIBBON) ? PRIMITIVE_CURVE_RIBBON : PRIMITIVE_CURVE_THICK); + size_t index = 0; for (size_t j = 0; j < num_curves(); ++j) { Curve curve = get_curve(j); - for (size_t k = 0; k < curve.num_segments(); ++k) { - pack.prim_tri_index.push_back_reserved(-1); - pack.prim_type.push_back_reserved(PRIMITIVE_PACK_SEGMENT(type, k)); - pack.prim_visibility.push_back_reserved(visibility); + for (size_t k = 0; k < curve.num_segments(); ++k, ++index) { + prim_tri_index[index] = -1; + prim_type[index] = PRIMITIVE_PACK_SEGMENT(type, k); + prim_visibility[index] = visibility; // Each curve segment points back to its curve index - pack.prim_index.push_back_reserved(j + prim_offset); - pack.prim_object.push_back_reserved(object); + prim_index[index] = j + prim_offset; + prim_object[index] = object; } } } -- cgit v1.2.3