[Bf-blender-cvs] [d809853513c] master: Cleanup: simplify Cycles primitive attribute map storage
Brecht Van Lommel
noreply at git.blender.org
Fri Feb 7 12:22:10 CET 2020
Commit: d809853513c1333c9d9a22ab6ba35617b5ed2b8c
Author: Brecht Van Lommel
Date: Mon Feb 3 21:40:58 2020 +0100
Branches: master
https://developer.blender.org/rBd809853513c1333c9d9a22ab6ba35617b5ed2b8c
Cleanup: simplify Cycles primitive attribute map storage
===================================================================
M intern/cycles/kernel/geom/geom_attribute.h
M intern/cycles/kernel/geom/geom_motion_curve.h
M intern/cycles/kernel/kernel_types.h
M intern/cycles/kernel/osl/osl_shader.cpp
M intern/cycles/render/attribute.cpp
M intern/cycles/render/attribute.h
M intern/cycles/render/geometry.cpp
M intern/cycles/render/hair.cpp
M intern/cycles/render/mesh.cpp
===================================================================
diff --git a/intern/cycles/kernel/geom/geom_attribute.h b/intern/cycles/kernel/geom/geom_attribute.h
index 456608bfa22..e1b0e6fb81c 100644
--- a/intern/cycles/kernel/geom/geom_attribute.h
+++ b/intern/cycles/kernel/geom/geom_attribute.h
@@ -29,17 +29,11 @@ ccl_device_inline uint subd_triangle_patch(KernelGlobals *kg, const ShaderData *
ccl_device_inline uint attribute_primitive_type(KernelGlobals *kg, const ShaderData *sd)
{
-#ifdef __HAIR__
- if (sd->type & PRIMITIVE_ALL_CURVE) {
- return ATTR_PRIM_CURVE;
- }
- else
-#endif
- if (subd_triangle_patch(kg, sd) != ~0) {
+ if ((sd->type & PRIMITIVE_ALL_TRIANGLE) && subd_triangle_patch(kg, sd) != ~0) {
return ATTR_PRIM_SUBD;
}
else {
- return ATTR_PRIM_TRIANGLE;
+ return ATTR_PRIM_GEOMETRY;
}
}
diff --git a/intern/cycles/kernel/geom/geom_motion_curve.h b/intern/cycles/kernel/geom/geom_motion_curve.h
index 7380c506bf4..0e2a00e9d2e 100644
--- a/intern/cycles/kernel/geom/geom_motion_curve.h
+++ b/intern/cycles/kernel/geom/geom_motion_curve.h
@@ -36,7 +36,7 @@ ccl_device_inline int find_attribute_curve_motion(KernelGlobals *kg,
* zero iterations and rendering is really slow with motion curves. For until other
* areas are speed up it's probably not so crucial to optimize this out.
*/
- uint attr_offset = object_attribute_map_offset(kg, object) + ATTR_PRIM_CURVE;
+ uint attr_offset = object_attribute_map_offset(kg, object) + ATTR_PRIM_GEOMETRY;
uint4 attr_map = kernel_tex_fetch(__attributes_map, attr_offset);
while (attr_map.x != id) {
diff --git a/intern/cycles/kernel/kernel_types.h b/intern/cycles/kernel/kernel_types.h
index 1e1d161ff9b..bf34450df4b 100644
--- a/intern/cycles/kernel/kernel_types.h
+++ b/intern/cycles/kernel/kernel_types.h
@@ -725,9 +725,8 @@ typedef enum PrimitiveType {
/* Attributes */
typedef enum AttributePrimitive {
- ATTR_PRIM_TRIANGLE = 0,
+ ATTR_PRIM_GEOMETRY = 0,
ATTR_PRIM_SUBD,
- ATTR_PRIM_CURVE,
ATTR_PRIM_TYPES
} AttributePrimitive;
diff --git a/intern/cycles/kernel/osl/osl_shader.cpp b/intern/cycles/kernel/osl/osl_shader.cpp
index db5ad06d3fc..0994bfaf950 100644
--- a/intern/cycles/kernel/osl/osl_shader.cpp
+++ b/intern/cycles/kernel/osl/osl_shader.cpp
@@ -382,10 +382,6 @@ int OSLShader::find_attribute(KernelGlobals *kg,
{
/* for OSL, a hash map is used to lookup the attribute by name. */
int object = sd->object * ATTR_PRIM_TYPES;
-#ifdef __HAIR__
- if (sd->type & PRIMITIVE_ALL_CURVE)
- object += ATTR_PRIM_CURVE;
-#endif
OSLGlobals::AttributeMap &attr_map = kg->osl->attribute_map[object];
ustring stdname(std::string("geom:") +
diff --git a/intern/cycles/render/attribute.cpp b/intern/cycles/render/attribute.cpp
index fcba901ae6c..05c0b5693bc 100644
--- a/intern/cycles/render/attribute.cpp
+++ b/intern/cycles/render/attribute.cpp
@@ -193,7 +193,7 @@ size_t Attribute::element_size(Geometry *geom, AttributePrimitive prim) const
case ATTR_ELEMENT_FACE:
if (geom->type == Geometry::MESH) {
Mesh *mesh = static_cast<Mesh *>(geom);
- if (prim == ATTR_PRIM_TRIANGLE) {
+ if (prim == ATTR_PRIM_GEOMETRY) {
size = mesh->num_triangles();
}
else {
@@ -205,7 +205,7 @@ size_t Attribute::element_size(Geometry *geom, AttributePrimitive prim) const
case ATTR_ELEMENT_CORNER_BYTE:
if (geom->type == Geometry::MESH) {
Mesh *mesh = static_cast<Mesh *>(geom);
- if (prim == ATTR_PRIM_TRIANGLE) {
+ if (prim == ATTR_PRIM_GEOMETRY) {
size = mesh->num_triangles() * 3;
}
else {
@@ -390,11 +390,9 @@ void Attribute::get_uv_tiles(Geometry *geom,
/* Attribute Set */
-AttributeSet::AttributeSet()
+AttributeSet::AttributeSet(Geometry *geometry, AttributePrimitive prim)
+ : geometry(geometry), prim(prim)
{
- triangle_mesh = NULL;
- subd_mesh = NULL;
- hair = NULL;
}
AttributeSet::~AttributeSet()
@@ -428,12 +426,7 @@ Attribute *AttributeSet::add(ustring name, TypeDesc type, AttributeElement eleme
#endif
/* this is weak .. */
- if (triangle_mesh)
- attr->resize(triangle_mesh, ATTR_PRIM_TRIANGLE, false);
- if (subd_mesh)
- attr->resize(subd_mesh, ATTR_PRIM_SUBD, false);
- if (hair)
- attr->resize(hair, ATTR_PRIM_CURVE, false);
+ attr->resize(geometry, prim, false);
return attr;
}
@@ -470,7 +463,7 @@ Attribute *AttributeSet::add(AttributeStandard std, ustring name)
if (name == ustring())
name = Attribute::standard_name(std);
- if (triangle_mesh || subd_mesh) {
+ if (geometry->type == Geometry::MESH) {
switch (std) {
case ATTR_STD_VERTEX_NORMAL:
attr = add(name, TypeDesc::TypeNormal, ATTR_ELEMENT_VERTEX);
@@ -530,7 +523,7 @@ Attribute *AttributeSet::add(AttributeStandard std, ustring name)
break;
}
}
- else if (hair) {
+ else if (geometry->type == Geometry::HAIR) {
switch (std) {
case ATTR_STD_UV:
attr = add(name, TypeFloat2, ATTR_ELEMENT_CURVE);
@@ -613,12 +606,7 @@ void AttributeSet::remove(Attribute *attribute)
void AttributeSet::resize(bool reserve_only)
{
foreach (Attribute &attr, attributes) {
- if (triangle_mesh)
- attr.resize(triangle_mesh, ATTR_PRIM_TRIANGLE, reserve_only);
- if (subd_mesh)
- attr.resize(subd_mesh, ATTR_PRIM_SUBD, reserve_only);
- if (hair)
- attr.resize(hair, ATTR_PRIM_CURVE, reserve_only);
+ attr.resize(geometry, prim, reserve_only);
}
}
@@ -648,15 +636,10 @@ AttributeRequest::AttributeRequest(ustring name_)
name = name_;
std = ATTR_STD_NONE;
- triangle_type = TypeDesc::TypeFloat;
- triangle_desc.element = ATTR_ELEMENT_NONE;
- triangle_desc.offset = 0;
- triangle_desc.type = NODE_ATTR_FLOAT;
-
- curve_type = TypeDesc::TypeFloat;
- curve_desc.element = ATTR_ELEMENT_NONE;
- curve_desc.offset = 0;
- curve_desc.type = NODE_ATTR_FLOAT;
+ type = TypeDesc::TypeFloat;
+ desc.element = ATTR_ELEMENT_NONE;
+ desc.offset = 0;
+ desc.type = NODE_ATTR_FLOAT;
subd_type = TypeDesc::TypeFloat;
subd_desc.element = ATTR_ELEMENT_NONE;
@@ -669,15 +652,10 @@ AttributeRequest::AttributeRequest(AttributeStandard std_)
name = ustring();
std = std_;
- triangle_type = TypeDesc::TypeFloat;
- triangle_desc.element = ATTR_ELEMENT_NONE;
- triangle_desc.offset = 0;
- triangle_desc.type = NODE_ATTR_FLOAT;
-
- curve_type = TypeDesc::TypeFloat;
- curve_desc.element = ATTR_ELEMENT_NONE;
- curve_desc.offset = 0;
- curve_desc.type = NODE_ATTR_FLOAT;
+ type = TypeDesc::TypeFloat;
+ desc.element = ATTR_ELEMENT_NONE;
+ desc.offset = 0;
+ desc.type = NODE_ATTR_FLOAT;
subd_type = TypeDesc::TypeFloat;
subd_desc.element = ATTR_ELEMENT_NONE;
diff --git a/intern/cycles/render/attribute.h b/intern/cycles/render/attribute.h
index d4bf630aeb6..f1fd30fd85a 100644
--- a/intern/cycles/render/attribute.h
+++ b/intern/cycles/render/attribute.h
@@ -170,12 +170,11 @@ class Attribute {
class AttributeSet {
public:
- Mesh *triangle_mesh;
- Mesh *subd_mesh;
- Hair *hair;
+ Geometry *geometry;
+ AttributePrimitive prim;
list<Attribute> attributes;
- AttributeSet();
+ AttributeSet(Geometry *geometry, AttributePrimitive prim);
~AttributeSet();
Attribute *add(ustring name, TypeDesc type, AttributeElement element);
@@ -206,8 +205,8 @@ class AttributeRequest {
AttributeStandard std;
/* temporary variables used by GeometryManager */
- TypeDesc triangle_type, curve_type, subd_type;
- AttributeDescriptor triangle_desc, curve_desc, subd_desc;
+ TypeDesc type, subd_type;
+ AttributeDescriptor desc, subd_desc;
explicit AttributeRequest(ustring name_);
explicit AttributeRequest(AttributeStandard std);
diff --git a/intern/cycles/render/geometry.cpp b/intern/cycles/render/geometry.cpp
index a75a114e4f2..880fb7b4c7d 100644
--- a/intern/cycles/render/geometry.cpp
+++ b/intern/cycles/render/geometry.cpp
@@ -56,7 +56,8 @@ NODE_ABSTRACT_DEFINE(Geometry)
return type;
}
-Geometry::Geometry(const NodeType *node_type, const Type type) : Node(node_type), type(type)
+Geometry::Geometry(const NodeType *node_type, const Type type)
+ : Node(node_type), type(type), attributes(this, ATTR_PRIM_GEOMETRY)
{
need_update = true;
need_update_rebuild = false;
@@ -300,9 +301,8 @@ void GeometryManager::update_osl_attributes(Device *device,
osl_attr.desc.offset = 0;
osl_attr.desc.flags = 0;
- og->attribute_map[i * ATTR_PRIM_TYPES + ATTR_PRIM_TRIANGLE][attr.name()] = osl_attr;
+ og->attribute_map[i * ATTR_PRIM_TYPES + ATTR_PRIM_GEOMETRY][attr.name()] = osl_attr;
og->attribute_map[i * ATTR_PRIM_TYPES + ATTR_PRIM_SUBD][attr.name()] = osl_attr;
- og->attribute_map[i * ATTR_PRIM_TYPES + ATTR_PRIM_CURVE][attr.name()] = osl_attr;
}
/* find geometry attributes */
@@ -318,16 +318,16 @@ void GeometryManager::update_osl_attributes(Device *device,
foreach (AttributeRequest &req, attributes.requests) {
OSLGlobals::Attribute osl_attr;
- if (req.triangle_desc.element != ATTR_ELEMENT_NONE) {
- osl_attr.desc = req.triangle_desc;
+ if (req.desc.element != ATTR_ELEMENT_NONE) {
+ osl_attr.desc = req.desc;
- if (req.triangle_type == TypeDesc::TypeFloat)
+ if (req.type == TypeDesc::TypeFloat)
osl_attr.type = TypeDesc::TypeFloat;
- else if (req.triangle_type == TypeDesc::TypeMatrix)
+ else if (req.type == TypeDesc::TypeMatrix)
osl_attr.type = TypeDesc::TypeMatrix;
- else if (req.triangle_type == TypeFloat2)
+ else if (req.type == TypeFloat2)
osl_attr.type = TypeFloat2;
- else if (req.triangle_type == TypeRGBA)
+ else if (req.type == TypeRGBA)
osl_attr.type = TypeRGBA;
else
osl_attr.type = TypeDesc::TypeColor;
@@ -335,36 +335,11 @@ void GeometryManager::update_osl_attributes(Device *device,
if (req.std != ATTR_STD_NONE) {
/* if standard attribute, add lookup by geom: name convention */
ustring stdname(string("geom:") + string(Attribute::standard_name(req.std)));
- og->attribute_map[i * ATTR_PRIM_TYPES + ATTR_PRIM_TRIANGLE][stdname] = osl_attr;
+ og->attribute_map[i * ATTR_PRIM_T
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list