2023-06-14 16:52:36 +10:00
|
|
|
/* SPDX-FileCopyrightText: 2011-2022 Blender Foundation
|
|
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 */
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "scene/attribute.h"
|
|
|
|
|
#include "scene/hair.h"
|
|
|
|
|
#include "scene/image.h"
|
|
|
|
|
#include "scene/mesh.h"
|
2021-12-01 17:30:46 +01:00
|
|
|
#include "scene/pointcloud.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2021-10-24 14:19:19 +02:00
|
|
|
#include "util/log.h"
|
|
|
|
|
#include "util/transform.h"
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
CCL_NAMESPACE_BEGIN
|
|
|
|
|
|
|
|
|
|
/* Attribute */
|
|
|
|
|
|
2020-03-08 14:21:29 +01:00
|
|
|
Attribute::Attribute(
|
|
|
|
|
ustring name, TypeDesc type, AttributeElement element, Geometry *geom, AttributePrimitive prim)
|
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
2021-01-22 15:01:26 +01:00
|
|
|
: name(name), std(ATTR_STD_NONE), type(type), element(element), flags(0), modified(true)
|
2020-03-08 14:21:29 +01:00
|
|
|
{
|
|
|
|
|
/* string and matrix not supported! */
|
2024-10-17 19:48:38 +02:00
|
|
|
assert(type == TypeFloat || type == TypeColor || type == TypePoint || type == TypeVector ||
|
|
|
|
|
type == TypeNormal || type == TypeMatrix || type == TypeFloat2 || type == TypeFloat4 ||
|
|
|
|
|
type == TypeRGBA);
|
2020-03-08 14:21:29 +01:00
|
|
|
|
|
|
|
|
if (element == ATTR_ELEMENT_VOXEL) {
|
|
|
|
|
buffer.resize(sizeof(ImageHandle));
|
|
|
|
|
new (buffer.data()) ImageHandle();
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
resize(geom, prim, false);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
Attribute::~Attribute()
|
|
|
|
|
{
|
2020-03-08 10:42:11 +01:00
|
|
|
/* For voxel data, we need to free the image handle. */
|
2024-12-26 17:53:59 +01:00
|
|
|
if (element == ATTR_ELEMENT_VOXEL && !buffer.empty()) {
|
2020-03-08 10:42:11 +01:00
|
|
|
ImageHandle &handle = data_voxel();
|
|
|
|
|
handle.~ImageHandle();
|
2014-03-29 13:03:48 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
void Attribute::resize(Geometry *geom, AttributePrimitive prim, bool reserve_only)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-03-08 14:21:29 +01:00
|
|
|
if (element != ATTR_ELEMENT_VOXEL) {
|
|
|
|
|
if (reserve_only) {
|
|
|
|
|
buffer.reserve(buffer_size(geom, prim));
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
buffer.resize(buffer_size(geom, prim), 0);
|
|
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2016-07-16 22:57:06 -04:00
|
|
|
void Attribute::resize(size_t num_elements)
|
|
|
|
|
{
|
2020-03-08 14:21:29 +01:00
|
|
|
if (element != ATTR_ELEMENT_VOXEL) {
|
|
|
|
|
buffer.resize(num_elements * data_sizeof(), 0);
|
|
|
|
|
}
|
2016-07-16 22:57:06 -04:00
|
|
|
}
|
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
void Attribute::add(const float &f)
|
|
|
|
|
{
|
2019-03-05 18:49:47 +01:00
|
|
|
assert(data_sizeof() == sizeof(float));
|
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
char *data = (char *)&f;
|
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t i = 0; i < size; i++) {
|
2013-01-03 12:08:54 +00:00
|
|
|
buffer.push_back(data[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
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
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
|
modified = true;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
|
|
2014-06-13 23:40:39 +02:00
|
|
|
void Attribute::add(const uchar4 &f)
|
|
|
|
|
{
|
2019-03-05 18:49:47 +01:00
|
|
|
assert(data_sizeof() == sizeof(uchar4));
|
|
|
|
|
|
|
|
|
|
char *data = (char *)&f;
|
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t i = 0; i < size; i++) {
|
2019-03-05 18:49:47 +01:00
|
|
|
buffer.push_back(data[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
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
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
|
modified = true;
|
2019-03-05 18:49:47 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Attribute::add(const float2 &f)
|
|
|
|
|
{
|
|
|
|
|
assert(data_sizeof() == sizeof(float2));
|
|
|
|
|
|
2014-06-13 23:40:39 +02:00
|
|
|
char *data = (char *)&f;
|
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t i = 0; i < size; i++) {
|
2014-06-13 23:40:39 +02:00
|
|
|
buffer.push_back(data[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
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
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
|
modified = true;
|
2014-06-13 23:40:39 +02:00
|
|
|
}
|
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
void Attribute::add(const float3 &f)
|
|
|
|
|
{
|
2019-03-05 18:49:47 +01:00
|
|
|
assert(data_sizeof() == sizeof(float3));
|
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
char *data = (char *)&f;
|
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t i = 0; i < size; i++) {
|
2013-01-03 12:08:54 +00:00
|
|
|
buffer.push_back(data[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
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
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
|
modified = true;
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
|
|
|
|
|
2013-12-31 17:33:55 +01:00
|
|
|
void Attribute::add(const Transform &f)
|
|
|
|
|
{
|
2019-03-05 18:49:47 +01:00
|
|
|
assert(data_sizeof() == sizeof(Transform));
|
|
|
|
|
|
2013-12-31 17:33:55 +01:00
|
|
|
char *data = (char *)&f;
|
|
|
|
|
size_t size = sizeof(f);
|
|
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t i = 0; i < size; i++) {
|
2013-12-31 17:33:55 +01:00
|
|
|
buffer.push_back(data[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
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
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
|
modified = true;
|
2013-12-31 17:33:55 +01:00
|
|
|
}
|
|
|
|
|
|
2014-04-13 12:51:06 +02:00
|
|
|
void Attribute::add(const char *data)
|
|
|
|
|
{
|
|
|
|
|
size_t size = data_sizeof();
|
|
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t i = 0; i < size; i++) {
|
2014-04-13 12:51:06 +02:00
|
|
|
buffer.push_back(data[i]);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
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
2021-01-22 15:01:26 +01:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
2014-04-13 12:51:06 +02:00
|
|
|
}
|
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
size_t Attribute::data_sizeof() const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2023-09-17 09:01:48 +10:00
|
|
|
if (element == ATTR_ELEMENT_VOXEL) {
|
2020-03-08 10:42:11 +01:00
|
|
|
return sizeof(ImageHandle);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (element == ATTR_ELEMENT_CORNER_BYTE) {
|
2016-07-16 19:42:28 -04:00
|
|
|
return sizeof(uchar4);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (type == TypeFloat) {
|
2011-05-31 11:31:00 +00:00
|
|
|
return sizeof(float);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (type == TypeFloat2) {
|
2019-03-05 18:49:47 +01:00
|
|
|
return sizeof(float2);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (type == TypeMatrix) {
|
2013-12-31 17:33:55 +01:00
|
|
|
return sizeof(Transform);
|
2023-09-17 09:01:48 +10:00
|
|
|
// The float3 type is not interchangeable with float4
|
|
|
|
|
// as it is now a packed type.
|
|
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (type == TypeFloat4) {
|
2023-02-27 10:39:19 +01:00
|
|
|
return sizeof(float4);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
if (type == TypeRGBA) {
|
2023-02-27 10:39:19 +01:00
|
|
|
return sizeof(float4);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
return sizeof(float3);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
size_t Attribute::element_size(Geometry *geom, AttributePrimitive prim) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2016-07-16 22:57:06 -04:00
|
|
|
if (flags & ATTR_FINAL_SIZE) {
|
|
|
|
|
return buffer.size() / data_sizeof();
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
size_t size = 0;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-05 17:03:59 +00:00
|
|
|
switch (element) {
|
2013-12-31 17:33:55 +01:00
|
|
|
case ATTR_ELEMENT_OBJECT:
|
|
|
|
|
case ATTR_ELEMENT_MESH:
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_ELEMENT_VOXEL:
|
2013-04-05 17:03:59 +00:00
|
|
|
size = 1;
|
|
|
|
|
break;
|
|
|
|
|
case ATTR_ELEMENT_VERTEX:
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_mesh() || geom->is_volume()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
2020-11-04 11:17:38 +01:00
|
|
|
size = mesh->get_verts().size() + mesh->get_num_ngons();
|
2020-02-02 12:04:19 +01:00
|
|
|
if (prim == ATTR_PRIM_SUBD) {
|
2020-11-04 11:17:38 +01:00
|
|
|
size -= mesh->get_num_subd_verts();
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
2024-10-30 16:45:56 +01:00
|
|
|
else if (geom->is_pointcloud()) {
|
2021-12-01 17:30:46 +01:00
|
|
|
PointCloud *pointcloud = static_cast<PointCloud *>(geom);
|
|
|
|
|
size = pointcloud->num_points();
|
|
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
2014-03-29 13:03:46 +01:00
|
|
|
case ATTR_ELEMENT_VERTEX_MOTION:
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_mesh()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
2021-07-29 12:06:07 +02:00
|
|
|
DCHECK_GT(mesh->get_motion_steps(), 0);
|
2020-11-04 11:17:38 +01:00
|
|
|
size = (mesh->get_verts().size() + mesh->get_num_ngons()) * (mesh->get_motion_steps() - 1);
|
2020-02-02 12:04:19 +01:00
|
|
|
if (prim == ATTR_PRIM_SUBD) {
|
2020-11-04 11:17:38 +01:00
|
|
|
size -= mesh->get_num_subd_verts() * (mesh->get_motion_steps() - 1);
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
2024-10-30 16:45:56 +01:00
|
|
|
else if (geom->is_pointcloud()) {
|
2021-12-01 17:30:46 +01:00
|
|
|
PointCloud *pointcloud = static_cast<PointCloud *>(geom);
|
|
|
|
|
size = pointcloud->num_points() * (pointcloud->get_motion_steps() - 1);
|
|
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
case ATTR_ELEMENT_FACE:
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_mesh() || geom->is_volume()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
2020-02-03 21:40:58 +01:00
|
|
|
if (prim == ATTR_PRIM_GEOMETRY) {
|
2020-02-02 12:04:19 +01:00
|
|
|
size = mesh->num_triangles();
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-11-04 11:17:38 +01:00
|
|
|
size = mesh->get_num_subd_faces() + mesh->get_num_ngons();
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
|
case ATTR_ELEMENT_CORNER:
|
2014-06-13 23:40:39 +02:00
|
|
|
case ATTR_ELEMENT_CORNER_BYTE:
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_mesh()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Mesh *mesh = static_cast<Mesh *>(geom);
|
2020-02-03 21:40:58 +01:00
|
|
|
if (prim == ATTR_PRIM_GEOMETRY) {
|
2020-02-02 12:04:19 +01:00
|
|
|
size = mesh->num_triangles() * 3;
|
|
|
|
|
}
|
|
|
|
|
else {
|
2020-11-04 11:17:38 +01:00
|
|
|
size = mesh->get_subd_face_corners().size() + mesh->get_num_ngons();
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
|
case ATTR_ELEMENT_CURVE:
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_hair()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Hair *hair = static_cast<Hair *>(geom);
|
|
|
|
|
size = hair->num_curves();
|
|
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
|
case ATTR_ELEMENT_CURVE_KEY:
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_hair()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Hair *hair = static_cast<Hair *>(geom);
|
2020-11-04 11:17:38 +01:00
|
|
|
size = hair->get_curve_keys().size();
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
2014-03-29 13:03:46 +01:00
|
|
|
case ATTR_ELEMENT_CURVE_KEY_MOTION:
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geom->is_hair()) {
|
2020-02-02 12:04:19 +01:00
|
|
|
Hair *hair = static_cast<Hair *>(geom);
|
2021-07-29 12:06:07 +02:00
|
|
|
DCHECK_GT(hair->get_motion_steps(), 0);
|
2020-11-04 11:17:38 +01:00
|
|
|
size = hair->get_curve_keys().size() * (hair->get_motion_steps() - 1);
|
2020-02-02 12:04:19 +01:00
|
|
|
}
|
2014-03-29 13:03:46 +01:00
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
default:
|
|
|
|
|
break;
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-04-05 17:03:59 +00:00
|
|
|
return size;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
size_t Attribute::buffer_size(Geometry *geom, AttributePrimitive prim) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2020-02-02 12:04:19 +01:00
|
|
|
return element_size(geom, prim) * data_sizeof();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool Attribute::same_storage(TypeDesc a, TypeDesc b)
|
|
|
|
|
{
|
2023-09-17 09:01:48 +10:00
|
|
|
if (a == b) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2018-07-06 10:17:58 +02:00
|
|
|
|
2024-10-17 19:48:38 +02:00
|
|
|
if (a == TypeColor || a == TypePoint || a == TypeVector || a == TypeNormal) {
|
|
|
|
|
if (b == TypeColor || b == TypePoint || b == TypeVector || b == TypeNormal) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
2012-06-09 18:56:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-07-16 19:42:28 -04:00
|
|
|
void Attribute::zero_data(void *dst)
|
|
|
|
|
{
|
|
|
|
|
memset(dst, 0, data_sizeof());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Attribute::add_with_weight(void *dst, void *src, float weight)
|
|
|
|
|
{
|
|
|
|
|
if (element == ATTR_ELEMENT_CORNER_BYTE) {
|
|
|
|
|
for (int i = 0; i < 4; i++) {
|
|
|
|
|
((uchar *)dst)[i] += uchar(((uchar *)src)[i] * weight);
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-17 19:48:38 +02:00
|
|
|
else if (same_storage(type, TypeFloat)) {
|
2016-07-16 19:42:28 -04:00
|
|
|
*((float *)dst) += *((float *)src) * weight;
|
|
|
|
|
}
|
2019-04-25 14:31:45 +02:00
|
|
|
else if (same_storage(type, TypeFloat2)) {
|
|
|
|
|
*((float2 *)dst) += *((float2 *)src) * weight;
|
|
|
|
|
}
|
2024-10-17 19:48:38 +02:00
|
|
|
else if (same_storage(type, TypeVector)) {
|
2023-02-27 10:39:19 +01:00
|
|
|
// Points are float3s and not float4s
|
|
|
|
|
*((float3 *)dst) += *((float3 *)src) * weight;
|
2016-07-16 19:42:28 -04:00
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
assert(!"not implemented for this type");
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
const char *Attribute::standard_name(AttributeStandard std)
|
|
|
|
|
{
|
2014-03-29 13:03:48 +01:00
|
|
|
switch (std) {
|
|
|
|
|
case ATTR_STD_VERTEX_NORMAL:
|
|
|
|
|
return "N";
|
|
|
|
|
case ATTR_STD_FACE_NORMAL:
|
|
|
|
|
return "Ng";
|
|
|
|
|
case ATTR_STD_UV:
|
|
|
|
|
return "uv";
|
|
|
|
|
case ATTR_STD_GENERATED:
|
|
|
|
|
return "generated";
|
|
|
|
|
case ATTR_STD_GENERATED_TRANSFORM:
|
|
|
|
|
return "generated_transform";
|
|
|
|
|
case ATTR_STD_UV_TANGENT:
|
|
|
|
|
return "tangent";
|
|
|
|
|
case ATTR_STD_UV_TANGENT_SIGN:
|
|
|
|
|
return "tangent_sign";
|
2020-02-18 17:19:16 +01:00
|
|
|
case ATTR_STD_VERTEX_COLOR:
|
|
|
|
|
return "vertex_color";
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_POSITION_UNDEFORMED:
|
|
|
|
|
return "undeformed";
|
|
|
|
|
case ATTR_STD_POSITION_UNDISPLACED:
|
|
|
|
|
return "undisplaced";
|
|
|
|
|
case ATTR_STD_MOTION_VERTEX_POSITION:
|
|
|
|
|
return "motion_P";
|
|
|
|
|
case ATTR_STD_MOTION_VERTEX_NORMAL:
|
|
|
|
|
return "motion_N";
|
|
|
|
|
case ATTR_STD_PARTICLE:
|
|
|
|
|
return "particle";
|
|
|
|
|
case ATTR_STD_CURVE_INTERCEPT:
|
|
|
|
|
return "curve_intercept";
|
2021-09-24 07:42:36 +02:00
|
|
|
case ATTR_STD_CURVE_LENGTH:
|
|
|
|
|
return "curve_length";
|
2018-02-14 14:32:38 +01:00
|
|
|
case ATTR_STD_CURVE_RANDOM:
|
|
|
|
|
return "curve_random";
|
2021-12-01 17:30:46 +01:00
|
|
|
case ATTR_STD_POINT_RANDOM:
|
|
|
|
|
return "point_random";
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_PTEX_FACE_ID:
|
|
|
|
|
return "ptex_face_id";
|
|
|
|
|
case ATTR_STD_PTEX_UV:
|
|
|
|
|
return "ptex_uv";
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_VOLUME_DENSITY:
|
|
|
|
|
return "density";
|
|
|
|
|
case ATTR_STD_VOLUME_COLOR:
|
|
|
|
|
return "color";
|
|
|
|
|
case ATTR_STD_VOLUME_FLAME:
|
|
|
|
|
return "flame";
|
|
|
|
|
case ATTR_STD_VOLUME_HEAT:
|
|
|
|
|
return "heat";
|
2018-02-18 03:13:07 +01:00
|
|
|
case ATTR_STD_VOLUME_TEMPERATURE:
|
|
|
|
|
return "temperature";
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_VOLUME_VELOCITY:
|
|
|
|
|
return "velocity";
|
2022-04-19 16:28:14 +02:00
|
|
|
case ATTR_STD_VOLUME_VELOCITY_X:
|
|
|
|
|
return "velocity_x";
|
|
|
|
|
case ATTR_STD_VOLUME_VELOCITY_Y:
|
|
|
|
|
return "velocity_y";
|
|
|
|
|
case ATTR_STD_VOLUME_VELOCITY_Z:
|
|
|
|
|
return "velocity_z";
|
2015-02-06 12:35:46 +05:00
|
|
|
case ATTR_STD_POINTINESS:
|
|
|
|
|
return "pointiness";
|
2019-11-27 12:07:20 +02:00
|
|
|
case ATTR_STD_RANDOM_PER_ISLAND:
|
|
|
|
|
return "random_per_island";
|
2021-09-20 16:16:11 +02:00
|
|
|
case ATTR_STD_SHADOW_TRANSPARENCY:
|
|
|
|
|
return "shadow_transparency";
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_NOT_FOUND:
|
|
|
|
|
case ATTR_STD_NONE:
|
|
|
|
|
case ATTR_STD_NUM:
|
|
|
|
|
return "";
|
|
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
return "";
|
|
|
|
|
}
|
|
|
|
|
|
2014-03-29 13:03:48 +01:00
|
|
|
AttributeStandard Attribute::name_standard(const char *name)
|
|
|
|
|
{
|
2018-02-18 03:20:39 +01:00
|
|
|
if (name) {
|
|
|
|
|
for (int std = ATTR_STD_NONE; std < ATTR_STD_NUM; std++) {
|
|
|
|
|
if (strcmp(name, Attribute::standard_name((AttributeStandard)std)) == 0) {
|
|
|
|
|
return (AttributeStandard)std;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-03-29 13:03:48 +01:00
|
|
|
|
|
|
|
|
return ATTR_STD_NONE;
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: optimize attributes device updates
When an `AttributeSet` is tagged as modified, which happens after the addition or
removal of an `Attribute` from the set, during the following GeometryManager device
update, we update and repack the kernel data for all attribute types. However, if we
only add or remove a `float` attribute, `float2` or `float3` attributes should not
be repacked for efficiency.
This patch adds some mechanisms to detect which attribute types are modified from
the AttributeSet.
Firstly, this adds an `AttrKernelDataType` to map the data type of the Attribute to
the one used in the kernel as there is no one to one match between the two since e.g.
`Transform` or `float4` data are stored as `float3s` in the kernel.
Then, this replaces the `AttributeSet.modified` boolean with a set of flags to detect
which types have been modified. There is no specific flag type (e.g.
`enum ModifiedType`), rather the flags used derive simply from the
`AttrKernelDataType` enumeration, to keep things synchronized.
The logic to remove an `Attribute` from the `AttributeSet` and tag the latter as modified
is centralized in a new `AttributeSet.remove` method taking an iterator as input.
Lastly, as some attributes like standard normals are not stored in the various
kernel attribute arrays (`DeviceScene::attribute_*`), the modified flags are only
set if the associated standard corresponds to an attribute which will be stored
in the kernel's attribute arrays. This makes it so adding or removing such attributes
does not trigger an unnecessary update of other type-related attributes.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D11373
2021-05-18 13:09:29 +02:00
|
|
|
AttrKernelDataType Attribute::kernel_type(const Attribute &attr)
|
|
|
|
|
{
|
|
|
|
|
if (attr.element == ATTR_ELEMENT_CORNER) {
|
|
|
|
|
return AttrKernelDataType::UCHAR4;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 19:48:38 +02:00
|
|
|
if (attr.type == TypeFloat) {
|
Cycles: optimize attributes device updates
When an `AttributeSet` is tagged as modified, which happens after the addition or
removal of an `Attribute` from the set, during the following GeometryManager device
update, we update and repack the kernel data for all attribute types. However, if we
only add or remove a `float` attribute, `float2` or `float3` attributes should not
be repacked for efficiency.
This patch adds some mechanisms to detect which attribute types are modified from
the AttributeSet.
Firstly, this adds an `AttrKernelDataType` to map the data type of the Attribute to
the one used in the kernel as there is no one to one match between the two since e.g.
`Transform` or `float4` data are stored as `float3s` in the kernel.
Then, this replaces the `AttributeSet.modified` boolean with a set of flags to detect
which types have been modified. There is no specific flag type (e.g.
`enum ModifiedType`), rather the flags used derive simply from the
`AttrKernelDataType` enumeration, to keep things synchronized.
The logic to remove an `Attribute` from the `AttributeSet` and tag the latter as modified
is centralized in a new `AttributeSet.remove` method taking an iterator as input.
Lastly, as some attributes like standard normals are not stored in the various
kernel attribute arrays (`DeviceScene::attribute_*`), the modified flags are only
set if the associated standard corresponds to an attribute which will be stored
in the kernel's attribute arrays. This makes it so adding or removing such attributes
does not trigger an unnecessary update of other type-related attributes.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D11373
2021-05-18 13:09:29 +02:00
|
|
|
return AttrKernelDataType::FLOAT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attr.type == TypeFloat2) {
|
|
|
|
|
return AttrKernelDataType::FLOAT2;
|
|
|
|
|
}
|
|
|
|
|
|
2024-10-17 19:48:38 +02:00
|
|
|
if (attr.type == TypeFloat4 || attr.type == TypeRGBA || attr.type == TypeMatrix) {
|
2021-11-16 14:03:59 +01:00
|
|
|
return AttrKernelDataType::FLOAT4;
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: optimize attributes device updates
When an `AttributeSet` is tagged as modified, which happens after the addition or
removal of an `Attribute` from the set, during the following GeometryManager device
update, we update and repack the kernel data for all attribute types. However, if we
only add or remove a `float` attribute, `float2` or `float3` attributes should not
be repacked for efficiency.
This patch adds some mechanisms to detect which attribute types are modified from
the AttributeSet.
Firstly, this adds an `AttrKernelDataType` to map the data type of the Attribute to
the one used in the kernel as there is no one to one match between the two since e.g.
`Transform` or `float4` data are stored as `float3s` in the kernel.
Then, this replaces the `AttributeSet.modified` boolean with a set of flags to detect
which types have been modified. There is no specific flag type (e.g.
`enum ModifiedType`), rather the flags used derive simply from the
`AttrKernelDataType` enumeration, to keep things synchronized.
The logic to remove an `Attribute` from the `AttributeSet` and tag the latter as modified
is centralized in a new `AttributeSet.remove` method taking an iterator as input.
Lastly, as some attributes like standard normals are not stored in the various
kernel attribute arrays (`DeviceScene::attribute_*`), the modified flags are only
set if the associated standard corresponds to an attribute which will be stored
in the kernel's attribute arrays. This makes it so adding or removing such attributes
does not trigger an unnecessary update of other type-related attributes.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D11373
2021-05-18 13:09:29 +02:00
|
|
|
return AttrKernelDataType::FLOAT3;
|
|
|
|
|
}
|
|
|
|
|
|
2020-02-02 12:04:19 +01:00
|
|
|
void Attribute::get_uv_tiles(Geometry *geom,
|
|
|
|
|
AttributePrimitive prim,
|
|
|
|
|
unordered_set<int> &tiles) const
|
|
|
|
|
{
|
|
|
|
|
if (type != TypeFloat2) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const int num = element_size(geom, prim);
|
|
|
|
|
const float2 *uv = data_float2();
|
|
|
|
|
for (int i = 0; i < num; i++, uv++) {
|
|
|
|
|
float u = uv->x, v = uv->y;
|
|
|
|
|
int x = (int)u, y = (int)v;
|
|
|
|
|
|
|
|
|
|
if (x < 0 || y < 0 || x >= 10) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* Be conservative in corners - precisely touching the right or upper edge of a tile
|
|
|
|
|
* should not load its right/upper neighbor as well. */
|
|
|
|
|
if (x > 0 && (u < x + 1e-6f)) {
|
|
|
|
|
x--;
|
|
|
|
|
}
|
|
|
|
|
if (y > 0 && (v < y + 1e-6f)) {
|
|
|
|
|
y--;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
tiles.insert(1001 + 10 * y + x);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* Attribute Set */
|
|
|
|
|
|
2020-02-03 21:40:58 +01:00
|
|
|
AttributeSet::AttributeSet(Geometry *geometry, AttributePrimitive prim)
|
Cycles: optimize attributes device updates
When an `AttributeSet` is tagged as modified, which happens after the addition or
removal of an `Attribute` from the set, during the following GeometryManager device
update, we update and repack the kernel data for all attribute types. However, if we
only add or remove a `float` attribute, `float2` or `float3` attributes should not
be repacked for efficiency.
This patch adds some mechanisms to detect which attribute types are modified from
the AttributeSet.
Firstly, this adds an `AttrKernelDataType` to map the data type of the Attribute to
the one used in the kernel as there is no one to one match between the two since e.g.
`Transform` or `float4` data are stored as `float3s` in the kernel.
Then, this replaces the `AttributeSet.modified` boolean with a set of flags to detect
which types have been modified. There is no specific flag type (e.g.
`enum ModifiedType`), rather the flags used derive simply from the
`AttrKernelDataType` enumeration, to keep things synchronized.
The logic to remove an `Attribute` from the `AttributeSet` and tag the latter as modified
is centralized in a new `AttributeSet.remove` method taking an iterator as input.
Lastly, as some attributes like standard normals are not stored in the various
kernel attribute arrays (`DeviceScene::attribute_*`), the modified flags are only
set if the associated standard corresponds to an attribute which will be stored
in the kernel's attribute arrays. This makes it so adding or removing such attributes
does not trigger an unnecessary update of other type-related attributes.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D11373
2021-05-18 13:09:29 +02:00
|
|
|
: modified_flag(~0u), geometry(geometry), prim(prim)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
AttributeSet::~AttributeSet() = default;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement element)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
Attribute *attr = find(name);
|
|
|
|
|
|
|
|
|
|
if (attr) {
|
|
|
|
|
/* return if same already exists */
|
2023-09-17 09:01:48 +10:00
|
|
|
if (attr->type == type && attr->element == element) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return attr;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
/* overwrite attribute with same name but different type/element */
|
|
|
|
|
remove(name);
|
|
|
|
|
}
|
|
|
|
|
|
2020-03-08 14:21:29 +01:00
|
|
|
Attribute new_attr(name, type, element, geometry, prim);
|
|
|
|
|
attributes.emplace_back(std::move(new_attr));
|
Cycles: optimize attributes device updates
When an `AttributeSet` is tagged as modified, which happens after the addition or
removal of an `Attribute` from the set, during the following GeometryManager device
update, we update and repack the kernel data for all attribute types. However, if we
only add or remove a `float` attribute, `float2` or `float3` attributes should not
be repacked for efficiency.
This patch adds some mechanisms to detect which attribute types are modified from
the AttributeSet.
Firstly, this adds an `AttrKernelDataType` to map the data type of the Attribute to
the one used in the kernel as there is no one to one match between the two since e.g.
`Transform` or `float4` data are stored as `float3s` in the kernel.
Then, this replaces the `AttributeSet.modified` boolean with a set of flags to detect
which types have been modified. There is no specific flag type (e.g.
`enum ModifiedType`), rather the flags used derive simply from the
`AttrKernelDataType` enumeration, to keep things synchronized.
The logic to remove an `Attribute` from the `AttributeSet` and tag the latter as modified
is centralized in a new `AttributeSet.remove` method taking an iterator as input.
Lastly, as some attributes like standard normals are not stored in the various
kernel attribute arrays (`DeviceScene::attribute_*`), the modified flags are only
set if the associated standard corresponds to an attribute which will be stored
in the kernel's attribute arrays. This makes it so adding or removing such attributes
does not trigger an unnecessary update of other type-related attributes.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D11373
2021-05-18 13:09:29 +02:00
|
|
|
tag_modified(attributes.back());
|
2020-03-08 14:21:29 +01:00
|
|
|
return &attributes.back();
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
Attribute *AttributeSet::find(ustring name) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-26 19:41:25 +01:00
|
|
|
for (const Attribute &attr : attributes) {
|
2023-09-17 09:01:48 +10:00
|
|
|
if (attr.name == name) {
|
2013-01-03 12:08:54 +00:00
|
|
|
return (Attribute *)&attr;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 19:41:25 +01:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-26 17:53:55 +01:00
|
|
|
return nullptr;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AttributeSet::remove(ustring name)
|
|
|
|
|
{
|
|
|
|
|
Attribute *attr = find(name);
|
|
|
|
|
|
|
|
|
|
if (attr) {
|
|
|
|
|
list<Attribute>::iterator it;
|
|
|
|
|
|
|
|
|
|
for (it = attributes.begin(); it != attributes.end(); it++) {
|
|
|
|
|
if (&*it == attr) {
|
Cycles: optimize attributes device updates
When an `AttributeSet` is tagged as modified, which happens after the addition or
removal of an `Attribute` from the set, during the following GeometryManager device
update, we update and repack the kernel data for all attribute types. However, if we
only add or remove a `float` attribute, `float2` or `float3` attributes should not
be repacked for efficiency.
This patch adds some mechanisms to detect which attribute types are modified from
the AttributeSet.
Firstly, this adds an `AttrKernelDataType` to map the data type of the Attribute to
the one used in the kernel as there is no one to one match between the two since e.g.
`Transform` or `float4` data are stored as `float3s` in the kernel.
Then, this replaces the `AttributeSet.modified` boolean with a set of flags to detect
which types have been modified. There is no specific flag type (e.g.
`enum ModifiedType`), rather the flags used derive simply from the
`AttrKernelDataType` enumeration, to keep things synchronized.
The logic to remove an `Attribute` from the `AttributeSet` and tag the latter as modified
is centralized in a new `AttributeSet.remove` method taking an iterator as input.
Lastly, as some attributes like standard normals are not stored in the various
kernel attribute arrays (`DeviceScene::attribute_*`), the modified flags are only
set if the associated standard corresponds to an attribute which will be stored
in the kernel's attribute arrays. This makes it so adding or removing such attributes
does not trigger an unnecessary update of other type-related attributes.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D11373
2021-05-18 13:09:29 +02:00
|
|
|
remove(it);
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
Attribute *AttributeSet::add(AttributeStandard std, ustring name)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-26 17:53:55 +01:00
|
|
|
Attribute *attr = nullptr;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
if (name.empty()) {
|
2013-01-03 12:08:54 +00:00
|
|
|
name = Attribute::standard_name(std);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2024-10-30 16:45:56 +01:00
|
|
|
if (geometry->is_mesh()) {
|
2013-04-05 17:03:59 +00:00
|
|
|
switch (std) {
|
|
|
|
|
case ATTR_STD_VERTEX_NORMAL:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeNormal, ATTR_ELEMENT_VERTEX);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_FACE_NORMAL:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeNormal, ATTR_ELEMENT_FACE);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_UV:
|
2019-03-05 14:54:54 +01:00
|
|
|
attr = add(name, TypeFloat2, ATTR_ELEMENT_CORNER);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_UV_TANGENT:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeVector, ATTR_ELEMENT_CORNER);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_UV_TANGENT_SIGN:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_CORNER);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
2020-02-18 17:19:16 +01:00
|
|
|
case ATTR_STD_VERTEX_COLOR:
|
2020-02-19 18:44:07 +01:00
|
|
|
attr = add(name, TypeRGBA, ATTR_ELEMENT_CORNER_BYTE);
|
2020-02-18 17:19:16 +01:00
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
case ATTR_STD_GENERATED:
|
|
|
|
|
case ATTR_STD_POSITION_UNDEFORMED:
|
|
|
|
|
case ATTR_STD_POSITION_UNDISPLACED:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypePoint, ATTR_ELEMENT_VERTEX);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
2014-03-29 13:03:46 +01:00
|
|
|
case ATTR_STD_MOTION_VERTEX_POSITION:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypePoint, ATTR_ELEMENT_VERTEX_MOTION);
|
2014-03-29 13:03:46 +01:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_MOTION_VERTEX_NORMAL:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeNormal, ATTR_ELEMENT_VERTEX_MOTION);
|
2014-03-29 13:03:46 +01:00
|
|
|
break;
|
2013-11-28 01:28:57 +01:00
|
|
|
case ATTR_STD_PTEX_FACE_ID:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_FACE);
|
2013-11-28 01:28:57 +01:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_PTEX_UV:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypePoint, ATTR_ELEMENT_VERTEX);
|
2013-11-28 01:28:57 +01:00
|
|
|
break;
|
2013-12-31 17:33:55 +01:00
|
|
|
case ATTR_STD_GENERATED_TRANSFORM:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeMatrix, ATTR_ELEMENT_MESH);
|
2013-12-31 17:33:55 +01:00
|
|
|
break;
|
2020-08-19 15:46:50 +02:00
|
|
|
case ATTR_STD_POINTINESS:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_VERTEX);
|
2020-08-19 15:46:50 +02:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_RANDOM_PER_ISLAND:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_FACE);
|
2020-08-19 15:46:50 +02:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-30 16:45:56 +01:00
|
|
|
else if (geometry->is_pointcloud()) {
|
2021-12-01 17:30:46 +01:00
|
|
|
switch (std) {
|
|
|
|
|
case ATTR_STD_UV:
|
|
|
|
|
attr = add(name, TypeFloat2, ATTR_ELEMENT_VERTEX);
|
|
|
|
|
break;
|
|
|
|
|
case ATTR_STD_GENERATED:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypePoint, ATTR_ELEMENT_VERTEX);
|
2021-12-01 17:30:46 +01:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_MOTION_VERTEX_POSITION:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat4, ATTR_ELEMENT_VERTEX_MOTION);
|
2021-12-01 17:30:46 +01:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_POINT_RANDOM:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_VERTEX);
|
2021-12-01 17:30:46 +01:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_GENERATED_TRANSFORM:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeMatrix, ATTR_ELEMENT_MESH);
|
2021-12-01 17:30:46 +01:00
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
2024-10-30 16:45:56 +01:00
|
|
|
else if (geometry->is_volume()) {
|
2020-08-19 15:46:50 +02:00
|
|
|
switch (std) {
|
|
|
|
|
case ATTR_STD_VERTEX_NORMAL:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeNormal, ATTR_ELEMENT_VERTEX);
|
2020-08-19 15:46:50 +02:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_FACE_NORMAL:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeNormal, ATTR_ELEMENT_FACE);
|
2020-08-19 15:46:50 +02:00
|
|
|
break;
|
2014-03-29 13:03:48 +01:00
|
|
|
case ATTR_STD_VOLUME_DENSITY:
|
|
|
|
|
case ATTR_STD_VOLUME_FLAME:
|
|
|
|
|
case ATTR_STD_VOLUME_HEAT:
|
2018-02-18 03:13:07 +01:00
|
|
|
case ATTR_STD_VOLUME_TEMPERATURE:
|
2022-04-19 16:28:14 +02:00
|
|
|
case ATTR_STD_VOLUME_VELOCITY_X:
|
|
|
|
|
case ATTR_STD_VOLUME_VELOCITY_Y:
|
|
|
|
|
case ATTR_STD_VOLUME_VELOCITY_Z:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_VOXEL);
|
2014-03-29 13:03:48 +01:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_VOLUME_COLOR:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeColor, ATTR_ELEMENT_VOXEL);
|
2014-03-29 13:03:48 +01:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_VOLUME_VELOCITY:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeVector, ATTR_ELEMENT_VOXEL);
|
2014-03-29 13:03:48 +01:00
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2024-10-30 16:45:56 +01:00
|
|
|
else if (geometry->is_hair()) {
|
2013-04-05 17:03:59 +00:00
|
|
|
switch (std) {
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
case ATTR_STD_VERTEX_NORMAL:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeNormal, ATTR_ELEMENT_CURVE_KEY);
|
Cycles: new Principled Hair BSDF variant with elliptical cross-section support
Implements the paper [A Microfacet-based Hair Scattering
Model](https://onlinelibrary.wiley.com/doi/full/10.1111/cgf.14588) by
Weizhen Huang, Matthias B. Hullin and Johannes Hanika.
### Features:
- This is a far-field model, as opposed to the previous near-field
Principled Hair BSDF model. The hair is expected to be less noisy, but
lower roughness values takes longer to render due to numerical
integration along the hair width. The hair also appears to be flat when
viewed up-close.
- The longitudinal width of the scattering lobe differs along the
azimuth, providing a higher contrast compared to the evenly spread
scattering in the near-field Principled Hair BSDF model. For a more
detailed comparison, please refer to the original paper.
- Supports elliptical cross-sections, adding more realism as human hairs
are usually elliptical. The orientation of the cross-section is aligned
with the curve normal, which can be adjusted using geometry nodes.
Default is minimal twist. During sampling, light rays that hit outside
the hair width will continue propogating as if the material is
transparent.
- There is non-physical modulation factors for the first three
lobes (Reflection, Transmission, Secondary Reflection).
### Missing:
- A good default for cross-section orientation. There was an
attempt (9039f76928) to default the orientation to align with the curve
normal in the mathematical sense, but the stability (when animated) is
unclear and it would be a hassle to generalise to all curve types. After
the model is in main, we could experiment with the geometry nodes team
to see what works the best as a default.
Co-authored-by: Lukas Stockner <lukas.stockner@freenet.de>
Pull Request: https://projects.blender.org/blender/blender/pulls/105600
2023-08-18 12:46:13 +02:00
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
case ATTR_STD_UV:
|
2019-03-20 16:59:49 +01:00
|
|
|
attr = add(name, TypeFloat2, ATTR_ELEMENT_CURVE);
|
|
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
case ATTR_STD_GENERATED:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypePoint, ATTR_ELEMENT_CURVE);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
2014-03-29 13:03:46 +01:00
|
|
|
case ATTR_STD_MOTION_VERTEX_POSITION:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat4, ATTR_ELEMENT_CURVE_KEY_MOTION);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
|
|
|
|
case ATTR_STD_CURVE_INTERCEPT:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_CURVE_KEY);
|
2013-04-05 17:03:59 +00:00
|
|
|
break;
|
2021-09-24 07:42:36 +02:00
|
|
|
case ATTR_STD_CURVE_LENGTH:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_CURVE);
|
2021-09-24 07:42:36 +02:00
|
|
|
break;
|
2018-02-14 14:32:38 +01:00
|
|
|
case ATTR_STD_CURVE_RANDOM:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_CURVE);
|
2018-02-13 14:20:47 +01:00
|
|
|
break;
|
2013-12-31 17:33:55 +01:00
|
|
|
case ATTR_STD_GENERATED_TRANSFORM:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeMatrix, ATTR_ELEMENT_MESH);
|
2013-12-31 17:33:55 +01:00
|
|
|
break;
|
2015-02-06 12:35:46 +05:00
|
|
|
case ATTR_STD_POINTINESS:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_VERTEX);
|
2015-02-06 12:35:46 +05:00
|
|
|
break;
|
2019-11-27 12:07:20 +02:00
|
|
|
case ATTR_STD_RANDOM_PER_ISLAND:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_FACE);
|
2019-11-27 12:07:20 +02:00
|
|
|
break;
|
2021-09-20 16:16:11 +02:00
|
|
|
case ATTR_STD_SHADOW_TRANSPARENCY:
|
2024-10-17 19:48:38 +02:00
|
|
|
attr = add(name, TypeFloat, ATTR_ELEMENT_CURVE_KEY);
|
2021-09-20 16:16:11 +02:00
|
|
|
break;
|
2013-04-05 17:03:59 +00:00
|
|
|
default:
|
|
|
|
|
assert(0);
|
|
|
|
|
break;
|
|
|
|
|
}
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
attr->std = std;
|
2019-04-17 06:17:24 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return attr;
|
|
|
|
|
}
|
|
|
|
|
|
2013-01-03 12:08:54 +00:00
|
|
|
Attribute *AttributeSet::find(AttributeStandard std) const
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-26 19:41:25 +01:00
|
|
|
for (const Attribute &attr : attributes) {
|
2023-09-17 09:01:48 +10:00
|
|
|
if (attr.std == std) {
|
2013-01-03 12:08:54 +00:00
|
|
|
return (Attribute *)&attr;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 19:41:25 +01:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-26 17:53:55 +01:00
|
|
|
return nullptr;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2022-06-02 16:42:53 +02:00
|
|
|
Attribute *AttributeSet::find_matching(const Attribute &other)
|
|
|
|
|
{
|
|
|
|
|
for (Attribute &attr : attributes) {
|
|
|
|
|
if (attr.name != other.name) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (attr.std != other.std) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (attr.type != other.type) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
if (attr.element != other.element) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
return &attr;
|
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
void AttributeSet::remove(AttributeStandard std)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
Attribute *attr = find(std);
|
|
|
|
|
|
|
|
|
|
if (attr) {
|
|
|
|
|
list<Attribute>::iterator it;
|
|
|
|
|
|
|
|
|
|
for (it = attributes.begin(); it != attributes.end(); it++) {
|
|
|
|
|
if (&*it == attr) {
|
Cycles: optimize attributes device updates
When an `AttributeSet` is tagged as modified, which happens after the addition or
removal of an `Attribute` from the set, during the following GeometryManager device
update, we update and repack the kernel data for all attribute types. However, if we
only add or remove a `float` attribute, `float2` or `float3` attributes should not
be repacked for efficiency.
This patch adds some mechanisms to detect which attribute types are modified from
the AttributeSet.
Firstly, this adds an `AttrKernelDataType` to map the data type of the Attribute to
the one used in the kernel as there is no one to one match between the two since e.g.
`Transform` or `float4` data are stored as `float3s` in the kernel.
Then, this replaces the `AttributeSet.modified` boolean with a set of flags to detect
which types have been modified. There is no specific flag type (e.g.
`enum ModifiedType`), rather the flags used derive simply from the
`AttrKernelDataType` enumeration, to keep things synchronized.
The logic to remove an `Attribute` from the `AttributeSet` and tag the latter as modified
is centralized in a new `AttributeSet.remove` method taking an iterator as input.
Lastly, as some attributes like standard normals are not stored in the various
kernel attribute arrays (`DeviceScene::attribute_*`), the modified flags are only
set if the associated standard corresponds to an attribute which will be stored
in the kernel's attribute arrays. This makes it so adding or removing such attributes
does not trigger an unnecessary update of other type-related attributes.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D11373
2021-05-18 13:09:29 +02:00
|
|
|
remove(it);
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Attribute *AttributeSet::find(AttributeRequest &req)
|
|
|
|
|
{
|
2023-09-17 09:01:48 +10:00
|
|
|
if (req.std == ATTR_STD_NONE) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return find(req.name);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 17:53:59 +01:00
|
|
|
return find(req.std);
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2017-08-25 22:51:44 +02:00
|
|
|
void AttributeSet::remove(Attribute *attribute)
|
|
|
|
|
{
|
|
|
|
|
if (attribute->std == ATTR_STD_NONE) {
|
|
|
|
|
remove(attribute->name);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
remove(attribute->std);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
Cycles: optimize attributes device updates
When an `AttributeSet` is tagged as modified, which happens after the addition or
removal of an `Attribute` from the set, during the following GeometryManager device
update, we update and repack the kernel data for all attribute types. However, if we
only add or remove a `float` attribute, `float2` or `float3` attributes should not
be repacked for efficiency.
This patch adds some mechanisms to detect which attribute types are modified from
the AttributeSet.
Firstly, this adds an `AttrKernelDataType` to map the data type of the Attribute to
the one used in the kernel as there is no one to one match between the two since e.g.
`Transform` or `float4` data are stored as `float3s` in the kernel.
Then, this replaces the `AttributeSet.modified` boolean with a set of flags to detect
which types have been modified. There is no specific flag type (e.g.
`enum ModifiedType`), rather the flags used derive simply from the
`AttrKernelDataType` enumeration, to keep things synchronized.
The logic to remove an `Attribute` from the `AttributeSet` and tag the latter as modified
is centralized in a new `AttributeSet.remove` method taking an iterator as input.
Lastly, as some attributes like standard normals are not stored in the various
kernel attribute arrays (`DeviceScene::attribute_*`), the modified flags are only
set if the associated standard corresponds to an attribute which will be stored
in the kernel's attribute arrays. This makes it so adding or removing such attributes
does not trigger an unnecessary update of other type-related attributes.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D11373
2021-05-18 13:09:29 +02:00
|
|
|
void AttributeSet::remove(list<Attribute>::iterator it)
|
|
|
|
|
{
|
|
|
|
|
tag_modified(*it);
|
|
|
|
|
attributes.erase(it);
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-08 00:09:08 +02:00
|
|
|
void AttributeSet::resize(bool reserve_only)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Attribute &attr : attributes) {
|
2020-02-03 21:40:58 +01:00
|
|
|
attr.resize(geometry, prim, reserve_only);
|
2013-01-03 12:08:54 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2018-03-01 11:54:01 +01:00
|
|
|
void AttributeSet::clear(bool preserve_voxel_data)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2018-03-01 11:54:01 +01:00
|
|
|
if (preserve_voxel_data) {
|
|
|
|
|
list<Attribute>::iterator it;
|
|
|
|
|
|
|
|
|
|
for (it = attributes.begin(); it != attributes.end();) {
|
|
|
|
|
if (it->element == ATTR_ELEMENT_VOXEL || it->std == ATTR_STD_GENERATED_TRANSFORM) {
|
|
|
|
|
it++;
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
attributes.erase(it++);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
attributes.clear();
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
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
2021-01-22 15:01:26 +01:00
|
|
|
void AttributeSet::update(AttributeSet &&new_attributes)
|
|
|
|
|
{
|
2022-06-02 16:42:53 +02:00
|
|
|
/* Remove any attributes not on new_attributes. */
|
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
2021-01-22 15:01:26 +01:00
|
|
|
list<Attribute>::iterator it;
|
|
|
|
|
for (it = attributes.begin(); it != attributes.end();) {
|
2022-06-02 16:42:53 +02:00
|
|
|
const Attribute &old_attr = *it;
|
|
|
|
|
if (new_attributes.find_matching(old_attr) == nullptr) {
|
|
|
|
|
remove(it++);
|
|
|
|
|
continue;
|
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
2021-01-22 15:01:26 +01:00
|
|
|
}
|
|
|
|
|
it++;
|
|
|
|
|
}
|
2021-04-29 15:46:06 +02:00
|
|
|
|
2022-06-02 16:42:53 +02:00
|
|
|
/* Add or update old_attributes based on the new_attributes. */
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Attribute &attr : new_attributes.attributes) {
|
2022-06-02 16:42:53 +02:00
|
|
|
Attribute *nattr = add(attr.name, attr.type, attr.element);
|
|
|
|
|
nattr->std = attr.std;
|
|
|
|
|
nattr->set_data_from(std::move(attr));
|
|
|
|
|
}
|
|
|
|
|
|
2021-04-29 15:46:06 +02:00
|
|
|
/* If all attributes were replaced, transform is no longer applied. */
|
|
|
|
|
geometry->transform_applied = false;
|
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
2021-01-22 15:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AttributeSet::clear_modified()
|
|
|
|
|
{
|
2024-12-26 19:41:25 +01:00
|
|
|
for (Attribute &attr : attributes) {
|
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
2021-01-22 15:01:26 +01:00
|
|
|
attr.modified = false;
|
|
|
|
|
}
|
Cycles: optimize attributes device updates
When an `AttributeSet` is tagged as modified, which happens after the addition or
removal of an `Attribute` from the set, during the following GeometryManager device
update, we update and repack the kernel data for all attribute types. However, if we
only add or remove a `float` attribute, `float2` or `float3` attributes should not
be repacked for efficiency.
This patch adds some mechanisms to detect which attribute types are modified from
the AttributeSet.
Firstly, this adds an `AttrKernelDataType` to map the data type of the Attribute to
the one used in the kernel as there is no one to one match between the two since e.g.
`Transform` or `float4` data are stored as `float3s` in the kernel.
Then, this replaces the `AttributeSet.modified` boolean with a set of flags to detect
which types have been modified. There is no specific flag type (e.g.
`enum ModifiedType`), rather the flags used derive simply from the
`AttrKernelDataType` enumeration, to keep things synchronized.
The logic to remove an `Attribute` from the `AttributeSet` and tag the latter as modified
is centralized in a new `AttributeSet.remove` method taking an iterator as input.
Lastly, as some attributes like standard normals are not stored in the various
kernel attribute arrays (`DeviceScene::attribute_*`), the modified flags are only
set if the associated standard corresponds to an attribute which will be stored
in the kernel's attribute arrays. This makes it so adding or removing such attributes
does not trigger an unnecessary update of other type-related attributes.
Reviewed By: brecht
Differential Revision: https://developer.blender.org/D11373
2021-05-18 13:09:29 +02:00
|
|
|
|
|
|
|
|
modified_flag = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AttributeSet::tag_modified(const Attribute &attr)
|
|
|
|
|
{
|
|
|
|
|
/* Some attributes are not stored in the various kernel attribute arrays
|
|
|
|
|
* (DeviceScene::attribute_*), so the modified flags are only set if the associated standard
|
|
|
|
|
* corresponds to an attribute which will be stored in the kernel's attribute arrays. */
|
|
|
|
|
const bool modifies_device_array = (attr.std != ATTR_STD_FACE_NORMAL &&
|
|
|
|
|
attr.std != ATTR_STD_VERTEX_NORMAL);
|
|
|
|
|
|
|
|
|
|
if (modifies_device_array) {
|
|
|
|
|
AttrKernelDataType kernel_type = Attribute::kernel_type(attr);
|
|
|
|
|
modified_flag |= (1u << kernel_type);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool AttributeSet::modified(AttrKernelDataType kernel_type) const
|
|
|
|
|
{
|
|
|
|
|
return (modified_flag & (1u << kernel_type)) != 0;
|
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
2021-01-22 15:01:26 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
/* AttributeRequest */
|
|
|
|
|
|
|
|
|
|
AttributeRequest::AttributeRequest(ustring name_)
|
|
|
|
|
{
|
|
|
|
|
name = name_;
|
2012-04-30 12:49:26 +00:00
|
|
|
std = ATTR_STD_NONE;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-10-17 19:48:38 +02:00
|
|
|
type = TypeFloat;
|
2020-02-03 21:40:58 +01:00
|
|
|
desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
|
desc.offset = 0;
|
|
|
|
|
desc.type = NODE_ATTR_FLOAT;
|
2016-07-16 19:42:28 -04:00
|
|
|
|
2024-10-17 19:48:38 +02:00
|
|
|
subd_type = TypeFloat;
|
2016-07-01 17:36:27 -04:00
|
|
|
subd_desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
|
subd_desc.offset = 0;
|
|
|
|
|
subd_desc.type = NODE_ATTR_FLOAT;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
AttributeRequest::AttributeRequest(AttributeStandard std_)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
|
|
|
|
name = ustring();
|
|
|
|
|
std = std_;
|
|
|
|
|
|
2024-10-17 19:48:38 +02:00
|
|
|
type = TypeFloat;
|
2020-02-03 21:40:58 +01:00
|
|
|
desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
|
desc.offset = 0;
|
|
|
|
|
desc.type = NODE_ATTR_FLOAT;
|
2016-07-16 19:42:28 -04:00
|
|
|
|
2024-10-17 19:48:38 +02:00
|
|
|
subd_type = TypeFloat;
|
2016-07-01 17:36:27 -04:00
|
|
|
subd_desc.element = ATTR_ELEMENT_NONE;
|
|
|
|
|
subd_desc.offset = 0;
|
|
|
|
|
subd_desc.type = NODE_ATTR_FLOAT;
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* AttributeRequestSet */
|
|
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
AttributeRequestSet::AttributeRequestSet() = default;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2024-12-26 17:53:59 +01:00
|
|
|
AttributeRequestSet::~AttributeRequestSet() = default;
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
bool AttributeRequestSet::modified(const AttributeRequestSet &other)
|
|
|
|
|
{
|
2023-09-17 09:01:48 +10:00
|
|
|
if (requests.size() != other.requests.size()) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
for (size_t i = 0; i < requests.size(); i++) {
|
|
|
|
|
bool found = false;
|
|
|
|
|
|
2023-09-17 09:01:48 +10:00
|
|
|
for (size_t j = 0; j < requests.size() && !found; j++) {
|
2011-04-27 11:58:34 +00:00
|
|
|
if (requests[i].name == other.requests[j].name && requests[i].std == other.requests[j].std) {
|
|
|
|
|
found = true;
|
2012-06-09 18:56:12 +00:00
|
|
|
}
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
2012-06-09 18:56:12 +00:00
|
|
|
if (!found) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
2012-06-09 18:56:12 +00:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AttributeRequestSet::add(ustring name)
|
|
|
|
|
{
|
2024-12-26 19:41:25 +01:00
|
|
|
for (AttributeRequest &req : requests) {
|
2018-02-18 03:20:39 +01:00
|
|
|
if (req.name == name) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2018-02-18 03:20:39 +01:00
|
|
|
}
|
|
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
requests.push_back(AttributeRequest(name));
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
void AttributeRequestSet::add(AttributeStandard std)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-26 19:41:25 +01:00
|
|
|
for (AttributeRequest &req : requests) {
|
2023-09-17 09:01:48 +10:00
|
|
|
if (req.std == std) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 19:41:25 +01:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
requests.push_back(AttributeRequest(std));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AttributeRequestSet::add(AttributeRequestSet &reqs)
|
|
|
|
|
{
|
2024-12-26 19:41:25 +01:00
|
|
|
for (AttributeRequest &req : reqs.requests) {
|
2023-09-17 09:01:48 +10:00
|
|
|
if (req.std == ATTR_STD_NONE) {
|
2011-04-27 11:58:34 +00:00
|
|
|
add(req.name);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
|
|
|
|
else {
|
2011-04-27 11:58:34 +00:00
|
|
|
add(req.std);
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-02-18 03:20:39 +01:00
|
|
|
void AttributeRequestSet::add_standard(ustring name)
|
|
|
|
|
{
|
2018-12-11 12:17:26 +01:00
|
|
|
if (name.empty()) {
|
2018-02-18 03:20:39 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
AttributeStandard std = Attribute::name_standard(name.c_str());
|
|
|
|
|
|
|
|
|
|
if (std) {
|
|
|
|
|
add(std);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
add(name);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
bool AttributeRequestSet::find(ustring name)
|
|
|
|
|
{
|
2024-12-26 19:41:25 +01:00
|
|
|
for (AttributeRequest &req : requests) {
|
2023-09-17 09:01:48 +10:00
|
|
|
if (req.name == name) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 19:41:25 +01:00
|
|
|
}
|
2018-07-06 10:17:58 +02:00
|
|
|
|
2011-04-27 11:58:34 +00:00
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2012-04-30 12:49:26 +00:00
|
|
|
bool AttributeRequestSet::find(AttributeStandard std)
|
2011-04-27 11:58:34 +00:00
|
|
|
{
|
2024-12-26 19:41:25 +01:00
|
|
|
for (AttributeRequest &req : requests) {
|
2023-09-17 09:01:48 +10:00
|
|
|
if (req.std == std) {
|
2011-04-27 11:58:34 +00:00
|
|
|
return true;
|
2023-09-17 09:01:48 +10:00
|
|
|
}
|
2024-12-26 19:41:25 +01:00
|
|
|
}
|
2011-04-27 11:58:34 +00:00
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
size_t AttributeRequestSet::size()
|
|
|
|
|
{
|
|
|
|
|
return requests.size();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void AttributeRequestSet::clear()
|
|
|
|
|
{
|
|
|
|
|
requests.clear();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CCL_NAMESPACE_END
|