Cycles: detect when attributes have changed

This patch has originally been written by Kévin Dietrich, thanks!
It is part of D10210.

As Brecht noted in D10210, this might not handle all cases yet.
I better solution should come soonish.
This commit is contained in:
Jacques Lucke 2021-02-17 12:04:45 +01:00
parent 17dddc9417
commit 9419452f85
3 changed files with 19 additions and 0 deletions

@ -440,6 +440,7 @@ Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement eleme
Attribute new_attr(name, type, element, geometry, prim);
attributes.emplace_back(std::move(new_attr));
modified = true;
return &attributes.back();
}
@ -461,6 +462,7 @@ void AttributeSet::remove(ustring name)
for (it = attributes.begin(); it != attributes.end(); it++) {
if (&*it == attr) {
modified = true;
attributes.erase(it);
return;
}
@ -606,6 +608,7 @@ void AttributeSet::remove(AttributeStandard std)
for (it = attributes.begin(); it != attributes.end(); it++) {
if (&*it == attr) {
modified = true;
attributes.erase(it);
return;
}
@ -671,12 +674,14 @@ void AttributeSet::update(AttributeSet &&new_attributes)
for (it = attributes.begin(); it != attributes.end();) {
if (it->std != ATTR_STD_NONE) {
if (new_attributes.find(it->std) == nullptr) {
modified = true;
attributes.erase(it++);
continue;
}
}
else if (it->name != "") {
if (new_attributes.find(it->name) == nullptr) {
modified = true;
attributes.erase(it++);
continue;
}
@ -691,6 +696,7 @@ void AttributeSet::clear_modified()
foreach (Attribute &attr, attributes) {
attr.modified = false;
}
modified = false;
}
/* AttributeRequest */

@ -179,6 +179,7 @@ class AttributeSet {
Geometry *geometry;
AttributePrimitive prim;
list<Attribute> attributes;
bool modified = true;
AttributeSet(Geometry *geometry, AttributePrimitive prim);
AttributeSet(AttributeSet &&) = default;

@ -1440,6 +1440,18 @@ void GeometryManager::device_update_preprocess(Device *device, Scene *scene, Pro
foreach (Geometry *geom, scene->geometry) {
geom->has_volume = false;
if (geom->attributes.modified) {
device_update_flags |= ATTRS_NEED_REALLOC;
}
if (geom->is_mesh()) {
Mesh *mesh = static_cast<Mesh *>(geom);
if (mesh->subd_attributes.modified) {
device_update_flags |= ATTRS_NEED_REALLOC;
}
}
foreach (Node *node, geom->get_used_shaders()) {
Shader *shader = static_cast<Shader *>(node);
if (shader->has_volume) {