Commit Graph

5443 Commits

Author SHA1 Message Date
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
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
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
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
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
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
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
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
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
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
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
Bastien Montagne
3d52ac536e BLI_listbase: Add a new BLI_listbase_findafter_string util.
Similar to existing `BLI_listbase_findafter_string_ptr`, but for cases
where the searched property is a char array, and not a char pointer.
2025-04-15 12:35:54 +02:00
Jacques Lucke
7f1a99e862 Refactor: BLI: Make some CPPType properties public instead of using methods
This makes accessing these properties more convenient. Since we only ever have
const references to `CPPType`, there isn't really a benefit to using methods to
avoid mutation.

Pull Request: https://projects.blender.org/blender/blender/pulls/137482
2025-04-14 17:48:17 +02:00
Jacques Lucke
be266a1c0c Refactor: Geometry Nodes: replace ComputeContextBuilder with ComputeContextCache
While `ComputeContextBuilder` worked well for building simple linear compute
contexts, it was fairly limiting for all the slightly more complex cases where
an entire tree of compute contexts is built. Using `ComputeContextCache` that is
easier to do more explicitly. There were only very few cases where using
`ComputeContextBuilder` would have still helped a bit, but it's not really worth
keeping that abstraction around just for those few cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/137370
2025-04-14 17:47:56 +02:00
Campbell Barton
d700bc5f54 Cleanup: remove use of unsafe string functions 2025-04-12 18:42:44 +10:00
Campbell Barton
3bf92a6e83 Cleanup: rename nullptr to null for null-characters 2025-04-11 23:55:00 +00:00
Campbell Barton
f2e4b35589 Cleanup: rename UTF8 stripping arguments to avoid confusion 2025-04-12 09:50:14 +10:00
Jacques Lucke
b92fdff697 Refactor: BLI: use FunctionRef in BLI_uniquename api
This simplifies the API usage, removes the need for intermediate structs
and reduces the overall amount of code.

Pull Request: https://projects.blender.org/blender/blender/pulls/137300
2025-04-10 20:30:45 +02:00
Sergey Sharybin
67fac1e391 Fix #137084: Image Editor shifts the images when Aspect Ratio is not 1.0
Seems to be an incorrect implementation of BLI_rctf_transform_calc_m3_pivot_min()
in 2a44bdfbd0.

Pull Request: https://projects.blender.org/blender/blender/pulls/137141
2025-04-08 15:27:47 +02:00
Omar Emara
47471ca2b0 Fix: Crash when sampling Float2 images
Blender crashes when using math interpolation functions to sample Float2
images. That's because 3 components is intentionally left out of various
switch case. To fix this, we handle 3 components and assert for expected
components count.

Pull Request: https://projects.blender.org/blender/blender/pulls/137094
2025-04-07 15:25:15 +02:00
Jesse Yurkovich
f60c528c48 Cleanup: Fix one-definition-rule violations for various structs
This fixes most "One Definition Rule" violations inside blender proper
resulting from duplicate structures of the same name. The fixes were
made similar to that of !135491. See also #120444 for how this has come
up in the past.

These were found by using the following compile options:
-flto=4 -Werror=odr -Werror=lto-type-mismatch -Werror=strict-aliasing

Note: There are still various ODR issues remaining that require
more / different fixes than what was done here.

Pull Request: https://projects.blender.org/blender/blender/pulls/136371
2025-04-04 21:05:16 +02:00
Germano Cavalcante
3ab65cff04 Windows: show popup after crash
Implements a crash dialog for Windows.

The crash popup provides the following actions:
- Restart: reopen Blender from the last saved or auto-saved time
- Report a Bug: forward to Blender bug tracker
- View Crash Log: open the .txt file with the crash log
- Close: Closes without any further action

Pull Request: https://projects.blender.org/blender/blender/pulls/129974
2025-04-04 18:38:53 +02:00
Campbell Barton
4139d4a8f0 Cleanup: spelling in comments (make check_spelling_*) 2025-04-04 12:48:04 +11:00
Campbell Barton
281cf7ff6d Cleanup: remove dead code from BLI_str_partition_ex
The check for `from_right` was always false.
2025-04-01 13:14:28 +11:00
Campbell Barton
52701243f5 Cleanup: suppress null-pointer-subtraction warning for CLANG 2025-04-01 11:57:16 +11:00
Jorn Visser
b1bb1d9815 Build: Make the FFTW threads library required to use FFTW
This is done because the library is necessary to make certain FFTW
functions thread safe, see #136557 as well.

Also pass each library variable separately to
`find_package_handle_standard_args` instead of as a list, as otherwise
it won't correctly detect if `libfftw3f` or `libfftw3f_threads` is
missing. This is because CMake considers a value false if it contains
`-NOTFOUND` at the end, but not if it's in the middle. For example,
CMake considers
`.../libfftw3f.a;.../libfftw3f_threads.a;FFTW3_LIBRARY_D-NOTFOUND` to be
false, but
`.../libfftw3f.a;FFTW3_LIBRARY_THREADS_F-NOTFOUND;.../libfftw3.a` to be
true.

---

I noticed that some other find modules also have the same list issue. I guess it was done this way to make CMake print all the found libraries instead of only the first.

Pull Request: https://projects.blender.org/blender/blender/pulls/136692
2025-03-31 14:42:35 +02:00
Campbell Barton
aa4f717b41 Docs: add missing \file blocks to blenlib & blenkernel 2025-03-29 15:18:50 +11:00
Jacques Lucke
98c4d107ea Fix: BLI_str_endswith returns false when both inputs are the same
Found this while reviewing #136021. It's somewhat surprising that this didn't cause issues before.

This patch also adds some unit tests for `BLI_str_endswith` and `BLI_str_startswith`.

Pull Request: https://projects.blender.org/blender/blender/pulls/136679
2025-03-28 22:48:26 +01:00
Sean Kim
2ad17b956a BLI: Add rolling average support to ScopedTimerAverage
Adds a new argument for the class constructor as well as a new macro to
support printing the rolling average of a number of samples intead of
the total average.

This can be useful for getting a sample of an average durations in
functions that are continually running, e.g. the main event loop.

Pull Request: https://projects.blender.org/blender/blender/pulls/136530
2025-03-28 22:28:59 +01:00
Jacques Lucke
202db40afb Refactor: move uvproject code from blenlib to blenkernel
I'm moving this for two (related) reasons:
* It depends a lot on the specifics of `Camera` and `Object` data-blocks.
* It links `Object::object_to_world()` which is not an inline function and thus
  easily leads to linker errors. It mostly seems like luck that this is not
  breaking our build due to early dead code elimination when linking binaries
  which use the blenlib static library such as `msgfmt`.

I found this while working on a compilation tool which would not be as lucky and
has a linker error because of the dependence on `Object::object_to_world`.

Pull Request: https://projects.blender.org/blender/blender/pulls/136547
2025-03-26 20:51:57 +01:00
Jacques Lucke
2a9ebda328 Cleanup: avoid duplicate definition of unit_m3 and unit_m4
It does not seem worth it to avoid including `BLI_math_matrix.h` here nowadays.

Pull Request: https://projects.blender.org/blender/blender/pulls/136387
2025-03-24 09:28:54 +01:00
Jacques Lucke
26c95c9968 Cleanup: avoid ambiguous type name
There was a potential conflict between blender::Map and Eigen::Map.
2025-03-23 13:35:48 +01:00