Fix T63588: Cycles unnecessarily updates background importance sampling map

This commit is contained in:
Tautvydas Andrikys 2020-05-14 17:41:37 +02:00 committed by Brecht Van Lommel
parent 5940485369
commit 33ce0cb5a1
Notes: blender-bot 2023-02-14 03:13:26 +01:00
Referenced by commit 52cc412e0f, Revert "Fix T63588: Cycles unnecessarily updates background importance sampling map"
Referenced by issue #77273, Cycles crash enabling Portal for area lights
Referenced by issue #63588, Cycles does need recalculate MIP after modifying a material
3 changed files with 24 additions and 11 deletions

View File

@ -181,6 +181,7 @@ bool Light::has_contribution(Scene *scene)
LightManager::LightManager()
{
need_update = true;
need_update_background = true;
use_light_visibility = false;
}
@ -901,7 +902,7 @@ void LightManager::device_update(Device *device,
VLOG(1) << "Total " << scene->lights.size() << " lights.";
device_free(device, dscene);
device_free(device, dscene, need_update_background);
use_light_visibility = false;
@ -915,9 +916,11 @@ void LightManager::device_update(Device *device,
if (progress.get_cancel())
return;
device_update_background(device, dscene, scene, progress);
if (progress.get_cancel())
return;
if (need_update_background) {
device_update_background(device, dscene, scene, progress);
if (progress.get_cancel())
return;
}
device_update_ies(dscene);
if (progress.get_cancel())
@ -929,14 +932,17 @@ void LightManager::device_update(Device *device,
}
need_update = false;
need_update_background = false;
}
void LightManager::device_free(Device *, DeviceScene *dscene)
void LightManager::device_free(Device *, DeviceScene *dscene, const bool free_background)
{
dscene->light_distribution.free();
dscene->lights.free();
dscene->light_background_marginal_cdf.free();
dscene->light_background_conditional_cdf.free();
if (free_background) {
dscene->light_background_marginal_cdf.free();
dscene->light_background_conditional_cdf.free();
}
dscene->ies_lights.free();
}
@ -989,6 +995,7 @@ int LightManager::add_ies(const string &content)
ies_slots[slot]->hash = hash;
need_update = true;
need_update_background = true;
return slot;
}
@ -1007,6 +1014,7 @@ void LightManager::remove_ies(int slot)
/* 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;
}
void LightManager::device_update_ies(DeviceScene *dscene)

View File

@ -88,6 +88,9 @@ class LightManager {
bool use_light_visibility;
bool need_update;
/* Need to update background (including multiple importance map) */
bool need_update_background;
LightManager();
~LightManager();
@ -97,7 +100,7 @@ class LightManager {
void remove_ies(int slot);
void device_update(Device *device, DeviceScene *dscene, Scene *scene, Progress &progress);
void device_free(Device *device, DeviceScene *dscene);
void device_free(Device *device, DeviceScene *dscene, const bool free_background = true);
void tag_update(Scene *scene);

View File

@ -318,9 +318,11 @@ void Shader::tag_update(Scene *scene)
* has use_mis set to false. We are quite close to release now, so
* better to be safe.
*/
if (this == scene->background->get_shader(scene) &&
scene->light_manager->has_background_light(scene)) {
scene->light_manager->need_update = true;
if (this == scene->background->get_shader(scene)) {
scene->light_manager->need_update_background = true;
if (scene->light_manager->has_background_light(scene)) {
scene->light_manager->need_update = true;
}
}
/* quick detection of which kind of shaders we have to avoid loading