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/attribute.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/attribute.cpp')
-rw-r--r-- | intern/cycles/render/attribute.cpp | 75 |
1 files changed, 74 insertions, 1 deletions
diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp index b478aae9ae2..6a3fbb7772f 100644 --- a/intern/cycles/render/attribute.cpp +++ b/intern/cycles/render/attribute.cpp @@ -28,7 +28,7 @@ CCL_NAMESPACE_BEGIN Attribute::Attribute( ustring name, TypeDesc type, AttributeElement element, Geometry *geom, AttributePrimitive prim) - : name(name), std(ATTR_STD_NONE), type(type), element(element), flags(0) + : name(name), std(ATTR_STD_NONE), type(type), element(element), flags(0), modified(true) { /* string and matrix not supported! */ assert(type == TypeDesc::TypeFloat || type == TypeDesc::TypeColor || @@ -82,6 +82,8 @@ void Attribute::add(const float &f) for (size_t i = 0; i < size; i++) buffer.push_back(data[i]); + + modified = true; } void Attribute::add(const uchar4 &f) @@ -93,6 +95,8 @@ void Attribute::add(const uchar4 &f) for (size_t i = 0; i < size; i++) buffer.push_back(data[i]); + + modified = true; } void Attribute::add(const float2 &f) @@ -104,6 +108,8 @@ void Attribute::add(const float2 &f) for (size_t i = 0; i < size; i++) buffer.push_back(data[i]); + + modified = true; } void Attribute::add(const float3 &f) @@ -115,6 +121,8 @@ void Attribute::add(const float3 &f) for (size_t i = 0; i < size; i++) buffer.push_back(data[i]); + + modified = true; } void Attribute::add(const Transform &f) @@ -126,6 +134,8 @@ void Attribute::add(const Transform &f) for (size_t i = 0; i < size; i++) buffer.push_back(data[i]); + + modified = true; } void Attribute::add(const char *data) @@ -134,6 +144,26 @@ void Attribute::add(const char *data) for (size_t i = 0; i < size; i++) buffer.push_back(data[i]); + + modified = true; +} + +void Attribute::set_data_from(Attribute &&other) +{ + assert(other.std == std); + assert(other.type == type); + assert(other.element == element); + + this->flags = other.flags; + + if (this->buffer.size() != other.buffer.size()) { + this->buffer = std::move(other.buffer); + modified = true; + } + else if (memcmp(this->data(), other.data(), other.buffer.size()) != 0) { + this->buffer = std::move(other.buffer); + modified = true; + } } size_t Attribute::data_sizeof() const @@ -627,6 +657,49 @@ void AttributeSet::clear(bool preserve_voxel_data) } } +void AttributeSet::update(AttributeSet &&new_attributes) +{ + /* add or update old_attributes based on the new_attributes */ + foreach (Attribute &attr, new_attributes.attributes) { + Attribute *nattr = nullptr; + + if (attr.std != ATTR_STD_NONE) { + nattr = add(attr.std, attr.name); + } + else { + nattr = add(attr.name, attr.type, attr.element); + } + + nattr->set_data_from(std::move(attr)); + } + + /* remove any attributes not on new_attributes */ + list<Attribute>::iterator it; + for (it = attributes.begin(); it != attributes.end();) { + if (it->std != ATTR_STD_NONE) { + if (new_attributes.find(it->std) == nullptr) { + attributes.erase(it++); + continue; + } + } + else if (it->name != "") { + if (new_attributes.find(it->name) == nullptr) { + attributes.erase(it++); + continue; + } + } + + it++; + } +} + +void AttributeSet::clear_modified() +{ + foreach (Attribute &attr, attributes) { + attr.modified = false; + } +} + /* AttributeRequest */ AttributeRequest::AttributeRequest(ustring name_) |