Commit Graph

4095 Commits

Author SHA1 Message Date
Brecht Van Lommel
c7a33a62a2 Cleanup: Directly include DNA_userdef_types.h and BLI_listbase.h
Instead of relying on them being included indirectly.

Pull Request: https://projects.blender.org/blender/blender/pulls/134406
2025-02-12 23:01:08 +01:00
Clément Foucault
15437344ef Cleanup: DRW: Replace DRW_stats with GPU_debug
The former is not useful anymore and is being replaced
by the later.

Pull Request: https://projects.blender.org/blender/blender/pulls/134455
2025-02-12 17:14:48 +01:00
Clément Foucault
db2610f2e4 DRW: Use new gpu::TexturePool inside TextureFromPool
Follow up to #134403.
2025-02-11 19:00:43 +01:00
Clément Foucault
144045cf63 Cleanup: DRW: Remove unused options 2025-02-11 13:03:00 +01:00
Clément Foucault
9bded245cc Cleanup: DRW: Remove global access function DRW_viewport_pixelsize_get 2025-02-11 13:02:54 +01:00
Clément Foucault
09e7e878e6 Cleanup: DRW: Remove unused legacy DRWViewport*List 2025-02-11 12:58:32 +01:00
Clément Foucault
a961c9050d Cleanup: GPU: Remove dependency on legacy common_math_lib.glsl
Replace usage of `common_math_lib.glsl` (deprecated) with gpu shader libs.

Pull Request: https://projects.blender.org/blender/blender/pulls/131579
2025-02-10 18:14:50 +01:00
Clément Foucault
86b70143d5 Cleanup: GPU: Remove unused Transform Feedback implementation
Most of the cleanup is inside the metal backend.

Pull Request: https://projects.blender.org/blender/blender/pulls/134349
2025-02-10 17:30:42 +01:00
Campbell Barton
e659e87a67 Cleanup: cmake formatting, sort file lists 2025-02-10 19:40:06 +11:00
Clément Foucault
5fcfc57103 Fix: DRW: Avoid division by zero in frustum_culling_planes_calc
This doesn't fix the float precision issue, just making sure we
don't hit undefined behavior.
2025-02-07 14:42:56 +01:00
Jeroen Bakker
a475678701 Cleanup: Subdiv: Move shaders to draw_shader
Subdivision had its own store of shaders. Best to move them to
`draw_shader.cc` where all draw manager related shaders are stored.

Includes some small tweaks:

- Use enum class for shader types
- patch evaluation must now be retrieved via the
  `DRW_shader_subdiv_get`. Previously there were 2 ways to retrieve
  them, and one didn't support all the variations.
- Use strongly types when possible (`GPUVertCompType`).

Pull Request: https://projects.blender.org/blender/blender/pulls/134213
2025-02-07 10:53:29 +01:00
Jeroen Bakker
d496e69eca Cleanup: Subdiv: Remove common_ prefix
The `common_` prefix can be confusing as there are other common_ files as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/134184
2025-02-07 07:48:49 +01:00
Campbell Barton
df3d1bf506 Cleanup: use const arguments & variables where appropriate 2025-02-05 14:38:56 +11:00
Clément Foucault
7bdafde54c Fix #133138: Overlay: Assert displaying subdiv surface modifier in edit-mode
The cause was that the shader was expecting both `pos` and `nor`
attribute but only one would be extracted.
This is because the mesh has cage display on but the batch cache
wouldn't extract the `vbo.vnor`.

This patch just make sure the vertex normal just follow the same
condition as the other edit normals batches.
2025-02-03 19:04:05 +01:00
Brecht Van Lommel
c7eb2f4204 Refactor: Remove _DEBUG, use WITH_DRAW_DEBUG instead
The `_DEBUG` flag is interfering with oneTBB, and now that there is a
`WITH_DRAW_DEBUG` option this is more appropriate.

See #115774 for more context.

Pull Request: https://projects.blender.org/blender/blender/pulls/133950
2025-02-03 12:32:04 +01:00
Hans Goudey
abc8796cab Curves: Optimize edit/sculpt mode index buffer creation
Avoid function call overhead and parallelize the creation of the edit
and sculpt mode lines index buffers. Also, remove an extra index that
was added for each curve when there are no cyclic curves.

Though ideally these index buffers would be generated on the GPU, this
simple change makes this part of the GPU data building almost 5x faster
(from 1.23 ms to 0.25 ms for curves with 80 thousand points).

Pull Request: https://projects.blender.org/blender/blender/pulls/133897
2025-01-31 21:47:16 +01:00
Guillem Baldi
2536b04a21 Fix #133104: Make Indices Overlay look like Attribute Viewer
The Indices Overlay used a blue color without shadow to render the
indices in edit mode unlike the Attribute Viewer which uses white text
with shadow. So for consistency, the Indices Overlay has been changed
to use the same style.

Pull Request: https://projects.blender.org/blender/blender/pulls/133262
2025-01-31 19:01:18 +01:00
Brecht Van Lommel
61eedabae9 Cleanup: Various clang-tidy warnings in draw
Pull Request: https://projects.blender.org/blender/blender/pulls/133734
2025-01-31 17:03:18 +01:00
Jesse Yurkovich
ca491185f8 Fix #132876: Remove assert and use proper limit when drawing instances
The assert would fire for perfectly valid scenes and the limit used, as
well as the cast, was incorrect.

Pull Request: https://projects.blender.org/blender/blender/pulls/133561
2025-01-27 18:28:20 +01:00
Miguel Pozo
956236f7d4 Fix: Draw: Add missing shaders to DRW_subdiv_free 2025-01-24 16:01:48 +01:00
Jeroen Bakker
9db5f61403 Fix: DrawManager: Missing include for draw manager tests
`draw_manager_testing.hh` was needed otherwise the compiler would print
a warning.

Pull Request: https://projects.blender.org/blender/blender/pulls/133538
2025-01-24 12:57:13 +01:00
Jacques Lucke
2fda20e1db Fix #132099: crash when using same geometry on objects with different material counts
The core issue was that the geometry batch cache (e.g. `MeshBatchCache` or
`PointCloudBatchCache`) was dependent on the object. This is problematic when
the the same geometry is used with multiple different objects because the cache
can't be consistent with all of them.

Fortunately, the only thing that was retrieved from the object was the number of
material slots, so if that can be avoided we should be fine. We can't just use
the number of material slots stored on the geometry because that may have no
material slots but still has material indices which are overridden on the object
level.

The solution is to take make the number of materials for a geometry only
dependent on the actual `material_index` attribute and not on the number of
available slots. More specifically, we find the maximal referenced material
index and handle that many materials. This number does not depend on how many
material slots there are on the object, but it still allows the object to
override materials slots that the mesh references.

A downside is that the maximum material index has to be computed which often
requires an iteration over the mesh. Fortunately, we can cache that quite easily
and the computation can be done in parallel. Also we are probably able to
eagerly update the material index in many cases when it's set instead of
computing it lazily. That is not implemented in this patch though.

The largest part of the patch is making the maximal material index easily
available on all the geometry types. Besides that, the material API is slightly
replaced and the drawing code now makes use of the updated API.

Pull Request: https://projects.blender.org/blender/blender/pulls/133498
2025-01-24 12:05:25 +01:00
Clément Foucault
cfd5d9e3ad Fix #132895: Overlay: Dashed/flickering wireframe overlay on solid shading
This add back the NDC offset that was present in the legacy overlay.

But instead of adding a new view for it, we add `ndc_offset_factor`
to `State` to simplify wire offseting

Instead of modifying the projection matrix, we compute the unit
offset and pass it to the shader which choose the appropriate
factor to apply to the vertex position.

The value is put inside `State` so that it can be referenced
easily by multiple overlays.
Later on (once we move the global UBO inside Overlay) we can
move this to a UBO.

This only implements it for wireframe and edit mesh vert and
edges.

Note: that there seems to be some code duplication with the
edit mesh vertex code. That's to be tackled in another commit.

Pull Request: https://projects.blender.org/blender/blender/pulls/133433
2025-01-23 18:08:20 +01:00
Clément Foucault
1ac4651778 Cleanup: DRW: Remove legacy common_view_lib.glsl
No functional changes. Only moving and renaming stuff.

Pull Request: https://projects.blender.org/blender/blender/pulls/131558
2025-01-23 18:06:22 +01:00
Hans Goudey
e07cd2b982 Cleanup: Remove unused and transitive includes in draw module
Especially through DRW_render.hh, there were a lot of unnecessary
includes almost everywhere in the module. This typically makes
dependencies less explicit and slows down compile times, so switch
to including what files actual use.

Pull Request: https://projects.blender.org/blender/blender/pulls/133450
2025-01-22 19:37:38 +01:00
Hans Goudey
d54a7bcb11 Cleanup: Use reinterpret_cast instead of two static casts 2025-01-22 12:50:01 -05:00
Brecht Van Lommel
890455affe Refactor: Rename function to clarify it's for sRGB only
Pull Request: https://projects.blender.org/blender/blender/pulls/133368
2025-01-21 18:05:56 +01:00
Miguel Pozo
80bd81a4f6 Fix #132890: Grease Pencil: Selection crash in wireframe mode
`dtxl->depth` may not be valid until draw time, so acquire the viewport
textures/framebuffers inside the draw callback instead.

Pull Request: https://projects.blender.org/blender/blender/pulls/132922
2025-01-16 15:14:54 +01:00
Laurynas Duburas
b9f241d468 Curves: Optimization in batch cache create
Prevents creation of Bezier curve's `IndexMask` when it is not needed.
It was created on every request, even when `CurvesBatchCache` was valid.
Also prevents redundant initialization of `GeometryDeformation`.

Pull Request: https://projects.blender.org/blender/blender/pulls/133017
2025-01-13 23:07:39 +01:00
Falk David
d413b0064f Cleanup: Move BKE_material.h to C++
The `BKE_material.h` is only renamed to `.hh` to preserve
the history of the file. Changes to the file are done in
the following commit.
2025-01-09 18:11:46 +01:00
Hans Goudey
0816234d65 Refactor: Make BMesh normals draw extraction similar to Mesh
This creates more boilerplate code, but it's easier to extend,
it's follows the same structure as the mesh extraction, and
it's more aligned to planned future performance improvements.

Pull Request: https://projects.blender.org/blender/blender/pulls/132866
2025-01-09 17:45:54 +01:00
Lukas Tönne
a46def32b4 Fix #123887: Clamp the Grease Pencil material index in GPU buffers to avoid invalid UBO lookup
The material index in Grease Pencil attributes can be negative, since they are a
generic attribute. The shader, however, requires clamping of the material index
to avoid an invalid lookup. This was already happening for the material buffer
setup (`grease_pencil_object_cache_populate`), but not for the actual VBO.

Fixes #131670

Pull Request: https://projects.blender.org/blender/blender/pulls/132804
2025-01-09 11:37:46 +01:00
Hans Goudey
9945563fac Mesh: Avoid computing corner normals for drawing if unnecessary
Only compute face corner normals if they are required for computing
tangents or if it's required because of the combination of sharp edges
and faces.

Pull Request: https://projects.blender.org/blender/blender/pulls/132821
2025-01-08 21:42:20 +01:00
Campbell Barton
7e8dcf77db Cleanup: pass UnitSettings as a const reference 2025-01-08 21:22:45 +11:00
Campbell Barton
e949ff7334 Fix unit scale use when when units were disabled
UnitSettings::scale_length was used to scale reported
values for operators (translate, shrink-fatten, voxel-size).

This isn't expected as the value isn't editable when the unit-system
is set to None.

Add BKE_unit_value_as_string_scaled utility function for clarity &
to ensure scaling is only applied when it should be.
2025-01-08 21:07:23 +11:00
Brecht Van Lommel
920e709069 Refactor: Make header files more clangd and clang-tidy friendly
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.

This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.

* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd

Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.

Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.

For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/

Pull Request: https://projects.blender.org/blender/blender/pulls/132608
2025-01-07 12:39:13 +01:00
Campbell Barton
5003253aca Cleanup: spelling & repeated terms 2025-01-07 13:20:19 +11:00
Hans Goudey
a4bfa399e9 Fix #132631: Sculpt multires drawing performance regression
Caused by 39f7c506b5.

GPU vertex buffers were way over-allocated. Not sure how that happened.
2025-01-06 14:25:35 -05:00
Hans Goudey
c3d7cd0424 Fix #132651: Multires sculpt drawing crash with color attribute overlay
Mistak in 39f7c506b5.

The VBOs need to be allocated! And we can just use a single dummy
type as well, rather than using the type from the attribute request
which is meaningless in this case.
2025-01-06 11:41:52 -05:00
Campbell Barton
d2d754be3f Cleanup: spelling in comments (make check_spelling*)
- Back-tick quote math expressions so differentiate them
  from English.
- Use doxygen code blocks for TEX expressions.
2025-01-04 16:26:39 +11:00
Hans Goudey
455326fd67 Fix #132488: Crash drawing edge attribute in sculpt mode 2024-12-31 09:44:16 -05:00
Hans Goudey
39f7c506b5 Refactor: Tweak draw_pbvh.cc code organization
With the goal of removing the type and custom data domain from
the attribute requests, tweak the order of the calls to ensure that
each vertex buffer is allocated until after we know about the source
mesh data format. After that, it makes more sense to have the loop
over BVH nodes inside each extraction function.

Pull Request: https://projects.blender.org/blender/blender/pulls/132467
2024-12-31 01:06:00 +01:00
Hans Goudey
6871fe8415 Cleanup: Use Span for GPU batch array
Pull Request: https://projects.blender.org/blender/blender/pulls/132464
2024-12-30 18:55:23 +01:00
Hans Goudey
7366dc1edb Cleanup: Remove unused draw cache function declarations 2024-12-30 12:12:23 -05:00
Hans Goudey
3d0988a719 Cleanup: Move some math C-API usage to C++ API
Mostly part of an attempt to remove some of the lesser-used
parts of the C math API.
2024-12-20 21:46:59 +01:00
Hans Goudey
bcfe4c34da Cleanup: Move BVH utils to C++ namespace 2024-12-19 18:22:29 +01:00
Hans Goudey
a67b5f6f63 Fix #131316: Edit overlays rendered for geometry instances
Geometry instances shouldn't be drawn with cage overlays or other
edit mode overlays since they don't necessarily correspond to original
data. In this case the draw manager thought they were in edit mode
because the object data is copied from the instance parent-- we need
_some_ object for rendering.

Pull Request: https://projects.blender.org/blender/blender/pulls/132081
2024-12-19 02:42:14 +01:00
Hans Goudey
ee7f30a371 Fix #131989: Mesh paint mode selection does not work
Caused by 839108f623.

The edit mapping was invalid so we just created a dummy GPU
batch for the selection edit data. But it was invalid because we
weren't in edit mode. The fix just requires tweaking the checks
for this data that's also used outside of edit mode.
2024-12-17 17:16:20 -05:00
Hans Goudey
75ede253aa Cleanup: Remove unused Grease Pencil legacy code 2024-12-17 11:43:34 -05:00
Jacques Lucke
b8228303bc Materials: take object and geometry material slot counts into account
Previously, the number of material slots on the geometry (e.g. mesh) was the
ground truth. However, this had limitations in the case when the object had more
material slots than the evaluated geometry. All extra slots on the object were
ignored.

This patch changes the definition so that the number of materials used for
rendering is the maximum of the number of material slots on the geometry and on
the object. This also implies that one always needs a reference to an object
when determining that number, but that was fairly straight forward to achieve in
current code.

This patch also cleans up the material count handling a fair amount by using the
`BKE_object_material_*_eval` API more consistently instead of manually accessing
`totcol`. Cycles uses the the same API indirectly through RNA.

Pull Request: https://projects.blender.org/blender/blender/pulls/131869
2024-12-16 18:08:06 +01:00