Commit Graph

186 Commits

Author SHA1 Message Date
Bastien Montagne
f9028a3be1 BLI_task: Add pooled threaded index range iterator.
This code allows to push a set of different operations all based on
iterations over a range of indices, and then process them all at once
over multiple threads.

This commit also adds unit tests for both old un-pooled, and new pooled
`task_parallel_range` family of functions, as well as some basic
performances tests.

This is mainly interesting for relatively low amount of individual
tasks, as expected.

E.g. performance tests on a 32 threads machine, for a set of 10
different tasks, shows following improvements when using pooled version
instead of ten sequential calls to `BLI_task_parallel_range()`:

    | Num Items | Sequential | Pooled  | Speed-up |
    | --------- | ---------- | ------- | -------- |
    |       10K |     365 us |  138 us |   2.5  x |
    |      100K |     877 us |  530 us |   1.66 x |
    |     1000K |    5521 us | 4625 us |   1.25 x |

Differential Revision: https://developer.blender.org/D6189
2019-11-25 11:58:09 +01:00
Bastien Montagne
29433da4c6 BLI_task: Add new generic BLI_task_parallel_iterator().
This new function is part of the 'parallel for loops' functions. It
takes an iterator callback to generate items to be processed, in
addition to the usual 'process' func callback.

This allows to use common code from BLI_task for a wide range of custom
iteratiors, whithout having to re-invent the wheel of the whole tasks &
data chuncks handling.

This supports all settings features from `BLI_task_parallel_range()`,
including dynamic and static (if total number of items is knwon)
scheduling, TLS data and its finalize callback, etc.

One question here is whether we should provide usercode with a spinlock
by default, or enforce it to always handle its own sync mechanism.
I kept it, since imho it will be needed very often, and generating one
is pretty cheap even if unused...

----------

Additionaly, this commit converts (currently unused)
`BLI_task_parallel_listbase()` to use that generic code. This was done
mostly as proof of concept, but performance-wise it shows some
interesting data, roughly:
 - Very light processing (that should not be threaded anyway) is several
   times slower, which is expected due to more overhead in loop management
   code.
 - Heavier processing can be up to 10% quicker (probably thanks to the
   switch from dynamic to static scheduling, which reduces a lot locking
   to fill-in the per-tasks chunks of data). Similar speed-up in
   non-threaded case comes as a surprise though, not sure what can
   explain that.

While this conversion is not really needed, imho we should keep it
(instead of existing code for that function), it's easier to have
complex handling logic in as few places as possible, for maintaining and
for improving it.

Note: That work was initially done to allow for D5372 to be possible... Unfortunately that one proved to be not better  than orig code on performances point of view.

Reviewed By: sergey

Differential Revision: https://developer.blender.org/D5371
2019-10-30 12:23:45 +01:00
Campbell Barton
0a38352588 Cleanup: clang-format, trailing space 2019-10-23 01:06:15 +11:00
Campbell Barton
047c66279a Cleanup: missing declaration warnings 2019-10-20 16:42:49 +11:00
Campbell Barton
dc2cd2d0dc Cleanup: clang-format, spelling 2019-10-10 10:29:50 +11:00
Howard Trickey
ec9044e2b2 Fix Delaunay 2d valid bmesh mode bug.
Wasn't checking for repeated vertices.
Also, made choices of edges to keep more aesthetically pleasing.
2019-10-09 09:26:55 -04:00
Campbell Barton
fae0685113 Cleanup: quiet warnings 2019-10-07 12:22:05 +11:00
Jacques Lucke
38cc53a168 BLI: make Map.add_or_modify more powerful
The function now allows custom return types defined
by the callbacks. This can be useful when a user of the
data structure has to implement some custom behavior.
2019-09-14 16:25:17 +02:00
Jacques Lucke
e73030e336 BLI: rename SetVector to VectorSet
The structure is a set built on top of a vector and not the other
way around.
2019-09-14 12:37:58 +02:00
Jacques Lucke
79e1165bd7 BLI: Improve forwarding semantics of some data structures
This makes it possible to use e.g. `std::unique_ptr` in a map.
2019-09-14 12:11:14 +02:00
Jacques Lucke
08539312b2 BLI: add some missing methods to Map and SetVector 2019-09-13 12:10:40 +02:00
Jacques Lucke
1c44d08a69 BLI: new C++ hash table data structures
This commit adds some new hashing based data structures to blenlib.
All of them use open addressing with probing currently.
Furthermore, they support small object optimization, but it is not
customizable yet. I'll add support for this when necessary.
The following main data structures are included:

**Set**
A collection of values, where every value must exist at most once.
This is similar to a Python `set`.

**SetVector**
A combination of a Set and a Vector. It supports fast search for
elements and maintains insertion order when there are no deletes.
All elements are stored in a continuous array. So they can be
iterated over using a normal `ArrayRef`.

**Map**
A set of key-value-pairs, where every key must exist at most once.
This is similar to a Python `dict`.

**StringMap**
A special map for the case when the keys are strings. This case is
fairly common and allows for some optimizations. Most importantly,
many unnecessary allocations can be avoided by storing strings in
a single buffer. Furthermore, the interface of this class uses
`StringRef` to avoid unnecessary conversions.

This commit is a continuation of rB369d5e8ad2bb7.
2019-09-13 10:06:02 +02:00
Jacques Lucke
058d218254 BLI: new StringRef and StringRefNull data structures
These two data structures reference strings somewhere in memory.
They do not own the referenced string. The string is considered
const.

A string referenced by StringRefNull can be expected to be
null-terminated. That is not the case for StringRef.

This commit is a continuation of rB369d5e8ad2bb7c2.
2019-09-12 16:55:35 +02:00
Jacques Lucke
369d5e8ad2 BLI: new C++ ArrayRef, Vector, Stack, ... data structures
Many generic C++ data structures have been developed in the
functions branch. This commit merges a first chunk of them into
master. The following new data structures are included:

Array: Owns a memory buffer with a fixed size. It is different
  from std::array in that the size is not part of the type.

ArrayRef: References an array owned by someone else. All elements
  in the referenced array are considered to be const. This should
  be the preferred parameter type for functions that take arrays
  as input.

MutableArrayRef: References an array owned by someone else. The
  elements in the referenced array can be changed.

IndexRange: Specifies a continuous range of integers with a start
  and end index.

IntrusiveListBaseWrapper: A utility class that allows iterating
  over ListBase instances where the prev and next pointer are
  stored in the objects directly.

Stack: A stack implemented on top of a vector.

Vector: An array that can grow dynamically.

Allocators: Three allocator types are included that can be used
  by the container types to support different use cases.

The Stack and Vector support small object optimization. So when
the amount of elements in them is below a certain threshold, no
memory allocation is performed.

Additionally, most methods have unit tests.

I'm merging this without normal code review, after I checked the
code roughly with Sergey, and after we talked about it with Brecht.
2019-09-12 14:23:21 +02:00
Sergey Sharybin
73a199e96a Depsgraph: Pass bmain to depsgraph object creation
Currently unused, but will allow to keep of an owner of the depsgraph.

Could also simplify other APIs in the future by avoiding to pass bmain
explicitly to relation update functions and things like that.
2019-09-11 10:43:27 +02:00
Howard Trickey
b380a98887 Fix two bugs in delaunay blenlib function.
Bugs were: (1) needed an epsilon test in CCW test in order to
handle new costraint edge that intersects an existing point
but only within epsilon; (2) the "valid bmesh" output mode
sometimes left a face that included outside frame point.
2019-09-07 20:31:24 +05:30
Campbell Barton
c883fe25da Cleanup: clang-format, unused arg 2019-08-16 01:59:32 +10:00
Howard Trickey
e4084f8b24 Fix CDT bug causing crash with some output modes.
Forgot to properly maintain the edge for faces while
dissolving edges.
2019-08-15 07:55:29 -04:00
Campbell Barton
4b9e05b428 Cleanup: clang-format, sort structs & cmake files 2019-08-15 01:34:58 +10:00
05417b2220 Text editor: syntax highlighting + line numbers on by default
The most common use of the text editor seems to be for scripting. Having
line numbers and syntax highlighting enabled by default seems sensible.

Syntax highlighting is now enabled by default, but is automatically
disabled when the datablock has a non-highlighted extension.
Highlighting is enabled for filenames like:
    - Text
    - Text.001
    - somefile.py
and is automatically disabled when the datablock has an extension for
which Blender has no syntax highlighter registered.

Reviewers: billreynish, campbellbarton

Subscribers: brecht, billreynish

Differential Revision: https://developer.blender.org/D5472
2019-08-14 16:59:37 +02:00
Campbell Barton
03b2371387 Cleanup: move trailing comments to avoid wrapping code
Some statements were split across multiple lines because of their
trailing comments.

In most cases it's clearer to put the comments above.
2019-08-14 23:32:24 +10:00
Campbell Barton
22cdadaa32 Cleanup: clang-format 2019-08-11 02:47:32 +10:00
Howard Trickey
b91643c711 Add Constrained Delaunay Triangulation routine to Blenlib.
See Design task T68277, and patch D5423.
This commit includes edits by @ideasman42 to patch in
branch temp-D5423-update, plus responses to his comments.
2019-08-10 08:24:20 -05:00
Campbell Barton
fa1d470692 GTest: test cases for polyfill2d bug T67109 2019-08-05 22:44:16 +10:00
Bastien Montagne
1324659dee GTests: BLI_task: Add basic tests for BLI_task_parallel_listbase(), and some performances benchmarks.
Nothing special to mention about regression test itself, it basically
mimics the one for `BLI_task_parallel_mempool()`...

Basic performances benchmarks do not tell us much, besides the fact that
for very light processing of listbase, even with 100k items,
single-thread remains an order of magnitude faster than threaded code.
Synchronization is just way too expensive in that case with current
code. This should be partially solvable with much bigger (and
configurable) chunk sizes though (current ones are just ridiculous
for such cases ;) )...
2019-06-04 23:51:03 +02:00
Ray Molenkamp
0fc97dc73d CTest: Fix Bli_task_test failing on windows.
The task_scheduler was not being explicitly freed, leading to
unpredictable behavior when the process was exiting. The test
would pass, but would sometimes segfault at process shutdown.
2019-05-21 06:51:24 -06:00
Campbell Barton
bdefce0b21 GTest: BLI_path_util tests
Unit tests for:

- BLI_path_extension_check
- BLI_path_frame_check_chars
- BLI_path_frame_range
- BLI_path_frame_get

D4749 by @zazizizou
2019-04-29 12:51:33 +10:00
Campbell Barton
e17e119a31 Cleanup: comment line length (tests) 2019-04-20 10:08:59 +02:00
Campbell Barton
4439e5d0ba Cleanup: add trailing commas to avoid right shift 2019-04-18 17:19:44 +02:00
Ray Molenkamp
12aa9b2108 Fix T63678 Link error of tests with MSVC.
Ideally OCIO removes their log2 implementation from the global namespace
but for now this linker tweak will have to do.
2019-04-17 07:58:48 -06:00
Campbell Barton
41d4a19865 ClangFormat: format '#if 0' code in source/ 2019-04-17 08:24:14 +02:00
Campbell Barton
e12c08e8d1 ClangFormat: apply to source, most of intern
Apply clang format as proposed in T53211.

For details on usage and instructions for migrating branches
without conflicts, see:

https://wiki.blender.org/wiki/Tools/ClangFormat
2019-04-17 06:21:24 +02:00
Campbell Barton
2986bc1d6e ClangFormat: add comments to ignore formatting 2019-04-16 16:57:47 +02:00
Campbell Barton
31c2e69d49 CMake: remove BLENDER_SORTED_LIBS
Use CMake's target_link_libraries instead of manually maintaining
library dependencies in a single list.

In practice adding new libraries often ended up being guess-work,
now each library lists the libraries it uses.

This was used for the game player executable so libraries
could optionally link to stubs.

If we need this functionality it can be done using target-properties
as described in T46725.
2019-04-16 12:36:44 +02:00
Campbell Barton
47adab4f99 CMake: prepare for BLENDER_SORTED_LIBS removal
No functional change, this adds LIB definition and args to cmake files.
Without this it's difficult to migrate away from 'BLENDER_SORTED_LIBS'
since there are many platforms/configurations that could break when
changing linking order.

Manually add and enable WITHOUT_SORTED_LIBS to try building
without sorted libs (currently fails since all variables are empty).
This check will eventually be removed.

See T46725.
2019-04-14 15:37:24 +02:00
Sergey Sharybin
f39a4a4a4e Cleanup: More C++ like nature for word split test
While it looks more longer, but also contains more comments
about what's going on.

Surely, this function almost never breaks and investing time
into maintaining its tests is not that important, but we should
have a good, clean, understandable tests so they act as a nice
example of how they are to be written. Especially important to
show correct language usage, without old school macros magic.

Doing this at a lunch breaks, so will be series of some updates
in the area.
2019-03-20 14:14:56 +01:00
Sybren A. Stüvel
0333cf00ba Fix BLI_path_frame_strip
The `BLI_path_frame_strip` function was completely broken, unless the
number of digits in the sequence number was the same as the length of
the extension. In other words, it would work fine for `file.0001.abc` (4
digit `0001` and 4 char `.abc`), but other combinations would truncate
to the shortest (`file.001.abc` would become `file.###.ab` and
`file.00001.a` would become `file.##.a`). The dependency between the
sequence number and the file extension is now removed.

The behaviour has changed a little bit in the case where there are no
numbers in the filename. Previously, `path="filename.abc"` would result
in `path="filename.abc"` and `ext=""`, but now it results in
`path="filename"` and `ext=".abc"`. This way `ext` always contains the
extension, and the behaviour is consistent regardless of whether there
were any numbers found.

Furthermore, I've removed the `bool set_frame_char` parameter, because
it was unclear, probably also buggy, and most importantly, never used.

I've also added a unit test for the `BLI_path_frame_strip` function.
2019-03-20 13:42:45 +01:00
Ray Molenkamp
55e79d8f36 Tests: BLI_heap_simple test fix build error with MSVC.
BLI_heap_simple.h uses types from BLI_sys_types.h causing a build error on windows.
2019-03-14 11:14:44 -06:00
Campbell Barton
ab5e69e660 Cleanup: remove contributors for CMake files
Following removal from C source code.

See: 8c68ed6df16d8893
2019-02-05 09:10:32 +11:00
Campbell Barton
744f633986 Cleanup: trailing commas
Needed for clan-format not to wrap onto one line.
2019-02-03 14:59:11 +11:00
Campbell Barton
6cbb4c576a Cleanup: manually remove header text not handled by automation 2019-02-02 01:49:31 +11:00
Bastien Montagne
6d89337257 Fix/cleanup typos and such in UI messages (and some comments). 2018-12-24 15:03:49 +01:00
Bastien Montagne
1ac311cedc Fix/cleanup another bunch of UI messages issues.
Also (mostly in comments): behaviour -> behavior (we use American English).
2018-12-24 12:32:43 +01:00
Jacques Lucke
aa63a87d37 BLI: New Edgehash and EdgeSet implementation
The new data structure uses open addressing instead of chaining to resolve collisions in the hash table.

This new structure was never slower than the old implementation in my tests. Code that first inserts all edges and then iterates through all edges (e.g. to remove duplicates) benefits the most, because the `EdgeHashIterator` becomes a simple for loop over a continuous array.

Reviewer: campbellbarton

Differential Revision: D4050
2018-12-13 11:21:31 +01:00
Bastien Montagne
278d9c8322 Merge branch 'master' into blender2.8
Conflicts:
	source/blenderplayer/CMakeLists.txt
	tests/gtests/blenlib/CMakeLists.txt
2018-11-28 16:52:47 +01:00
Bastien Montagne
c16321cb9d Fix building gtests and bplayer after recent NumaAPI addition.
Seriously... like, seriously...
2018-11-28 16:50:02 +01:00
Bastien Montagne
1ff8be24ef Cleanup/Refactor: move Main stuff into BKE's new main.c file (and header).
We already had a BKE_main.h header, no reason not to put there
Main-specific functions, BKE_library has already more than enough to
handle with IDs and library management!
2018-11-07 20:58:53 +01:00
Alexander Gavrilov
84fa806491 BLI_kdopbvh: add an option to use a priority queue in find_nearest.
Simple find_nearest relies on a heuristic for efficient culling of
the BVH tree, which involves a fast callback that always updates the
result, and the caller reusing the result of the previous find_nearest
to prime the process for the next vertex.

If the callback is slow and/or applies significant restrictions on
what kind of nodes can qualify for the result, the heuristic can't
work. Thus for such tasks it is necessary to order and prune nodes
before the callback at BVH tree level using a priority queue.

Since, according to code history, for simple find_nearest the
heuristic approach is faster, this mode has to be an option.
2018-11-06 21:20:16 +03:00
Bastien Montagne
aa9912ec04 Proper fix for new 'SimpleHeap' gtests...
This reverts reverting commit rB55324b8a2e6799300, and do proper 'cleanup' (sigh)
in gtest as well.

Sorry for the noise, did not understood what had happened here
immediately. :/
2018-11-06 16:25:00 +01:00
Bastien Montagne
55324b8a2e Revert rBfee6ab18e7e9 in BLI_heap_test.cc
Most certainly commite by mistake, FastHeap is not in BLI yet!
2018-11-06 16:06:53 +01:00