From 9bd1c8caf72e9b1c2a71929a8968389eea8ca5b3 Mon Sep 17 00:00:00 2001 From: Sergey Sharybin Date: Wed, 20 Apr 2016 18:12:26 +0200 Subject: Cycles: Multi-thread object transform update Simple idea, use threads when dealing with "Copying Transformations to device" scene update step. Only do it if there's enough objects in the scene. Hopefully only brings less synchronization time and doesn't break anything. From tests on my desktop this brings down transform update time from 58sec to 11sec on victor_cpu.blend scene from out benchmark. --- intern/cycles/render/object.h | 60 ++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'intern/cycles/render/object.h') diff --git a/intern/cycles/render/object.h b/intern/cycles/render/object.h index 379d1748cdd..c2a79ca8dc4 100644 --- a/intern/cycles/render/object.h +++ b/intern/cycles/render/object.h @@ -17,9 +17,12 @@ #ifndef __OBJECT_H__ #define __OBJECT_H__ +#include "scene.h" + #include "util_boundbox.h" #include "util_param.h" #include "util_transform.h" +#include "util_thread.h" #include "util_types.h" CCL_NAMESPACE_BEGIN @@ -76,7 +79,12 @@ public: ~ObjectManager(); void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress& progress); - void device_update_transforms(Device *device, DeviceScene *dscene, Scene *scene, uint *object_flag, Progress& progress); + void device_update_transforms(Device *device, + DeviceScene *dscene, + Scene *scene, + uint *object_flag, + Progress& progress); + void device_update_flags(Device *device, DeviceScene *dscene, Scene *scene, @@ -87,6 +95,56 @@ public: void tag_update(Scene *scene); void apply_static_transforms(DeviceScene *dscene, Scene *scene, uint *object_flag, Progress& progress); + +protected: + /* Global state of object transform update. */ + struct UpdateObejctTransformState { + /* Global state used by device_update_object_transform(). + * Common for both threaded and non-threaded update. + */ + + /* Type of the motion required by the scene settings. */ + Scene::MotionType need_motion; + + /* Mapping from particle system to a index in packed particle array. + * Only used for read. + */ + map particle_offset; + + /* Mesh area. + * Used to avoid calculation of mesh area multiple times. Used for both + * read and write. Acquire surface_area_lock to keep it all thread safe. + */ + map surface_area_map; + + /* Packed object arrays. Those will be filled in. */ + uint *object_flag; + float4 *objects; + float4 *objects_vector; + + /* Flags which will be synchronized to Integrator. */ + bool have_motion; + bool have_curves; + + /* ** Scheduling queue. ** */ + + Scene *scene; + + /* Some locks to keep everything thread-safe. */ + thread_spin_lock queue_lock; + thread_spin_lock surface_area_lock; + + /* First unused object index in the queue. */ + int queue_start_object; + }; + void device_update_object_transform(UpdateObejctTransformState *state, + Object *ob, + const int object_index); + void device_update_object_transform_task(UpdateObejctTransformState *state); + bool device_update_object_transform_pop_work( + UpdateObejctTransformState *state, + int *start_index, + int *num_objects); }; CCL_NAMESPACE_END -- cgit v1.2.3