Commit Graph

6348 Commits

Author SHA1 Message Date
Hans Goudey 4d841e1b35 Mesh: Reimplement and unify topology maps
Combine the newer less efficient C++ implementations and the older
less convenient C functions. The maps now contain one large array of
indices, split into groups by a separate array of offset indices.
Though performance of creating the maps is relatively unchanged, the
new implementation uses 4 bytes less per source element than the C
maps, and 20 bytes less than the newer C++ functions (which also
had more overhead with larger N-gons). The usage syntax is simpler
than the C functions as well.

The reduced memory usage is helpful for when these maps are cached
in the near future. It will also allow sharing the offsets between
maps for different domains like vertex to corner and vertex to face.

A simple `GroupedSpan` class is introduced to make accessing the
topology maps much simpler. It combines offset indices and a separate
span, splitting it into chunks in an efficient way.

Pull Request: https://projects.blender.org/blender/blender/pulls/107861
2023-05-24 13:16:57 +02:00
Campbell Barton 129f6b7b84 Cleanup: spelling in comments, replace slang/informal terms 2023-05-24 20:27:13 +10:00
Campbell Barton b621c6ba07 Merge branch 'blender-v3.6-release' 2023-05-24 16:34:05 +10:00
Campbell Barton d56c38525c Fix flipped check for file-copy failure on OBJ export
The check for file-copy success was flipped,
document the return value.

Relocate move next to copy as they're related functions.
2023-05-24 16:31:39 +10:00
Campbell Barton 1f6b3c20c8 Fix potential buffer overflow for BLI_copy & BLI_path_move on WIN32
Avoid unsafe strcat use for file copy & move on WIN32.
Allocate the necessary space for the string.
2023-05-24 16:28:01 +10:00
Campbell Barton 44d9a5eb72 Merge branch 'blender-v3.6-release' 2023-05-24 13:36:06 +10:00
Campbell Barton 574b2db317 Fix buffer overflow in BLI_path_abs on WIN32
Loading paths without a drive-prefix could overflow by 3 bytes.
Replace unsafe strcat with BLI_strncpy.
2023-05-24 13:33:27 +10:00
Campbell Barton 13c815085b Cleanup: spelling in comments 2023-05-24 11:21:18 +10:00
Hans Goudey f78639ff9f Cleanup: Fix uninitialized variable warning in bit span test 2023-05-23 13:15:21 -04:00
Sergey Sharybin 793446cbdc BLI: Replace some macros with inlined functions for C++
Covers the macro ARRAY_SIZE() and STRNCPY.

The problem this change is aimed to solve it to provide cross-platform
compiler-independent safe way pf ensuring that the functions are used
correctly.

The type safety was only ensured for GCC and only for C. The C++
language and Clang compiler would not have detected issues of passing
bare pointer to neither of those macros.

Now the STRNCPY() will only accept a bounded array as the destination
argument, on any compiler.

The ARRAY_SIZE as well, but there are a bit more complications to it
in terms of transparency of the change.

In one place the ARRAY_SIZE was used on float3 type. This worked in the
old code because the type implements subscript operator, and the type
consists of 3 floats. One would argue this is somewhat hidden/implicit
behavior, which better be avoided. So an in-lined value of 3 is used now
there.

Another place is the ARRAY_SIZE used to define a bounded array of the
size which matches bounded array which is a member of a struct. While
the ARRAY_SIZE provides proper size in this case, the compiler does not
believe that the value is known at compile time and errors out with a
message that construction of variable-size arrays is not supported.

Solved by converting the field to std::array<> and adding dedicated
utility to get size of std::array at compile time. There might be a
better way of achieving the same result, or maybe the approach is
fine and just need to find a better place for such utility.

Surely, more macro from the BLI_string.h can be covered with the C++
inlined functions, but need to start somewhere.

There are also quite some changes to ensure the C linkage is not
enforced by code which includes the headers.

Pull Request: https://projects.blender.org/blender/blender/pulls/108041
2023-05-23 09:21:45 +02:00
Campbell Barton 472e6563b0 Cleanup: replace strncpy calls with BLI_strncpy
Prefer BLI_strncpy as it ensures the string is null terminated.
2023-05-23 15:09:58 +10:00
Jacques Lucke 64c33871bd Cleanup: add missing inline
This is necessary for correctness of the code to avoid duplicate symbols.
In practice, this wasn't necessary yet, because usually we pass lambdas
into these functions which cause every instantiation to have a different
signature.
2023-05-22 09:32:35 +02:00
Jacques Lucke 7725bacd6a BLI: support aligned parallel reduce
Alignment here means that the size of the range passed into callback
is a multiple of the alignment value (which has to be a power of two).
This can help with performance when loops in the callback are are
unrolled and/or vectorized. Otherwise, it can potentially reduce
performance by splitting work into more unequally sized chunks.
For example, chunk sizes might be 4 and 8 instead of 6 and 6 when
alignment is 4.
2023-05-22 09:30:51 +02:00
Jacques Lucke 3895261454 BLI: add size_in_bytes method to MutableSpan 2023-05-22 09:25:25 +02:00
Jacques Lucke 2b49d4eeea BLI: support transferring ownership of buffers between linear allocators
This can be useful when e.g. each thread has its own `LinearAllocator`,
but in the end they are combined into one.
2023-05-22 09:25:09 +02:00
Jacques Lucke 92512f224d BLI: support keeping track of how much memory a linear allocator uses
This is useful when debugging how much memory a particular function
allocates from this allocator. The change also reduces the size of
`LinearAllocator`.
2023-05-22 09:15:43 +02:00
Jacques Lucke 153e1c0492 BLI: fix overload resolution with FunctionRef parameters 2023-05-22 09:03:21 +02:00
Jacques Lucke b58cfde48a BLI: improve IndexRange
Defining `operator-` for the iterator allows it to be used in more generic
iterator code. The `index_range` method is the same that exists on many
other containers like `Vector`.
2023-05-21 15:13:57 +02:00
Jacques Lucke f6d824bca6 BLI: move tbb part of parallel_for to implementation file
Previously, `tbb::parallel_for` was instantiated every time `threading::parallel_for`
is used. However, when actual parallelism is used, the overhead of a function
call is negilible. Therefor it is possible to move that part out of the header
without causing noticable performance regressions.

This reduces the size of the Blender binary from 308.2 to 303.5 MB, which is
a reduction of about 1.5%.
2023-05-21 13:31:32 +02:00
Campbell Barton 8925ea1890 Merge branch 'blender-v3.6-release' 2023-05-20 21:18:02 +10:00
Campbell Barton bf36a61e62 Cleanup: spelling in comments & some corrections 2023-05-20 21:17:09 +10:00
Campbell Barton e620ae054f Merge branch 'blender-v3.6-release' 2023-05-19 19:26:01 +10:00
Campbell Barton 8a4ab1b3fe Fix assertion in BLI_path_normalize & add test 2023-05-19 19:25:08 +10:00
Campbell Barton 8ad2ee7f12 Cleanup: function style C++ casts, use printing & ELEM macros 2023-05-19 11:35:59 +10:00
Campbell Barton a5207ae24d Fix error returning the path length from BLI_path_normalize
Error in [0] caused the returned length to be wrong when skipping the
prefix. Also fix normalized path comparison failing on windows.

[0]: f45a985217
2023-05-17 17:47:35 +10:00
Campbell Barton e27cb91442 BLI_path: add native path canonicalize function
This function handles cleaning valid system paths that are functional
when passed to `open(..)` but may be relative to the current working
directory or have redundant slashers that can be normalized.
2023-05-17 13:42:51 +10:00
Campbell Barton 1d32a36540 Cleanup: add utility functions for checking WIN32 drive letters
Avoid character checks in-line.
2023-05-17 13:13:10 +10:00
Campbell Barton f45a985217 Cleanup: use BLI_path_slash_ensure instead of performing this in-line
- Add BLI_path_slash_ensure_ex which takes the string length.
- Normalize functions now return the string length,
  so ensuring trailing a trailing slash is a simple check.

This would have avoided the off-by-one error from
761eac2f5d.
2023-05-17 13:12:49 +10:00
Campbell Barton 761eac2f5d Fix buffer overflow in BLI_path_append 2023-05-17 13:11:17 +10:00
Campbell Barton 0ae286be03 Fix trailing slashes causing normalized path comparison to fail 2023-05-17 13:11:17 +10:00
Sybren A. Stüvel 88f536dc02 Add always-positive modulo function
Add modulo function `mod_f_positive(f, n)` that returns a positive result,
regardless of the sign of `f`.

For example, `mod_f_positive(-0.1, 1.0)` returns `0.9`, whereas the
standard `fmodf()` function would return `-0.1`.

This is useful for rewrapping values to a specific interval.
2023-05-16 11:41:17 +02:00
Campbell Barton 0de1791164 Cleanup: quiet C4189 warning for MSVC 2023-05-16 14:33:02 +10:00
Campbell Barton 802af4e04b BLI_file: split BLI_rename into two functions
Include the term "overwrite" so users of this function are aware
this function will delete the destination file (unlike LIBC rename).

- Add BLI_rename_overwrite (previously called BLI_rename).
- BLI_rename is now a wrapper for rename.

Use BLI_rename when renaming in the file selector.
2023-05-16 13:15:48 +10:00
Campbell Barton d2a3689b4a Docs: add doc-string for BLI_rename
Since this may delete the destination file,
it's important to note when that happens.

Also note why path comparison isn't used in code-comments.
2023-05-16 13:01:39 +10:00
Campbell Barton 8ab0196607 BLI_file: BLI_rename no longer checks for the destination path on WIN32
This change was made to prevent renaming files in the file selector from
deleting the file, see: #12255 & [0]. This check is no longer needed as
file selectors now checks the destination doesn't exist before renaming.

Generally, having low level file handling functions behave differently
between platforms is something to avoid with the potential of leading
to unexpected behavior.

Also unify WIN32/UNIX BLI_rename.

[0]: 41ad6f9d0a
2023-05-16 12:59:50 +10:00
Campbell Barton 8d5255d6a1 Fix BLI_rename returning success on failure for WIN32
When the `from` file didn't exist, BLI_rename returned success,
the in-line doc-string was incorrect - remove in favor of the header's
doc-string. This error existed since the initial revision.
Note that this was fixed [0] for other systems.

[0]: 622019a085
2023-05-16 11:24:49 +10:00
Campbell Barton 5d695b4f06 Fix memory leak in BLI_file_older for WIN32
Error from [0] which added UTF16 path support,
resolve using `BLI_stat` to avoid inline allocation.

[0]: f11a6d3a84
2023-05-16 11:24:14 +10:00
Campbell Barton 98dd91f418 WM: make all blend file paths absolute & normalized on read/write
Ensure the file path G.main->filepath is always absolute and normalized.

- It was possible to call WM_OT_open_mainfile with only a filename,
  if this resolved from the CWD, Blender's internal filepath
  would not be absolute as expected.

- It was possible to open files on UNIX with an additional forward slash
  causing the blend file path it's self to contain a '//' prefix,
  this is error prone as running BLI_path_abs(..) multiple times would
  add the blend file prefix each time.

- Remove requirement for "filepath" to be an absolute path when saving.
  Instead, expand the path - making it absolute, as this constraint
  wasn't applied open opening files, prefer making save/open behave
  consistently.

- Assert when BLI_path_abs/BLI_path_rel receive a basepath that has
  a "//" (relative) prefix itself.
2023-05-15 19:58:40 +10:00
Campbell Barton 7eb55a5fa9 BLI_path: add BLI_path_normalize_native for non-blend file paths
System paths with multiple leading slashes get normalized to one slash.
2023-05-15 19:58:39 +10:00
Campbell Barton a0c6dde5a2 Fix word selection failing when the selected word boundary wasn't space
Double-clicking between alpha-numeric & punctuation for e.g.
did nothing instead of selecting the word.

Instead of a special check for white-space, use the enum values as a
priority so alpha-numeric characters are priories above others
in a way that doesn't prevent groups of other character types
from being selected.
2023-05-15 11:04:25 +10:00
Campbell Barton 26362f283f Cleanup: pass an immutable position to BLI_str_cursor_step_bounds_*
Having some arguments be input/output and others output only was
confusing, a function that detects a range from a position
can simply calculate the range - modifying the input position isn't
needed.

Instead, note that word select puts the cursor at the end by convention.

Also use `r_` prefix for output only arguments.
2023-05-15 10:52:27 +10:00
Campbell Barton 5eee40a63e Cleanup: remove empty lines before function doc-string 2023-05-15 10:29:38 +10:00
Campbell Barton c6f3fc5d9b Cleanup: use doxygen groups for BLI_path_util.h 2023-05-15 10:24:13 +10:00
Campbell Barton d32fc1a3ea Cleanup: rename BLI_path_rel basename -> basepath
"basename" typically refers to the filename without any slashes
(as returned by `BLI_path_basename`), making the argument misleading.
2023-05-15 09:54:52 +10:00
Campbell Barton fcca4298ef Cleanup: improve doc-string & naming for internal frame-range extraction 2023-05-15 09:54:52 +10:00
Campbell Barton 1715f1c1f4 Fix potential buffer overflows from incorrect strcpy use
BLI_path_sequence_decode & BLI_path_filename_ensure ignored maximum
buffer size arguments.
2023-05-15 09:54:51 +10:00
Campbell Barton ab2dfc842a BLI_path: include FILE_MAX in BLI_path_{abs,rel} function signatures
These are now the only two BLI_path functions which assume paths are
FILE_MAX size which makes sense as they're using the `//` file prefix.
Something that's specific to file paths stored in DNA.

Use FILE_MAX in the function signature as a form of documentation.
2023-05-15 09:53:40 +10:00
Campbell Barton e225a53e54 BLI_path: use PATH_MAX instead of FILE_MAX for system paths
FILE_MAX is used mainly for blend-file paths, avoid using this
when paths may be system-paths.
2023-05-15 09:53:40 +10:00
Campbell Barton fd71bb7844 BLI_path: remove FILE_MAX size limit for BLI_path_cmp_normalized
Allocate larger paths if necessary, as this may be used for system
paths where the blend-file size limit isn't implied.
2023-05-15 09:53:40 +10:00
Campbell Barton 13a3dfd788 BLI_path: remove FILE_MAX limit on BLI_path_frame{_range} functions
- Use BLI_str_replace_range to avoid a temporary string copy.
- Also add a buffer size argument to BLI_path_frame_range.
2023-05-15 09:09:08 +10:00
Campbell Barton 1d371706cf BLI_string: add BLI_str_replace_range for replacing a range
Add a convenient way to replace a range of text in the middle of a
string that make shrink or grow the string that handles corner cases
and keeps the string null terminated.
2023-05-15 09:08:59 +10:00
Harley Acheson 1ad4f67d78 BLI: New functions specifically for word/sequence selection
Double-clicking to select words/sequences now using the same functions
specifically for this task, rather than boundary-seeking functions.

Pull Request: https://projects.blender.org/blender/blender/pulls/107927
2023-05-14 21:50:53 +02:00
Campbell Barton a534e05476 Cleanup: use dirpath & filename for directories and file names
Use `filename` instead of `names`, `dirpath` instead of `dir`.
2023-05-13 17:34:29 +10:00
Campbell Barton 557344b64c Cleanup: correct UTF8 code-commets, remove imbdds reference 2023-05-13 17:34:25 +10:00
Campbell Barton b1a426eac7 Cleanup: use string copy & printf macros 2023-05-13 17:34:21 +10:00
Bastien Montagne 3b647faec8 Fix (unreported) three wrong next/prev pointers order in ListBase link structs.
There was even one case in BLI ListBase tests!

Order was opposite of the one expected by the BLI ListBase code... Not
sure how, but this did not cause any issue apparently? But would expect
it to at least affect the order in which items in the list would be
iterated.
2023-05-12 19:02:39 +02:00
Bastien Montagne d87d2dd4ba BLI: Add basic validation tool for ListBase.
Mainly a debug tool, makes it very easy to detect broken listbase.
2023-05-12 19:02:39 +02:00
Sybren A. Stüvel 64f9a30cbd Test: actually use the right matrix for unit test
No functional changes, just a test working in debug mode too ;-)
2023-05-11 16:38:17 +02:00
Sybren A. Stüvel 39ba60e88d Math: add unit test for `mat3_normalized_to_quat_fast`
Add a unit test for the fix in 98334b8f7d

No functional changes.
2023-05-11 14:29:48 +02:00
Sybren A. Stüvel 98334b8f7d Fix #107745: Matrix conversion can produce non-unit quaternion
Due to cumulative floating point errors the quaternions produced by
`mat3_normalized_to_quat_fast()` could be non-unit length. This is now
detected, and quaternions are normalised when necessary.

This is a slight roll-back of 756538b4a1,
which removed the normalisation altogether, but did introduce this issue.
2023-05-11 12:28:04 +02:00
Jeroen Bakker 8aff713270 Vulkan: Convert VertexBuffer to Contain Supported Attributes
Vulkan doesn't have a conversion from uint32_t/int32_t to float. It does
have conversions from 16/8 bits. Main reason is that Vulkan expects that
there is no benefit when converting 32 bits from one type to the other
and should be solved by passing the right data type.

In Blender however this isn't the case as there are benefits on other
GPU backends (OpenGL for example).

This PR adds helper function to check if conversion is needed and
perform any conversions in place. It also implements the function to
upload vertex buffers to the GPU.

NOTE: Test cases have been added to validate this, but they are not
able to run on the Vulkan backend just yet, because they require the
graphics pipeline to be available.

Pull Request: https://projects.blender.org/blender/blender/pulls/107733
2023-05-11 12:23:23 +02:00
Campbell Barton 575c3f3b25 BLI_string: replace UTF8 skip table & macros with functions
Using a function that operates on ranges instead of the lookup table
makes BLI_strncpy_utf8 around 2.8x faster in my tests.
2023-05-11 17:35:34 +10:00
Campbell Barton cc9678b5fe Fix BLI_strncpy_utf8 over-read for code points containing a null byte
BLI_strncpy_utf8 didn't check for null bytes within bytes stepped
over by the variable length UTF8 encoding.

While a valid UTF8 string wont include these, it's possible Latin1
encoding or a truncated string includes such characters.

In this case, the entire string is copied as it's not the purpose of
this function to correct or strip invalid/truncated encoding,
only to prevent it from happening in the first place.
2023-05-11 11:44:38 +10:00
Ray Molenkamp 3958f4cb02 Cleanup: Fix build warning with MSVC
This cleans up the following warning

BLI_mempool.c(291):warning C4100: 'pool':unreferenced formal parameter

Warning introduced by c1d4b6f339
2023-05-10 12:59:11 -06:00
Hans Goudey 3f44b24cf2 BLI: Use inline instead of static for bounds functions
Avoid instantiating the templates separately in every translation unit.
This saves 20 KB in my Blender binary. Also remove a timer mistakenly
committed.
2023-05-09 12:54:55 -04:00
Brad Smith 322dab936f Build: fixes for OpenBSD
Pull Request: https://projects.blender.org/blender/blender/pulls/107666
2023-05-09 13:19:16 +02:00
Campbell Barton c183962c5d Cleanup: quiet unused variable warnings in release builds 2023-05-09 20:32:13 +10:00
Campbell Barton 7f7804e62d Cleanup: use doxygen groups for BLI_string_tests 2023-05-09 20:32:13 +10:00
Campbell Barton 788a57c6ef Cleanup: reserve the suffix 'len' for string length 2023-05-09 15:02:12 +10:00
Campbell Barton 3958ae7241 Cleanup: use STRNCPY, SNPRINTF macros 2023-05-09 14:08:19 +10:00
Campbell Barton 2d99b935f3 BLI_string: add macros to wrap BLI_vsnprintf 2023-05-09 13:16:09 +10:00
Campbell Barton cd49cb08e3 BLI_string: call BLI_string_debug_size from functions with a buffer size 2023-05-08 19:12:48 +10:00
Campbell Barton 55f7f082a8 Cleanup: avoid BLI_path_basename when the filename is known 2023-05-08 19:12:48 +10:00
Campbell Barton 8a852de147 BLI_fileops: change BLI_dir_create_recursive string size handling
Replace MAXPATHLEN with FILE_MAX, always allocate if the buffer isn't
big enough since creating a truncated directory isn't useful.

Having some code-paths only run in an ifdef complicated the code
and made it more difficult to follow.

Also assert the path doesn't contain ".." directories as they aren't
supported.
2023-05-08 12:49:44 +10:00
Campbell Barton de5aca9418 Refactor: unify UNIX/WIN32 BLI_dir_create_recursive & some improvements
- Don't duplicate/allocate the path on each recursion,
  instead make a single copy which is modified in-place.

- Move slash-stepping to a BLI_path utility function that accesses
  the end position of the parent directory, handles multiple slashes
  and '/./'.
2023-05-07 23:09:56 +10:00
Campbell Barton df54b627b3 Cleanup: use of the term 'len' & 'maxlen'
Only use the term len & maxlen when they represent the length & maximum
length of a string. Instead of the available bytes to use.

Also include the data they're referencing as a suffix, otherwise it's
not always clear what the length is in reference to.
2023-05-07 16:46:37 +10:00
Campbell Barton 5258604531 Cleanup: use of the term 'len' in BLI_string_utf8, BLI_string_utils
Reserve the term `len` for string length, some functions used this for
an string/array length, others a destination buffer size
(even within a single function declaration).

Also improve naming consistency across different functions.
2023-05-07 14:56:11 +10:00
Campbell Barton 464a40c1a5 Cleanup: use the name of the CMake WITH_STRSIZE_DEBUG for the define
Prefer matching names so there is no reason to confuse the identifiers.
2023-05-07 13:55:19 +10:00
Chris Blackbourn 0eba9e41bf Cleanup: Convert float to double during uv unwrap
`sinf(float_angle)` is sometimes producing different results on
x86_64 cpus and apple silicon cpus. Convert to double precision
to increase accuracy and consistency.

Partial fix for #104513. More to come.
2023-05-07 12:07:40 +12:00
Campbell Barton 70cd2a9741 RNA: use memcpy for copying strings when the length is known
There is no advantage in using BLI_strncpy/BLI_strncpy_utf8 when the
destination string has been allocated and won't be concatenated.

Also no need to calloc memory which is filled by strcpy afterwards.
2023-05-05 15:36:50 +10:00
Campbell Barton c80e9641ed Cleanup: replace UTF8 string copy macro with function 2023-05-05 14:36:09 +10:00
Campbell Barton dc4e48fca0 Cleanup: quiet clang-tidy char subscript warning 2023-05-05 14:21:13 +10:00
Campbell Barton 8cbb42c640 Cleanup: de-duplicate internal function for file/directory split
Also note that BLI_path_basename can be used in place of
BLI_path_split_file_part when a copy isn't needed.
2023-05-05 10:02:46 +10:00
Campbell Barton cf16eab370 Cleanup: avoid calling stat twice in BLI_dir_create_recursive 2023-05-04 13:12:35 +10:00
Campbell Barton aa7d7c8e4b Cleanup: naming in BLI_path, reserve `len` for string length
- Names ending with len sometimes referred to the buffer size.
  The same names were used for both buffer size and string length
  depending on the function in some cases.

- Rename str/string to path for generic path functions.

- Rename BLI_path_rel arguments (file, relfile) to (path, basename)
  as it wasn't so clear which is being made relative, `file` can be a
  directory so rename to `path` (matches naming for BLI_path_abs).
2023-05-04 13:09:28 +10:00
Campbell Barton 069db83152 BLI_string: move DEBUG_STRSIZE check into a macro, check sizes after nil
- Avoid inline ifdef checks for DEBUG_STRSIZE
- Add BLI_string_debug_size_after_nil to ensure strings to manipulate
  have the expected buffer size after the nil terminator.
- Add checks to more string manipulation functions.

Further changes are required for this to be enabled during regular
development as the RNA currently allocates the strings length but
passes in the buffer size as a limit which conflicts with DEBUG_STRSIZE.
2023-05-04 13:09:28 +10:00
Campbell Barton 40ff2cfdc5 BLI_path: correct buffer size argument
Pass the size of the string passed in, although in practice
this didn't cause any problems.
2023-05-04 13:09:28 +10:00
Hans Goudey 1f76863f80 BLI: Remove clamping from generic span slicing
Similar to a5e7657cee
2023-05-03 12:10:54 -04:00
Jacques Lucke 0de54b84c6 Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.

A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.

The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.

The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
  to initialize the simulation state. In later frames these sockets are not
  evaluated anymore. The `Delta Time` at the first frame is zero, but the
  simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
  state of the previous frame. Nodes in the simulation zone can edit that
  data in arbitrary ways, also taking into account the `Delta Time`. The new
  simulation state has to be passed to the `Simulation Output` node where it
  is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
  zone are not evaluated, because the `Simulation Output` node can return
  the previously cached data directly.

It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.

Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.

There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.

All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.

The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.

Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.

Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:59 +02:00
Thomas Dinges 8775cf804e Fix compilation on Windows after f30434ac99. 2023-05-03 11:55:24 +02:00
Campbell Barton bcedbdcf6f Cleanup: improve code-comments, naming, use defines, correct spelling 2023-05-03 17:34:27 +10:00
Campbell Barton 6b9a500a3a Cleanup: disambiguate terms "name", "file" & "str" / "string"
- Rename name/filename/path to filepath when it's used for full paths.
- Rename name/path to dirpath when it refers to a directory.
- Rename file to filepath or path (when it may be a file or dir).
- Rename ImBuf::name & anim::name to filepath.
2023-05-03 15:26:14 +10:00
Campbell Barton 1f96fa1129 Cleanup: rename BLI_make_existing_file for clarity
Rename BLI_make_existing_file to BLI_file_ensure_parent_dir_exists.
The previous name read as if it would make (touch) the file,
where as it ensures the directory component of the path exists.

Move from BLI_path to BLI_fileops as path utilities should only
manipulate paths and not deal with file IO creation
(this has more in common with BLI_file_touch for e.g.).
2023-05-03 11:49:47 +10:00
Campbell Barton bb341eaf12 BLI_path: use module prefix for BLI_filename_make_safe
Rename BLI_filename_make_safe -> BLI_path_make_safe_filename.
2023-05-03 11:48:52 +10:00
Campbell Barton 01aead42fc Cleanup: re-order split prefix/suffix return arguments last 2023-05-03 11:25:30 +10:00
Campbell Barton 947465c511 Cleanup: rename BLI_split_name_num, order return arguments last 2023-05-03 11:25:30 +10:00
Campbell Barton f30434ac99 BLI_string_utils: BLI_uniquename no longer accepts NULL defname
A NULL defname would early exit (doing nothing) this isn't good behavior
as this function should always make the name unique and a NULL defname
is likely an error in the code which would allow duplicate names.
This is also inconsistent with BLI_uniquename_cb which always
wrote the defname into the name if it was empty.

Mark this argument as never-NULL.
2023-05-03 11:25:30 +10:00
Campbell Barton 4115fcbc38 Cleanup: update, add function attributes for BLI_string & BLI_path
Explicitly list ATTR_NONNULL indices in most cases so it's explicit
that arguments aren't NULL (and adding new arguments that can be NULL
isn't such a hassle).
2023-05-03 11:25:30 +10:00
Jacques Lucke 20b19f2b12 Fix: calculating duplicates in kdtree does not work with selection
This fixes a crash where merging vertices by distance leads to a crash since
0652945dbd. The change did not cause
the bug though, it just made the underlying issue visible.

The issue was that `kdtree_order` assumed that the `KDTreeNode.index` didn't
have gaps, i.e. every index in a certain range is used. However, that is not the
case when only a subset of the vertices of a mesh are added to the kdtree.

Pull Request: https://projects.blender.org/blender/blender/pulls/107535
2023-05-02 14:25:55 +02:00
Campbell Barton 27e4ab80fb BLI_path: disallow passing NULL arguments to BLI_path_split_dir_file
Instead BLI_path_split_dir_part & BLI_path_split_file_part can be used.
2023-05-02 21:32:51 +10:00
Campbell Barton 1ab72e8459 Cleanup: use BLI_path_* prefix for path splitting functions
Also order string size after each string instead of grouping strings and
their sizes afterwards.
2023-05-02 21:08:13 +10:00
Campbell Barton f154d37335 BLI_path: add a size argument to BLI_path_frame
Resolves potential buffer overflow in
USDVolumeWriter::construct_vdb_file_path which passed in a smaller
fixed size buffer than FILE_MAX.
2023-05-02 17:19:48 +10:00
Campbell Barton 0428043967 BLI_string: add BLI_strncat, replace use of strcat that could overflow 2023-05-02 17:19:48 +10:00
Campbell Barton 6859bb6e67 Cleanup: format (with BraceWrapping::AfterControlStatement "MultiLine") 2023-05-02 09:37:49 +10:00
Campbell Barton 1c026befca Cleanup: spelling in comments, remove annotations that aren't validated 2023-04-30 15:08:26 +10:00
Jacques Lucke 7d38cef6d1 Geometry Nodes: use new BitGroupVector to find attribute propagation sets
A `BitGroupVector` is a compact data structure that allows storing multiple
bits per element, for example 5 bits per vertex. The implementation is
mostly just a wrapper around `BitVector`. There is some additional logic
to make sure that the bit span of every element is bounded (according
to the `is_bounded_span` function). This makes it more efficient to operate
on groups as a whole (e.g. `or` one group into another). In some sense,
this data structure can also be interpreted as a 2D bit array. Functions
like `append` can be added when they become necessary.

The new data structure is used to replace some `MultiValueMap` in
geometry nodes. This simplifies the code.
2023-04-28 16:54:43 +02:00
Jacques Lucke fee9a3796c Cleanup: Add not equal operator to compute constext hash 2023-04-28 10:24:32 -04:00
Jacques Lucke ac1827edda BLI: Add utility method to check if CPPType matches multiple types 2023-04-28 10:24:32 -04:00
Hans Goudey 67700ced54 BLI: Add "take front" and "take back" methods to bit spans
This is consistent with `Span`, and also allows returning a bounded
bit span when taking the front of an existing bounded span, which
can simplify using optimized bit processing.

Pull Request: https://projects.blender.org/blender/blender/pulls/107441
2023-04-28 16:14:03 +02:00
Hans Goudey b87ccedd75 BLI: Add bit span operations and bounded bit spans
Most of this patch is by Jacques Lucke, from the simulation branch.

This commit adds generic expression evaluation for bit spans, helping
to generalize the optimizations that avoid processing a single bit
at a time. Operations like "for each 1 index", "or", and "and" are
already implemented in this pull request. Bits in full integers are
processed 64 at a time, then remaining bits are processed all at once.
The operations allow implementing a `copy_from` method for bit spans.

Currently this optimized evaluation is only implemented for simpler
bounded bit spans. Bounded bit spans have constraints on their bit
ranges that make them more efficient to process. Large spans must start
at the beginning of the first int, and small spans must start and end
within the first int.

Knowing these constraints at compile time reduces the number of edge
cases in the operations, but mainly allows skipping alignment between
multiple spans with different offsets.

Pull Request: https://projects.blender.org/blender/blender/pulls/107408
2023-04-28 15:43:34 +02:00
Campbell Barton ff0cf45bc2 Fix potential buffer overflows from invalid string size arguments
- FILENAME_MAX was used when the output was later limited by FILE_MAX.
- Some were passing in incorrect/dummy sizes in a couple of places.
2023-04-28 21:49:05 +10:00
Campbell Barton 6701d24084 BLI_path: add string size arguments to sequence encode/decode functions 2023-04-28 21:33:38 +10:00
Jacques Lucke bfcc2b1c4c BLI: add utility methods for serialization
This simplifies the code that works with the `BLI_serialize.hh` header.
The various `lookup` methods do a linear search. If there are only a
few elements that can even be faster than building the map first.
In the future it might be nice to transparently build and cache the
map internally if necessary.
2023-04-28 13:30:26 +02:00
Jacques Lucke b4d914b676 BLI: support weak users and version in implicit sharing info
The main goal of these changes is to support checking if some data has
been changed over time. This is used by the WIP simulation nodes during
baking to detect which attributes have to be stored in every frame because
they have changed.

By using a combination of a weak user count and a version counter, it is
possible to detect that an attribute (or any data controlled by implicit
sharing) has not been changed with O(1) memory and time. It's still
possible that the data has been changed multiple times and is the same
in the end and beginning of course. That wouldn't be detected using this
mechanism.

The `ImplicitSharingInfo` struct has a new weak user count. A weak
reference is one that does not keep the referenced data alive, but makes sure
that the `ImplicitSharingInfo` itself is not deleted. If some piece of
data has one strong and multiple weak users, it is still mutable. If the
strong user count goes down to zero, the referenced data is freed.
Remaining weak users can check for this condition using `is_expired`.

This is a bit similar to `std::weak_ptr` but there is an important difference:
a weak user can not become a strong user while one can create a `shared_ptr`
from a `weak_ptr`. This restriction is necessary, because some code might
be changing the referenced data assuming that it is the only owner. If
another thread suddenly adds a new owner, the data would be shared again
and the first thread would not have been allowed to modify the data in
the first place.

There is also a new integer version counter in `ImplicitSharingInfo`.
It is incremented whenever some code wants to modify the referenced data.
Obviously, this can only be done when the data is not shared because then
it would be immutable. By comparing an old and new version number of the
same sharing info, one can check if the data has been modified. One has
to keep a weak reference to the sharing info together with the old version
number to ensure that the new sharing info is still the same as the old one.
Without this, it can happen that the sharing info was freed and a new
one was allocated at the same pointer address. Using a strong reference
for this purpose does not work, because then the data would never be
modified because it's shared.
2023-04-28 12:05:00 +02:00
Campbell Barton 0c27c6f876 Cleanup: spelling in comments
Also remove redundant comment.
2023-04-28 12:23:29 +10:00
Campbell Barton 3ad82ec5a4 Refactor: path normalize now collapses multiple '..' directories at once
- Avoid a separate memmove call for each `..`.
- Avoid ambiguous path stepping, where separator literals
  needed to be checked to avoid fence post errors.
- Correct & update the doc-string.
2023-04-28 12:23:29 +10:00
Hans Goudey a6baf7beae BLI: Allow different integer types when filling span indices 2023-04-27 08:50:41 -04:00
Hans Goudey 4daa7ae649 BLI: Add methods to generic spans to retrieve size in bytes 2023-04-26 23:50:57 -04:00
Campbell Barton 0a3a6cd154 Cleanup: use ptrdiff_t in assertion to prevent overflow 2023-04-26 19:02:24 +10:00
Jacques Lucke bf58af2d65 Cleanup: fix build errors/warnings 2023-04-26 10:55:45 +02:00
Joseph Eagar c1d4b6f339 Core: Add ASAN support to BLI_mempool
This patch adds address sanitizer support to memory pools.

when ASAN is enabled the following happens:
* 32 byte red zones are inserted between pool elements.
* The BLI_mempool struct itself is marked as a red zone.
* Access to the pool goes through a thread mutex (except when compiling makesdna).

This is very useful for finding bugs in code that uses BMesh.

Pull Request: #104668
2023-04-26 01:32:41 -07:00
Jacques Lucke a57584e40d BLI: extract MapItem type to simplify iterating over map items 2023-04-25 12:15:02 +02:00
Campbell Barton 10fc2d6d96 Cleanup: remove basepath argument from BLI_path_normalize{_dir}
Keep these operations separate to simplify path handling logic & docs.
Many callers passed NULL and there were times paths were passed in which
didn't make any sense (where the paths had already been made absolute).
2023-04-24 12:23:04 +10:00
Campbell Barton 6ab225074d Cleanup: minor changes to BLI_path_normalize
- Don't attempt to skip the WIN32 drive component on relative paths
  it's possible this would have unexpected behavior but paths like
  are already unlikely to work as expected, e.g. "//C:\".
- Remove early returns for empty paths as there is no need for special
  handling.
- Add path normalize NOP tests
2023-04-24 11:58:47 +10:00
Hans Goudey 993d24c174 Cleanup: Miscellaneous improvements to subdivision geometry nodes
- Implement mesh creation in GeometrySet agnostic way, with less context
- Remove useless comments
- Use a field to clamp crease values instead of clamping when copying
- Small variable name tweaks
- Use `BKE_subdiv_new_from_mesh` instead of "update"
- Remove crease layers before writing, avoiding potential copy
2023-04-23 15:27:20 -04:00
Campbell Barton 2ed6f738da BLI_path: support normalizing relative paths
Follow Python's os.path.normpath's handing on relative paths in more
situations.

- Leading './' is always stripped.
- Relative paths such as `//./a` & `///a` normalize to `//a`.
- Support for trailing `/..` on the end of paths.
- Avoid empty paths for relative paths that would otherwise
  resolve to an empty string, e.g:  `a/b/c/../../..` resolves to `.`.
2023-04-23 22:22:08 +10:00
Campbell Barton 1e5f2698af Cleanup: minor improvements to BLI_path_normalize
- Calculate spans of redundant `//` & `/./` before calling `memmove`.
- Loop backwards when removing path elements for greater efficiency.
- When removing `/../` components, avoid continuously searching from
  the start of the path and instead search from the last found '/../'.
2023-04-23 14:35:09 +10:00
Campbell Barton 651f9404a1 Cleanup: rename path_util 'Clean' tests to 'Normalize'
The function was renamed from `clean` but the tests weren't.
2023-04-23 14:30:52 +10:00
Campbell Barton ac251cbe25 BLI_path: de-duplicate WIN32 logic for BLI_path_normalize
The only WIN32 specific behavior the drive or UNC prefix is skipped
(except for it's slash), allowing WIN32 & Unix paths to share the same
code-path.

Note that this changes behavior for WIN32 when there are too many parent
directories, where ".." that move before the root directory are removed
instead of being left in the path. e.g:
`C:\a\..\..\b` resolved to `C:\..\b` whereas now the result is `C:\b`.
This matches Python's `os.path.normpath`.
2023-04-23 14:30:51 +10:00
Jacques Lucke 8523e361e8 BLI: use decay_t to determine type to hash
Goal is to fix a compile error on macos.
2023-04-22 15:01:56 +02:00
illua1 15f9e42c4f Geometry Nodes: new Index of Nearest node
The node outputs the index of the closest element to itself. See #102387
for the original design.

This is different from the Sample Nearest node in two important ways:
* It does not have a geometry input, instead the geometry is taken from the
  field evaluation context.
* The node can exclude the "current" element from the search.
* The group id input can be used to build subsets of elements that only
  consider each other as neighbors and ignore elements with other ids.

Pull Request: https://projects.blender.org/blender/blender/pulls/104619
2023-04-22 13:11:51 +02:00
Campbell Barton 5e76622f47 Cleanup: remove redundant code 2023-04-21 23:27:21 +10:00
Campbell Barton 19dbe049db Fix #106469: unstable tessellation with quad-flipping detection
The result of detecting if a quad should flip the default 0-2 split
when tessellated only used a pre-calculated normal when available,
since the method of detecting the flip was different, the check for a
concave face could change depending on the existence of polygon-normals.

In practice this meant cycles render preview could use a different
tessellation than the GPU display.

While [0] exposed the bug, it's an inherent problem with having 2
methods of detecting concave quads.

Remove is_quad_flip_v3_first_third_fast_with_normal(..) and always
use is_quad_flip_v3_first_third_fast(..), because having to calculate
the normal inline has significant overhead.

Note that "bow-tie" quads may now render with a subdivision in a
different direction although they must be very distorted with both
triangles along the 0-2 split pointing away from each other.

Thanks to @HooglyBoogly for investigating the issue.

[0]: 16fbadde36.
2023-04-21 15:02:47 +10:00
Campbell Barton 5721b34e53 Cleanup: add win32 suffix to BLI_path_is_abs
Naming made it seem this might be the opposite of BLI_path_is_rel,
when it checks for WIN32 specific path prefixes.
2023-04-21 09:46:06 +10:00
Campbell Barton 417b62522d Cleanup: code-comments in path_util.c
- Remove duplicate doc-string.
- Use full sentences.
- Use back-ticks for path literals
  (to avoid confusion with doxy-slash commands).
2023-04-21 09:34:30 +10:00
Campbell Barton fc749d9d25 Cleanup: replace binary '&' with '&&' check
As the intention is to check both statements are true, avoid bitwise
operations on boolean results.
2023-04-21 09:13:09 +10:00
Jacques Lucke 8e69b41bdf Cleanup: use const for implicit sharing info
Generally, one does not know if the sharing info is currently shared
and should therefore be const. Better keep it const almost all the
time and only remove the constness when absolutely necessary
and the code has checked that it is valid.
2023-04-20 23:32:33 +02:00
Campbell Barton 770b193253 Cleanup: use function style casts & nullptr, spelling in comments 2023-04-20 18:28:50 +10:00
Campbell Barton 639ec2e5a9 BLI_path: add BLI_path_extension_or_end
Some callers that access the extension operated on the end of the path
even when there was no extension. Using this avoids having to assign
the end of the string using a separate check.
2023-04-20 12:32:25 +10:00
Campbell Barton b778e09492 Cleanup: use memmove instead of a string copy for BLI_path_suffix 2023-04-20 11:58:30 +10:00
Campbell Barton 7884de02f3 Tests: add BLI_path_extension replace/ensure tests for overflow handling 2023-04-20 11:58:29 +10:00
Campbell Barton 95296dc3aa Cleanup: remove "Path" prefix from path_utils tests 2023-04-20 11:58:27 +10:00
Campbell Barton 9be0304b67 Cleanup: order expected value last in path_util tests 2023-04-20 11:58:25 +10:00
Campbell Barton b6e527febb Tests: add more path extension tests 2023-04-20 11:58:23 +10:00
Campbell Barton 5294758830 Fix buffer overflow in BLI_path_frame_strip with long extensions
The file extension was copied into a buffer without checking it's size.
While large extensions aren't typical, some callers used small fixed
size buffers so an unusually named file could crash.
2023-04-20 11:47:22 +10:00
Campbell Barton 80edd10168 Fix regression in BLI_path_suffix for long extensions
Changes from [0] passed in a pointer size to BLI_strncpy.

[0]: f8e23e495b
2023-04-20 11:18:26 +10:00
Harley Acheson acb34c718e Fix #107120: Small fixes to OS File Operations
Small fixes to recent file operations changes. FileOperations enum
starting with zero results in bad behavior with EnumPropertyItem. Typo
fix.

Pull Request: https://projects.blender.org/blender/blender/pulls/107138
2023-04-19 19:43:15 +02:00
Campbell Barton 86611a5fcc Tests: add tests for BLI_path_extension ensure & replace 2023-04-19 21:15:43 +10:00
Campbell Barton c0f7801660 Fix regression in BLI_path_extension_ensure
Error in [0] removed trailing '.' stripping.

[0]: f8e23e495b
2023-04-19 20:33:55 +10:00
Campbell Barton 19ac02767c Fix regression in recent BLI_path extension logic
Error in [0] meant BLI_path_extension_replace &
BLI_path_extension_ensure did nothing when the input path had no
extension.

[0]: f8e23e495b
2023-04-19 18:38:56 +10:00
Sergey Sharybin 3c34b13cf8 Fix set but unused variable in mesh intersect
A bit tricky, since there is also variable shadowing involved.
2023-04-19 10:02:09 +02:00
Campbell Barton 26a194abbd BLI_path: add BLI_path_extension_strip as an alternative to replace
While replacing the extension with an empty string works,
it required a redundant string-size argument which took a dummy
value in some cases. Avoid having to pass in a redundant string size by
adding a function that strips the extension.
2023-04-19 12:59:43 +10:00
Campbell Barton f8e23e495b BLI_path: improve behavior of BLI_path_extension
Finding the extension included hidden files (starting with a '.'),
now finding the extension matches Python's `os.path.splitext` behavior
which has the advantate a hidden file is not considered one long
extension - with an empty name part.

Also update code to use BLI_path_extension in cases which previously
in-lined this logic.

BLI_path_frame_get path argument is now const,
it was being manipulated unnecessarily.
2023-04-19 11:33:26 +10:00
Campbell Barton 7f241fc773 Tests: add test for BLI_path_suffix & BLI_path_sequence_decode 2023-04-19 11:33:26 +10:00
Campbell Barton b132118f89 Cleanup: balance doxygen grouping, minor grouping adjustment 2023-04-19 09:02:21 +10:00
Campbell Barton 88f5dd3c72 Cleanup: format 2023-04-19 08:02:42 +10:00
Campbell Barton eb2867de90 Cleanup: spelling in comments 2023-04-19 08:02:41 +10:00
Harley Acheson 1469613d65 Fix Build Warnings
A differing const argument and an unused var caused by conditionals.

Introduced in 694f792ee1
2023-04-18 13:59:07 -07:00
Harley Acheson 72aeee96ac Fix Build Warning in fileops.c
Marking unused function arguments caused by conditionals.

Introduced in 694f792ee1
2023-04-18 12:53:45 -07:00
Harley Acheson 694f792ee1 UI: OS File Operations Within File Browser
Adds a submenu to the File Browser selected item context menu that
allows opening the item or viewing the location in an OS browsing
window. On Win32 also allows other actions like editing, searching,
opening command prompt, etc.

Pull Request: https://projects.blender.org/blender/blender/pulls/104531
2023-04-18 20:39:30 +02:00
Falk David 66158498de BLI: Return number of values removed from remove_if
Make the `remove_if` function for `Vector`, `VectorSet`, `Set`, and `Map` return the number of elements it removed.

Pull Request: https://projects.blender.org/blender/blender/pulls/107069
2023-04-18 13:28:14 +02:00
Hans Goudey 2a4323c2f5 Mesh: Move edges to a generic attribute
Implements #95966, as the final step of #95965.

This commit changes the storage of mesh edge vertex indices from the
`MEdge` type to the generic `int2` attribute type. This follows the
general design for geometry and the attribute system, where the data
storage type and the usage semantics are separated.

The main benefit of the change is reduced memory usage-- the
requirements of storing mesh edges is reduced by 1/3. For example,
this saves 8MB on a 1 million vertex grid. This also gives performance
benefits to any memory-bound mesh processing algorithm that uses edges.

Another benefit is that all of the edge's vertex indices are
contiguous. In a few cases, it's helpful to process all of them as
`Span<int>` rather than `Span<int2>`. Similarly, the type is more
likely to match a generic format used by a library, or code that
shouldn't know about specific Blender `Mesh` types.

Various Notes:
- The `.edge_verts` name is used to reflect a mapping between domains,
  similar to `.corner_verts`, etc. The period means that it the data
  shouldn't change arbitrarily by the user or procedural operations.
- `edge[0]` is now used instead of `edge.v1`
- Signed integers are used instead of unsigned to reduce the mixing
  of signed-ness, which can be error prone.
- All of the previously used core mesh data types (`MVert`, `MEdge`,
  `MLoop`, `MPoly` are now deprecated. Only generic types are used).
- The `vec2i` DNA type is used in the few C files where necessary.

Pull Request: https://projects.blender.org/blender/blender/pulls/106638
2023-04-17 13:47:41 +02:00
Hans Goudey dcb3b1c1f9 Geometry: Use implicit sharing for curve and mesh offsets
Similar to 7eee378ecc, this change decreases memory usage and
improves performance when copying curves and meshes without changing
their topology. The same change used for custom data layers is applied
to face and curve offset indices, which aren't stored as a custom data
layer.

The implicit sharing info for the offsets is stored in the mesh and
curve runtime structs, since it doesn't need to be written to files
directly. When changing the offsets pointer directly, the sharing info
must be updated accordingly. To make that easier, a few utility
functions take care of common operations like making an array mutable,
resizing an array, and creating sharing info for allocated data.

This commit also clarifies the intention to not allocate the offsets
at all when there are no curves/faces. That slightly complicates some
of the logic, but there's no reason for the single `0` integer to be
allocated.

Pull Request: https://projects.blender.org/blender/blender/pulls/106907
2023-04-14 17:58:13 +02:00
Hans Goudey 988f23cec3 Attributes: Add 2D integer vector attribute type
This type will be used to store mesh edges in #106638, but it could
be used for anything else too. This commit adds support for:
- The new type in the Python API
- Editing the type in the edit mode "Attribute Set" operator
- Rendering the type in EEVEE and Cycles for all geometry types
- Geometry nodes attribute interpolation and mixing
- Viewing the type in the spreadsheet and using row filters

The attribute uses the `blender::int2` type in most code, and
the `vec2i` DNA type in C code when necessary. The enum names
are based on `INT32_2D` for consistency with `INT8` and `INT32`.

Pull Request: https://projects.blender.org/blender/blender/pulls/106677
2023-04-14 16:08:05 +02:00
Bastien Montagne c63b2e5187 BLI timeit utils: Add accessor to time value for TIMEBLOCK macros. 2023-04-14 13:29:19 +02:00
Hans Goudey a7bee90c1d Cleanup: Add access method for point cloud positions
The position attribute has special meaning for point clouds, and
meshes and curves have access methods for the attribute as well.
This saves boilerplate and gives more consistency between types.
2023-04-13 12:49:16 -04:00
Jacques Lucke 7eee378ecc Custom Data: support implicit sharing for custom data layers
This integrates the new implicit-sharing system (from fbcddfcd68)
with `CustomData`. Now the potentially long arrays referenced by custom
data layers can be shared between different systems but most importantly
between different geometries. This makes e.g. copying a mesh much cheaper
because none of the attributes has to be copied. Only when an attribute
is modified does it have to be copied.

Also see the original design task: #95845.

This reduces memory and improves performance by avoiding unnecessary
data copies. For example, the used memory after loading a highly
subdivided mesh is reduced from 2.4GB to 1.79GB. This is about 25%
less which is the expected amount because in `main` there are 4 copies
of the data:
1. The original data which is allocated when the file is loaded.
2. The copy for the depsgraph allocated during depsgraph evaluation.
3. The copy for the undo system allocated when the first undo step is
  created right after loading the file.
4. GPU buffers allocated for drawing.

This patch only gets rid of copy number 2 for the depsgraph. In theory
the other copies can be removed as part of follow up PRs as well though.

-----

The patch has three main components:
* Slightly modified `CustomData` API to make it work better with implicit
  sharing:
  * `CD_REFERENCE` and `CD_DUPLICATE` have been removed because they are
    meaningless when implicit-sharing is used.
  * `CD_ASSIGN` has been removed as well because it's not an allocation
    type anyway. The functionality of using existing arrays as custom
    data layers has not been removed though.
  * This can still be done with `CustomData_add_layer_with_data` which
    also has a new argument that allows passing in information about
    whether the array is shared.
  * `CD_FLAG_NOFREE` has been removed because it's no longer necessary. It
    only existed because of `CD_REFERENCE`.
  * `CustomData_copy` and `CustomData_merge` have been split up into a
    functions that do copy the actual attribute values and those that do
    not. The latter functions now have the `_layout` suffix
    (e.g. `CustomData_copy_layout`).
* Changes in `customdata.cc` to make it actually use implicit-sharing.
* Changes in various other files to adapt to the changes in `BKE_customdata.h`.

Pull Request: https://projects.blender.org/blender/blender/pulls/106228
2023-04-13 14:57:57 +02:00
zanqdo 2b565c6bd0 UI: Add slash character support to fuzzy search initials mode
Nodes with names separated by a slash / can
not be searched by their initials.

This commit adds the slash character to
the list of separators for this type of
fuzzy search.

Pull Request: https://projects.blender.org/blender/blender/pulls/106838
2023-04-12 23:53:36 +02:00
Campbell Barton 6fa80d1e1d Cleanup: add doc-strings to upper/lowecase functions
Move detailed note into the implementation.
2023-04-12 11:24:12 +10:00
Harley Acheson e369bf4a6d UI: Text Object International Case Change
Allow Text Object operator FONT_OT_case_set to correctly transform the case
of strings written in almost all scripts that differentiate letter case.

Pull Request: https://projects.blender.org/blender/blender/pulls/106581
2023-04-07 23:40:42 +02:00
Hans Goudey 4b2ea18ec9 Cleanup: Deduplicate OffsetIndices utility for meshes and curves
The "reverse map" of corners to faces and points to curves is the same
for meshes and curves now. Move it to the offset indices header to
reflect this.

This unification can go further in the future, but I'd rather wait
until the design is clearer for now.

Pull Request: https://projects.blender.org/blender/blender/pulls/106570
2023-04-04 22:12:17 +02:00
Hans Goudey 7966cd16d6 Mesh: Replace MPoly struct with offset indices
Implements #95967.

Currently the `MPoly` struct is 12 bytes, and stores the index of a
face's first corner and the number of corners/verts/edges. Polygons
and corners are always created in order by Blender, meaning each
face's corners will be after the previous face's corners. We can take
advantage of this fact and eliminate the redundancy in mesh face
storage by only storing a single integer corner offset for each face.
The size of the face is then encoded by the offset of the next face.
The size of a single integer is 4 bytes, so this reduces memory
usage by 3 times.

The same method is used for `CurvesGeometry`, so Blender already has
an abstraction to simplify using these offsets called `OffsetIndices`.
This class is used to easily retrieve a range of corner indices for
each face. This also gives the opportunity for sharing some logic with
curves.

Another benefit of the change is that the offsets and sizes stored in
`MPoly` can no longer disagree with each other. Storing faces in the
order of their corners can simplify some code too.

Face/polygon variables now use the `IndexRange` type, which comes with
quite a few utilities that can simplify code.

Some:
- The offset integer array has to be one longer than the face count to
  avoid a branch for every face, which means the data is no longer part
  of the mesh's `CustomData`.
- We lose the ability to "reference" an original mesh's offset array
  until more reusable CoW from #104478 is committed. That will be added
  in a separate commit.
- Since they aren't part of `CustomData`, poly offsets often have to be
  copied manually.
- To simplify using `OffsetIndices` in many places, some functions and
  structs in headers were moved to only compile in C++.
- All meshes created by Blender use the same order for faces and face
  corners, but just in case, meshes with mismatched order are fixed by
  versioning code.
- `MeshPolygon.totloop` is no longer editable in RNA. This API break is
  necessary here unfortunately. It should be worth it in 3.6, since
  that's the best way to allow loading meshes from 4.0, which is
  important for an LTS version.

Pull Request: https://projects.blender.org/blender/blender/pulls/105938
2023-04-04 20:39:28 +02:00
Clément Foucault 897a735151 BLI: Rotation: Add CartesianBasis `transform_point` and `invert` 2023-04-01 13:24:35 +02:00
Chris Blackbourn 531f99ffbd UV: simplify uv packing api and simplify uv packing
Fix #invert_m2_m2 with repeated arguments.

Change UV Packing to use {pivot, half_diagonal} representation.
2023-04-01 11:35:07 +13:00
Sergey Sharybin a12a8a71bb Remove "All Rights Reserved" from Blender Foundation copyright code
The goal is to solve confusion of the "All rights reserved" for licensing
code under an open-source license.

The phrase "All rights reserved" comes from a historical convention that
required this phrase for the copyright protection to apply. This convention
is no longer relevant.

However, even though the phrase has no meaning in establishing the copyright
it has not lost meaning in terms of licensing.

This change makes it so code under the Blender Foundation copyright does
not use "all rights reserved". This is also how the GPL license itself
states how to apply it to the source code:

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software ...

This change does not change copyright notice in cases when the copyright
is dual (BF and an author), or just an author of the code. It also does
mot change copyright which is inherited from NaN Holding BV as it needs
some further investigation about what is the proper way to handle it.
2023-03-30 10:51:59 +02:00
Chris Blackbourn 9ea6771d10 Cleanup: simplify sorting during uv packing
Prevent double-sorting during uv packing with bounding-box packing.

Slight speed improvement, slight packing efficiency improvement.
2023-03-30 12:23:49 +13:00
Sergey Sharybin d32d787f5f Clang-Format: Allow empty functions to be single-line
For example

```
OIIOOutputDriver::~OIIOOutputDriver()
{
}
```

becomes

```
OIIOOutputDriver::~OIIOOutputDriver() {}
```

Saves quite some vertical space, which is especially handy for
constructors.

Pull Request: https://projects.blender.org/blender/blender/pulls/105594
2023-03-29 16:50:54 +02:00
Campbell Barton 1ddbe7cadd Cleanup: move doc-strings into headers, remove duplicates
In some cases move implementation details into the function body.
2023-03-29 14:37:34 +11:00
Campbell Barton ce659dbc4e Cleanup: use doxygen sections 2023-03-29 14:17:32 +11:00
Campbell Barton 35f770a689 Cleanup: duplicate words in comments 2023-03-29 14:17:32 +11:00
Jacques Lucke d81d743537 BLI: support == and != for Set
This makes it more convenient to check if two sets contain the same keys.
2023-03-28 14:16:57 +02:00
Jacques Lucke fbcddfcd68 BLI: add core types for supporting implicit-sharing
The overall goal is to use implicit-sharing in many places in Blender
that currently do unnecessary copies. See #95845 for more details.

This commit only adds the base data structures in blenlib and uses those
in `GeometrySet` and `AnonymousAttributeID`, which used a more ad-hoc
version of implicit sharing already. #105994 lists some more places where
support for implicit sharing can be added (most notably: custom data layers).

Pull Request: https://projects.blender.org/blender/blender/pulls/105994
2023-03-28 13:57:51 +02:00
Campbell Barton bbcfdb844c Cleanup: quiet strict-prototypes warning with CLANG 2023-03-28 15:57:48 +11:00
Campbell Barton 1b0816929f Cleanup: quiet unreachable-code-generic-assoc warnings with CLANG
Duplicate types in type checking macros caused many warnings.
2023-03-28 15:57:48 +11:00
Campbell Barton 55f6c97185 Fix redundant memcmp in BLI_array_store, correct assertion
Assert failed in BLI_array_store_test, failing to compare chunks
caused an unnecessary memcmp call in rare cases.
2023-03-28 15:57:48 +11:00
Campbell Barton bb2dc141f2 Cleanup: spelling in comments 2023-03-27 12:08:14 +11:00
Omar Emara 2f4a7d67b7 Realtime Compositor: Implement Anti-Aliasing node
This patch implements the Anti-Aliasing node by porting SMAA from
Workbench into a generic library that can be used by the realtime
compositor and potentially other users. SMAA was encapsulated in an
algorithm to prepare it for use by other nodes that require SMAA
support.

Pull Request: https://projects.blender.org/blender/blender/pulls/106114
2023-03-26 16:59:13 +02:00
Clément Foucault 9c8cb823a0 BLI: Fix compilation when importing `BLI_math_rotation.hh`
It worked until now because `<iostream>` was included by other headers
before the rotation ones. But this didn't work in all cases. This commit
make sure all rotation type headers include it.
2023-03-24 17:42:34 +01:00
Sergey Sharybin 08466a93e3 Fix security warning generated by std::tmpnam
Effectively replicate the behavior of the function in the manner
which is used for autosave file.

There might be better a solution which is cross-platform and does
not suffer from the time of check, time of use (TOCTOU) vector of
attack. This seems to be a bigger project to figure out, so until
then silence the warning: it is fine since the directory is only
used to chdir to, so worst case an external attacker can introduce
is a test failure.
2023-03-24 14:52:43 +01:00
Sergey Sharybin 8c38d29feb BLI: Add utility to access system-wide temporary directory
It provides path to a directory suitable for storing temporary files
which satisfies the following conditions:

- The directory exists.
- The return path has trailing directory separator.

It is based on the code used in the appdir.c to get the temporary
directory.

For the C++ people: this is similar to the temp_directory_path()
from the std::filesystem.

No functional changes expected as it is a new code which is planned
to be used on other places as a followup development.
2023-03-24 14:52:43 +01:00
Campbell Barton 3dcd4df70c UI: support the primary clipboard for console & 3D text selection
Only the text editor supported the primary clipboard & only for modal
selection. Now selecting text in the console & 3D text editing also
sets the primary clipboard under X11 & Wayland.

Notes:

- Pasting from the primary clipboard isn't yet exposed in the key-map
  so in practice it's only useful for pasting text outside of Blender.
- Use skip-save option when pasting from the primary selection
  so this is never used by the regular paste shortcut.
- This commit adds a primary-clipboard flag to WM_capabilities_flag() so
  creating the the copy-buffer is only performed when necessary.
2023-03-24 17:09:39 +11:00
Campbell Barton 2de2db0f79 Cleanup: BLI_array_store comments, use const variables 2023-03-23 10:52:40 +11:00
Campbell Barton 274c554f4c BLI_array_store: avoid unnecessary memcmp when detecting duplicates
Memory chunks that were in the same hashed bucket but had different keys
were comparing memory unnecessary.

In practice this didn't happen all that often in my tests so the
performance improvement isn't significant.

Follow up to 4f10800094.
2023-03-23 10:52:38 +11:00
Campbell Barton 35b69c578c Merge branch 'blender-v3.5-release' 2023-03-23 01:12:18 +11:00
Campbell Barton 4f10800094 Mesh: optimize edit-mesh undo with selection (address #105205)
BLI_array_store still performed poorly for boolean arrays or any arrays
where many memory chunks had identical contents since the temporary hash
had many collisions, making lookups slow.

Resolve by ensuring duplicate chunks aren't added to the hash table.

Also increase the memory chunk size for edit-mesh undo to 64kb
which performs well with high poly meshes as it reduces the overhead of
having to manage many small memory chunks.

Notes:

- Before this change performance was quite bad (10-20x worse than v3.3).
- Performance from the test in #105046 is roughly the same as before.
- Performance of #105205 compared with v3.3 is close, even faster at
  times but varies much more (likely caused by threading).
2023-03-23 01:09:35 +11:00
Hans Goudey 40bd35c9c4 BLI: Add dirty and cached checks to shared cache
While these aren't needed that often, it can be helpful to avoid
using a cache if it isn't necessary and it doesn't already exist.
2023-03-22 08:50:27 -04:00
Hans Goudey 7c952d6d15 Cleanup: Avoid unused includes in EnumerableThreadSpecific header 2023-03-22 07:43:26 -04:00
Campbell Barton e4300bbf2d Cleanup: quiet warnings by using system-includes for ./extern/
extern/json & extern/fmtlib reported warnings with GCC 12.2.1.
As these libraries aren't maintained as part of Blender, treat them as
system-includes.
2023-03-22 14:18:14 +11:00
Hans Goudey dab0ab673e BLI: Add a default constructor to OffsetIndices
Though it's not common, sometimes it is necessary to declare this class
without immediately assigning a value, and `Span` already supports this.
2023-03-21 16:53:57 -04:00
Hans Goudey 309553fc07 BLI: Simplify and extend OffsetIndices class
Add `index_range()` and `is_empty()` functions, rename `ranges_num()`
to `size()` (clarifying the final extra integer as an implementation
detail). Also remove the `size(index)` function which gave almost the
same assembly as `[index].size()` (https://godbolt.org/z/PYzqYs3Kr).
2023-03-20 13:34:14 -04:00