Commit Graph

9427 Commits

Author SHA1 Message Date
Clément Foucault
2892b494bd Cleanup: DRW: Remove some global access to DRWContext
Rel #136090
2025-03-18 17:48:54 +01:00
Clément Foucault
8c7cb9d3c7 Cleanup: DRW: Flatten global access to DRWContext
Rel #136090
2025-03-18 17:28:00 +01:00
Clément Foucault
0105b33a5f Refactor: DRW: Move some functions to DRWContext
This reduces the API and make it more clear where there
is the global access.

This also removes some of these global access by merging
the `DRW_context_get()` calls.
2025-03-17 17:19:13 +01:00
Clément Foucault
686c571c09 Cleanup: Overlay: Remove DRWContext C-API calls 2025-03-17 16:24:23 +01:00
Clément Foucault
8d8b20f31f Cleanup: EEVEE: Remove workaround for state functions
Now the states are set accordingly inside the init function.
2025-03-17 16:24:23 +01:00
Clément Foucault
894c7fa4e2 EEVEE: Remove EEVEE Next mention inside the code
This only changes file and function names.
The EEVEE identifier is still `BLENDER_EEVEE_NEXT`.

No functional changes.
2025-03-17 15:37:04 +01:00
Clément Foucault
e08c64d68e Cleanup: DRW: Remove DrawData
These have been replaced by better alternatives overtime.

Pull Request: https://projects.blender.org/blender/blender/pulls/136073
2025-03-17 15:16:07 +01:00
Clément Foucault
959d82f2ab Merge branch 'blender-v4.4-release' 2025-03-17 14:25:43 +01:00
Clément Foucault
e31bfce08a Fix: Overlay: Broken Shading on Armature envelope
There was a copy paste mistake in the create info refactor
patch commited in b295df7345.
2025-03-17 14:24:31 +01:00
Campbell Barton
5aec1308e6 Cleanup: quiet missing-declarations warnings 2025-03-17 21:44:08 +11:00
Clément Foucault
92968c23fe Refactor: DRW: Make DrawEngine a virtual class
This removes the old `DrawEngineType` and use the new `DrawEngine`
virtual class instead.

This removes a lot of boilerplate functions that were only there for
legacy reason.

To this end, some engines that were based on static functions have been
refactored into `Instance` classes. This was particularly cumbersome
for the Grease pencil engine which needed some more refactoring.

The `Engine` class that is in each namespace is a workaround to isolate
the internal implementation (i.e. the `Instance`) to the engine
modules. Without this, the whole engine is getting included in each
compile unit that includes the `Instance` class. Eventually, if we get
rid of these intricate dependencies, we could remove the `Engine` class.

Pull Request: https://projects.blender.org/blender/blender/pulls/136001
2025-03-17 10:31:22 +01:00
Hans Goudey
23a88e0eec Fix #136039: Grease pencil edit mode crash with Bezier curves
Caused by 5f6e94ca58.
That commit mixed up `elb` and `epb`. Hopefully with clearer
names now that mistake will be harder to make.
2025-03-16 22:39:28 -04:00
Clément Foucault
626118984e Compositor: Use last_update for ID update
This replaces the deprecated DrawData mechanism by the
usage of the update timestamp `last_update`.

The compositor keeps the `last_update` value of the cached ID
and compares it with the value on the ID at the time of evaluation.

Rel #134690

Pull Request: https://projects.blender.org/blender/blender/pulls/134878
2025-03-14 10:25:32 +01:00
Clément Foucault
4ba3b1985c Overlay: Avoid engine recreation for clipping region toggle
This changes the shader module reference to a pointer and
set it during `init()`
2025-03-13 22:06:56 +01:00
Miguel Pozo
d7efed77b8 Merge branch 'blender-v4.4-release' 2025-03-13 19:59:10 +01:00
Miguel Pozo
08bd2d687d Fix #135848: Selection-Next: Backface culling (2)
Alternative fix for #135848.
Initially fixed by #135867, but broken again by #135917.

This performs the early return manually for the depth prepass.

Pull Request: https://projects.blender.org/blender/blender/pulls/135924
2025-03-13 19:26:15 +01:00
Clément Foucault
e5ae55af88 Cleanup: Overlay: Resolve warning about unused variable with C++ shader 2025-03-13 16:34:13 +01:00
Clément Foucault
9f97d19ebd Cleanup: DRW: Resolve warning about unused variable in release 2025-03-13 16:33:46 +01:00
Clément Foucault
dfb5be53cd Fix #135922: DRW: Blender crashes when saving a file
Was using the wrong viewport variable (that could be
nullptr) for the drawing.
2025-03-13 16:27:04 +01:00
Clément Foucault
cdacaa0a13 Fix: DRW: Warning about missing declaration in lite build 2025-03-13 16:27:04 +01:00
Hans Goudey
70095e9041 Cleanup: DRW: Use data span to fill lattice line index buffer
Pull Request: https://projects.blender.org/blender/blender/pulls/135921
2025-03-13 16:19:18 +01:00
Hans Goudey
284ac406d6 Mesh: Avoid function call overhead when extracting UV lines indices
Similar to other changes from #116901.
2025-03-13 16:19:17 +01:00
Miguel Pozo
083878c46b Merge branch 'blender-v4.4-release' 2025-03-13 16:14:24 +01:00
Miguel Pozo
ce41fbaefa Revert "Fix #135848: Selection-Next: Backface culling"
This reverts commit
44b64ca9df.
The fix is broken by
04a57dd937.
2025-03-13 16:11:33 +01:00
Clément Foucault
04a57dd937 Fix #135898: Selection: Make selection not depth aware
No depth awareness is wanted during object mode selection.
The hits are depth ordered in some selection mode but none
is supposed to reject based on depth.

Pull Request: https://projects.blender.org/blender/blender/pulls/135917
2025-03-13 15:16:05 +01:00
Miguel Pozo
44b64ca9df Fix #135848: Selection-Next: Backface culling
Allow extending the DRWState on select_bind so backface culling can be used when needed.

Note: There's still a difference in behavior with Overlay Legacy, causing backface culled flat objects to still be selectable at the edges, due to the "MeshFlat" workaround.
Pull Request: https://projects.blender.org/blender/blender/pulls/135867
2025-03-13 14:23:17 +01:00
Jesse Yurkovich
e492794e1e Fix: Resolve several int -> uint conversion shader warnings
Resolves several int -> uint conversion warnings. Warnings like the
following will be printed otherwise:

```
      |
  225 |   uint shadow_type = flags & 0xF;
      |                      ^
      | gpu_shader_text_vert.glsl:17:22: Warning: some implementations
        may not support implicit int -> uint conversions for `&'
        operators; consider casting explicitly for portability
```

Pull Request: https://projects.blender.org/blender/blender/pulls/135890
2025-03-13 14:22:21 +01:00
Clément Foucault
94c7c84bcd Refactor: DRW: Simplify the DRWContext classes and methods
This refactor part of `draw_manager_c.cc` to make it more understandable
and less bug prone.

- Splits the context handing to `draw_gpu_context.cc`
- Rename `draw_manager_c.cc` to `draw_context.cc`
- Merge `DRWContextState` into `DRWContext`
- Merge lots of static functions into `DRWContext` to avoid global access
- Deduplicate code between entry point functions
- Move context init logic to `DRWContext` constructor
- Move resource init logic to `DRWContext::acquire_data`
- Move extraction `TaskGraph` out of `DRWContext`
- Reduce / centralize complexity of enabling draw engines
- Reduce the amount of `drw_get` calls
- Remove unused code

Pull Request: https://projects.blender.org/blender/blender/pulls/135821
2025-03-13 13:47:02 +01:00
Campbell Barton
ff8baa6791 Cleanup: pass BMUVOffsets by const reference 2025-03-13 17:06:32 +11:00
Campbell Barton
78c3f6a1ee Cleanup: adjust order of terms for BMesh UV map function calls
Order more generic terms first for better ordering, more useful
completion.
2025-03-13 15:23:46 +11:00
Campbell Barton
6ef7dae8ef Cleanup: spelling in comments (make check_spelling_*) 2025-03-13 13:41:17 +11:00
Hans Goudey
5f6e94ca58 Grease Pencil: Avoid GPU API overhead when extracting index buffers
Similar changes done elsewhere (#116901), replace usage of the GPU API's
`GPU_indexbuf_add_generic_vert` function by simply writing the index
data that we need. This avoids a function call and min/max tests for
every index added.

Pull Request: https://projects.blender.org/blender/blender/pulls/135404
2025-03-12 21:55:18 +01:00
Hans Goudey
2cf5838b87 Grease Pencil: Slightly optimize IndexMask usage in draw extraction
Instead of computing an index mask for all curves, then returning an
intersection with the visible curves, just use the visible curves as
a universe for the original calculation. Also add another early out
for when there are no NURBS curves.
2025-03-12 21:55:18 +01:00
Hans Goudey
32e96f1ff7 Grease Pencil: Avoid overhead counting visible points for drawing
Currently the drawing data extraction code uses the offset indices API
quite inefficiently, copying the size of every selected every curve, then
accumulating those sizes. Instead just use the existing API function that
counts the size of all selected curves. Also for the weight overlay, avoid
doing the same calculation twice.
2025-03-12 21:55:18 +01:00
Clément Foucault
f7e4fbc636 DRW: Add different mutex for GPUShader critical section
This removes the use of `system_gpu_context_mutex`
which was making render command submission threadsafe.

The only issue is the concurent usage of GPUShader objects.
To fix this, we only guard the submission section which
are the only parts that uses the GPUShaders.

Removing this critical section all together requires some changes
in the GPUShader. See #135406

Rel #134690

Pull Request: https://projects.blender.org/blender/blender/pulls/135595
2025-03-11 12:06:11 +01:00
Clément Foucault
92df5ba10f Fix #135650: Workbench: Missing update changing shading pop-over settings
This was previously taken care of by the `view_update` callback.
Nowadays, the best way is to manually check for changes inside
the engine.
2025-03-10 13:34:41 +01:00
Clément Foucault
86d7f1bcee Merge branch 'blender-v4.4-release' 2025-03-10 13:07:47 +01:00
Clément Foucault
690a165630 Fix #135652: Overlay: Overlays draw in front of mesh in Paint modes
This was caused by a missing prepass.
Only early out if drawing the prepass, otherwise, run all checks.
This is much safer.
2025-03-10 13:07:35 +01:00
Jeroen Bakker
40696ca452 SubDiv: Migrate GPU subdivision to use GPU module
Blender already had its own copy of OpenSubDiv containing some local fixes
and code-style. This code still used gl-calls. This PR updates the calls
to use GPU module. This allows us to use OpenSubDiv to be usable on other
backends as well.

This PR was tested on OpenGL, Vulkan and Metal. Metal can be enabled,
but Vulkan requires some API changes to work with loose geometry.

![metal.png](/attachments/bb042c3a-1a87-4140-9958-a80da10d417b)

# Considerations

**ShaderCreateInfo**

intern/opensubdiv now requires access to GPU module. This to create buffers
in the correct context and trigger correct dispatches. ShaderCreateInfo is used
to construct the shader for cross compilation to Metal/Vulkan. However opensubdiv
shader caching structures are still used.

**Vertex buffers vs storage buffers**

Implementation tries to keep as close to the original OSD implementation. If
they used storage buffers for data, we will use GPUStorageBuf. If it uses vertex
buffers, we will use gpu::VertBuf.

**Evaluator const**

The evaluator cannot be const anymore as the GPU module API only allows
updating SSBOs when constructing. API could be improved to support updating
SSBOs.

Current implementation has a change to use reads out of bounds when constructing
SSBOs. An API change is in the planning to remove this issue. This will be fixed in
an upcoming PR. We wanted to land this PR as the visibility of the issue is not
common and multiple other changes rely on this PR to land.

Pull Request: https://projects.blender.org/blender/blender/pulls/135296
2025-03-10 07:31:59 +01:00
Hans Goudey
7cd1c2c7b6 Cleanup: Use reference to fill MeshRenderData
Mainly to make a future diff smaller (MeshRenderData will
no longer be allocated on the heap).
2025-03-08 10:59:02 -05:00
Hans Goudey
99fa22a01f Fix #135175: Bounds overlay doesn't include all evaluated geometry
In the report, the bounds didn't include the curves generated from the
original legacy curve object. Generally we need to access the evaluated
geometry bounds here when the object is a geometry object.

This depends on 06f6d77979 for consistent behavior with
curve radii. That's why the fix is limited to main rather than 4.4.

Pull Request: https://projects.blender.org/blender/blender/pulls/135639
2025-03-07 18:23:40 +01:00
Falk David
39ceab03be Merge branch 'blender-v4.4-release' 2025-03-07 16:23:53 +01:00
Falk David
a904d3a1b2 Fix #135539: Grease Pencil: Depth placement not working in rendered mode
The issue was happening because the `is_render_depth_available`
state flag was false leading to the depths being cleared.

When we use `is_depth_only_drawing`, we expect
that the depth is valid because the Grease Pencil
engine will write them.

Pull Request: https://projects.blender.org/blender/blender/pulls/135619
2025-03-07 16:17:15 +01:00
Germano Cavalcante
7688677e29 Refactor: DRW: Replace 'DRW_draw_depth_object' with 'DRW_draw_depth_loop'
`DRW_draw_depth_object` seems completely out of spec (using DRW batches
to draw onto non-DRW framebuffer + no DST setup).

Pull Request: https://projects.blender.org/blender/blender/pulls/135598
2025-03-07 13:47:09 +01:00
Clément Foucault
4179960ede Overlay: Add DepthOnly GPU debug capture scope
Allow to capture the depth loop.
2025-03-07 11:18:33 +01:00
Clément Foucault
2131ef0a20 DRW: Use depsgraph update count to replace view_update
This avoid having to flush explicitely and the need for syncing.
It also removes a lot of complexity in the process.

These updates are not granular and do not need to so much
boiler plate code.

The depsgraph update counter now becomes atomic to avoid
undefined behavior when a depsgraph is being destroyed and
its memory reused (same thinking as the non-copy-on-eval IDs).

I tested some use cases (object update, sculpt update,
shading update) and they are all working.

Pull Request: https://projects.blender.org/blender/blender/pulls/135580
2025-03-06 19:15:29 +01:00
Miguel Pozo
db053ff8c5 Fix: EEVEE: Avoid double lock in ShaderModule::module_free
Use a separate lock for the module ops.

Pull Request: https://projects.blender.org/blender/blender/pulls/135587
2025-03-06 18:13:18 +01:00
Clément Foucault
f8c23fc793 Cleanup: EEVEE: Unused variables 2025-03-06 16:24:59 +01:00
Clément Foucault
5a32440edf Refactor: DRW: Replace by enabled engine list by static members
Iteration is done through templates.

Removes the need for the enabled engine list/vector.

Reduces API complexity.
2025-03-06 15:20:35 +01:00
Clément Foucault
4f909ba6fd DRW: Make DRWContext thread local
The owner of the context is now always the local context.
The `DRWContext` is now a temporary object that owns
no data.

The draw debug API is being put in a non-working state by
this PR as it conflicts with the new lifetime / ownership of
the `DRWContext` class.
A new design with a global (threadsafe) debug module is needed
to add back support for these debug features. Note that these
are not user facing features.

Some parts of EEVEE are still calling the global context and that
caused crashes in the volume probe baking pipeline where
the context is not yet known. Sort circuiting these function
calls in this case fixes the issue, but a more longer term
solution would be to alway have a `DRWContext` available inside
`eevee::Instance`.

I did some testing and didn't find much of a difference in frame time.
However, we should still strive to remove all global access in the future
to avoid potential overhead of `thread_local`.

Pull Request: https://projects.blender.org/blender/blender/pulls/135521
2025-03-06 15:18:02 +01:00