Commit Graph

323 Commits

Author SHA1 Message Date
Jacques Lucke
a58dc25b07 Cleanup: improve custom data type names
This is related to T76659.

This just renames data type names to `CD_PROP_STRING`, `CD_PROP_FLOAT`
and `CD_PROP_INT32`. It makes them a bit more specific and removes
unnecessary abbreviations.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D7980
2020-06-10 15:47:31 +02:00
Jacques Lucke
4fefe3ac3b BLI: rename tests from "array_ref" to "span"
This was missing in an earlier commit.
2020-06-10 14:50:29 +02:00
Jacques Lucke
a71f073dfb BLI: add Map.pop_try method
I found this pattern in depsgraph code more than once.
2020-06-10 14:47:22 +02:00
Jacques Lucke
84a0a6d16c BLI: update behavior of Map.lookup_or_add
Previously, this function would expect a callback function as parameter.
This behavior is now in Map.lookup_or_add_cb. The new version just
takes the key and value directly.
2020-06-10 14:15:04 +02:00
Jacques Lucke
f7c0f1b8b8 BLI: rename ArrayRef to Span
This also renames `MutableArrayRef` to `MutableSpan`.
The name "Span" works better, because `std::span` will provide
similar functionality in C++20. Furthermore, a shorter, more
concise name for a common data structure is nice.
2020-06-09 11:58:47 +02:00
Jacques Lucke
9bb7d6ed68 BLI: put C++ data structures in "blender" namespace instead of "BLI"
We plan to use the "blender" namespace in other modules as well.
2020-06-09 10:27:24 +02:00
Jacques Lucke
d8678e02ec BLI: generally improve C++ data structures
The main focus here was to improve the docs significantly. Furthermore,
I reimplemented `Set`, `Map` and `VectorSet`. They are now (usually)
faster, simpler and more customizable. I also rewrote `Stack` to make
it more efficient by avoiding unnecessary copies.

Thanks to everyone who helped with constructive feedback.

Approved by brecht and sybren.

Differential Revision: https://developer.blender.org/D7931
2020-06-09 10:15:43 +02:00
Jacques Lucke
0a907657d4 Functions: Run-time type system and index mask
This adds a new `CPPType` that encapsulates information about how to handle
instances of a specific data type. This is necessary for the function evaluation
system, which will be used to evaluate most of the particle node trees.

Furthermore, this adds an `IndexMask` class which offers a surprisingly useful
abstraction over an array containing unsigned integers. It makes two assumptions
about the underlying integer array:
* The integers are in ascending order.
* There are no duplicates.

`IndexMask` will be used to "select" certain particles that will be
processed in a data-oriented way. Sometimes, operations don't have to
be applied to all particles, but only some, those that are in the indexed by
the `IndexMask`. The two limitations imposed by an `IndexMask` allow for
better performance.

Reviewers: brecht

Differential Revision: https://developer.blender.org/D7957
2020-06-08 17:37:43 +02:00
Jeroen Bakker
e8b8e16b24 Code Cleanup: fcurve function naming 2020-06-05 09:30:15 +02:00
Jeroen Bakker
fe6be70875 CleanUp: Introduce BKE_fcurve_create 2020-06-05 08:41:35 +02:00
Campbell Barton
3c40d2485f Merge branch 'blender-v2.83-release' 2020-05-25 21:01:38 +10:00
Campbell Barton
d65f60764b GTest: BLI_ghash_performance_test was failing
Change the seed from 0 to 1, so BLI_ghash_performance_test doesn't
assert with duplicate keys.
2020-05-25 20:52:10 +10:00
Jeroen Bakker
9ef272bae3 Task: Graph Flow Task Scheduling
Add TBB::flow graph scheduling to BLI_task.

Using flow graphs, a graph of nodes (tasks) and links can be defined.
Work can flow though the graph. During this process the execution of the nodes will be
scheduled among the available threads.

We are planning to use this to improve the threading in the draw manager.

The implemented API is still limited it only supports sequential flows. Joins and buffers
are not supported. We could eventually support them as part of an CPP API. These features
from uses compile time templates and are hard to make a clean C-API for this.

Reviewed By: Sergey Sharybin, Brecht van Lommel

Differential Revision: https://developer.blender.org/D7578
2020-05-25 12:38:12 +02:00
Jacques Lucke
0c9e73845c BLI: improve Vector test 2020-05-21 14:35:19 +02:00
Brecht Van Lommel
4f622c9a08 Fix Windows build after recent guardedalloc changes 2020-05-20 00:32:17 +02:00
163f21db8c Cleanup: USD test, clarfied comment
No functional changes
2020-05-08 15:41:50 +02:00
163a48f203 Cleanup: Alembic, moved axis conversion functions into their own files
The long-term goal is to move code out of `abc_util.{h,cc}` into either
files with better, more concrete names, or simply into the one file
where they are used.

No functional changes.
2020-05-08 12:19:43 +02:00
1771c7e441 Merge remote-tracking branch 'origin/blender-v2.83-release' 2020-05-04 18:08:17 +02:00
0c8b872188 Fix T76355: USD test fails in debug mode
Thanks @LazyDodo for the help!

No functional changes.
2020-05-04 18:03:19 +02:00
Jacques Lucke
df16c23832 Add StringMap.LookupOrAdd and StringMap.LookupOrAddDefault 2020-05-04 17:12:23 +02:00
b3553c0961 Cleanup: USD tests, use EXPECT_LT and EXPECT_FALSE where appropriate
Unfortunately there is no `EXPECT_NOT_LT`; as the `HierarchyContext` only
has an `operator<()` function, testing for `(A < B) == false` is different
than simply testing `(A >= B)`.

No functional changes.
2020-05-04 16:17:54 +02:00
Campbell Barton
76be35efb2 Cleanup: clang-format 2020-05-03 13:42:49 +10:00
28bdf669a9 Fix: added missing buildinfo to BKE_fcurve test 2020-05-01 12:45:53 +02:00
9a4844cfdb Tests: Animation, added unittests for FCurve evaluation
This introduces unittests for FCurve evaluation.

No functional changes to actual Blender code.

Differential Revision: https://developer.blender.org/D6778
2020-05-01 11:56:59 +02:00
Brecht Van Lommel
d8a3f3595a Task: Use TBB as Task Scheduler
This patch enables TBB as the default task scheduler. TBB stands for Threading Building Blocks and is developed by Intel. The library contains several threading patters. This patch maps blenders BLI_task_* function to their counterpart. After this patch we can add more patterns. A promising one is TBB:graph that can be used for depsgraph, draw manager and compositor.

Performance changes depends on the actual hardware. It was tested on different hardwares from laptops to workstations and we didn't detected any downgrade of the performance.
* Linux Xeon E5-2699 v4 got FPS boost from 12 to 17 using Spring's 04_010_A.anim.blend.
* AMD Ryzen Threadripper 2990WX 32-Core Animation playback goes from 9.5-10.5 FPS to 13.0-14.0 FPS on Agent 327 , 10_03_B.anim.blend.

Reviewed By: brecht, sergey

Differential Revision: https://developer.blender.org/D7475
2020-04-30 08:09:21 +02:00
Jacques Lucke
4d06c1c25b BLI: add VectorSet.is_empty method 2020-04-28 19:18:12 +02:00
Jacques Lucke
a72eed7dd5 BLI: rename Vector.empty to Vector.is_empty 2020-04-28 17:04:07 +02:00
Jacques Lucke
c05ef1459c BLI: add Set.clear method 2020-04-28 16:41:37 +02:00
Jacques Lucke
d575b72c16 BLI: add Set.is_empty method 2020-04-28 16:35:49 +02:00
Jacques Lucke
9c65ac7311 BLI: add Map.lookup_or_add_default method 2020-04-28 13:55:36 +02:00
Brecht Van Lommel
20100009f6 Fix armature roll test failing on macOS 2020-04-28 13:31:59 +02:00
Jacques Lucke
9c2715ffda BLI: add Map.is_empty() method 2020-04-28 11:44:10 +02:00
Jacques Lucke
c5f4d5e448 BLI: add LinearAllocator
This allocator is useful when it is necessary to allocate many small elements.
2020-04-24 23:52:55 +02:00
Jacques Lucke
1f2b1d520f BLI: improve StringRef.copy 2020-04-24 23:35:17 +02:00
Jacques Lucke
62f6255b47 BLI: Implement StringMap.add and StringMap.add_or_modify 2020-04-24 22:33:48 +02:00
Jacques Lucke
8f5a4a4da3 BLI: various data structure improvements
* Rename template parameter N to InlineBufferCapacity
* Expose InlineBufferCapacity parameter for Set and Map
* Add some comments
* Fixed an error that I introduced recently
2020-04-23 20:05:53 +02:00
Brecht Van Lommel
3b47f335c6 BLI: remove TaskParallelRangePool
This is not currently used and will take some work to support with TBB, so
remove it until we have a new implementation based on TBB.

Fixes T76005, parallel range pool tests failing.

Ref D7475
2020-04-23 15:39:34 +02:00
Brecht Van Lommel
8f51f60948 Fix T76005: BLI_task test failing after recent changes
This was an error in changes made to this test to accomodate the new reduce
callback.
2020-04-23 14:04:29 +02:00
Jacques Lucke
614621747e BLI: optimize VectorSet implementation
Instead of building on top of `BLI::Vector`, just use a raw array
and handle the growing in `BLI::VectorSet`.

After this change, the existing `EdgeSet` can be reimplemented using
`BLI::VectorSet` without performance regressions.
2020-04-23 12:02:06 +02:00
Ray Molenkamp
6c9bebd827 Tests: Fix build error in BKE_armature test
Test does not link due to missing symbols, needs
buildinfoobj to link against when WITH_BUILDINFO is on
2020-04-22 07:47:32 -06:00
93e193399d Tests: added unit test for mat3_vec_to_roll() function
This was used to investigate T73840. Since the armature math is far from
simple, I thought it would be a good idea to start writing some unit
tests for it.

No functional changes in Blender itself.
2020-04-21 17:58:27 +02:00
Jacques Lucke
29e9506a7f BLI: simplify naming of listbase wrapper 2020-04-21 17:38:19 +02:00
Jacques Lucke
3059353b38 BLI: Use .hh extension for C++ headers in blenlib 2020-04-21 17:31:56 +02:00
Jeroen Bakker
2d6ad88466 CleanUp: Renamed BLI_task_pool_userdata to BLI_task_pool_user_data
In preparation for {D7475}
2020-04-21 15:37:36 +02:00
Jeroen Bakker
d923fb784f Task: Separate Finalize into Reduce And Free
In preparation of TBB we need to split the finalize function into reduce
and free. Reduce is used to combine results and free for freeing any
allocated memory.

The reduce function is called to join user data chunk into another, to reduce the
result to the original userdata_chunk memory. These functions should have no side
effects so that they can be run on any thread.
The free functions should free data created during execution (TaskParallelRangeFunc).

Original patch by Brecht van Lommel
{rB61f49db843cf5095203112226ae386f301be1e1a}.

Reviewed By: Brecht van Lommel, Bastien Montagne

Differential Revision: https://developer.blender.org/D7394
2020-04-17 16:06:54 +02:00
78f56d5582 TaskScheduler: Minor Preparations for TBB
Tasks: move priority from task to task pool {rBf7c18df4f599fe39ffc914e645e504fcdbee8636}
Tasks: split task.c into task_pool.cc and task_iterator.c {rB4ada1d267749931ca934a74b14a82479bcaa92e0}

Differential Revision: https://developer.blender.org/D7385
2020-04-09 19:18:14 +02:00
17da3b5d82 USD: ensure test does not depend on BLI_assert()
The test failure in T75491 only showed up in debug builds because
`BLI_assert()` is a no-op in release builds. This is now replaced by a
proper GTests call to `ADD_FAILURE()`, ensuring that the test fails
regardless of build mode.
2020-04-09 12:14:51 +02:00
Campbell Barton
d14e768069 Cleanup: BLI_path.h function renaming
Use BLI_path_ prefix, more consistent names:

  BLI_parent_dir              -> BLI_path_parent_dir
  BLI_parent_dir_until_exists -> BLI_path_parent_dir_until_exists
  BLI_ensure_filename         -> BLI_path_filename_ensure
  BLI_first_slash             -> BLI_path_slash_find
  BLI_last_slash              -> BLI_path_slash_rfind
  BLI_add_slash               -> BLI_path_slash_ensure
  BLI_del_slash               -> BLI_path_slash_rstrip
  BLI_path_native_slash       -> BLI_path_slash_native

Rename 'cleanup' to 'normalize', similar to Python's `os.path.normpath`.

  BLI_cleanup_path  -> BLI_path_normalize
  BLI_cleanup_dir   -> BLI_path_normalize_dir
  BLI_cleanup_unc   -> BLI_path_normalize_unc
  BLI_cleanup_unc16 -> BLI_path_normalize_unc16

Clarify naming for extracting, creating numbered paths:

  BLI_stringenc -> BLI_path_sequence_encode
  BLI_stringdec -> BLI_path_sequence_decode

Part of T74506 proposal.
2020-04-07 12:10:36 +10:00
Dalai Felinto
2d1cce8331 Cleanup: make format after SortedIncludes change 2020-03-19 09:33:58 +01:00
Sergey Sharybin
5a664c6e98 Fix another implicit cast of boot to int
Use proper comparison to nullptr.

It is important to use nullptr since NULL is actually an integer,
which leads to another type of warnings.
2020-03-16 12:15:16 +01:00
Sergey Sharybin
7df435325b Fix implicit cast from bool to int in path tests 2020-03-16 10:53:46 +01:00
Howard Trickey
cebff2ff30 Fix a syntax error in test spec for BLI_delaunay_2d_test.
Test specs are read from strings, and there was a comma instead
of a decimal point, and then an extra decimal point in the Quad0 test.
This test has been flaky on Windows buildbot. Perhaps this is why.
2020-03-15 17:14:04 -04:00
eb522af4fe Cleanup: move Alembic, AVI, Collada, and USD to source/blender/io
This moves the `alembic`, `avi`, `collada`, and `usd` modules into a common
`io` directory.

This also cleans up some `#include "../../{somedir}/{somefile}.h"` by
adding `../../io/{somedir}` to `CMakeLists.txt` and then just using
`#include "{somefile}.h"`.

No functional changes.
2020-03-06 16:19:45 +01:00
Bastien Montagne
c328049535 Initial step for IDTypeInfo refactor 'cleanup' project.
Introduce new IDTypeInfo structure.

Each ID type will have its own, with some minimal basic common info,
and ID management callbacks.

This patch only does it for Object type, for demo/testing purpose.
Moving all existing IDs is a goal of next "cleanup Friday".

Note that BKE_idcode features should then be merged back into BKE_idtype -
but this will have to be done later, once all ID types have been properly
converted to the new system.

Another later TODO might be to try and add callbacks for file read/write,
and lib_query ID usages looper.

This is part of T73719.

Thanks to @brecht for initial idea, and reviewing the patch.

Differential Revision: https://developer.blender.org/D6966
2020-03-05 10:58:58 +01:00
Campbell Barton
a5c984a57d Cleanup: cmake indentation 2020-03-04 11:02:35 +11:00
Tiago Chaves
14c9f64def BLI_math: add clamp_v# and clamp_v#_v#v# utility functions 2020-03-04 10:25:44 +11:00
Howard Trickey
ed29ff944a Fix delaunay triangulation, bad indices for output faces.
If there were merged vertices, sometimes the output faces
had wrong vertex indices. Added a test for this, and fixed.
2020-03-03 08:41:26 -05:00
Ish Bosamiya
5afa4b1dc8 Fix T65568: sewing and self collision issue
As explained in T65568 by @LucaRood, the self collision system should exclude triangles that are connected by sewing springs.

Differential Revision: https://developer.blender.org/D6911
2020-03-02 11:02:26 -03:00
Howard Trickey
f2557d137a Fix problem with Delaunay triangulalation re output mapping.
The array giving original vertex indices should not contain
entries for newly created vertices. Added a test to check this.
2020-03-01 12:25:44 -05:00
Howard Trickey
cb8b424c6b Made BLI_delaunay_2d_cdt_calc better at tiny feature elimination.
The 'random' unit tests and some examples from the new boolean code
triggered asserts and crashes. This fixes those.
There is a new flag in the input that optionally disables a pass
over input to snap segment edges to other segments.
2020-02-29 13:26:27 -05:00
Campbell Barton
1135c2cd17 Cleanup: CMake formatting 2020-02-15 10:40:41 +11:00
Jacques Lucke
68cc982dcb BLI: improve various C++ data structures
The changes come from the `functions` branch, where I'm using
these structures a lot.

This also includes a new `BLI::Optional<T>` type, which is similar
to `std::Optional<T>` which can be used when Blender starts using
C++17.
2020-02-10 14:09:01 +01:00
Howard Trickey
7038a3a774 Disable some longer running tests from previous commit. 2020-01-28 09:52:45 -05:00
Howard Trickey
2867c35d4e Fix T73271, Delaunay Triangulation not robust enough.
A big rework of the code now uses exact predicates for orientation
and incircle. Also switched the main algorithm to use a faster
divide and conquer algorithm, which is possible with the exact
predicates.
2020-01-28 09:45:46 -05:00
1107af1abb Fix OBJECT_GUARDED_FREE compiler error when type is in namespace 2020-01-27 12:22:01 +01:00
Campbell Barton
cdebc8a9f6 Cleanup: include missing CMake headers 2020-01-25 20:15:35 +11:00
Alexander Gavrilov
79d9874028 Merge branch 'blender-v2.82-release' 2020-01-24 20:48:38 +03:00
Alexander Gavrilov
fc1f5bded4 Depsgraph: fix false positive time dependencies for simple drivers.
The dependency graph has to know whether a driver must be re-evaluated
every frame due to a dependency on the current frame number. For python
drivers it was using a heuristic based on searching for certain sub-
strings in the expression, notably including '('.

When the expression is actually evaluated using Python, this can't be
easily improved; however if the Simple Expression evaluator is used,
this check can be done precisely by accessing the parsed data.

Differential Revision: https://developer.blender.org/D6624
2020-01-24 20:48:02 +03:00
Sergey Sharybin
6fff73e3f0 Merge branch 'blender-v2.82-release' 2020-01-23 16:59:50 +01:00
Sergey Sharybin
517870a4a1 CMake: Refactor external dependencies handling
This is a more correct fix to the issue Brecht was fixing in D6600.

While the fix in that patch worked fine for linking it broke ASAN
runtime under some circumstances.
For example, `make full debug developer` would compile, but trying
to start blender will cause assert failure in ASAN (related on check
that ASAN is not running already).

Top-level idea: leave it to CMake to keep track of dependency graph.

The root of the issue comes to the fact that target like "blender" is
configured to use a lot of static libraries coming from Blender sources
and to use external static libraries. There is nothing which ensures
order between blender's and external libraries. Only order of blender
libraries is guaranteed.

It was possible that due to a cycle or other circumstances some of
blender libraries would have been passed to linker after libraries
it uses, causing linker errors.

For example, this order will likely fail:

  libbf_blenfont.a libfreetype6.a libbf_blenfont.a

This change makes it so blender libraries are explicitly provided
their dependencies to an external libraries, which allows CMake to
ensure they are always linked against them.

General rule here: if bf_foo depends on an external library it is
to be provided to LIBS for bf_foo.
For example, if bf_blenkernel depends on opensubdiv then LIBS in
blenkernel's CMakeLists.txt is to include OPENSUBDIB_LIBRARIES.

The change is made based on searching for used include folders
such as OPENSUBDIV_INCLUDE_DIRS and adding corresponding libraries
to LIBS ion that CMakeLists.txt. Transitive dependencies are not
simplified by this approach, but I am not aware of any downside of
this: CMake should be smart enough to simplify them on its side.
And even if not, this shouldn't affect linking time.

Benefit of not relying on transitive dependencies is that build
system is more robust towards future changes. For example, if
bf_intern_opensubiv is no longer depends on OPENSUBDIV_LIBRARIES
and all such code is moved to bf_blenkernel this will not break
linking.

The not-so-trivial part is change to blender_add_lib (and its
version in Cycles). The complexity is caused by libraries being
provided as a single list argument which doesn't allow to use
different release and debug libraries on Windows. The idea is:

- Have every library prefixed as "optimized" or "debug" if
  separation is needed (non-prefixed libraries will be considered
  "generic").

- Loop through libraries passed to function and do simple parsing
  which will look for "optimized" and "debug" words and specify
  following library to corresponding category.

This isn't something particularly great. Alternative would be to
use target_link_libraries() directly, which sounds like more code
but which is more explicit and allows to have more flexibility
and control comparing to wrapper approach.

Tested the following configurations on Linux, macOS and Windows:

- make full debug developer
- make full release developer
- make lite debug developer
- make lite release developer

NOTE: Linux libraries needs to be compiled with D6641 applied,
otherwise, depending on configuration, it's possible to run into
duplicated zlib symbols error.

Differential Revision: https://developer.blender.org/D6642
2020-01-23 16:59:18 +01:00
Jacques Lucke
9c9ea37770 Fix: Use a minimal alignment of 8 in MEM_lockfree_mallocN_aligned
`posix_memalign` requires the `alignment` to be at least `sizeof(void *)`.
Previously, `MEM_mallocN_aligned` would simply return `NULL` if a too small
`alignment` was used. This was an OS specific issue.

The solution is to use a minimal alignment of `8` for all aligned allocations.
The unit tests have been extended to test more possible alignments (some
of which were broken before).

Reviewers: brecht

Differential Revision: https://developer.blender.org/D6660
2020-01-23 14:21:48 +01:00
Sergey Sharybin
7fc7df1bd3 CMake: Fix linking of ffmpeg_test on macOS
Part of the issue was missing library path to png library.
Other part was missing iconv passed to linker.
2020-01-16 15:52:19 +01:00
473bcff5cb Fix linking error with ffmpeg_test on Linux
The exact reason is unclear, but we might as well link just the few libraries
that are actually needed for ffmpeg.
2020-01-15 11:42:20 +01:00
Ray Molenkamp
f8b34d5ca4 test: Add basic codec test for ffmpeg.
This add a basic sanity check that validates
the features we use from ffmpeg are actually
available

Differential Revision: https://developer.blender.org/D5999

Reviewed By: sybren
2020-01-14 11:31:02 -07:00
6bca11a847 Fix build error in tests on Clang / macOS 2020-01-08 17:21:40 +01:00
Julian Eisel
f52d9a878d Fix T72878: Alphabetical sorting in Outliner sorts shorter names last
E.g. "Cube" would be placed after "Cube.001", which is not what you'd
expect. 2.80 handled this correctly.

Loosely based on D6525 by @radcapricorn, but found a bug in that and
prefered to do some further adjustments.

Also activates test for this case.
2020-01-08 16:08:10 +01:00
Julian Eisel
525b0e0ccb Tests: Natural string comparing (BLI_strcasecmp_natural())
Adds tests covering a good amount of common cases and corner cases for
`BLI_strcasecmp_natural()`.
Could of course always add more tests for more cases, but don't want to
spend too much time on this.
2020-01-08 16:08:10 +01:00
Howard Trickey
a0892bb690 Fix crash in delaunay triangulation due to epsilon issues. 2019-12-21 12:23:02 -05:00
Campbell Barton
7d2d2ffa76 Cleanup: spelling 2019-12-17 16:30:39 +11:00
c4203ef17d USD: disabled unit test that fails on the buildbot
I can't fix this quickly right now, so I'd rather drop the entire test
for now.
2019-12-13 18:59:23 +01:00
e6c40bc9e1 USD: Simplified unit test and made it work on Windows as well 2019-12-13 18:59:23 +01:00
322555faa3 USD: Remove file created in unit test after the test is done
No functional changes in the USD exporter, just some cleanup code added
to the unit test.
2019-12-13 15:08:44 +01:00
ec62413f80 USD: Introducing a simple USD Exporter
This commit introduces the first version of an exporter to Pixar's
Universal Scene Description (USD) format.

Reviewed By: sergey, LazyDodo

Differential Revision: https://developer.blender.org/D6287

- The USD libraries are built by `make deps`, but not yet built by
  install_deps.sh.
- Only experimental support for instancing; by default all duplicated
  objects are made real in the USD file. This is fine for exporting a
  linked-in posed character, not so much for thousands of pebbles etc.
- The way materials and UV coordinates and Normals are exported is going
  to change soon.
- This patch contains LazyDodo's fixes for building on Windows in D5359.

== Meshes ==

USD seems to support neither per-material nor per-face-group
double-sidedness, so we just use the flag from the first non-empty
material slot. If there is no material we default to double-sidedness.

Each UV map is stored on the mesh in a separate primvar. Materials can
refer to these UV maps, but this is not yet exported by Blender. The
primvar name is the same as the UV Map name. This is to allow the
standard name "st" for texture coordinates by naming the UV Map as such,
without having to guess which UV Map is the "standard" one.

Face-varying mesh normals are written to USD. When the mesh has custom
loop normals those are written. Otherwise the poly flag `ME_SMOOTH` is
inspected to determine the normals.

The UV maps and mesh normals take up a significant amount of space, so
exporting them is optional. They're still enabled by default, though.
For comparison: a shot of Spring (03_035_A) is 1.2 GiB when exported
with UVs and normals, and 262 MiB without. We probably have room for
optimisation of written UVs and normals.

The mesh subdivision scheme isn't using the default value 'Catmull
Clark', but uses 'None', indicating we're exporting a polygonal mesh.
This is necessary for USD to understand our normals; otherwise the mesh
is always rendered smooth. In the future we may want to expose this
choice of subdivision scheme to the user, or auto-detect it when we
actually support exporting pre-subdivision meshes.

A possible optimisation could be to inspect whether all polygons are
smooth or flat, and mark the USD mesh as such. This can be added when
needed.

== Animation ==

Mesh and transform animation are now written when passing
`animation=True` to the export operator. There is no inspection of
whether an object is actually animated or not; USD can handle
deduplication of static values for us.

The administration of which timecode to use for the export is left to
the file-format-specific concrete subclasses of
`AbstractHierarchyIterator`; the abstract iterator itself doesn't know
anything about the passage of time. This will allow subclasses for the
frame-based USD format and time-based Alembic format.

== Support for simple preview materials ==

Very simple versions of the materials are now exported, using only the
viewport diffuse RGB, metallic, and roughness.

When there are multiple materials, the mesh faces are stored as geometry
subset and each material is assigned to the appropriate subset. If there
is only one material this is skipped.

The first material if any) is always applied to the mesh itself
(regardless of the existence of geometry subsets), because the Hydra
viewport doesn't support materials on subsets. See
https://github.com/PixarAnimationStudios/USD/issues/542 for more info.

Note that the geometry subsets are not yet time-sampled, so it may break
when an animated mesh changes topology.

Materials are exported as a flat list under a top-level '/_materials'
namespace. This inhibits instancing of the objects using those
materials, so this is subject to change.

== Hair ==

Only the parent strands are exported, and only with a constant colour.
No UV coordinates, no information about the normals.

== Camera ==

Only perspective cameras are supported for now.

== Particles ==

Particles are only written when they are alive, which means that they
are always visible (there is currently no code that deals with marking
them as invisible outside their lifespan).

Particle-system-instanced objects are exported by suffixing the object
name with the particle's persistent ID, giving each particle XForm a
unique name.

== Instancing/referencing ==

This exporter has experimental support for instancing/referencing.

Dupli-object meshes are now written to USD as references to the original
mesh. This is still very limited in correctness, as there are issues
referencing to materials from a referenced mesh.

I am still committing this, as it gives us a place to start when
continuing the quest for proper instancing in USD.

== Lights ==

USD does not directly support spot lights, so those aren't exported yet.
It's possible to add this in the future via the UsdLuxShapingAPI. The
units used for the light intensity are also still a bit of a mystery.

== Fluid vertex velocities ==

Currently only fluid simulations (not meshes in general) have explicit
vertex velocities. This is the most important case for exporting
velocities, though, as the baked mesh changes topology all the time, and
thus computing the velocities at import time in a post-processing step
is hard.

== The Building Process ==

- USD is built as monolithic library, instead of 25 smaller libraries.
  We were linking all of them as 'whole archive' anyway, so this doesn't
  affect the final file size. It does, however, make life easier with
  respect to linking order, and handling upstream changes.
- The JSON files required by USD are installed into datafiles/usd; they
  are required on every platform. Set the `PXR_PATH_DEBUG` to any value
  to have the USD library print the paths it uses to find those files.
- USD is patched so that it finds the aforementioned JSON files in a path
  that we pass to it from Blender.
- USD is patched to have a `PXR_BUILD_USD_TOOLS` CMake option to disable
  building the tools in its `bin` directory. This is sent as a pull
  request at https://github.com/PixarAnimationStudios/USD/pull/1048
2019-12-13 10:27:40 +01:00
Campbell Barton
dfb6af3011 Cleanup: extra semicolon, comma warnings 2019-12-10 12:01:58 +11:00
f445f72eca Tests: Blendfile-loading test class
This new test class minimally sets up Blender so that it can load blend
files and construct a depsgraph without crashing.

Note that it hasn't been tested on very complex blend files, so it may
still crash when the loaded blend file references/requires uninitialised
data structures.

The test will certainly crash with Blend files created with Blender
older than 2.80, as the versioning code requires space types to be
registered. This is normally done by initialising the window manager,
which is not done in this test. The WM requires Python to run, which in
turn requires that Blender finds the release directory in the same
directory that contains the running executable, which is not the case
for GTest tests (they are written to `bin/tests/executablename`.

Reviewed By: sergey, mont29

Differential Revision: https://developer.blender.org/D6246
2019-11-28 17:41:32 +01:00
Bastien Montagne
fcbec6e97e BLI_task: Add pooled threaded index range iterator, Take II.
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

Note: Compared to previous commit yesterday, this reworks atomic handling in
parallel iter code, and fixes a dummy double-free bug.

Now we should only use the two critical values for synchronization from
atomic calls results, which is the proper way to do things.

Reading a value after an atomic operation does not guarantee you will
get the latest value in all cases (especially on Windows release builds
it seems).
2019-11-26 14:30:41 +01:00
Bastien Montagne
3f87ac3684 Revert "BLI_task: Add pooled threaded index range iterator."
This reverts commit f9028a3be1f77c01edca44a68894e2ba9d9cfb14.

This is giving weird heisenbug crash on only Windows release builds...
Reverting until we understand to issue.
2019-11-25 19:54:40 +01:00
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