Commit Graph

424 Commits

Author SHA1 Message Date
Campbell Barton
fd589fdca4 Cleanup: various non functional C++ changes 2024-04-20 13:46:14 +10:00
Campbell Barton
cf37424203 Cleanup: use const pointers, quiet cppcheck unreadVariable warning 2024-04-17 11:36:38 +10:00
Campbell Barton
20b0805213 Cleanup: use const pointers where possible 2024-04-16 12:27:47 +10:00
Campbell Barton
90f1d1cc61 Cleanup: use doxygen formatting for guarded-allocator 2024-04-16 12:27:13 +10:00
Jacques Lucke
00648411ea MEM: support overaligned types in MEM_cnew_array
This is similar to the recent change for `MEM_cnew`: 60a3d85b888c70330b7f9e691d8e82d66561d0f1.
A new function called `MEM_calloc_arrayN_aligned` is added that is used by both `cnew` functions now.

Pull Request: https://projects.blender.org/blender/blender/pulls/120632
2024-04-15 19:11:06 +02:00
Jacques Lucke
e3b8d45c93 Cleanup: move mallocn to c++
Required for a cleaner solution for #120632.
2024-04-15 13:02:17 +02:00
dupoxy
1079f0918e Cleanup: use function style cast in MAKE_ID macro
Ref: !120630
2024-04-14 23:08:45 +10:00
Campbell Barton
a70d6d79dd Cleanup: various non-functional C++ changes 2024-04-14 12:24:17 +10:00
Clément Foucault
d1d90ecbec Cleanup: MEM: Remove outdated comment 2024-04-12 18:01:26 +02:00
Clément Foucault
60a3d85b88 MEM: Make MEM_cnew return aligned memory
Now made it so that `MEM_cnew()` can be used for types with any
alignment.

Fixes #120407.

Pull Request: https://projects.blender.org/blender/blender/pulls/120569
2024-04-12 17:52:27 +02:00
Sergey Sharybin
a4b36cd0d5 Guarded allocator: Ensure alignment and size of MemHead
Ensure that the MemHead and MemHeadAligned are such that memory
allocation followed with the head offset keeps the allocation
aligned to at least MEM_MIN_CPP_ALIGNMENT.

Pull Request: https://projects.blender.org/blender/blender/pulls/120582
2024-04-12 17:22:46 +02:00
Sergey Sharybin
fac451e513 Cleanup: Convert guarded allocator to C++
Pull Request: https://projects.blender.org/blender/blender/pulls/120577
2024-04-12 16:44:49 +02:00
Campbell Barton
09ee8d97e6 Cleanup: use C-style comments for descriptive text 2024-04-11 17:44:27 +10:00
Campbell Barton
52ce8d408f Cleanup: use const arguments & variables 2024-04-04 10:55:10 +11:00
Jacques Lucke
8ea425d95d Fix #118402: enforce expected minimum alignment in MEM_CXX_CLASS_ALLOC_FUNCS
This `operator new` added in ecc3e78d787cce8a3f202e7de26575e2d47baea2
are only called if the alignment is greater than `__STDCPP_DEFAULT_NEW_ALIGNMENT__`.
This is generally 8 or 16 depending on the platform. `MEM_mallocN` does
guarantee 16 byte alignment currently (in fact it's usually not 16 byte aligned
because of `MemHead`). Now `MEM_mallocN_aligned` is used with the default
alignment, even if we don't know that the type does not require it.

An alternative would be to pass the alignment to `MEM_CXX_CLASS_ALLOC_FUNCS`,
but that would be more intrusive.

Pull Request: https://projects.blender.org/blender/blender/pulls/118568
2024-02-21 18:14:11 +01:00
Jacques Lucke
ecc3e78d78 Fix #118402: support overaligned types in MEM_CXX_CLASS_ALLOC_FUNCS
Previously, the alignment of structs that use `MEM_CXX_CLASS_ALLOC_FUNCS`
were not taken into account when doing the allocation. This can cause some data
to be mis-aligned and leads to crashes when cpu instructions or code expect the
data to be aligned.

The fix is to provide an overload of `operator new` that accepts the alignment as parameter.

More info: https://en.cppreference.com/w/cpp/language/new (search for `align_val_t`).

Pull Request: https://projects.blender.org/blender/blender/pulls/118526
2024-02-20 18:44:26 +01:00
Hans Goudey
da6b45f9b8 Cleanup: Make format 2024-01-16 10:56:55 -05:00
Eugene Kuznetsov
10dfa07e36 Linux: Use huge pages in jemalloc to speed up allocations
Enable huge pages for jemalloc. This requests the Linux kernel to use
huge (2 MB) pages for large allocations. This has the effect of speeding
up first accesses to those allocations, and possibly also speeds up future
accesses by reducing TLB faults.

By default, 4 KB pages are used unless the user enables huge pages through
a kernel parameter or an obscure sysfs setting.

For Cycles benchmarks, this gives about a 5% CPU rendering performance
improvement. It likely also improves performance in other areas of Blender.

Pull Request: https://projects.blender.org/blender/blender/pulls/116663
2024-01-16 16:37:40 +01:00
Brecht Van Lommel
364beee159 Tests: add option to build one binary per GTest file
Bundling many tests in a single binary reduces build time and disk space
usage, but is less convenient for running individual tests command line
as filter flags need to be used.

This adds WITH_TESTS_SINGLE_BINARY to generate one executable file per
source file. Note that enabling this option requires a significant amount
of disk space.

Due to refactoring, the resulting ctest names are a bit different than
before. The number of tests is also a bit different depending if this
option is used, as one uses gtests discovery and the other is organized
purely by filename, which isn't always 1:1.

Co-authored-by: Sergey Sharybin <sergey@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/114604
2024-01-03 18:35:50 +01:00
Brecht Van Lommel
f63accd3b6 Cleanup: move CMake test utility functions into testing.cmake
Combining functions from macros.cmake and Modules/GTestTesting.cmake.
It was unusual to have Blender specific code in the Modules folder.

Pull Request: https://projects.blender.org/blender/blender/pulls/116719
2024-01-03 14:49:11 +01:00
Brecht Van Lommel
d377ef2543 Clang Format: bump to version 17
Along with the 4.1 libraries upgrade, we are bumping the clang-format
version from 8-12 to 17. This affects quite a few files.

If not already the case, you may consider pointing your IDE to the
clang-format binary bundled with the Blender precompiled libraries.
2024-01-03 13:38:14 +01:00
Brecht Van Lommel
4ce14a639f Revert "Cleanup: move CMake test utility functions into testing.cmake"
This breaks execution of some Windows tests.

This reverts commit 4190a61020eb1ddde5097ac21aaf0bb77118f140.
2024-01-02 19:06:39 +01:00
Brecht Van Lommel
4190a61020 Cleanup: move CMake test utility functions into testing.cmake
Combining functions from macros.cmake and Modules/GTestTesting.cmake.
It was unusual to have Blender specific code in the Modules folder.
2024-01-02 15:34:52 +01:00
Campbell Barton
9898602e9d Cleanup: clarify #ifndef checks in trailing #endif comments 2023-12-07 10:38:54 +11:00
Campbell Barton
20fd012adb Valgrind: suppress warnings with MemPool & MEM_* trailing padding
Suppress false positive Valgrind warnings which flooded the output.

- BLI_mempool alloc/free & iteration.
- Set alignment padding bytes at the end of MEM_* allocations
  as "defined" since this causes many false positive warnings
  in blend file writing and MEMFILE comparisons.
- Set MEM_* allocations as undefined when `--debug-memory`
  is passed in to account for debug initialization.
- Initialize pad bytes in TextLine allocations.
2023-12-05 17:12:32 +11:00
Campbell Barton
d4f1a9b0ad Build: resolve build error on MSVC
Address error introduced by [0].

[0]: 6b967287c964e4deb9755d35f37998ba9ff06c34
2023-09-28 14:23:11 +10:00
Campbell Barton
6b967287c9 MEM_guarded_alloc: restore execinfo.h back-trace on Linux/Apple
Recently [0] replaced back-traces from `execinfo.h` with ASAN's
`__asan_describe_address` since the linking options to hide symbols
cause the stack-traces only to include addresses (without functions).
Although using ASAN makes sense when enabled, in my tests the
stack-traces are sometimes empty. Using CMAKE_BUILD_TYPE=RelWithDebInfo
for e.g. wasn't showing a stack-trace for the leak fixed in [1].

A utility is now included to conveniently expand the addresses from
these stack traces (`tools/utils/addr2line_backtrace.py`).

Restore support for the execinfo stack-trace reporting, used when ASAN
is disabled.

[0]: 2e79ca320557073ccf00f021dca988be6f361acd
[1]: a9f0d19197e83ae6be7c1ccc71770361be16f742
2023-09-28 12:45:04 +10:00
Campbell Barton
b7f3e0d84e Cleanup: spelling & punctuation in comments
Also remove some unhelpful/redundant comments.
2023-09-14 13:25:24 +10:00
Campbell Barton
057c9364fc Cleanup: use braces around statements 2023-09-12 14:48:20 +10:00
Campbell Barton
bc1ffdce5b Cleanup: spelling in comments 2023-08-18 08:56:12 +10: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
Campbell Barton
311fa9768d Cleanup: spelling in comments 2023-08-12 16:29:51 +10:00
Bastien Montagne
bcc0b9f73f Tweaks to previous commit affecting debug reports of our guarded allocator.
Somehow missed these tweaks (from @LazyDodo) in own recent 2e79ca3205
commit, sorry for the noise.
2023-08-10 17:56:36 +02:00
Bastien Montagne
2e79ca3205 Fix #110971: Replace our own barely-working backtrace on memleaks feature with ASAN utils.
Instead of storing the backtrace in all memory blocks, and trying to get
meaningful info out of this list of pointers when printing leaked ones,
just use `__asan_describe_address` when ASAN is enabled.

This also work on Windows, in addition to linux and (presumably) OSX,
but does require to build with ASAN enabled.

The previous code was not working very well anymore, for some reason the
call to `backtrace_symbols` seems to fail to give any meaningful
information nowadays on most of Blender code. And it was only
implemented for linux and OSX.

Based on an idea from @LazyDodo, many thanks!

Pull Request: https://projects.blender.org/blender/blender/pulls/111006
2023-08-10 17:54:56 +02:00
Bastien Montagne
c5feb0cada MEM_guarded_alloc: Fix LSAN not reporting memory leaks.
The fact that the guarded-allocated memory blocks are all linked to the
static `membase` listbase is enough for LSAN to not detect them as
leaks.

So this commit adds a new (private) callback to clear the memlist, which
is only used in the destructor of the `MemLeakDetector` class.

Many thanks to @Sergey for identifying the root issue here.

Pull Request: https://projects.blender.org/blender/blender/pulls/110995
2023-08-10 15:05:53 +02:00
Campbell Barton
ed01e16aa6 Cleanup: quiet uninitialized warnings 2023-07-29 13:47:57 +10:00
Jacques Lucke
d1aeb1c3b4 Cleanup: add static assert for detect bad usage of MEM_SAFE_FREE
Without this, there is not compilation error when doing e.g.:
```
int a;
MEM_SAFE_FREE(a);
```
2023-07-28 13:50:02 +02:00
Jacques Lucke
3e6025c1b1 Cleanup: move some files to c++
Also see #103343.

Pull Request: https://projects.blender.org/blender/blender/pulls/110529
2023-07-27 13:10:42 +02:00
Ray Molenkamp
57ad866d81 Cleanup: CMake: Modernize bf_guardedalloc dependencies
Pretty straightforward

- Removes any guardedalloc paths from INC
- Adds a dependency though LIB

Pull Request: https://projects.blender.org/blender/blender/pulls/109925
2023-07-10 18:44:19 +02:00
Ray Molenkamp
f0ee4c3ffe Cleanup: Cmake: use alias target for bf_intern_atomic
This introduces an alias target `bf::intern::atomic` for
`bf_intern_atomic`. This has the following benefits:

- Any target name with `::` in it will be recognized as an actual
target by cmake, rather than a library name it may not know about.
and will be validated by cmake to exist. Which means if you make
a typo in the LIB section, CMake will error out telling you it
doesn't know about this specific target rather than passing it on
to the build system, where you'll either get build or linker errors
because of said typo.

- Given there is quite a cleanup still to do in the build system,
it won't always be obvious which targets have been updated to
modern targets and which still need to be done. Having a namespaced
target name is a good indicator there.

Pull Request: https://projects.blender.org/blender/blender/pulls/109784
2023-07-07 15:37:02 +02:00
Ray molenkamp
2dac20e35f CMake/Cleanup: Use bf_intern_atomic target
Use the bf_intern_atomic target rather than adding a relative path
to it in the INC section.

Pull Request: https://projects.blender.org/blender/blender/pulls/109424
2023-06-28 19:12:55 +02:00
Campbell Barton
d27be2b95d Cleanup: remove sprintf use in guarded allocator
Also remove vsprintf in exr_printf (commented out).
2023-06-27 15:31:21 +10:00
Jeroen Bakker
0c154b6c61 Cleanup: Make format 2023-06-15 08:25:49 +02:00
Campbell Barton
65f99397ec License headers: use SPDX-FileCopyrightText in all sources 2023-06-15 13:35:34 +10:00
Campbell Barton
49594c37ae License headers: use SPDX-FileCopyrightText for CMake files 2023-06-14 23:36:23 +10:00
Brecht Van Lommel
835252fd1c Merge branch 'blender-v3.6-release' into main 2023-06-13 19:48:48 +02:00
Brad Smith
c1d353c17b Build: fix NetBSD error in guardedalloc
Pull Request: https://projects.blender.org/blender/blender/pulls/108831
2023-06-13 19:46:11 +02:00
Campbell Barton
e27bcb6e3e Cleanup: remove redundant struct qualifier 2023-06-04 19:27:38 +10:00
Brad Smith
670da740ba Build: fix OpenBSD error in guardedalloc
Pull Request: https://projects.blender.org/blender/blender/pulls/108252
2023-05-30 13:55:37 +02:00
Brad Smith
a50768616f Build: fix OpenBSD error in guardedalloc
Pull Request: https://projects.blender.org/blender/blender/pulls/108252
2023-05-25 15:21:48 +02:00