Commit Graph

27166 Commits

Author SHA1 Message Date
Hans Goudey
b2d201cbea Cleanup: Remove outdated SubdivCCG masks assert
Missed in 1618448abd.
2024-09-11 16:35:14 -04:00
Hans Goudey
8d08701a68 Cleanup: Tweaks to SubdivCCG range utilities
Allow retrieving a face's range without a CCGKey
2024-09-11 16:08:27 -04:00
Sean Kim
ab5ce3061a Fix #127357: Expand operator crashes when cursor is not on mesh
Prior to 0df133559c, the `active_vert_` property was only ever
invalidated if the entire `SculptSession` was refreshed, even if the
cursor moved off of the mesh or if the underlying mesh type changed.

The Sculpt Expand operator was dependent on this value not being cleared
to still behave in a reasonable way from a user perspective

This commit introduces a new variable, `last_active_vert_` and
corresponding accessor methods to `SculptSession` to specifically fix
this usecase. When the active vert is cleared, if it had a valid value,
we store it in the new `last_active_vert_` variable.

Pull Request: https://projects.blender.org/blender/blender/pulls/127433
2024-09-11 19:48:31 +02:00
Hans Goudey
f1f0f2daaa Refactor: Sculpt: Move cached automask factor out of attribute system
Part of #118145.
The attribute system should be used to store user-edited data, not
temporary caches during a stroke. It's simpler and more obvious to
just store this as part of the cache created for every brush stroke.

Pull Request: https://projects.blender.org/blender/blender/pulls/127463
2024-09-11 19:25:13 +02:00
Hans Goudey
1618448abd Sculpt: Store multires grids data in separate arrays
For `SubdivCCG`, replace the dynamic array-of-struct data with separate
arrays for positions, normals, and masks. This decreases memory
bandwidth requirements for loops that only access one of these arrays.
It also significantly simplifies data access, making it more similar
to mesh data where it can just be accessed with indices.

In a simple test this change speeds up the multires sculpt brush
benchmark by 32%. It also slightly reduced BVH build time by about 12%.

In practice this means completely replacing usage of `CCGElem` for
`SubdivCCG`. The struct is still used in the older subsurf baking code
though. Removing that is a much trickier task that doesn't have short
term benefits.

Part of #118145.

Pull Request: https://projects.blender.org/blender/blender/pulls/127262
2024-09-11 15:54:46 +02:00
Jacques Lucke
e18aa65973 Fix: quit.blend is not saved as recovery file
This was broken in efb511a76d. The memfile-undo step always had
this flag set, but the non-memfile file-write did not.
2024-09-11 14:38:04 +02:00
Sergey Sharybin
a9208e9f8e Fix #126825: Crash on duplicating child collection of liboverride hierarchy
Pass CollectionChild explicitly, so the duplication code is not confused
about where the to copy light linking settings from.

Pull Request: https://projects.blender.org/blender/blender/pulls/127237
2024-09-11 11:19:23 +02:00
Campbell Barton
e00fed43e6 Cleanup: redundant struct declarations 2024-09-11 16:25:25 +10:00
Hans Goudey
853269aeb0 Sculpt: Make multires BVH build similar to mesh
Structure the multires grids PBVH build to be similar to meshes,
splitting face indices into groups instead of grid indices. This
removes one step of indexing, decreases the amount of temporary
data, and allows sharing the majority of the implementation with
the mesh BVH build.

In a test file with 4 million faces at multires level 1, this reduced
BVH build time from 149 to 70 ms. The improvement will be
significantly lower for higher subdivision levels.

Pull Request: https://projects.blender.org/blender/blender/pulls/127429
2024-09-10 22:46:04 +02:00
Iliya Katueshenock
0b7090ca37 BKE: Utilities to create curves and point clouds without attributes
Same as #118297.

Pull Request: https://projects.blender.org/blender/blender/pulls/120368
2024-09-10 21:48:59 +02:00
Hans Goudey
a4b42daf80 Refactor: Sculpt: General cleanups to ensure PBVH function 2024-09-10 15:39:03 -04:00
Hans Goudey
7cd6b7175f Sculpt: Parallelize max face size reduction during grid BVH build 2024-09-10 15:29:53 -04:00
Hans Goudey
883568c0b1 Cleanup: Improve face size variable name 2024-09-10 15:29:53 -04:00
Hans Goudey
8cd80b0fac Cleanup: Correct comment and add note
I think the limit is unnecessary because I can't think of a good
reason for it and there is no reasoning in the git history.
2024-09-10 15:29:53 -04:00
Falk David
942499382d GPv3: Vertex Paint Mode
This adds the vertex paint mode and all of the tools
from GPv2:
 * Average
 * Blur
 * Draw
 * Replace
 * Smear

Pull Request: https://projects.blender.org/blender/blender/pulls/125674
2024-09-10 18:56:31 +02:00
Sybren A. Stüvel
3fdc9e9637 Refactor: convert BKE_action.h to C++
Move the contents of `BKE_action.h` into `BKE_action.hh` and remove
C-isms.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/127407
2024-09-10 14:55:47 +02:00
Sybren A. Stüvel
636d83fbea Refactor: convert BKE_nla.h to C++
Rename `BKE_nla.h` to `BKE_nla.hh` and remove C-isms.

No functional changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/127395
2024-09-10 13:41:01 +02:00
Iliya Katueshenock
957330043f Refactor: Attributes: support different source and destination domains in propagation utilities
Pull Request: https://projects.blender.org/blender/blender/pulls/127026
2024-09-10 12:59:03 +02:00
Sybren A. Stüvel
ed0cfe7312 Anim: fix crash drawing Action groups when built without Action Slots
Fix a crash that happens when drawing Action groups in the dope sheet, when
Blender is built without experimental features (hence without Action
slots) and it has loaded a blend file with slotted Actions.

Basically a pointer needs to be set to `nullptr` when reading such a file,
as it ensures that the rest of the code treats the group as "from a legacy
Action".

Pull Request: https://projects.blender.org/blender/blender/pulls/127339
2024-09-10 10:59:29 +02:00
Hans Goudey
dc4ff79f64 Cleanup: Formatting
VS Code doesn't stage the whitespace changes apparently.
2024-09-09 09:56:13 -04:00
Hans Goudey
6462216ef7 Cleanup: Sculpt: Simplify arguments to BVH build function
Pass the already partitioned span face indices rather than the full
array and separate start and end indices.
2024-09-09 09:50:00 -04:00
Hans Goudey
eee34de007 Sculpt: Simplify and optimize BVH build node partitioning
Use `std::partition` instead of implementing something similar
ourselves. This is much easier to understand, and it's also much
faster and requires less memory during the build.

I observed a change in the runtime building a 16 million face
BVH from 492 to 389 ms, a 1.27x improvement (with a Ryzen
7950x).

`std::partition` is not multithreaded. I expect there would be
some improvement from multithreading this, at least for the
first few splits.

Currently this only applies to Mesh sculpting.

Pull Request: https://projects.blender.org/blender/blender/pulls/127332
2024-09-09 15:16:28 +02:00
Hans Goudey
1bc0ec1b80 Sculpt: Improve mesh BVH build time by storing less temporary data
Each time the face bounds are used after they're initially computed, we
recompute the center of the bounds. We only use the actual bounds to
calculate the bounds of each node to decide how it should be split.
This commit changes to store the bounds centers instead, and just use
the full bounds as a type for the parallel reduction.

In a test with a 16 million face grid on a Ryzen 7840U, I observed a
1.28x decrease in BVH build time, from 1072 to 836 ms.

I didn't apply a similar change to multires grids BVH building because
it's not clear the same bottleneck exists due to the lower ratio of
"primitives" (grids) to final subdivided vertices.
2024-09-08 16:54:51 -04:00
Jacques Lucke
2ddc574ad9 Fix #127233: performance regression with new attribute filters
When I first developed the attribute filters they were just a `FunctionRef`
and thus could be stored by value in this struct. Now that they are a
virtual type, that is not possible anymore.
2024-09-07 19:04:54 +02:00
Hans Goudey
2952498724 Cleanup: Sculpt: Add debug timing for multires BVH build 2024-09-06 12:13:04 -04:00
Sybren A. Stüvel
fe96a0c3f6 Anim: fix crash when writing empty action groups
It was just a missing 'else' clause around some should-have-been-
conditional code.

Pull Request: https://projects.blender.org/blender/blender/pulls/127241
2024-09-06 14:33:57 +02:00
Jeroen Bakker
458faa6486 Preferences: GPU backend selection
This PR allows users to select a GPU backend.

In the system tab of the user preferences the GPU backend can be selected in the `Display Graphics` panel.
It will require a restart of Blender before the changes become effective.

During startup minimum requirements are checked. Blender will switch automatically
to OpenGL when no compatible Vulkan device could be detected. A dialog will be shown
to inform the user.

The setting of the in the `Display Graphics` panel are still overridden when blender is started
using the `--gpu-backend` option. When starting blender with `--debug-gpu` the backend
detection will print to the console.

See PR for detailed information and screenshots of the UI.

Implements #126504
Pull Request: https://projects.blender.org/blender/blender/pulls/126545
2024-09-06 08:28:41 +02:00
Campbell Barton
2954323c2d Fix missing depsgraph tags after removing an object from a collection
Follow up to fix for #127213, resolving the bug in other contexts.
2024-09-06 12:05:33 +10:00
Hans Goudey
e05d55f4c9 Cleanup: Remove unnecessary PBVH free function
Just call `reset()` directly instead.
2024-09-05 14:51:19 -04:00
Hans Goudey
c6e426fc8f Refactor: Sculpt: Pass object to sculpt session free function 2024-09-05 14:46:35 -04:00
Hans Goudey
d33e708343 Refactor: Sculpt: Use function to access PBVH
Part of #118145.
In the future we want to move the ownership of the BVH tree to the
original mesh rather than `SculptSession`, in order to persist it
across some more general non-topology changing operations like
node tools. The first step of that change is replacing all places
that used `SculptSession::pbvh` for access with a function.
2024-09-05 14:16:40 -04:00
Hans Goudey
4c8e1fbeca Cleanup: Reduce indentation in sculpt object update function 2024-09-05 14:07:16 -04:00
Hans Goudey
39e653d479 Cleanup: Sculpt: Add geometry index accessor functions to node structs
Add `.faces()`, `.verts()`,`.all_verts()`, and `.grids()` functions to nodes.
Don't change BMesh data access yet. More complex const correctness
makes that situation more difficult.

Pull Request: https://projects.blender.org/blender/blender/pulls/127201
2024-09-05 20:07:03 +02:00
Mike93
cc5ed48cd3 Modifiers: Add custom attribute weight support to bevel modifier
As of 2a56403cb0, bevel weight data is stored as a generic
attribute. The bevel modifier is currently hard-coded to use the
`bevel_weight_edge` attribute as the data source for the weights.
This commit adds a string textbox where the user can specify alternate
attributes for the bevel's edge weights.

The string name field is added as a search button which provides a list
of all attributes in the original mesh. This is meant to work similarly
to geometry nodes, so mismatched attribute data types and domains are
automatically converted/interpolated as necessary. Attributes created
by previous modifiers can also be used, but they won't appear in the
search menu.

Co-authored-by: Hans Goudey <hans@blender.org>
Pull Request: https://projects.blender.org/blender/blender/pulls/117366
2024-09-05 17:15:34 +02:00
Hans Goudey
5e63435e74 Sculpt: Store faces instead of triangles in BVH
Currently each sculpt BVH node stores the indices of its triangles.
It also stores triangles of vertex indices local to the node, and also
potentially the indices of the face corners in the node.

The problem with this is that the leaf nodes store plenty of redundant
information. The triangles in each face aren't split up between multiple
nodes, so storing triangle instead of face indices is unnecesssary. For
the local vertex triangles, there is also duplicate information-- twice
the number of indices as necessary for quad meshes. We also often need
a node's faces, which is currently done with a triangle to face map
using 4 bytes per triangle.

This "double storage" results in extra processing too. For example,
during BVH builds we need to combine twice the number of "Bounds"
objects for a quad mesh. And we have to recalculate a node's face
indices every time we want them.

This commit replaces the PBVH triangle indices with face indices, and
replaces the local vertex triangles array by using a `VectorSet` to store
each node's vertex indices. This results in significant performance and
memory usage improvements.

|                   | Before   | After    | Improvement |
| ----------------- | -------- | -------- | ----------- |
| BVH build time    | 1.29 s   | 0.552 s  | 2.3x        |
| Brush stroke time | 3.57 s   | 2.52 s   | 1.4x        |
| Memory usage      | 4.14 GiB | 3.66 GiB | 1.3x        |

All testing is done with a 16 million vertex grid and a Ryzen 7950x.

My guess is that the brush stroke time is improved by the added sorting
of node vertex indices, and by the overall increase in memory bandwidth
availability for mesh data. Personally I'm pleasantly surprised by the
whole improvement, since I usually try to avoid hash table data
structures for this sort of use case. But a lookup into this set ends up
just being a boolean and with an array lookup, so it's quite cheap.

Pull Request: https://projects.blender.org/blender/blender/pulls/127162
2024-09-05 16:21:43 +02:00
Jacques Lucke
871b25b219 Geometry: generalize attribute filters beyond just for anonymous attributes
This introduces the concept of an #AttributeFilter. It's used to tell a geometry
algorithm which attributes it should process/propagate and which can be ignored.

We already had something similar before named
`AnonymousAttributePropagationInfo`. However, as the name implies, this was
specific to anonymous attributes. This had some downsides:
* A lot of code had to be aware of the concept of anonymous attributes even if
  it did nothing special with anonymous attributes.
* For non-anonymous attributes we often had a separate `Set<std::string> skip`
  parameter. It's not nice to have to pass two kinds of filters around and to
  have to construct a `Set<std::string>` in many cases.

`AttributeFilter` solves both of these downsides.

Technically, `AttributeFilter` could also just be a `FunctionRef<bool(StringRef
attribute_name)>`, but that also has some issues:
* The `bool` return value is often ambiguous, i.e. it's not clear if it means
  that the attribute should be processed or not. Using an enum works better.
* Passing function refs around and combining them works, but can very easily
  lead to dangling references.
* The default value of a `FunctionRef` is "empty", i.e. it can't be called. It's
  generally more nice to not have a special case for the default value. Now the
  default `AttributeFilter` propagates all attributes without any extra handling
  on the call-site.

Pull Request: https://projects.blender.org/blender/blender/pulls/127155
2024-09-05 11:33:35 +02:00
Christoph Lendenfeld
a661a7bf89 Refactor: Move Pose code out of the kernel
Move the functions
* `BKE_pose_apply_action_selected_bones`
* `BKE_pose_apply_action_all_bones`
* and `BKE_pose_apply_action_blend`

out of the blender kernel and into animrig.

This will allow solving #126969 without having to include
animrig code in the blender kernel.

Pull Request: https://projects.blender.org/blender/blender/pulls/126978
2024-09-05 10:41:34 +02:00
Campbell Barton
acde253b9d Fix invalid MeshRuntime::deformed_only for evaluated edit-meshes
Between 2.93 & 3.2 a regression was introduced where evaluated
meshes from the modifier stack would always have their deformed_only
value set to false.

Resolve by enabling for meshes returned by
BKE_mesh_wrapper_from_editmesh and ensure the value is kept when the
modifier duplicates the cage mesh.

Resolves #123138.
2024-09-05 15:56:39 +10:00
Hans Goudey
c6fe321718 Fix: Sculpt: Data race saving BMesh node original data
Replace modification of vertex indices with a VectorSet for local
index calculation, allowing proper parallelization of the saving.
2024-09-04 21:35:37 -04:00
Hans Goudey
9c86d5e861 Cleanup: Sculpt: Use C++ Array for original BMesh node data 2024-09-04 21:35:37 -04:00
Hans Goudey
fafe7ccc35 Cleanup: Add define for printing PBVH build timing information
Pull Request: https://projects.blender.org/blender/blender/pulls/127160
2024-09-04 22:33:29 +02:00
Hans Goudey
2aed58a285 Sculpt: Finalize mesh leaf nodes in a separate loop
Decreases BVH build runtime by approximately 6%.
Improve cache locality in the initial splitting loop and the finalization
of mesh leaf nodes by processing them in separate loops. The second
loop calculates the node's vertex indices.
2024-09-04 22:33:27 +02:00
Hans Goudey
fdb5af79d5 Cleanup: Remove unused variable 2024-09-04 22:33:27 +02:00
Hans Goudey
613055016d Sculpt: Parallelize bounds calculation during BVH build
Speeds up building the sculpt BVH tree by over 3x.
The total bounds for all the triangles/grids in the current node is
recalculated for every iteration of the node splitting algorithm that
builds the BVH tree. The first step was parallelized, but since the
number of elements is just divided in half every time, many of the
subsequent bounds calculations are significantly large to benefit from
parallelism too (actually all of them for mesh BVH currently, since the
leaf size is about 4000).
2024-09-04 22:33:27 +02:00
Hans Goudey
689f3aeb91 Refactor: Sculpt: Simplify BVH build material index split 2024-09-04 22:33:27 +02:00
Hans Goudey
89095826fd Fix: Debug build error after recent cleanup
The assert is redundant with asserts in `Span` now.
2024-09-04 13:58:58 -04:00
Hans Goudey
d84522390c Sculpt: Ignore sharp faces when building BVH tree
For historical reasons, the BVH tree considered face sharpness similar
to material indices and tried to make the value match for all faces in a
node. This is unnecessary because PBVH drawing supports mixed
sharpness within a node.
2024-09-04 13:26:16 -04:00
Hans Goudey
b14badf3ea Cleanup: Subdiv: Use Span and float3 for vertex positions 2024-09-04 13:13:43 -04:00
Hans Goudey
d601bf7e3d Sculpt: Restructure PBVH drawing to avoid overhead
This commit rewrites the PBVH drawing using many of the principles from the
ongoing sculpt refactor. First of all, per BVH node overhead is minimized.
Previously the main entry point to the drawing API was per node, so there
was significant overhead fetching global data and maintaining caches on
a per-node basis. Now all of that "global" work happens for the entire
geometry.

We also now avoid creating wireframe index buffers and batches unless
the viewport actually requests wireframe data. This was theoretically
possible before, but the whole logic flow was so convoluted that the
optimization was too difficult. Similarly, multithreading is used more
consistently now. Because of OpenGL, flushing vertex/index buffers to
the GPU has to happen on the main thread, but everything else can be
multithreaded. With outer loops processing all relevant PBVH nodes,
it's now trivial to apply multithreading wherever possible.

Testing performance, overall this commit results in a 10% improvement in
the time between opening a file with a large mesh sculpt and the first
possible interaction. Specifically I measured a change from 8.4 to 7.6
seconds on a completely visible 16 million vertex mesh with a Ryzen 7950x.
I also measured a decrease in memory usage from 4.79 to 4.31 GB.
For multires I observed a similar improvement in memory usage,
though less of a performance improvement.

There are still significant opportunities for future improvement. #122775
would be particularly helpful. #99983 would be helpful too, though more
complicated, and #97665 describes the problems a bit more generally.

Part of #118145.

Pull Request: https://projects.blender.org/blender/blender/pulls/127002
2024-09-04 17:40:50 +02:00
Hans Goudey
e5988cf912 Refactor: Sculpt: Miscellaneous cleanups to node intersect/nearest loops
- Use `float3` C++ vector instead of pointers
- Return directly instead of using temporary boolean variable
- Use separate loops for "original positions" case to simplify hot loops
2024-09-04 11:07:23 -04:00