Blender Git Loki
Git Commits -> Revision 5cf6f57
Revision 5cf6f57 by Jacques Lucke (master) April 17, 2021, 14:41 (GMT) |
Geometry Nodes: use virtual arrays in internal attribute api A virtual array is a data structure that is similar to a normal array in that its elements can be accessed by an index. However, a virtual array does not have to be a contiguous array internally. Instead, its elements can be layed out arbitrarily while element access happens through a virtual function call. However, the virtual array data structures are designed so that the virtual function call can be avoided in cases where it could become a bottleneck. Most commonly, a virtual array is backed by an actual array/span or is a single value internally, that is the same for every index. Besides those, there are many more specialized virtual arrays like the ones that provides vertex positions based on the `MVert` struct or vertex group weights. Not all attributes used by geometry nodes are stored in simple contiguous arrays. To provide uniform access to all kinds of attributes, the attribute API has to provide virtual array functionality that hides the implementation details of attributes. Before this refactor, the attribute API provided its own virtual array implementation as part of the `ReadAttribute` and `WriteAttribute` types. That resulted in unnecessary code duplication with the virtual array system. Even worse, it bound many algorithms used by geometry nodes to the specifics of the attribute API, even though they could also use different data sources (such as data from sockets, default values, later results of expressions, ...). This refactor removes the `ReadAttribute` and `WriteAttribute` types and replaces them with `GVArray` and `GVMutableArray` respectively. The `GV` stands for "generic virtual". The "generic" means that the data type contained in those virtual arrays is only known at run-time. There are the corresponding statically typed types `VArray<T>` and `VMutableArray<T>` as well. No regressions are expected from this refactor. It does come with one improvement for users. The attribute API can convert the data type on write now. This is especially useful when writing to builtin attributes like `material_index` with e.g. the Attribute Math node (which usually just writes to float attributes, while `material_index` is an integer attribute). Differential Revision: https://developer.blender.org/D10994 |
Commit Details:
Full Hash: 5cf6f570c65daa3325055e54bb07fa864f269960
Parent Commit: 4dca440
Lines Changed: +1305, -1702
41 Modified Paths:
/source/blender/blenkernel/BKE_attribute_access.hh (+109, -198) (Diff)
/source/blender/blenkernel/BKE_geometry_set.hh (+74, -108) (Diff)
/source/blender/blenkernel/intern/attribute_access.cc (+212, -387) (Diff)
/source/blender/blenkernel/intern/attribute_access_intern.hh (+32, -187) (Diff)
/source/blender/blenkernel/intern/geometry_component_mesh.cc (+174, -221) (Diff)
/source/blender/blenkernel/intern/geometry_component_pointcloud.cc (+29, -30) (Diff)
/source/blender/blenkernel/intern/geometry_set_instances.cc (+8, -7) (Diff)
/source/blender/blenlib/BLI_virtual_array.hh (+3, -0) (Diff)
/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc (+19, -24) (Diff)
/source/blender/functions/FN_generic_virtual_array.hh (+15, -13) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc (+15, -15) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc (+23, -24) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc (+11, -13) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc (+9, -12) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc (+46, -41) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc (+10, -13) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc (+10, -14) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc (+36, -41) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc (+23, -40) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc (+37, -28) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc (+15, -19) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc (+9, -11) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc (+10, -9) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_separate_xyz.cc (+21, -26) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc (+81, -64) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc (+4, -7) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc (+10, -12) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc (+4, -4) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc (+4, -4) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc (+4, -4) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc (+6, -4) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc (+30, -33) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc (+4, -4) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_rotate.cc (+13, -13) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc (+6, -6) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_separate.cc (+9, -9) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc (+7, -12) (Diff)
/source/blender/nodes/intern/node_geometry_exec.cc (+31, -19) (Diff)
/source/blender/nodes/intern/type_conversions.cc (+112, -0) (Diff)
/source/blender/nodes/NOD_geometry_exec.hh (+26, -26) (Diff)
/source/blender/nodes/NOD_type_conversions.hh (+4, -0) (Diff)
/source/blender/blenkernel/BKE_geometry_set.hh (+74, -108) (Diff)
/source/blender/blenkernel/intern/attribute_access.cc (+212, -387) (Diff)
/source/blender/blenkernel/intern/attribute_access_intern.hh (+32, -187) (Diff)
/source/blender/blenkernel/intern/geometry_component_mesh.cc (+174, -221) (Diff)
/source/blender/blenkernel/intern/geometry_component_pointcloud.cc (+29, -30) (Diff)
/source/blender/blenkernel/intern/geometry_set_instances.cc (+8, -7) (Diff)
/source/blender/blenlib/BLI_virtual_array.hh (+3, -0) (Diff)
/source/blender/editors/space_spreadsheet/spreadsheet_data_source_geometry.cc (+19, -24) (Diff)
/source/blender/functions/FN_generic_virtual_array.hh (+15, -13) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_align_rotation_to_vector.cc (+15, -15) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_clamp.cc (+23, -24) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_color_ramp.cc (+11, -13) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_combine_xyz.cc (+9, -12) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_compare.cc (+46, -41) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_convert.cc (+10, -13) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_fill.cc (+10, -14) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_map_range.cc (+36, -41) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_math.cc (+23, -40) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_mix.cc (+37, -28) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_proximity.cc (+15, -19) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_randomize.cc (+9, -11) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_sample_texture.cc (+10, -9) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_separate_xyz.cc (+21, -26) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_attribute_vector_math.cc (+81, -64) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_bounding_box.cc (+4, -7) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_join_geometry.cc (+10, -12) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_cone.cc (+4, -4) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_grid.cc (+4, -4) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_mesh_primitive_uv_sphere.cc (+4, -4) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_points_to_volume.cc (+6, -4) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_distribute.cc (+30, -33) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_instance.cc (+4, -4) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_rotate.cc (+13, -13) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_scale.cc (+6, -6) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_separate.cc (+9, -9) (Diff)
/source/blender/nodes/geometry/nodes/node_geo_point_translate.cc (+7, -12) (Diff)
/source/blender/nodes/intern/node_geometry_exec.cc (+31, -19) (Diff)
/source/blender/nodes/intern/type_conversions.cc (+112, -0) (Diff)
/source/blender/nodes/NOD_geometry_exec.hh (+26, -26) (Diff)
/source/blender/nodes/NOD_type_conversions.hh (+4, -0) (Diff)