Commit Graph

3900 Commits

Author SHA1 Message Date
Chris Clyne
5a27280916 EEVEE: Light & Shadow linking
This adds feature parity with Cycles regarding light and shadow liking.

Technically, this extends the GBuffer header to 32 bits, and uses
the top bits to store the object's light set membership index.
The same index is also added to `ObjectInfo` in place of padding bytes.

For shadow linking, the shadow blocker sets bitmask is stored per
tilemap. It is then used during the GPU culling phase to cull objects
that do not belong to the shadow's sets.

Co-authored-by: Clément Foucault <foucault.clem@gmail.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/127514
2024-10-03 18:41:06 +02:00
Hans Goudey
ce301be39e Fix #128328: Missing PBVH draw data reupload of non-visible nodes
For example, undoing an entire-mesh operation when only a small part
of it is visible wouldn't affect the currently out-of-view BVH nodes.
2024-09-29 21:20:12 -04:00
Hans Goudey
5e46e3d28a Subdiv: Remove topology refiner C-API wrapper
Remove the indirection previously used for the topology refiner
to separate C and C++ code. Instead retrieve the base level in
calling code and call opensubdiv API functions directly. This
avoids copying arrays of mesh indices and should reduce
function call overhead since index retrieval can now be inlined.
It also lets us remove a lot of boilerplate shim code.

The downside is increased need for WITH_OPENSUBDIV defines
in various parts of blenkernel, but I think that is required to avoid
the previous indirection and have the kernel deal with OpenSubdiv
more directly.

Pull Request: https://projects.blender.org/blender/blender/pulls/120825
2024-09-27 19:01:12 +02:00
Pratik Borhade
7665e28b37 GPv3: Assert in weight paint with zero points
Memory allocated to vertex buffer but the total verts are zero. This
triggers assert in bind function when `vbo_size_` is zero. Exit out of
funtion early to prevent the assert.
Also wrap `DRW_shgroup_call_no_cull` with if check.

Pull Request: https://projects.blender.org/blender/blender/pulls/128248
2024-09-27 17:29:08 +02:00
Miguel Pozo
2223d995fc Fix: Draw: Bounds usage
The first commit ensures IsectBoxes are not set up unless
they are valid.

The second commit renames
`drw_bounds_are_valid` to `drw_bounds_corners_are_valid`,
and `drw_bounds_culling_enabled` to `drw_bounds_are_valid`
so it's harder to set up an invalid `IsectBox` by mistake.

(Continuation of #127807)

Pull Request: https://projects.blender.org/blender/blender/pulls/128125
2024-09-25 19:58:38 +02:00
Laurynas Duburas
84dedfaf4b Curves: smooth handles
Adds antialiasing to curve's handles and thickness to active ones.
Also handles now react to
 `Preferences > Interface > Display > Resolution Scale` and
`Preferences > Themes > 3D Viewport > Edge Width` as they do in
legacy curves.

Pull Request: https://projects.blender.org/blender/blender/pulls/122910
2024-09-25 15:21:31 +02:00
Campbell Barton
1ceab37693 Cleanup: use blender::float3 for BKE_bmbvh_* API 2024-09-24 15:35:59 +10:00
Falk David
3c8d4becc8 Cleanup: GPv3: Return reference from GreasePencil::layer() functions
Since we only assert and never return `nullptr`, it's better to just return a reference.
The access into the span already asserts anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/128025
2024-09-23 13:54:02 +02:00
Campbell Barton
0fc27c8d81 Cleanup: spelling in comments 2024-09-20 13:14:57 +10:00
Hans Goudey
9d225f7116 Sculpt: Avoid face corners counting overhead in drawing code
Currently the `sum_group_sizes` call used to count the number
of elements in GPU vertex buffers for each PBVH node stands out
in profiles, taking a few percent of the total time when building
PBVH GPU data. Since the number of corners in a node doesn't
change, it's simpler to just store it in the node. We could
eventually cache it somewhere else too, if there was a benefit
to not storing it in the node itself.
2024-09-19 22:31:55 -04:00
Hans Goudey
43e4f93ca3 Cleanup: Use index mask utility function for setting bits 2024-09-19 15:16:58 -04:00
Clément Foucault
02cf5f5f0f Fix #127774: Flat Object matrix leads to incorrect culling
Object with degenerate transform matrix can lead to flat
bounds on GPU. This in turn lead to NaN intersection planes
inside `IsectBox`.

Compute (pseudo) size of matrix and bypass culling is any
axis is too small.

The other part of the patch makes sure that there is a
distinction between disabled culling and invalid
bounding boxes.

Pull Request: https://projects.blender.org/blender/blender/pulls/127807
2024-09-19 14:09:57 +02:00
Hans Goudey
5c792e429f Fix #127638: Crash switching to wireframe with custom bone shape
The "edge fac" buffer's dependency on loose geometry indices wasn't
encoded properly in `calc_loose_geom`.
2024-09-16 11:17:45 -04:00
Clément Foucault
0d9ab189d1 Fix: #126524: Overlay: Missing loose geometry wireframe with sub-D mesh
This was caused by default normal for these loose geom
to not be zero.

Setting it to zero fixes the drawing issue.
2024-09-16 16:57:06 +02:00
Clément Foucault
d3b655f76d Fix: #127135: Curve and hair drawing asserting on 0 sized VBO
These buffers are bound as texture buffers and will have
their backend object created whether or not the subsequent
drawcall is emited.

Ensuring a minimum size fixes the issue.
2024-09-16 16:01:59 +02:00
Clément Foucault
019bc5127a Overlay-Next: Xray Outline
Port the outline wire prepass shader to primitive
expansion API and enable it for xray mode.

Rel #102179

Pull Request: https://projects.blender.org/blender/blender/pulls/127657
2024-09-16 11:24:40 +02:00
Hans Goudey
c6ce6dbe01 BLI: Add IndexMask set_bits function
This is like "to_bits" but doesn't clear the bit span first.

Pull Request: https://projects.blender.org/blender/blender/pulls/127625
2024-09-14 21:09:41 +02:00
Hans Goudey
c5ccc8ceea Fix #127602: Sculpt multires drawing crash with material index attribute
The evaluated mesh is empty since its data is replaced with the SubdivCCG.
2024-09-14 13:23:38 -04:00
Hans Goudey
0499e061d0 Cleanup: Sculpt: Remove drawing update tests
Updating attributes is now done specifically for each attribute,
and topology and visibility updates tag the draw cache data
explicitly too. That makes checking for updates with these
tags unnecessary.
2024-09-14 13:01:42 -04:00
Hans Goudey
b77ff173b0 Refactor: Sculpt: Use bit vector for visibility update tags
Also refactor topology update tags, which are used quite similarly
(they mean the same for the drawing code, except for BMesh).

Part of #118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
76c322047e Sculpt: Only re-upload mask attribute data
Similar to the previous commits, previously all GPU buffers
were recreated when only masks changed. Now only
that masks are re-uploaded, using the same mechanism.

Part of #118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
d24e8029d2 Sculpt: Only re-upload face color attribute data
Similar to the previous commit, previously all GPU buffers
were recreated when only a color attribute changed. Now only
that attribute is re-uploaded, using the same mechanism.

Part of #118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
60ab232afb Sculpt: Only re-upload face set data when changed
Similar to the previous commit, previously all GPU buffers
were recreated when only face sets changed. Now only face
sets are re-uploaded, using the same mechanism.

Part of #118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
0c677e9494 Sculpt: Only change position draw buffers on PBVH deformation
Previously tagging node positions dirty set the `PBVH_UpdateDrawBuffers`
flag which was then used by `node_draw_update_mask` and
`tag_all_attributes_dirty`, which, as hinted by the name, causes a refresh
of all the PBVH GPU vertex buffers, not just positions and normals.

Instead of using that flag, add a function to the draw cache to tag only
position-related data dirty. This should give a performance improvement
when there are also face sets, masks, and/or generic attributes being
extracted for drawing.

Part of $118145.
2024-09-14 13:01:42 -04:00
Hans Goudey
afa1a6bebf Fix: Data race writing to bitmap in PBVH draw
Mistake in d601bf7e3d.
A bit vector can't be written to in parallel.
2024-09-14 13:01:42 -04:00
Clément FOUCAULT
fc5d3fb998 Overlay-Next: Use unique handle per object
Add a new function to the draw manager to only
issue a unique resource ID per `ObjectRef`.
This avoids the memory overhead of duplicating
the handle for each overlay.

The handle is stored inside the `ObjectRef` on
first query.

Rel #102179
2024-09-14 12:43:39 +02:00
Hans Goudey
13f179a9c0 Cleanup: Add utility function to sum offset indices group sizes
I've done this a few times and would have benefited from a utility
function for it, apparently it's done in a few more places too. The
utilities aren't multithreaded for now, it doesn't seem important
and often multithreading happens at a different level of the call
stack anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/127517
2024-09-12 20:28:35 +02:00
Hans Goudey
5ff4e5fcb9 Sculpt: Avoid rebuilding draw vertex buffers for visibility changes
Use the possibility from ad7d7212c1
to make changes to visibility a bit snappier.
2024-09-12 11:39:55 -04:00
Hans Goudey
bd96b378a6 Sculpt: Avoid processing hidden nodes for drawing
When "update only visible" is turned on (during strokes or based on
the mode option), skip updating draw buffers for invisible nodes.
2024-09-12 11:39:55 -04:00
Hans Goudey
f52b813c36 Fix #127462: Sculpt drawing crash with hidden mesh faces
Mistake in ad7d7212c1.
2024-09-12 11:39:55 -04:00
Clément Foucault
c82ddedb9b Overlay-Next: Image Space
Port all Image editor overlays.

Rel #102179

Pull Request: https://projects.blender.org/blender/blender/pulls/127366
2024-09-11 18:26:34 +02:00
Laurynas Duburas
30724ddecd Overlay-Next: Fade
Overlay-Next version of  Fade in Mesh edit mode and Fade geometry in armature pose mode.

Rel #102179

Pull Request: https://projects.blender.org/blender/blender/pulls/127247
2024-09-11 17:29:26 +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
Campbell Barton
e00fed43e6 Cleanup: redundant struct declarations 2024-09-11 16:25:25 +10:00
Hans Goudey
5d429bb063 Fix #127400: Sculpt mode drawing uses wrong version of color attribute 2024-09-10 14:55:25 -04:00
Hans Goudey
ad7d7212c1 Sculpt: Face corner indexed mesh GPU data extraction
Reduce VBO data uploaded to the GPU by a bit less than 2x, at the cost of
creating triangle index buffers. Since the index buffers only need to be
created when topology changes, this means significantly less data needs
to be uploaded to the GPU while sculpting. The hot loops for extracting
mesh data also don't need to access triangles or face visibility, and also
drawing can become more efficient with indices for cached vertex values.

Part of #118145.

Pull Request: https://projects.blender.org/blender/blender/pulls/127351
2024-09-09 18:19:16 +02:00
Vitalijs Komasilovs
0db13bef19 Fix #126463: EEVEE: wrong texture binding for Curves Info node
Fixing texture binding according to `Curves Info` node attributes.

Pull Request: https://projects.blender.org/blender/blender/pulls/127206
2024-09-09 13:03:04 +02:00
Miguel Pozo
eab640e044 Draw: Batch shader compilation for image render
Enable deferred parallel batch compilation for image renders.
This replaces the use of the `WM_job` system with a regular thread,
since `WM_job` requires access to the main context,
which is not accessible from the render thread.
It also simplifies the system so it creates a single thread at startup
and deletes it at exit.

Pull Request: https://projects.blender.org/blender/blender/pulls/125005
2024-09-06 18:13:43 +02:00
Clément Foucault
dc89c935fa GPv3: Implement Wireframe batch
Fix #120604

Pull Request: https://projects.blender.org/blender/blender/pulls/127147
2024-09-06 16:50:21 +02:00
Laurynas Duburas
4948ade694 Overlay-Next: Edit-Mesh measurements
Overlay-Next version of mesh measurements.

Rel #102179

Pull Request: https://projects.blender.org/blender/blender/pulls/127124
2024-09-06 16:45:40 +02:00
Clément FOUCAULT
a4cd59e369 Overlay-Next: Prepass: Grease Pencil
Allow selection of grease pencil objects.

Rel #102179

Pull Request: https://projects.blender.org/blender/blender/pulls/127238
2024-09-06 13:29:53 +02:00
Hans Goudey
07d7404390 Fix: Correct wireframe drawing after recent PBVH storage refactor
Somehow this untested implementation made it in, I thought I had
tested this. The mistake I made was imagining the VBOs were "indexed"
using the node vertex indices, but we use a flat duplicate-per-triangle
vertex VBO format.
2024-09-05 15:42:15 -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
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
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
Clément FOUCAULT
093192a9d0 Cleanup: DRW: Remove unused variable warning 2024-09-05 12:23:43 +02:00
Campbell Barton
3a1e637e26 Cleanup: spelling in comments 2024-09-05 11:31:47 +10: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
Clément Foucault
508b39661d Overlay-Next: Armature
Functional Changes:
- Custom shapes using empties now supports line width.
- Line width is supported on MacOS.
- Fixed Stick bone drawing on MacOS.

Some shaders are duplicated and ported to the new
primitive expansion API.

The legacy code inside `overlay_armature.cc` have been
guarded behind `NO_LEGACY_OVERLAY` which can
be enabled to make sure no legacy code is used unnoticed.
This allows for spotting more easily code that needs to be
ported. Moreover, it is easier to remove this legacy code
when the time comes.

Rel #102179

Pull Request: https://projects.blender.org/blender/blender/pulls/126474
2024-09-04 12:56:37 +02:00