diff options
author | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2021-01-22 17:01:26 +0300 |
---|---|---|
committer | Kévin Dietrich <kevin.dietrich@mailoo.org> | 2021-01-22 18:08:25 +0300 |
commit | bbe6d44928235cd4a5cfbeaf1a1de78ed861bb92 (patch) | |
tree | c3a8653dfdf38029caebfd9978ea4644535bae3d /intern/cycles/render/light.cpp | |
parent | 131a758b6f88a2be816e9351d216bcfb9c965c4b (diff) |
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
Diffstat (limited to 'intern/cycles/render/light.cpp')
-rw-r--r-- | intern/cycles/render/light.cpp | 27 |
1 files changed, 18 insertions, 9 deletions
diff --git a/intern/cycles/render/light.cpp b/intern/cycles/render/light.cpp index 2bde3242b26..6e9dea564c2 100644 --- a/intern/cycles/render/light.cpp +++ b/intern/cycles/render/light.cpp @@ -162,7 +162,9 @@ Light::Light() : Node(node_type) void Light::tag_update(Scene *scene) { - scene->light_manager->need_update = is_modified(); + if (is_modified()) { + scene->light_manager->tag_update(scene, LightManager::LIGHT_MODIFIED); + } } bool Light::has_contribution(Scene *scene) @@ -183,7 +185,7 @@ bool Light::has_contribution(Scene *scene) LightManager::LightManager() { - need_update = true; + update_flags = UPDATE_ALL; need_update_background = true; use_light_visibility = false; last_background_enabled = false; @@ -962,7 +964,7 @@ void LightManager::device_update(Device *device, Scene *scene, Progress &progress) { - if (!need_update) + if (!need_update()) return; scoped_callback_timer timer([scene](double time) { @@ -1000,7 +1002,7 @@ void LightManager::device_update(Device *device, scene->film->set_use_light_visibility(use_light_visibility); - need_update = false; + update_flags = UPDATE_NONE; need_update_background = false; } @@ -1015,9 +1017,14 @@ void LightManager::device_free(Device *, DeviceScene *dscene, const bool free_ba dscene->ies_lights.free(); } -void LightManager::tag_update(Scene * /*scene*/) +void LightManager::tag_update(Scene * /*scene*/, uint32_t flag) +{ + update_flags |= flag; +} + +bool LightManager::need_update() const { - need_update = true; + return update_flags != UPDATE_NONE; } int LightManager::add_ies_from_file(const string &filename) @@ -1063,7 +1070,7 @@ int LightManager::add_ies(const string &content) ies_slots[slot]->users = 1; ies_slots[slot]->hash = hash; - need_update = true; + update_flags = UPDATE_ALL; need_update_background = true; return slot; @@ -1082,8 +1089,10 @@ void LightManager::remove_ies(int slot) ies_slots[slot]->users--; /* If the slot has no more users, update the device to remove it. */ - need_update |= (ies_slots[slot]->users == 0); - need_update_background |= need_update; + if (ies_slots[slot]->users == 0) { + update_flags |= UPDATE_ALL; + need_update_background = true; + } } void LightManager::device_update_ies(DeviceScene *dscene) |