Commit Graph

6307 Commits

Author SHA1 Message Date
Campbell Barton
32fb40fa76 Cleanup: use function style casts for C++ 2023-07-14 12:31:00 +10:00
Campbell Barton
ef1ddbaaca Cleanup: remove double spaces after a full-stop 2023-07-13 13:40:25 +10:00
Hans Goudey
9a879b27b3 Cleanup: Fix macOS build error, move set performance test out of header
Fixes, similar to a5a72019a9

Pull Request: https://projects.blender.org/blender/blender/pulls/110017
2023-07-12 18:04:13 +02:00
Hans Goudey
a5a72019a9 Cleanup: Move Map performance test out of header
Avoid including <unordered_map> in BLI_map.hh
for the performance test only used in the test file.
2023-07-12 09:45:25 -04:00
Jacques Lucke
3f33e0c6cd Cleanup: clang format in disabled code segments
This formats code that is disabled using `#if 0`. Formatting was achieved
by temporarily changing `#if 0` to `#if 1 /*something*/`, then formatting,
and then changing it back to `#if 0`.
2023-07-12 14:18:59 +02:00
Hans Goudey
087612c042 Cleanup: Reduce use and scope of templates in vertex paint
Many high-level functions with unrelated code were templated based on
the color attribute domain and type. In the end, those were just a few
branches though, similar to other branches. So to reduce binary bloat
and clarify code, move tempates to the point where separate types are
actually needed. Also move constant code out of loops, and use generic
arrays and spans to store some caches. The binary ended up 53 KB
smaller for me, which isn't much but it's in the right direction.

Performance wise nothing really changes. The vast majority of time in
vertex paint is spent on unrelated things like calculating normals or
uploading GPU buffers anyway.

The one ugly part I didn't account for when I started is the casting
between the "ColorGeometry" and "ColorPaint" types. I'm not sure that
this is correct, but it's just a more explicit version of what was
there already.

Pull Request: https://projects.blender.org/blender/blender/pulls/109941
2023-07-11 15:52:28 +02:00
Campbell Barton
36b2291610 Cleanup: spelling in comments 2023-07-11 14:40:47 +10:00
Hans Goudey
5ca29d293b Fix: BLI: Assert in generic array move constructor
When assigning a default constructed virtual array,
an assert checking for a non-null type was triggered.
2023-07-10 16:22:55 -04:00
Ray Molenkamp
04235d0e55 Cleanup: CMake: Modernize bf_blenlib dependencies
Pretty straightforward

- Remove any blenlib paths from INC
- Add a dependency though LIB

Pull Request: https://projects.blender.org/blender/blender/pulls/109934
2023-07-10 22:04:18 +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
Hoshinova
41335edf22 Fix #109254: Voronoi distance output is clamped at 8
The Voronoi distance output is clamped at 8, which is apparent for distance
metrics like Minkowski with low exponents.

This patch fixes that by setting the initial distance of the search loop to
FLT_MAX instead of 8. And for the Smooth variant of F1, the "h" parameter is set
to 1 for the first iteration using a signal value, effectively ignoring the
initial distance and using the computed distance at the first iteration instead.

Pull Request: https://projects.blender.org/blender/blender/pulls/109286
2023-07-10 17:42:24 +02:00
Ray Molenkamp
7cebb61486 Cleanup: CMake: Modernize bf_dna dependencies
There's quite a few libraries that depend on dna_type_offsets.h
but had gotten to it by just adding the folder that contains it to
their includes INC section without declaring a dependency to
bf_dna in the LIB section.

which occasionally lead to the lib building before bf_dna and the
header being missing, while this generally gets fixed in CMake by
adding bf_dna to the LIB section of the lib, however until last
week all libraries in the LIB section were linked as INTERFACE so
adding it in there did not resolve the build issue.

To make things still build, we sprinkled add_dependencies wherever
we needed it to force a build order.

This diff :

Declares public include folders for the bf_dna target so there's
no more fudging the INC section required to get to them.

Removes all dna related paths from the INC section for all
libraries.

Adds an alias target bf:dna to signify it has been updated to
modern cmake

Declares a dependency on bf::dna for all libraries that require it

Removes (almost) all calls to add_dependencies for bf_dna

Future work:

Because of the manual dependency management that was done, there is
now some "clutter" with libs depending on bf_dna that realistically
don't. Example bf_intern_opencolorio itself has no dependency on
bf_dna at all, doesn't need it, doesn't use it. However the
dna include folder had been added to it in the past since bf_blenlib
uses dna headers in some of its public headers and
bf_intern_opencolorio does use those blenlib headers.

Given bf_blenlib now correctly declares the dependency on bf_dna
as public bf_intern_opencolorio will get the dna header directory
automatically from CMake, hence some cleanup could be done for
bf_intern_opencolorio

Because 99% of the changes in this diff have been automated, this diff
does not seek to address these issues as there is no easy way to
determine why a certain dependency is in place. A developer will have
to make a pass a this at some later point in time. As I'd rather not
mix automated and manual labour.

There are a few libraries that could not be automatically processed
(ie bf_blendthumb) that also will need this manual look-over.

Pull Request: https://projects.blender.org/blender/blender/pulls/109835
2023-07-10 15:07:37 +02:00
Campbell Barton
09f1844d75 Cleanup: correct doxy-groups 2023-07-09 21:40:17 +10:00
Campbell Barton
6290451712 Cleanup: spelling in comments 2023-07-09 21:22:45 +10: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
Campbell Barton
40ef6c400b Cleanup: utility function to multiple rctf/rcti 2023-07-07 15:42:07 +10:00
Campbell Barton
23acedd432 Cleanup: code-comments 2023-07-07 15:11:19 +10:00
Iliya Katueshenock
1beece5f16 Cleanup: Unused spin lock mutex warning
Pull Request: https://projects.blender.org/blender/blender/pulls/109777
2023-07-06 19:43:40 +02:00
Hoshinova
c9fbbea261 Cleanup: Assign corresponding expressions to variable params.max_distance
Pull Request: https://projects.blender.org/blender/blender/pulls/109328
2023-07-06 18:13:22 +02:00
Campbell Barton
6a79639ef7 Cleanup: use function style casts, remove void function argument
Also remove redundant parenthesis.
2023-07-06 10:40:25 +10:00
Hans Goudey
2b4666b17b Geometry Nodes: Fill new quad poly offsets in parallel
Add an offset indices utility to do fill constant size new offsets in
parallel, which was already done in the duplicate elements node.

For example, filling poly offsets for a new part of a mesh that is only
quads. In the extrude node this was single-threaded before, so the
new poly offsets is about 10x faster, saving about 10 out of 157 ms
when extruding 2 million faces.
2023-07-05 15:39:33 -04:00
Jacques Lucke
0b7d8a20bf Cleanup: Move many editors files to C++
This moves the following `editors/*` directories to C++:
- animation, armature, lattice, mesh, metaball, object, scene.

Much of the changes in this commit (inserting casts in particular)
was automated. Further changes like switching to functional style
casts can be done separately by existing automated scripts.

See #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/109715
2023-07-05 20:03:41 +02: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
Campbell Barton
785bd13b9a Cleanup: spelling in comments 2023-07-05 14:09:33 +10:00
Campbell Barton
9e26960b77 Cleanup: code-comments 2023-07-04 12:36:41 +10:00
Campbell Barton
9753e70e37 Cleanup: move BLI_str_replace into BLI_string_utils.h
String search & replace is a higher level function (unlike BLI_string.h)
which handlers lower level replacements for printing and string copying.

Also use BLI_string_* prefix (matching other utilities).

This makes it possible to use BLI_string in Blender's internal utilities
without depending on DynStr, MemArena... etc.
2023-07-04 12:02:25 +10: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
Germano Cavalcante
d0bbae8596 Fix #109641: Snapping doesn't respect Clipping Border
The clip planes in `rv3d->clip` were not being added.
2023-07-03 14:37:33 -03:00
Sergey Sharybin
5907ab0364 Fix redefinition SSE2NEON_PRECISE_SQRT on Apple Silicon
After some recent changes BLI_math_base got (indirectly) included
from DNA file, causing defines conflict in Cycles: Cycles wants the
default fast behavior of square root, and BLI color wants it to be
more preciese.

Proposed solution is to move the SSE block away from the math_base
closer to code which uses it. The initial intent was to make those
functions reusable, but for a long long time the color utilities
are the only users of those functions.

This change does not prevent the error from re-occurring in the
future if some code includes sse2neon and BLI color utilities, but
it makes such conflict situation much less likely to happen, for
now.

The downside of this change is that the code now need to include
BLI_simd.h explicitly to access BLI_HAVE_SSE2 instead of relying
on it being included indirectly with math headers. The mitigation
for this is to change semantic of the BLI_HAVE_SSE2: now it is
defined to 1 if SSE2 is supported and to 0 otherwise. This makes
it so the code needs to check if using `#if BLI_HAVE_SSE2` and
if the BLI_simd.h is not included it will generate warning when
using GCC or Clang.

This change in semantic is is something the current patches would
need to ensure is handled correctly.

Pull Request: https://projects.blender.org/blender/blender/pulls/109664
2023-07-03 19:18:30 +02:00
Sergey Sharybin
4cd10ddfdb Fix naive 4x4 matrix multiplication C++ implementation
Is not visible on any of the officially platforms, as everywhere
SSE2 is available (on Apple Silicon via sse2neon).

Only got noticed by some intermittent issue during development
which made BLI_HAVE_SSE2 unaccessible.

Seems that transpose was done a bit wrong. Not sure if worth trying
to fold the equation into C++ types, as that requires extra memory
transfers for transpose. Opted for a more naive folding, which
avoids extra copies.

Added a regression test for it, verified against numpy, the BLI
SSE2 implementation.
2023-07-03 19:18:28 +02:00
Campbell Barton
1a758aa793 BLI_dynstr: remove workaround for vsnprintf on WIN32
Based on code-comments it seems vsnprintf didn't return the un-clamped
string length on MS-Windows, this is no longer the case.
BLI_dynstr used allocation doubling in a loop (with a 65536 limit)
in an attempt to allocate sufficient space.

This workaround isn't needed anymore. Expose BLI_sprintfN_with_buffer &
BLI_vsprintfN_with_buffer functions that take a fixed buffer to avoid
allocation for smaller strings.
This simplifies BLI_dynstr_appendf considerably.
2023-07-03 17:01:32 +10:00
Campbell Barton
33a7b80a6f BLI_string: use vsnprintf for BLI_sprintfN & BLI_vsprintfN
Avoid having to create & free the DynStr, which created an additional
temporary buffer. Gives around 1.5x overall speedup.
2023-07-03 13:57:25 +10:00
Campbell Barton
10bbf29d49 BLI_string: add BLI_vsprintfN
Avoid having to use BLI_dynstr to format a string using a va_list.
2023-07-03 13:14:06 +10:00
Campbell Barton
35389e8b35 Cleanup: use const qualifier for arguments & variables 2023-06-29 10:56:33 +10: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
275ac77f16 Cleanup: quiet clang warnings from using u8 defines 2023-06-28 12:19:51 +10:00
Ray molenkamp
eff9e2f4ce CMake: plumbing for modern CMake usage
This is the minimal change required to start using modern CMake in the
blender build system. This change is designed to allow small
incremental changes to the build system rather than doing it in one
big bang which would be unmaintainable (for me)

The biggest functional change is, previously all libraries in the
`LIB` section of a `blender_add_lib` call had the `INTERFACE` scope,
which is rarely, if ever the correct scope. This diff changes this to
`PRIVATE`

Concrete implications of this diff :

The `LIB`, `INC` and `INC_SYS` sections of an `blender_add_lib` call
now allow scoping keywords (`PUBLIC`, `PRIVATE,` `INTERFACE`) to
declare the scope of the dependency.

Right now the only library using any modern cmake is
`bf_intern_atomic` which is an header only interface library that will
just advertise its include directories.

This allows us to clean up any `CMakeLists.txt` that adds
`../../../intern/atomic` to its `INC` section to remove it in `INC` by
adding a `PRIVATE bf_intern_atomic` to the `LIB` section.

Pull Request: https://projects.blender.org/blender/blender/pulls/107858
2023-06-27 20:57:50 +02:00
Harley Acheson
4a80d0b6d5 Refactor: UTF-8 Character Defines
Use defined UTF-8 Universal character names in place of byte escape
sequences and literals.

Pull Request: https://projects.blender.org/blender/blender/pulls/109163
2023-06-26 06:05:18 +02:00
Campbell Barton
82d9eb09db Cleanup: use term SIZE instead of LEN for defines for buffer sizes
Reserve "LEN" for lengths that don't include the null byte.
2023-06-26 10:09:57 +10:00
Campbell Barton
9a4e823f3f Cleanup: minor changes to string join logic
- When string join truncates, break out of the outer loop too.
- Use BLI_string_len_array when calculating the array size for
  BLI_string_join_array_by_sep_charN.
- Add tests.
2023-06-25 16:45:02 +10:00
Campbell Barton
f4a65cfe5d BLI_string: remove potentially unsafe BLI_sprintf
Replace by BLI_snprintf or string joining.

See #108917.
2023-06-25 13:34:31 +10:00
Campbell Barton
b9bf639ba4 BLI_string: remove BLI_strcpy_rlen
Avoid BLI_strcpy_rlen use as this has the same problems as strcpy
(it just returned the length which is useful at times).
Use memcpy instead when the size is calculated immediately beforehand.

Other uses of have been replaced by BLI_string_join_array that prevents
buffer overruns by taking the destination buffer length.
2023-06-24 18:49:29 +10:00
Hoshinova
3efc63b398 Fix #109253: Voronoi Smooth F1 breaks when Smoothness is 0
The Voronoi Smooth F1 mode breaks when the Smoothness is 0 for OSL. This is
due to a zero division in the shader.

To fix this, standard F1 is used when Smoothness is 0.

Pull Request: https://projects.blender.org/blender/blender/pulls/109255
2023-06-23 15:56:09 +02:00
Hans Goudey
eeecc24014 Cleanup: BLI: Deduplicate bounds merging
Also declare variables and arguments consta
2023-06-22 21:24:48 -04:00
Jacques Lucke
ec18e11c37 Cleanup: remove unnecessary "for_write" in method name
This suffix is only preferred when the non-const version does more
work than the const version of a method (e.g. because it may duplicate
data because of implicit sharing).
2023-06-21 09:26:41 +02:00
Campbell Barton
472c461816 Cleanup: spelling in comments 2023-06-21 11:28:58 +10:00
Iliya Katueshenock
7b93431c2d BLI: add assert for negative indices in MutableSpan
Pull Request: https://projects.blender.org/blender/blender/pulls/109143
2023-06-20 09:54:32 +02:00
Campbell Barton
2e087374d9 BLI_rect: support a zero limit for BLI_rctf_compare
Use <= comparison for BLI_rctf_compare so two rectangles which
are exactly the same return true with a limit of zero.

Matches compare_ff, compare_v3v3 etc.

In practice, this shouldn't result in user visible functional changes.
2023-06-20 14:14:16 +10:00
Campbell Barton
69d92bd3de Cleanup: remove strcpy usage
Remove strcpy use in:

- bone_autoside_name
- BLI_string_flip_side_name
- datatoc_icon utility.
- RNA define error messages.
- RNA UI registration.
- extern/xdnd.
2023-06-20 13:26:38 +10:00
Campbell Barton
2100ebca7a Cleanup: use the term "value" for RNA get/set functions
This is already used in most functions.
2023-06-20 13:23:30 +10:00