Welcome to mirror list, hosted at ThFree Co, Russian Federation.

git.blender.org/blender.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
AgeCommit message (Collapse)Author
2022-08-30Cleanup: formatCampbell Barton
2022-08-28Cleanup: Slightly improve virtual array implementation consistencyHans Goudey
Previously the base virtual array implementation optimized for common cases where data is stored as spans or single values. However, that didn't make sense when there are already sub-classes that handle those cases specifically. Instead, implement the faster materialize methods for each class. Now, if the base class is reached, it means no optimizations for avoiding virtual function call overhead are used. Differential Revision: https://developer.blender.org/D15549
2022-08-28Curves: Avoid creating types array when unnecessaryHans Goudey
When the curve type attribute doesn't exist, there is no reason to create an array for it only to fill the default value, which will add overhead to subsequent "add" operations. I added a "get_if_single" method to virtual array to simplify this check. Also use the existing functions for filling curve types. Differential Revision: https://developer.blender.org/D15560
2022-08-02Cleanup: Simplify const cast in virtual array constructionHans Goudey
2022-07-08Fix bug in recently added MutableVArraySpan move constructorBrecht Van Lommel
2022-07-07BLI: make some spans default constructibleJacques Lucke
`GSpan` and spans based on virtual arrays were not default constructible before, which made them hard to use sometimes. It's generally fine for spans to be empty. The main thing the keep in mind is that the type pointer in `GSpan` may be null now. Generally, code receiving spans as input can assume that the type is not-null, but sometimes that may be valid. The old #type() method that returned a reference to the type still exists. It asserts when the type is null.
2022-07-02BLI: improve span access to virtual arraysJacques Lucke
* Make the class names more consistent. * Implement missing move-constructors and assignment-operators.
2022-06-25BLI: improve support for trivial virtual arraysJacques Lucke
This commits reduces the number of function calls through function pointers in `blender::Any` when the stored type is trivial. Furthermore, this implements marks some classes as trivial, which we know are trivial but the compiler does not (the standard currently says that any class with a virtual destructor is non-trivial). Under some circumstances we know that final child classes are trivial though. This allows for some optimizations. Also see https://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p1077r0.html.
2022-06-25BLI: improve check for common virtual array implementationsJacques Lucke
This reduces the amount of code, and improves performance a bit by doing more with less virtual method calls. Differential Revision: https://developer.blender.org/D15293
2022-06-06BLI: fix memory error when moving VArray_SpanJacques Lucke
The issue was that the new span still referenced data that was potentially stored in the old VArray_Span.
2022-06-05Curves: use uv coordinates to attach curves to meshJacques Lucke
This implements the new way to attach curves to a mesh surface using a uv map (based on the recent discussion in T95776). The curves data block now not only stores a reference to the surface object but also a name of a uv map on that object. Having a uv map is optional for most operations, but it will be required later for animation (when the curves are supposed to be deformed based on deformation of the surface). The "Empty Hair" operator in the Add menu sets the uv map name automatically if possible. It's possible to start working without a uv map and to attach the curves to a uv map later on. It's also possible to reattach the curves to a new uv map using the "Curves > Snap to Nearest Surface" operator in curves sculpt mode. Note, the implementation to do the reverse lookup from uv to a position on the surface is trivial and inefficient now. A more efficient data structure will be implemented separately soon. Differential Revision: https://developer.blender.org/D15125
2022-05-31Functions: speedup preparing multi-function parametersJacques Lucke
My benchmark which spend most time preparing function parameters takes `250 ms` now, from `510 ms` before. This is mainly achieved by doing less unnecessary work and by giving the compiler more inlined code to optimize. * Reserve correct vector sizes and use unchecked `append` function. * Construct `GVArray` parameters directly in the vector, instead of moving/copying them in the vector afterwards. * Inline some constructors, because that allows the compiler understand what is happening, resulting in less code. This probably has negilible impact on the user experience currently, because there are other bottlenecks. Differential Revision: https://developer.blender.org/D15009
2022-05-13Cleanup: spelling in comments, capitalize tagsCampbell Barton
Also add missing task-ID reference & remove colon after \note as it doesn't render properly in doxygen.
2022-04-26Geometry Nodes: refactor array devirtualizationJacques Lucke
Goals: * Better high level control over where devirtualization occurs. There is always a trade-off between performance and compile-time/binary-size. * Simplify using array devirtualization. * Better performance for cases where devirtualization wasn't used before. Many geometry nodes accept fields as inputs. Internally, that means that the execution functions have to accept so called "virtual arrays" as inputs. Those can be e.g. actual arrays, just single values, or lazily computed arrays. Due to these different possible virtual arrays implementations, access to individual elements is slower than it would be if everything was just a normal array (access does through a virtual function call). For more complex execution functions, this overhead does not matter, but for small functions (like a simple addition) it very much does. The virtual function call also prevents the compiler from doing some optimizations (e.g. loop unrolling and inserting simd instructions). The solution is to "devirtualize" the virtual arrays for small functions where the overhead is measurable. Essentially, the function is generated many times with different array types as input. Then there is a run-time dispatch that calls the best implementation. We have been doing devirtualization in e.g. math nodes for a long time already. This patch just generalizes the concept and makes it easier to control. It also makes it easier to investigate the different trade-offs when it comes to devirtualization. Nodes that we've optimized using devirtualization before didn't get a speedup. However, a couple of nodes are using devirtualization now, that didn't before. Those got a 2-4x speedup in common cases. * Map Range * Random Value * Switch * Combine XYZ Differential Revision: https://developer.blender.org/D14628
2022-04-25BLI: optimize constructing new virtual arrayJacques Lucke
Differential Revision: https://developer.blender.org/D14745
2022-04-24Cleanup: remove special cases for getting internal span or singleJacques Lucke
Those are handled in the called function already.
2022-04-07Cleanup: Compilation warning about virtual functionsSergey Sharybin
Method which overrides a base class's virtual methods are expetced to be marked with `override`. This also gives better idea to the developers about what is going on.
2022-04-07BLI: add missing materialize methods for virtual arraysJacques Lucke
This does two things: * Introduce new `materialize_compressed` methods. Those are used when the dst array should not have any gaps. * Add materialize methods in various classes where they were missing (and therefore caused overhead, because slower fallbacks had to be used).
2022-03-19BLI: move generic data structures to blenlibJacques Lucke
This is a follow up to rB2252bc6a5527cd7360d1ccfe7a2d1bc640a8dfa6.
2022-02-24Cleanup: Typo in commentHans Goudey
2022-02-11File headers: SPDX License migrationCampbell Barton
Use a shorter/simpler license convention, stops the header taking so much space. Follow the SPDX license specification: https://spdx.org/licenses - C/C++/objc/objc++ - Python - Shell Scripts - CMake, GNUmakefile While most of the source tree has been included - `./extern/` was left out. - `./intern/cycles` & `./intern/atomic` are also excluded because they use different header conventions. doc/license/SPDX-license-identifiers.txt has been added to list SPDX all used identifiers. See P2788 for the script that automated these edits. Reviewed By: brecht, mont29, sergey Ref D14069
2022-01-07Cleanup: remove redundant const qualifiers for POD typesCampbell Barton
MSVC used to warn about const mismatch for arguments passed by value. Remove these as newer versions of MSVC no longer show this warning.
2021-12-27BLI: add utility to check if type is any specific typeJacques Lucke
This adds `blender::is_same_any_v` which is the almost the same as `std::is_same_v`. The difference is that it allows for checking multiple types at the same time. Differential Revision: https://developer.blender.org/D13673
2021-12-20Docs: use doxygen formatting for BLICampbell Barton
Differentiate doc-strings from title/section text.
2021-11-30Cleanup: spelling in comments & stringsCampbell Barton
2021-11-26Cleanup: remove warningsJacques Lucke
This assert was producing warning in debug builds because it was never hit under some circumstances.
2021-11-26Geometry Nodes: optimize Set Position nodeJacques Lucke
This implements four optimizations in the Set Position node: * Check whether the position input is the current position and ignore it if it is. This results in a speedup when only the Offset input is used. * Use multi-threading when copying to computed values to the position attribute. All geometry types benefit from this. * Use devirtualization for the offset and position input. This optimizes the common case that they are either single values or computed in the fly in a span. * Write to `Mesh->mvert` directly instead of creating a temporary span. This makes setting mesh vertex positions even more efficient. In my simple benchmark I'm using a White Noise node to offset the position of 1,000,000 vertices. The speed is `20 ms -> 4.5 ms` in the multi-threaded case and `32 ms -> 22 ms` in the single-threaded case.
2021-11-26Geometry Nodes: deduplicate virtual array implementationsJacques Lucke
For some underlying data (e.g. spans) we had two virtual array implementations. One for the mutable and one for the immutable case. Now that most code does not deal with the virtual array implementations directly anymore (since rBrBd4c868da9f97a), we can get away with sharing one implementation for both cases. This means that we have to do a `const_cast` in a few places, but this is an implementation detail that does not leak into "user code" (only when explicitly casting a `VArrayImpl` to a `VMutableArrayImpl`, which should happen nowhere).
2021-11-25BLI: remove special cases for is_span and is_single methodsJacques Lucke
Those were not implemented consistently and don't really help in practice.
2021-11-24Geometry Nodes: use simpler types when devirtualizing virtual arrayJacques Lucke
The compiler is more likely to optimize away the function call overhead when the used type is simpler and not virtual.
2021-11-16Geometry Nodes: refactor virtual array systemJacques Lucke
Goals of this refactor: * Simplify creating virtual arrays. * Simplify passing virtual arrays around. * Simplify converting between typed and generic virtual arrays. * Reduce memory allocations. As a quick reminder, a virtual arrays is a data structure that behaves like an array (i.e. it can be accessed using an index). However, it may not actually be stored as array internally. The two most important implementations of virtual arrays are those that correspond to an actual plain array and those that have the same value for every index. However, many more implementations exist for various reasons (interfacing with legacy attributes, unified iterator over all points in multiple splines, ...). With this refactor the core types (`VArray`, `GVArray`, `VMutableArray` and `GVMutableArray`) can be used like "normal values". They typically live on the stack. Before, they were usually inside a `std::unique_ptr`. This makes passing them around much easier. Creation of new virtual arrays is also much simpler now due to some constructors. Memory allocations are reduced by making use of small object optimization inside the core types. Previously, `VArray` was a class with virtual methods that had to be overridden to change the behavior of a the virtual array. Now,`VArray` has a fixed size and has no virtual methods. Instead it contains a `VArrayImpl` that is similar to the old `VArray`. `VArrayImpl` should rarely ever be used directly, unless a new virtual array implementation is added. To support the small object optimization for many `VArrayImpl` classes, a new `blender::Any` type is added. It is similar to `std::any` with two additional features. It has an adjustable inline buffer size and alignment. The inline buffer size of `std::any` can't be relied on and is usually too small for our use case here. Furthermore, `blender::Any` can store additional user-defined type information without increasing the stack size. Differential Revision: https://developer.blender.org/D12986
2021-04-29Functions: make copying virtual arrays to span more efficientJacques Lucke
Sometimes functions expect a span instead of a virtual array. If the virtual array is a span internally already, great. But if it is not (e.g. the position attribute on a mesh), the elements have to be copied over to a span. This patch makes the copying process more efficient by giving the compiler more opportunity for optimization.
2021-04-17Geometry Nodes: use virtual arrays in internal attribute apiJacques Lucke
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
2021-04-17Functions: extend virtual array functionalityJacques Lucke
This adds support for mutable virtual arrays and provides many utilities for creating virtual arrays for various kinds of data. This commit is preparation for D10994.
2021-03-23Cleanup: use BLI_assert_unreachable in some placesJacques Lucke
2021-03-23Cleanup: single quotes for Python enums, spellingCampbell Barton
2021-03-22Functions: devirtualize virtual arrays in simple functionsJacques Lucke
In some multi-functions (such as a simple add function), the virtual method call overhead to access array elements adds significant overhead. For these simple functions it makes sense to generate optimized versions for different types of virtual arrays. This is done by giving the compiler all the information it needs to devirtualize virtual arrays. In my benchmark this speeds up processing a lot of data with small function 2-3x. This devirtualization should not be done for larger functions, because it increases compile time and binary size, while providing a negilible performance benefit.
2021-03-22Cleanup: spelling, expand on commentsCampbell Barton
2021-03-21Functions: refactor virtual array data structuresJacques Lucke
When a function is executed for many elements (e.g. per point) it is often the case that some parameters are different for every element and other parameters are the same (there are some more less common cases). To simplify writing such functions one can use a "virtual array". This is a data structure that has a value for every index, but might not be stored as an actual array internally. Instead, it might be just a single value or is computed on the fly. There are various tradeoffs involved when using this data structure which are mentioned in `BLI_virtual_array.hh`. It is called "virtual", because it uses inheritance and virtual methods. Furthermore, there is a new virtual vector array data structure, which is an array of vectors. Both these types have corresponding generic variants, which can be used when the data type is not known at compile time. This is typically the case when building a somewhat generic execution system. The function system used these virtual data structures before, but now they are more versatile. I've done this refactor in preparation for the attribute processor and other features of geometry nodes. I moved the typed virtual arrays to blenlib, so that they can be used independent of the function system. One open question for me is whether all the generic data structures (and `CPPType`) should be moved to blenlib as well. They are well isolated and don't really contain any business logic. That can be done later if necessary.