[Bf-blender-cvs] [9419452f859] master: Cycles: detect when attributes have changed

Jacques Lucke noreply at git.blender.org
Wed Feb 17 12:16:43 CET 2021


Commit: 9419452f859117aa17dda7d89810c83bbdcda288
Author: Jacques Lucke
Date:   Wed Feb 17 12:04:45 2021 +0100
Branches: master
https://developer.blender.org/rB9419452f859117aa17dda7d89810c83bbdcda288

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.

===================================================================

M	intern/cycles/render/attribute.cpp
M	intern/cycles/render/attribute.h
M	intern/cycles/render/geometry.cpp

===================================================================

diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp
index ce4ae6e4295..331d30802f1 100644
--- a/intern/cycles/render/attribute.cpp
+++ b/intern/cycles/render/attribute.cpp
@@ -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 */
diff --git a/intern/cycles/render/attribute.h b/intern/cycles/render/attribute.h
index f9997d3c422..c1be62addc0 100644
--- a/intern/cycles/render/attribute.h
+++ b/intern/cycles/render/attribute.h
@@ -179,6 +179,7 @@ class AttributeSet {
   Geometry *geometry;
   AttributePrimitive prim;
   list<Attribute> attributes;
+	bool modified = true;
 
   AttributeSet(Geometry *geometry, AttributePrimitive prim);
   AttributeSet(AttributeSet &&) = default;
diff --git a/intern/cycles/render/geometry.cpp b/intern/cycles/render/geometry.cpp
index f79b1689c14..575042360aa 100644
--- a/intern/cycles/render/geometry.cpp
+++ b/intern/cycles/render/geometry.cpp
@@ -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) {



More information about the Bf-blender-cvs mailing list