Use float3, float3x3, and Array for data used for mesh crazyspace
calculation. Propagate the change wherever necessary to not add
more casting to the old C types.
Because `ObjectRuntime` (and therefore `DEGObjectIterData`) became
non-trivial structs, the code that swaps iterators for RNA depsgraph
object iteration had to be changed a bit to be more friendly to C++
memory semantics.
Pull Request: https://projects.blender.org/blender/blender/pulls/114998
This commit removes knowledge about face sets from the PBVH,
and changes iteration over faces to not depend on the PBVH face
iterator abstraction. Though this adds slightly more boilerplate to
iteration over faces, it makes the whole process more data oriented
and allows use of index-based utilities like `gather` and `scatter`
in the mesh case, and simpler iteration over BMesh faces for
dynamic topology.
Setting face sets is now specialized per PBVH type in a few places
in a similar way. The general goal is to reduce branching and function
calls at the lowest level of hot loops, and to make code more aware
of the data structures it uses, both for performance and clarity.
Since the remaining uses of the face iterator are removed,
the iterator itself is removed too.
Related commits:
- 97f2b01ea9
- 756dea7ca1
- a6a2af5fdd
Pull Request: https://projects.blender.org/blender/blender/pulls/114417
These two values are already stored in the mesh, and they have no
relation to the PBVH's goal as an acceleration structure. Similar to
a6a2af5fdd, remove the values from the PBVH and
just access them from the mesh as necessary.
Pair-reviewed in person with Sergey
Mainly to simplify code and also add some add type safety, replace
`GSet` with `blender::Set` for the storage of BMesh triangles and
vertices on each PBVH node. Some initial tests point to better
performance too, but the numbers are hard to verify so far.
Because of the larger `PBVHNode`, memory usage slightly increases
(observed a 2% increase with a 1M face grid) for regular Mesh sculpting,
but it seems `Set` is more memory efficient than `GSet`, because I also
observed a 10% decrease in memory usage for dynamic topology.
In the future nodes can be split in a more data-oriented fashion to
reduce memory usage overall.
This also makes it simpler to switch to another type in the future.
Pull Request: https://projects.blender.org/blender/blender/pulls/113907
Significantly reduce the amount of manual memory management by
replacing owning pointers with `blender::Array`. This also simplifies
counting the size of the undo steps and iterating over the array values
in some cases.
This is already separated per PBVH type, we can make use of that
to simplify the loops for the types with the aim of sharing code in
a simpler and more performance-friendly way. Ideally this could
be written as `array_utils::scatter`, but we don't have that utility
function now, so just write the raw loop for now.
Pass the mesh to the drawing functions so it doesn't have to be
retrieved from the PBVH. It's nice to rely less on the PBVH `me`
pointer, since it's a fairly ugly "back pointer" which isn't necessarily
good design.
The assert was assuming that the attribute request is properly
initialized and that was not the case: the "special" data layers
like coordinates, normals, masks, and face sets did not initialize
domain in the attribute request.
The domain is now properly initialized. As well as there is an
assert added in other PBVH types for the face sets. It is possible
to add asserts in more places, but it is not directly related to
this CL.
Pull Request: https://projects.blender.org/blender/blender/pulls/113354
The grid was pointer was moved to the next element at every loop, which
made `vi.grid` and `vi.mask` disagree. Instead, iterate the grid before
accessing data, so the pointers agree. To avoid unrolling the first loop
iteration or adding a branch for the first iteration, start the grid at
a -1 offset.
Pull Request: https://projects.blender.org/blender/blender/pulls/113015
After 97f2b01ea9, the iterator's mask data is just read only,
so there's no point in storing it as a pointer. This simplifies the code
using the mask data, since the default only needs to be handled once.
Currently the iteration over a PBVH node's vertices retrieves mutable
access to the mask custom data layer. This isn't threadsafe, but it is
done in the multithreaded loops over all nodes.
In general, we need to be more careful and conservative about storage
of non-const pointers to mesh data. Ideally we would only have one
mutable reference to a resource at a time. And we should avoid doing
work like looking up custom data layers more than we need to.
To that end, make the pointer to the custom data layer used everywhere
const, and retrieve mutable access before parallel node iteration with
a specific function, and write to the mask data with that in mind.
This pushes us in the direction of sharing less code per PBVH type.
In my opinion that's a good thing, because we can actually optimize for
each type. For example, `write_mask_data` gives a picture of
how each of these hot loops could become much simpler.
Pull Request: https://projects.blender.org/blender/blender/pulls/112690
Switch from face pointers to indices, with the following benefits:
- Halve memory usage required for array (saves 16 MB with 1 million quads).
- Allow better code reuse with index-based utilities.
- Ease future replacement of `SubdivCCGFace` with mesh's face offsets.
- Allow future replacement of array with `Mesh::corner_to_face_map()`
- Potentially lower memory bandwidth required during multires evaluation
- Simplify retrieval of index in `BKE_subdiv_ccg_grid_to_face_index`.
For clarity, `gridfaces` was renamed to `grid_to_face_map`.
Pull Request: https://projects.blender.org/blender/blender/pulls/111078
Keeping a mutable reference to vertex normals for the entire lifetime
of the PBVH structure makes caching the normals and sharing the cache
harder than it should be. Generally code is safer when we reduce the
number of mutable references to data.
Currently the normals are modified in two places. First is the sculpt
mesh normal recalculation. There we can just retrieve the normals from
the mesh each time. Second is the restore from an undo step. That is
unnecessary because the normals are marked for recalculation anyway.
It doesn't even make much sense to store the normals in an undo step
when we can easily recalculate them based on new positions.
This change helps with #110479. These were also the last place that
kept a mutable reference to normals. I tested undo and redo after
sculpting, and it works well for each PBVH type.
Pull Request: https://projects.blender.org/blender/blender/pulls/111470
Call functions directly in lambdas rather than passing their
arguments in a separate void * argument. This can be changed
more in the future to move callback arguments out of smaller
structs.
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.
While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.
Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.
Some directories in `./intern/` have also been excluded:
- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.
An "AUTHORS" file has been added, using the chromium projects authors
file as a template.
Design task: #110784
Ref !110783.
The goal is to move to more data oriented design, reducing memory
usage and simplifying code by clarifying data access, avoiding
unnecessary levels of abstraction, and reusing code.
- Simplify threading with the C++ threading API
- Pass the faces to update with an IndexMask instead of a pointer array
- IndexMask uses less memory and simplifies masking and iteration
- Store the grid to face map with indices instead of pointers
- Now this is exactly the same as `build_loop_to_face_map`
Use StringRef where possible to avoid copying strings, avoid
redundant string returns, and use std::string for attribute
request names now that all the relevant code is C++.
Dynamic topology drawing can now use the smooth status saved in each
edge. Because of that, the "Smooth Shading" draw option is unnecessary
and just adds confusion because of inconsistency between dynamic
topology drawing and other modes.
Fixes#109191
Pull Request: https://projects.blender.org/blender/blender/pulls/110548
One thing to point out is that `PBVH::nodes` is now stored in a `Vector`
which replaces the manual amortized growth. That requires explicitly
setting the defaults of PBVHNode fields for default initialization.
Similar to f0b53777c8
Implements part of #101689.
The "poly" name was chosen to distinguish the `MLoop` + `MPoly`
combination from the `MFace` struct it replaced. Those two structures
persisted together for a long time, but nowadays `MPoly` is gone, and
`MFace` is only used in some legacy code like the particle system.
To avoid unnecessarily using a different term, increase consistency
with the UI and with BMesh, and generally make code a bit easier to
read, this commit replaces the `poly` term with `poly`. Most variables
that use the term are renamed too. `Mesh.totface` and `Mesh.fdata` now
have a `_legacy` suffix to reduce confusion. In a next step, `pdata`
can be renamed to `face_data` as well.
Pull Request: https://projects.blender.org/blender/blender/pulls/109819
Make it harder to retrieve a mutable attribute from const a const mesh,
and use the attribute search function to check multiple domains and
colors at once.
* Renamed BKE_pbvh_raycast_project_ray_root to
BKE_pbvh_clip_ray_ortho for greater
clarity.
* BKE_pbvh_clip_ray_ortho no longer strictly clips
within the input ray interval. This is not necassary
for orthographic views and was too prone to floating
point error. The function is only called to clip
brush rays for orthographic views so this is acceptable.
Split much of BKE_pbvh.h into BKE_pbvh_api.hh.
BKE_pbvh.h is included by BKE_paint.h, which in
turn is included by large amounts of code including
RNA.
This makes it extremely difficult to change
or clean up the PBVH API, since each modification
of BKE_pbvh.h can take 20-30 minutes to compile,
even on a quad-core system with an SSD. This
commit fixes that by moving most of BKE_pbvh.h
into another file and just having the core,
external-facing interfaces in BKE_pbvh.h.