Commit Graph

7211 Commits

Author SHA1 Message Date
Jacques Lucke
64a13f4be2 Refactor: BLI: simplify extending get_default_hash function
This simplifies extending `blender::get_default_hash` to more than 4 parameters
by just adding extra factors to the list. The behavior should be the same as
before.

Pull Request: https://projects.blender.org/blender/blender/pulls/139392
2025-05-24 21:01:05 +02:00
Jacques Lucke
a6486d11c2 Cleanup: add missing include 2025-05-24 18:55:53 +02:00
Miguel Pozo
4f00a470cd Core: VectorList improvements
- Add a custom Iterator, so it can be iterated as a 1D list.
- Add missing functions like `first`, `is_empty`, `clear`, and
  subscript operator.
- Add a `size_` member variable for faster `size` calls.
- Add compile-time asserts to ensure the Capacity sizes are valid.
- Add unit tests.

See #138947 for the motivation behind this.

Pull Request: https://projects.blender.org/blender/blender/pulls/139102
2025-05-23 15:34:26 +02:00
Miguel Pozo
9222daacb7 Fix: Core: bitscan_reverse_uint64 on Windows
Pull Request: https://projects.blender.org/blender/blender/pulls/139283
2025-05-22 17:30:45 +02:00
Campbell Barton
b5d3b3c1a3 Refactor: const-correctness in BLI_array_store API 2025-05-22 17:18:39 +10:00
Brecht Van Lommel
ee1a460f42 Revert "Refactor: Add and use MEMCPY_STRUCT_AFTER_CHECKED"
Needs more review, see #138830.

This reverts commit 5ac631d02b.
2025-05-20 17:32:49 +02:00
Brecht Van Lommel
5ac631d02b Refactor: Add and use MEMCPY_STRUCT_AFTER_CHECKED
Check if either the memory is zero or already matches the default value,
and copy. This simplifies a common pattern to a single line.

Preparing for default initializers in DNA (#134531).

Pull Request: https://projects.blender.org/blender/blender/pulls/138830
2025-05-20 13:27:08 +02:00
Jacques Lucke
0837037d13 Geometry Nodes: initial support for volume grids in function nodes
This patch implements basic support for evaluating function nodes on volume
grids. Conceptually, a function node always creates a new grid for the output,
though the output is often a modified version of the input. The topology of the
output grid is a union of all the input grids.

All input grids have to have the same transform. Otherwise one has to use
resampling to make grids compatible.

Non-grid inputs are allowed to be single values or fields. The fields are
evaluated in a voxel/tile context, so they compute a value per voxel or per
tile.

One optimization is missing that will probably be key in the future: the ability
to merge multiple function nodes and execute them at the same time. Currently
the entire function evaluation is started and finished for every function node
that outputs a grid. This will add significant overhead in some situations.
Implementing this optimization requires some more changes outside of the scope
of this patch though. It's good to have something that works first.

Note: Not all function nodes are supported yet, because we don't have grid types
for all of them yet. Most notably, there are no color/float4 grids yet.
Implementing those properly is not super straight forward and may require some
more changes, because there isn't a 1-to-1 mapping between grid types and socket
types (a float4 grid may correspond to a color or vector socket later on).

Using grids with function nodes and fields can result in false positive warnings
in the UI currently. That's a limitation of our current socket type inferencing
and can be improved once we have better socket shape inferencing.

Pull Request: https://projects.blender.org/blender/blender/pulls/125110
2025-05-19 18:30:58 +02:00
Campbell Barton
b3dfde88f3 Cleanup: spelling in comments (check_spelling_* target)
Also uppercase acronyms: API, UTF & ASCII.
2025-05-17 10:17:37 +10:00
Jacques Lucke
5a449439ef Refactor: BLI: simplify compute context hash generation and make it lazy
Currently, there was a lot of boilerplate to compute the compute context hash.
Now, the complexity is abstracted away to make it a simple function call.

Furthermore, this makes the compute context hash generation lazy. The goal here
is to make it very cheap to construct the compute context hash in the first,
while making it a little bit more expensive (still quite cheap overall) to
access the hash when any data has to be logged. This trade-off makes sense when
we want to pass the compute context to more lower-level places in order to be
able to create better error messages with more contextual information. For
example, we'd want to create error messages during multi-function evaluation
which happens during field evaluation within a node.

Pull Request: https://projects.blender.org/blender/blender/pulls/138912
2025-05-15 21:18:23 +02:00
Campbell Barton
e97e9c2904 Cleanup: various non functional changes for C++ 2025-05-15 10:26:47 +10:00
Philipp Oeser
b8d82c510f Fix #138782: "Set Origin > Geometry to Origin" can be inaccurate
"Origin to Geometry" was also affected

With very large meshes (report was about this failing for imported
terrain data), we lack precision in `BKE_mesh_center_median`.

First intuition was to just use doubles, but based on the work done
in !132759 to get a more numerically stable way to compute a mean,
we can use that instead.

So this PR moves `compute_sum` into `blender::array_utils`
and re-uses that for `BKE_mesh_center_median`

Pull Request: https://projects.blender.org/blender/blender/pulls/138813
2025-05-14 17:56:07 +02:00
Hans Goudey
8f5952f4c1 Cleanup: Formatting 2025-05-12 22:18:01 -04:00
Hans Goudey
f83830409e Cleanup: Remove outdated todo comment
There isn't really a reason why the sculpt and BLI
BVH trees have to have the same threading threshold.
2025-05-12 21:54:04 -04:00
Sergey Sharybin
7ceb4495c5 Refactor: OpenColorIO integration
Briefly about this change:
- OpenColorIO C-API is removed.
- The information about color spaces in ImBuf module is removed.
  It was stored in global ListBase in colormanagement.cc.
- Both OpenColorIO and fallback implementation supports GPU drawing.
- Fallback implementation supports white point, RGB curves, etc.
- Removed check for support of GPU drawing in IMB.

Historically it was implemented in a separate library with C-API, this
is because way back C++ code needed to stay in intern. This causes all
sort of overheads, and even calls that are strictly considered bad
level.

This change moves OpenColorIO integration into a module within imbuf,
next to movie, and next to IMB_colormanagement which is the main user
of it. This allows to avoid copy of color spaces, displays, views etc
in the ImBuf: they were used to help quickly querying information to
be shown on the interface. With this change it can be stored in the
same data structures as what is used by the OpenColorIO integration.
While it might not be fully avoiding duplication it is now less, and
there is no need in the user code to maintain the copies.

In a lot of cases this change also avoids allocations done per access
to the OpenColorIO. For example, it is not needed anymore to allocate
image descriptor in a heap.

The bigger user-visible change is that the fallback implementation now
supports GLSL drawing, with the whole list of supported features, such
as curve mapping and white point. This should help simplifying code
which relies on color space conversion on GPU: there is no need to
figure out fallback solution in such cases. The only case when drawing
will not work is when there is some actual bug, or driver issue, and
shader has failed to compile.

The change avoids having an opaque type for color space, and instead
uses forward declaration. It is a bit verbose on declaration, but helps
avoiding unsafe type-casts. There are ways to solve this in the future,
like having a header for forward declaration, or to flatten the name
space a bit.

There should be no user-level changes under normal operation.
When building without OpenColorIO or the configuration has a typo or
is missing a fuller set of color management tools is applies (such as the
white point correction).

Pull Request: https://projects.blender.org/blender/blender/pulls/138433
2025-05-09 14:01:43 +02:00
Jacques Lucke
eea2c6b00b Fix: Nodes: missing name escaping when constructing RNA paths
This also adds a version of `BLI_str_escape` that returns an std::string,
because it's much easier to use in C++ code.
2025-05-09 11:09:00 +02:00
Jacques Lucke
4a760c1a70 Nodes: show link errors directly on link
Previously, we had shown link errors on the target node as part of the node
warning system. While better than not showing any information about invalid
links (as was the state before that), it's still not ideal because it's easy to
miss when just looking at the link.

This patch adds an error icon in the middle of the invalid link. When hovering
over it, it shows the error text. When the middle of the link is not in view but
part of the link is, then the error icon will also stay visible.

Pull Request: https://projects.blender.org/blender/blender/pulls/138529
2025-05-09 04:06:00 +02:00
Jacques Lucke
3a2d4d151f Cleanup: move linear allocator description to class 2025-05-07 20:49:02 +02:00
Jacques Lucke
52a283a1ee Cleanup: fix misleading comment
LinearAllocator does not REallocate, it just allocates a new buffer.
2025-05-07 20:48:26 +02:00
Hans Goudey
fbb659c4c5 Cleanup: Remove unused TaskPool user_mutex 2025-05-07 11:32:38 -04:00
Jacques Lucke
5fb8c8caa5 Cleanup: use new Mutex in file cache 2025-05-07 05:04:45 +02:00
Jacques Lucke
b7a1325c3c BLI: use blender::Mutex by default which wraps tbb::mutex
This patch adds a new `BLI_mutex.hh` header which adds `blender::Mutex` as alias
for either `tbb::mutex` or `std::mutex` depending on whether TBB is enabled.

Description copied from the patch:
```
/**
 * blender::Mutex should be used as the default mutex in Blender. It implements a subset of the API
 * of std::mutex but has overall better guaranteed properties. It can be used with RAII helpers
 * like std::lock_guard. However, it is not compatible with e.g. std::condition_variable. So one
 * still has to use std::mutex for that case.
 *
 * The mutex provided by TBB has these properties:
 * - It's as fast as a spin-lock in the non-contended case, i.e. when no other thread is trying to
 *   lock the mutex at the same time.
 * - In the contended case, it spins a couple of times but then blocks to avoid draining system
 *   resources by spinning for a long time.
 * - It's only 1 byte large, compared to e.g. 40 bytes when using the std::mutex of GCC. This makes
 *   it more feasible to have many smaller mutexes which can improve scalability of algorithms
 *   compared to using fewer larger mutexes. Also it just reduces "memory slop" across Blender.
 * - It is *not* a fair mutex, i.e. it's not guaranteed that a thread will ever be able to lock the
 *   mutex when there are always more than one threads that try to lock it. In the majority of
 *   cases, using a fair mutex just causes extra overhead without any benefit. std::mutex is not
 *   guaranteed to be fair either.
 */
 ```

The performance benchmark suggests that the impact is negilible in almost
all cases. The only benchmarks that show interesting behavior are the once
testing foreach zones in Geometry Nodes. These tests are explicitly testing
overhead, which I still have to reduce over time. So it's not unexpected that
changing the mutex has an impact there. What's interesting is that on macos the
performance improves a lot while on linux it gets worse. Since that overhead
should eventually be removed almost entirely, I don't really consider that
blocking.

Links:
* Documentation of different mutex flavors in TBB:
  https://www.intel.com/content/www/us/en/docs/onetbb/developer-guide-api-reference/2021-12/mutex-flavors.html
* Older implementation of a similar mutex by me:
  https://archive.blender.org/developer/differential/0016/0016711/index.html
* Interesting read regarding how a mutex can be this small:
  https://webkit.org/blog/6161/locking-in-webkit/

Pull Request: https://projects.blender.org/blender/blender/pulls/138370
2025-05-07 04:53:16 +02:00
Jacques Lucke
ed29ab303c Blenloader: extract blenloader core library for use in blendthumb
We recently started using blenloader code in blendthumb to avoid having to
reimplement some parts of .blend file parsing. While this works, it has the side
effect that on Windows referencing blenloader code increased the binary size of
blendthumb from < 1MB to ~75 MB. That happens because this dependency drags
along lots of other code which effectively is unused, but the compiler is unable
to remove it.

There didn't seem to be a simple solution to make msvc optimize the unused code
away. This patch solves the issue by extracting the shared code into a separate
`blenloader_core` module which does not depend on the rest of Blender (except
blenlib). Therefore, using this new module in blendthumb does not drag along all
the other dependencies, bring its file size back down.

In the future, more code may be moved from blenloader to blenloader_core, but
for now I extracted these two headers:
* `BLO_core_bhead.hh`: Various `BHead` types and related parsing functions.
* `BLO_core_blend_header.hh`: Parsing of the header at the beginning of .blend
  files.

Pull Request: https://projects.blender.org/blender/blender/pulls/138371
2025-05-07 04:51:50 +02:00
Campbell Barton
fd6ac498b0 Cleanup: spelling in comments, strings (make check_spelling_*)
Also replace some triple-quoted non-doc-string strings with commented
blocks in examples.
2025-05-06 00:18:39 +00:00
Jacques Lucke
1b61e419a6 Geometry Nodes: support caching imported files
Currently, the import nodes always reimport on each evaluation. This patch adds
support for caching the loaded geometries. This is integrated with
`BLI_memory_cache.hh` and thus also takes the cache size limit into account. If
an imported file is modified on disk, the cache is invalidated. However,
Geometry Nodes will not automatically reevaluate when a file changes, so the
user would have to trigger the evaluation in some other way.

This is an alternative solution to #124369. The main benefits are that the cache
invalidation happens automatically and that the cache system is more general and
does not have to know about e.g. the different file types.

Caching speeds up node setups that heavily rely on import nodes significantly.

Pull Request: https://projects.blender.org/blender/blender/pulls/138425
2025-05-05 19:25:05 +02:00
Hans Goudey
c108d7bfd4 Cleanup: Missing include for integer type in BLI_generic_key.hh 2025-05-05 12:41:36 -04:00
Sergey Sharybin
b1c8f90b32 Math: Use lvalue ref-qualifier for compound assignment operators
The goal is to make issues like the ones fixed in #138310 become visible
much earlier in the development cycle.

This PR covers the most obvious places where it could be applied. There
are probably more places, but they can be covered later.

Pull Request: https://projects.blender.org/blender/blender/pulls/138315
2025-05-02 15:25:32 +02:00
Nathan Vegdahl
30698cf885 Fix #137932: compute correct armature bounds
There were actually two issues here:

1. The dimension reported for armatures were often wildly incorrect,
   including negative values and zero!
2. The dimensions reported for objects are supposed to be invariant with
   rotation, representing the dimensions along the object's local axes.
   However, armature objects' reported dimensions changed with rotation.

The respective causes were:

1. `BKE_armature_min_max()` was using an incorrect formula (acknowledged
   in a comment) for transforming the bounding box between spaces. This
   worked fine for some of the places that `BKE_armature_min_max()` was
   called, since they just reverse the transform using the same(!)
   erroneous formula, but it didn't work for others.
2. `BKE_armature_min_max()` first computed the bounds in world space,
   and then transformed them into object space, rather than computing
   them in object space directly like the respective functions for other
   object types. Even when done correctly, this causes the reported
   dimension to vary with rotation.

This PR fixes these issues by simply computing the armature bounding box
in object space directly instead.

There is one place in the code base that was directly using the
world-space bounds: `view3d_calc_minmax_selected()`. However, for every
object type other than armatures, it takes the object-space bounds and
transforms them (with an incorrect formula!) to world space.  So this PR
also changes `view3d_calc_minmax_selected()`'s armature code to do the
same, except with a correct formula.

Note that the reason for using the correct transform formula (departing
from other object types) is that the world-space bounds for armatures
were already correct prior to this PR due to being computed in that
space. Therefore using the incorrect formula has the potential to
introduce regressions in this case.

Pull Request: https://projects.blender.org/blender/blender/pulls/137961
2025-05-01 12:25:52 +02:00
Campbell Barton
43af16a4c1 Cleanup: spelling in comments, correct comment block formatting
Also use doxygen comments more consistently.
2025-05-01 11:44:33 +10:00
Hans Goudey
2037145e43 Fix: Broken VectorSet move construction after recent change
Caused by a2fac05e9d.
Like the move constructor for `Vector`, all the template arguments must
be specified for the compiler to pick the move constructor over the copy
constructor when the defaults aren't used. We can test this with a non-
moveable type like unique_ptr.

Pull Request: https://projects.blender.org/blender/blender/pulls/138215
2025-04-30 18:51:33 +02:00
Hans Goudey
a2fac05e9d BLI: Add configurable inline buffer to VectorSet
Allow configuring the inline buffer capacity for the slots array, and
add an inline buffer for the keys vector. Previously there was always
an allocation when adding an element.

The inline capacity is manually configured in a few places as part of
this commit.

Pull Request: https://projects.blender.org/blender/blender/pulls/136461
2025-04-29 18:52:30 +02:00
Aras Pranckevicius
8528feb7ee Cleanup: replace some spinlocks with atomics or mutexes
- ImBuf reference counting: turn that into just an atomic integer
- Cachefile safety: turn into a mutex, since work under the spinlock
  was quite heavy (hashtable creation, other memory allocations)
- Movie clip editor: turn into a mutex, since work under the spinlock
  was very heavy (reading files from disk, etc.)
- Mesh intersect: remove the previously commented out spinlock path;
  replace BLI mutex with C++ mutex for shorter code

Pull Request: https://projects.blender.org/blender/blender/pulls/137989
2025-04-29 10:42:45 +02:00
Campbell Barton
c90e8bae0b Cleanup: spelling in comments & replace some use of single quotes
Previously spell checker ignored text in single quotes however this
meant incorrect spelling was ignored in text where it shouldn't have
been.

In cases single quotes were used for literal strings
(such as variables, code & compiler flags),
replace these with back-ticks.

In cases they were used for UI labels,
replace these with double quotes.

In cases they were used to reference symbols,
replace them with doxygens symbol link syntax (leading hash).

Apply some spelling corrections & tweaks (for check_spelling_* targets).
2025-04-26 11:17:13 +00:00
Campbell Barton
682e5e3597 Cleanup: spelling in comments (make check_spelling_*) 2025-04-26 00:48:04 +00:00
Campbell Barton
2d4290f285 Cleanup: spelling in comments (make check_spelling_*)
Also inconsistent capitalization.
2025-04-24 22:45:22 +00:00
Harley Acheson
9dd4e90136 UI: Line Break on Conditional Punctuation
This PR adds new typographical line breaking opportunities, characters
that break depending on what follows. For example comma if not followed
by a space or a number. Period if not followed by a space or another
period. Along with related non-Latin equivalents, like Greek question
mark, full width punctuation, Hebrew, Arabic, etc.

Pull Request: https://projects.blender.org/blender/blender/pulls/137934
2025-04-24 20:42:32 +02:00
Brecht Van Lommel
e21924d0ff Cleanup: Fix kdtree node warnings with GCC
Alternative fix to 50023eab75.

Pull Request: https://projects.blender.org/blender/blender/pulls/137962
2025-04-24 16:00:44 +02:00
Campbell Barton
d5b254216b Cleanup: correct references to UI_interface_c.hh 2025-04-23 05:29:14 +00:00
Campbell Barton
22d0391583 Cleanup: spelling in comments, use doxygen comments for doc-strings 2025-04-23 13:16:20 +10:00
Howard Trickey
dd559259d8 Modeling: Add a new boolean solver based on the Manifold library.
Adds the 'manifold' solver option to the Boolean geo node and to
the Boolean modifier. This solver is about as fast, or faster,
than the current float solver, and is robust against floating
point issues like the Exact solver. But currently it only
works on mesh arguments that are strictly manifold.

See https://projects.blender.org/blender/blender/issues/120182
for many more details.
2025-04-22 21:23:37 -04:00
Brecht Van Lommel
50023eab75 Fix: Invalid kdtree node allocation after recent refactor
Address the root cause and fix one definition rule violation.
Broken by fb2ba20b67.

Pull Request: https://projects.blender.org/blender/blender/pulls/137845
2025-04-22 14:32:39 +02:00
Brecht Van Lommel
fb2ba20b67 Refactor: Use more typed MEM_calloc<> and MEM_malloc<>
Pull Request: https://projects.blender.org/blender/blender/pulls/137822
2025-04-22 11:22:18 +02:00
Brecht Van Lommel
d061b00455 Refactor: Eliminate various unsafe memcpy and memset
Some of these already have warnings with clang-tidy, others are more
safe in case these structs get (copy) constructors in the future.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Brecht Van Lommel
388a21e260 Refactor: Eliminate various void pointers passed to MEM_freeN
It's safer to pass a type so that it can be checked if delete should be
used instead. Also changes a few void pointer casts to const_cast so that
if the data becomes typed it's an error.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Brecht Van Lommel
637c6497e9 Refactor: Use more typed MEM_calloc<>, avoid unnecessary size_t cast
Handle some cases that were missed in previous refactor. And eliminate
unnecessary size_t casts as these could hide issues.

Pull Request: https://projects.blender.org/blender/blender/pulls/137404
2025-04-21 17:59:41 +02:00
Campbell Barton
3933f45f52 Cleanup: move doc-strings to declarations
Move into headers or to the top of the function body for internal
implementation details, in some cases remove duplicate doc-strings.
2025-04-18 22:58:36 +10:00
Campbell Barton
234a4ce3a0 Cleanup: CLANG warning with recent function signature change 2025-04-18 12:56:09 +10:00
Campbell Barton
6711256578 Cleanup: move BLI_file_alias_target doc-string to the header
Also adjust the function signature to include the array size.
2025-04-18 12:49:51 +10:00
Jacques Lucke
b6342a7e94 Cleanup: simplify allocating buffers for a CPPType
This reduces verbosity when using `LinearAllocator` or `ResourceScope` to
allocate values for a `CPPType`. Now, this is simplified and one also does not
have to manually add a destructor call anymore.

Pull Request: https://projects.blender.org/blender/blender/pulls/137685
2025-04-17 22:01:07 +02:00
Jacques Lucke
7988fc631b Cleanup: BLI: use IndexMask forward declaration in CPPType
This avoids recursive dependencies when we want to make it easier to
allocate `CPPType` values with e.g. `LinearAllocator` efficiently.

Pull Request: https://projects.blender.org/blender/blender/pulls/137678
2025-04-17 20:41:53 +02:00