Commit Graph

194 Commits

Author SHA1 Message Date
Sergey Sharybin efa4ae17f0 OpenSubdiv: Only store edges topology for non-smooth edges
This change makes it so vertices of edge are only stored when edge
has non-zero crease. This allows to lower memory footprint of 1.5M
faces from 78 MiB to 54 MiB in the case all creases are zero.

Meshes with crease are more hard to predict due to array-based
storage, so it all depends on index of edge with crease. Worst case
(all edges are creased) still stays at 78 MiB.
2020-05-27 12:07:16 +02:00
Sergey Sharybin 8cd17a9529 OpenSubdiv: Allow any order of edge topology/sharpness assignment
Makes it possible to set adjacent vertices after edge sharpness.

Initially it seemed like useful sanity check, but with time it
became rather a burden.
2020-05-27 12:07:16 +02:00
Sergey Sharybin 42cb1e3a2c OpenSubdiv: Optimize faces storage in mesh topology
Avoid per-face pointer and allocation: store everything as continuous
arrays.

Memory footprint for 1.5M faces:

- Theoretical worst case (all vertices and edges have crease) memory
  goes down from 114 MiB to 96 MiB (15% improvement).

  This case is not currently achievable since Blender does not expose
  vertex crease yet.

- Current real life worst case (all edges have crease) memory goes
  down from 108 MiB to 90 MiB (17% improvement).

- Best case (no creases at all) memory goes down from 96 MiB to 78 MiB
  (19% improvement).
2020-05-27 12:07:16 +02:00
Sergey Sharybin c971731b8f OpenSubdiv: Add regression tests for mesh topology
While this looks trivial it already allowed to catch issues in one
of previous attempt to optimize memory usage. It will totally be
useful for an upcoming refactor of face topology storage.
2020-05-27 12:07:16 +02:00
Sergey Sharybin 38b50fe393 OpenSubdiv: Hide individual topology elements
Move all API to happen via MeshTopology.

This is a preparation for an upcoming memory optimization.
2020-05-27 12:07:16 +02:00
Sergey Sharybin 15bcfc5b19 OpenSubdiv: Cleanup, remove unused code
There is no need in edge map anymore.
2020-05-27 12:07:16 +02:00
Sergey Sharybin 12c42738f3 OpenSubdiv: Add TODO avoid checking face-varying topology for equality 2020-05-27 12:07:16 +02:00
Sergey Sharybin 8e9fdd2f31 OpenSubdiv: Move preliminary geometry counters check to mesh topology 2020-05-27 12:07:16 +02:00
Sergey Sharybin a444400900 OpenSubdiv: Keep explicit storage of base mesh faces
Allows to perform comparison by doing linear comparison of indices.

Before cyclic match was used to deal with possibly changed winding from
OpenSubdiv side.

Speeds up comparison (and hence improves FPS), makes code more reliable
nut uses more memory.
2020-05-27 12:07:16 +02:00
Sergey Sharybin 1e0de7c2ea OpenSubdiv: Compare edge topology
This change makes it so topology refiner comparison will check vertices
of all existing/provided edges.

The initial claim that due to manifold nature of mesh there is no need
in "deep" edges check was wrong: some areas might only provide edges
with non-zero creases. So if crease of one edge goes changes from 1.0
to 0.0 and crease of other edge goes from 0.0 to 1.0 the old comparison
code would not have caught it.
2020-05-27 12:07:16 +02:00
Sergey Sharybin 6a8193e505 OpenSubdiv: Refactor, move mesh topology comparison to own file
Makes it easier to follow and extend.
2020-05-27 12:07:16 +02:00
Sergey Sharybin ece54172d0 OpenSubdiv: Use explicit storage for edge sharpness
Similar to previous change in vertex sharpness, explicitly store value
provided by the converter.

Allows to avoid rather fragile check for boundary edges.

Also allows to avoid need in constructing edge map. This lowers memory
footprint of the comparison process and avoids memory allocations
during the comparison (which is an extra benefit from the performance
point of view).
2020-05-27 12:07:16 +02:00
Sergey Sharybin 16aef5dc4a OpenSubdiv: Allow use of regular ordered map 2020-05-27 12:07:16 +02:00
Sergey Sharybin ad4cef38e3 OpenSubdiv: Refactor, move comparison to own file 2020-05-27 12:07:16 +02:00
Sergey Sharybin 614d70a87d OpenSubdiv: Compare sharpness based on converter
This change starts the transition of topology refiner comparison
to compare actual values given by the converter, which will not be
affected by the refinement or face winding synchronization steps.

Currently is only implemented for vertex sharpness, but will be
extended further as followup development.

Fixes T71908: Subdiv: Incorrect topology comparison, leading to poor performance
2020-05-27 12:07:16 +02:00
Sergey Sharybin 717d968fb9 OpenSubdiv: Add explicit storage for mesh topology
The idea is to use this explicit storage for topology comparison rather
than using base level. While this will have memory overhead it allows
to simplify comparison of such things as:

- Vertex sharpness (where base level from topology refiner will have it
  refined, meaning it will be different from what application requested
  for non-manifold and corner vertices).

- It will allow to simplify face-vertices comparison, where currently
  O(N^2) algorithm is used due to possible difference in face winding.

- It will also allow to avoid comparison-time allocation of edge map.

Currently no functional changes, just preparing for development which
will happen next.
2020-05-27 12:07:16 +02:00
Sergey Sharybin 5d8515ed86 OpenSubdiv: Add move semantic to the namespace 2020-05-27 12:07:16 +02:00
Sergey Sharybin b5ef644ef6 OpenSubdiv: Refactor, pass higher level object through comparison 2020-05-27 12:07:16 +02:00
Sergey Sharybin 444ca1a117 OpenSubdiv: Refactor, move utils to base
Also split them across utilities and types.
2020-05-27 12:07:16 +02:00
Sergey Sharybin 39cf673132 OpenSubdiv: Refactor, move base C-API file to base folder 2020-05-27 12:07:16 +02:00
Sergey Sharybin 98197343e8 OpenSubdiv: Cleanup, use C++ range based loop
Avoid indirection via define.
2020-05-27 12:07:16 +02:00
Sergey Sharybin be03a756e5 OpenSubdiv: Cleanup, move utility function to base type conversion 2020-05-27 12:07:16 +02:00
Sergey Sharybin 0ff665e4ce OpenSubdiv: Refactor, move type conversion to base fodler 2020-05-27 12:07:16 +02:00
Sergey Sharybin 4886a704b3 OpenSubdiv: Refactor, move evaluator to own folder 2020-05-27 12:07:16 +02:00
Sergey Sharybin 6fc9d106ad OpenSubdiv: Completely disable topology verification
Previously it was enabled for debug builds, now it is to be enabled
explicitly.

The reason for this is to reduce overhead when debugging other areas
which might involve subdivision surface. When conversion is to be
debugged set this manually in the code.
2020-05-27 12:07:16 +02:00
Sergey Sharybin 0d089ce881 OpenSubdiv: Refactor, move edge map to base folder 2020-05-27 12:07:16 +02:00
Sergey Sharybin 4ab36c4393 OpenSubdiv: Refactor creation of topology refiner
Consolidate it inside of the topology refiner implementation class,
which would allow to store extra data acquired during construction
of the OpenSubdiv's object.
2020-05-27 12:07:15 +02:00
Sergey Sharybin 57aae2a355 OpenSubdiv: Refactor, use C++ allocation for internal classes
Only use OBJECT_GUARDED_{NEW. DELETE} for structures which are part of
public C-API (and hence can not have new/delete operators overloaded).

Could try being brave and override new/delete from under C++ ifdef.
2020-05-27 12:07:15 +02:00
Sergey Sharybin c81a5f58f8 OpenSubdiv: Refactor, move topology refiner factory to topology folder 2020-05-27 12:07:15 +02:00
Sergey Sharybin 67fe31d751 OpenSubdiv: Refactor, move topology refiner to own folder
In the future factory will also be moved there.
2020-05-27 12:07:15 +02:00
Sergey Sharybin 7c0bea0d65 OpenSubdiv: Refactor, move device specific code to own files
Also, move all device files to own folder.

Makes it so checks for device availability are done in a localized
place.
2020-05-27 12:07:15 +02:00
Sebastián Barschkis 0a19b8a5b4 OpenSubdiv: Remove old GPU code
This code was accidentally reintroduced in e73d7d27dc.
2020-05-19 21:35:47 +02:00
Sebastián Barschkis e73d7d27dc Merge branch 'blender-v2.83-release' 2020-05-19 21:23:54 +02:00
Jacques Lucke cfb7664d5b Fix: build error due to missing definitions
Reviewers: sergey, brecht

Differential Revision: https://developer.blender.org/D7787
2020-05-19 17:36:40 +02:00
Sergey Sharybin 31fc01eecb OIpenSubdiv: Cleanup, move to a better sounding namespace
The code is not only part of C-API, but also implements Blender-specific
glue level implementation.
2020-05-18 17:25:07 +02:00
Sergey Sharybin 2ad5131f77 OpenSubdiv: Cleanyp, remove old GPU code
All parts of drawing (shaders, GL mesh descriptor, material partitioner
and so on) needs to be redone for the draw manager and new OpenSubdiv
library.

Removing untested code which is doomed to be replaced to make localized
refactoring easier.
2020-05-18 17:06:48 +02:00
Sergey Sharybin 22f68f85a4 OpenSubdiv: Cleanup, remove unused topology orientation code
The code was trying to make winding consistent and manifold, same as
OpenSubdiv expects it to.

Unfortunately, the code was having some issues in corner cases so the
winding wasn't really correct.
Fortunately, the latter (compared to when this code was originally
written) supports orientation on OpenSubdiv side.

Removing code which is currently unused in Blender and which had
known issues. Is simple enough to bring the code from Git history
if the functionality is needed in the future.
2020-05-18 17:06:48 +02:00
Sergey Sharybin 9aeb475e99 Subdiv: Fix wrong non-manifold subdivision in certain cases
Was happening when only partial subset of callbacks was specified.

The reason was that there was a callback to specify edges sharpness
but no callback to specify vertex sharpness, so the special case for
non-manifold edges was not run.

Fixes T75697: Multires in simple mode doesn't work correct on a plane
2020-04-22 14:26:12 +02:00
Dalai Felinto 2d1cce8331 Cleanup: `make format` after SortedIncludes change 2020-03-19 09:33:58 +01:00
Sergey Sharybin 8622372256 OpenSubdiv: Make non-full geometry less strict for sharpness
Allow to mark individual vertices as infinitely sharp even if there is
no full topology and no access to edges: infinite sharp vertices do not
need connectivity information.
2020-03-13 14:07:44 +01:00
Sergey Sharybin bcac081ad5 OpenSubdiv: Allow less topology callbacks assigned
Useful for cases when topology does not need to have any
crease or UV layers. Now instead of assigning callbacks
which returns zero data is possible to simply assign the
callback itself to NULL.
2020-02-28 14:30:49 +01:00
Brecht Van Lommel 3788901107 Cleanup: fix compiler warnings 2020-01-27 12:19:49 +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
Sergey Sharybin 9f48a04799 Fix T63766: Multiresolution behavior when using crease edge
Switch to Gregory basis patches which are tangent continuous across their
boundaries.

Originally we've used BSpline basis patches to be more compatible with the
old subdivision code, but a lot of things changed anyway.
2019-12-05 16:38:26 +01:00
Sergey Sharybin f305972377 OpenSubdiv: Initial implementation of batched evaluation
The idea is to give multiple coordinates to evaluator and evaluate them
all at once, avoiding any possible overhead.
2019-10-30 15:15:56 +01:00
Sergey Sharybin 05ee67a7c8 OpenSubdiv: Make internal evaluator aware of batched evaluation
Allows to pass multiple patch coordinates for evaluation.
2019-10-30 15:15:55 +01:00
Sergey Sharybin ca3a96c243 OpenSubdiv: Use more generic access to patch coordinates
Saves another unnecessary temporary data copy during evaluation.
2019-10-30 15:15:55 +01:00
Sergey Sharybin d3c87876c9 OpenSubdiv: Cleanup, remove old compatibility code
Consider that all builders have face-varying evaluation now.
2019-10-30 15:15:55 +01:00
Sergey Sharybin 5843827fb9 OpenSubdiv: Cleanup, remove unused class 2019-10-30 15:15:55 +01:00
Sergey Sharybin 4227a35b32 OpenSubdiv: Avoid unnecessary memory copies
Make evaluator itself to write directly to the output buffer.

Brings unmeasurable speedup and makes it possible to simplify
some buffer class logic.
2019-10-30 15:15:55 +01:00