24 Commits

Author SHA1 Message Date
Hans Goudey
f4421dfc8e Curves: Cache whether any curve is cyclic
Replacing the "cyclic offsets" cache from cfb8696a73.
That was more information than was necessary in the end.
This is implemented by de-duplicating the existing "contains"
function that's implemented twice for boolean virtual arrays.

Pull Request: https://projects.blender.org/blender/blender/pulls/144761
2025-08-25 18:22:36 +02:00
Jacques Lucke
55e2fd2929 Cleanup: unify naming for named constructors
Previously, we used an inconsistent naming scheme for such "named constructors".
Now it always uses `from_*`.

Pull Request: https://projects.blender.org/blender/blender/pulls/142175
2025-07-17 09:09:16 +02:00
Campbell Barton
aa4f717b41 Docs: add missing \file blocks to blenlib & blenkernel 2025-03-29 15:18:50 +11:00
Brecht Van Lommel
e2e1984e60 Refactor: Convert remainder of blenlib to C++
A few headers like BLI_math_constants.h and BLI_utildefines.h keep working
for C code, for remaining makesdna and userdef defaults code in C.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
2025-02-12 23:01:08 +01:00
Hans Goudey
9266fbab02 Fix: Complete recent fix to array_utils boolean mix utility
1d53025868 missed the fix to the VArray case.
2024-06-14 18:44:03 -04:00
Jacques Lucke
1d53025868 Fix #121806: smooth shading not updating correctly
`booleans_mix_calc` was incorrect. While it computed the correct result in
many common cases, under some specific circumstances, at was wrong.
Whether it was wrong also depended on how the range was split up for
multi-threading which is not deterministic.

The function was used in `Mesh::normals_domain` which then also returned
the wrong domain in some cases.
2024-06-14 20:12:03 +02:00
Iliya Katushenock
37b2c12cfa Geometry Nodes: Sort Elements node
Implements the design in #109983

Pull Request: https://projects.blender.org/blender/blender/pulls/114194
2024-01-12 14:30:34 +01:00
casey bianco-davis
58041799bc GPv3: Overlay: Only show visible and editable materials
This PR makes it so that locked materials as well as hidden materials will not have their edit points and edit lines visible.

Note: Previously in grease pencil, strokes with hidden materials would still display the edit lines. This behavior is now fixed in GPv3.

Pull Request: https://projects.blender.org/blender/blender/pulls/115740
2023-12-08 10:38:12 +01:00
casey bianco-davis
5a79023409 GPv3: Cyclical set operator
Simply sets the cyclical property selected strokes. Note this does not add extra geometry like the legacy operator.

Note: also adds a key bind 'alt c' to toggle, same as for curves.

Resolves #113671

Pull Request: https://projects.blender.org/blender/blender/pulls/111904
2023-10-20 10:12:24 +02:00
Hans Goudey
e1fd7a8a7b Cleanup: Simplify grease pencil line overlay size counting
Avoid the need to iterate over every curve, and only iterate over the
cyclic attribute if it exists. This removes the check that avoided
creating cyclic segments for curves with only two points. If that
was necessary, some of the complexity would return, but the
new `array_utils` function wouldn't be necessary.

Pull Request: https://projects.blender.org/blender/blender/pulls/113814
2023-10-17 18:29:17 +02:00
Hans Goudey
7507251071 Cleanup: Extract attribute function to copy values from group to group
Use the typical combination of an "array utils" function used by an
attribute interpolation function. This helps moves us towards having
a more centralized implementaiton of attribute propagation that can
be changed and optimized more easily.
2023-10-09 15:23:48 +02:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Hans Goudey
53416281bd BLI: Optimize utility for index counting
The utility counts the number of occurrences of each index in an array.
It's used to build offsets for mesh topology maps, or to count the
number of connected elements. Some users are geometry nodes,
the subdivision draw cache, and mesh to curve conversion.

This PR parallelizes the counting to take advantage of multiple
threads. On a Ryzen 7950x, when counting connected edges to
vertices, I observed an improvement from 10.2 to 3.0 ms.
This most likely makes the counting less efficient, but it is
quite a nice performance improvement.

The new code was much slower for me at less than four threads,
so I added a check so that counting remains single threaded in
that case.

Pull Request: https://projects.blender.org/blender/blender/pulls/109628
2023-07-05 16:05:16 +02:00
Hans Goudey
a3bfd6e20d Cleanup: Extract utility for counting indices
This utility counts the number of occurrences of each index in an array.
This is used for building mesh topology maps offsets, or for counting
the number of connected elements. Some users are geometry nodes,
the subdivision draw cache, and mesh to curve conversion.

See #109628
2023-07-03 18:47:03 -04:00
Sergey Sharybin
c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Jacques Lucke
2cfcb8b0b8 BLI: refactor IndexMask for better performance and memory usage
Goals of this refactor:
* Reduce memory consumption of `IndexMask`. The old `IndexMask` uses an
  `int64_t` for each index which is more than necessary in pretty much all
  practical cases currently. Using `int32_t` might still become limiting
  in the future in case we use this to index e.g. byte buffers larger than
  a few gigabytes. We also don't want to template `IndexMask`, because
  that would cause a split in the "ecosystem", or everything would have to
  be implemented twice or templated.
* Allow for more multi-threading. The old `IndexMask` contains a single
  array. This is generally good but has the problem that it is hard to fill
  from multiple-threads when the final size is not known from the beginning.
  This is commonly the case when e.g. converting an array of bool to an
  index mask. Currently, this kind of code only runs on a single thread.
* Allow for efficient set operations like join, intersect and difference.
  It should be possible to multi-thread those operations.
* It should be possible to iterate over an `IndexMask` very efficiently.
  The most important part of that is to avoid all memory access when iterating
  over continuous ranges. For some core nodes (e.g. math nodes), we generate
  optimized code for the cases of irregular index masks and simple index ranges.

To achieve these goals, a few compromises had to made:
* Slicing of the mask (at specific indices) and random element access is
  `O(log #indices)` now, but with a low constant factor. It should be possible
  to split a mask into n approximately equally sized parts in `O(n)` though,
  making the time per split `O(1)`.
* Using range-based for loops does not work well when iterating over a nested
  data structure like the new `IndexMask`. Therefor, `foreach_*` functions with
  callbacks have to be used. To avoid extra code complexity at the call site,
  the `foreach_*` methods support multi-threading out of the box.

The new data structure splits an `IndexMask` into an arbitrary number of ordered
`IndexMaskSegment`. Each segment can contain at most `2^14 = 16384` indices. The
indices within a segment are stored as `int16_t`. Each segment has an additional
`int64_t` offset which allows storing arbitrary `int64_t` indices. This approach
has the main benefits that segments can be processed/constructed individually on
multiple threads without a serial bottleneck. Also it reduces the memory
requirements significantly.

For more details see comments in `BLI_index_mask.hh`.

I did a few tests to verify that the data structure generally improves
performance and does not cause regressions:
* Our field evaluation benchmarks take about as much as before. This is to be
  expected because we already made sure that e.g. add node evaluation is
  vectorized. The important thing here is to check that changes to the way we
  iterate over the indices still allows for auto-vectorization.
* Memory usage by a mask is about 1/4 of what it was before in the average case.
  That's mainly caused by the switch from `int64_t` to `int16_t` for indices.
  In the worst case, the memory requirements can be larger when there are many
  indices that are very far away. However, when they are far away from each other,
  that indicates that there aren't many indices in total. In common cases, memory
  usage can be way lower than 1/4 of before, because sub-ranges use static memory.
* For some more specific numbers I benchmarked `IndexMask::from_bools` in
  `index_mask_from_selection` on 10.000.000 elements at various probabilities for
  `true` at every index:
  ```
  Probability      Old        New
  0              4.6 ms     0.8 ms
  0.001          5.1 ms     1.3 ms
  0.2            8.4 ms     1.8 ms
  0.5           15.3 ms     3.0 ms
  0.8           20.1 ms     3.0 ms
  0.999         25.1 ms     1.7 ms
  1             13.5 ms     1.1 ms
  ```

Pull Request: https://projects.blender.org/blender/blender/pulls/104629
2023-05-24 18:11:41 +02:00
Hans Goudey
c9dac7e77c BLI: Add utility to find true/false mix in boolean array
This is useful for #108014, when determining whether there
are any sharp faces and edges in a mesh.
2023-05-24 09:54:25 -04:00
Hans Goudey
63a44e29ac Mesh: Parallelize extraction of UV maps
Since UVs are now stored as 2D vectors in meshes, they can be copied
directly to the vertex buffers. Somewhat surprisingly, multithreading
the copying into the vertex buffer provides a good speedup-- on a CPU
with many cores at least.

Here is a test uploading two UV maps created in geometry
nodes with a 1 million quad mesh, with a Ryzen 7950x:
|         | Before  | After  | Speedup |
| ------- | ------- | ------ | ------- |
| Average | 24.3 ms | 7.5 ms | 3.2x    |
| Min     | 17.6 ms | 7.0 ms | 2.5x    |

I added the copying utilities to the array utils header, since the
need for them has come up in a few different places already, and the
existing function with a selection argument didn't make sense here.

Pull Request: https://projects.blender.org/blender/blender/pulls/105793
2023-03-19 16:18:19 +01:00
Jacques Lucke
03fab057f1 Cleanup: correct asserts 2023-01-17 13:13:43 +01:00
Hans Goudey
c26616b2c1 Curves: Support boolean attribute selection type, simplifications
Use the same `".selection"` attribute for both curve and point domains,
instead of a different name for each. The attribute can now have
either boolean or float type. Some tools create boolean selections.
Other tools create float selections. Some tools "upgrade" the attribute
from boolean to float.

Edit mode tools that create selections from scratch can create boolean
selections, but edit mode should generally be able to handle both
selection types. Sculpt mode should be able to read boolean selections,
but can also and write float values between zero and one.

Theoretically we could just always use floats to store selections,
but the type-agnosticism doesn't cost too much complexity given the
existing APIs for dealing with it, and being able to use booleans is
clearer in edit mode, and may allow future optimizations like more
efficient ways to store boolean attributes.

The attribute API is usually used directly for accessing the selection
attribute. We rely on implicit type conversion and domain interpolation
to simplify the rest of the code.

Differential Revision: https://developer.blender.org/D16057
2023-01-03 23:05:29 -05:00
Hans Goudey
a803dbe7ed Geometry Nodes: Use common utility for copying attribute data
Attribute copying often uses identical logic for copying selected
elements or copying with an index map. Instead of reimplementing
this in each file, use the common implementation in the array_utils
namespace. This makes the commonality more obvious, gives improved
performance (this implementation is multithreaded), reduces binary
size (I observed a 173KB reduction), and probably reduces compile time.
2022-10-19 12:38:48 -05:00
Mattias Fredriksson
ce54f48556 BLI: Add generic utlity for gathering values with indices
Add new functions to `array_utils` namespace called `gather(..)`.
Versions of `GVArray::materialize_compressed_to_uninitialized(..)` with
threading have been reimplemented locally in multiple geometry node
contexts. The purpose of this patch is therefore to:
 * Assemble these implementations in a single file.
 * Provide a naming convention that is easier to recognize.

Differential Revision: https://developer.blender.org/D15786
2022-09-17 22:12:02 -05:00
Hans Goudey
643e94c032 Cleanup: Add missing licence headers
Missed in eaf416693d
2022-09-14 08:54:04 -05:00
Mattias Fredriksson
eaf416693d Geometry Nodes: Port the trim curve node to the new data-block
The trim functionality is implemented in the geometry module, and
generalized a bit to be potentially useful for bisecting in the future.
The implementation is based on a helper type called `IndexRangeCyclic`
which allows iteration over all control points between two points on a
curve.

Catmull Rom curves are now supported-- trimmed without resampling first.
However, maintaining the exact shape is not possible. NURBS splines are
still converted to polylines using the evaluated curve concept.

Performance is equivalent or faster then a 3.1 build with regards to
node timings. Compared to 3.3 and 3.2, it's easy to observe test cases
where the node is at least 3 or 4 times faster.

Differential Revision: https://developer.blender.org/D14481
2022-09-13 11:36:14 -05:00