From bfb6fce6594e9cf133bd18aee311c1e5e32dc799 Mon Sep 17 00:00:00 2001 From: Patrick Mours Date: Thu, 10 Dec 2020 14:18:25 +0100 Subject: Cycles: Add CPU+GPU rendering support with OptiX Adds support for building multiple BVH types in order to support using both CPU and OptiX devices for rendering simultaneously. Primitive packing for Embree and OptiX is now standalone, so it only needs to be run once and can be shared between the two. Additionally, BVH building was made a device call, so that each device backend can decide how to perform the building. The multi-device for instance creates a special multi-BVH that holds references to several sub-BVHs, one for each sub-device. Reviewed By: brecht, kevindietrich Differential Revision: https://developer.blender.org/D9718 --- intern/cycles/render/hair.cpp | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'intern/cycles/render/hair.cpp') diff --git a/intern/cycles/render/hair.cpp b/intern/cycles/render/hair.cpp index d67bd209142..a64b8242337 100644 --- a/intern/cycles/render/hair.cpp +++ b/intern/cycles/render/hair.cpp @@ -14,6 +14,8 @@ * limitations under the License. */ +#include "bvh/bvh.h" + #include "render/hair.h" #include "render/curves.h" #include "render/scene.h" @@ -492,4 +494,35 @@ void Hair::pack_curves(Scene *scene, } } +void Hair::pack_primitives(PackedBVH &pack, int object, uint visibility) +{ + 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 + + 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); + + 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); + // 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); + } + } +} + CCL_NAMESPACE_END -- cgit v1.2.3