Commit Graph

3417 Commits

Author SHA1 Message Date
Jason Fielder 18f7d158fe GPU: cleanup texture view usage flags
Texture usage flag `GPU_TEXTURE_USAGE_MIP_SWIZZLE_VIEW`
was originally implemented and used too conservatively for many
cases in which the underlying API flags were not required.

Renaming to `GPU_TEXTURE_USAGE_FORMAT_VIEW` to reflect
the only essential use case for when a texture view is initialized with
a different texture format to the source texture. Texture views can
still be created without this flag when mip range or base level is
adjusted,

This flag is still required by stencil views and internally by the Metal
backend for certain feature support such as SRGB render toggling.

Patch also includes some small changes to the Metal backend to
adapt to this new compatibility and correctly capture all texture view
use-cases.

Related to #115269

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/115300
2023-11-24 15:21:00 +01:00
Miguel Pozo ae1e2951c7 Fix #115144: isect_data_setup compiler error
Rename `isect_data_setup` functions to avoid shader compiler errors.

Pull Request: https://projects.blender.org/blender/blender/pulls/115175
2023-11-23 16:02:10 +01:00
Hans Goudey 8d2b203a3d Cleanup: Remove unnecessary keywords in C++ header 2023-11-20 22:12:27 -05:00
Hans Goudey ea78af4b5d Cleanup: Move draw_subdivision.h to C++ 2023-11-20 22:07:11 -05:00
Hans Goudey 301731692e Cleanup: Access sculpt attributes with C++ attribute API
Access masks and face sets through the `BKE_attribute.hh` API. This
us more flexibility long term, and makes code a bit simpler in the
meantime.
2023-11-20 13:14:34 -05:00
Hans Goudey f2bcd73bd2 Mesh: Move sculpt mask to a generic attribute
Store paint masks as generic float attributes, with the name
`".sculpt_mask"`. This is similar to 060a534141, which made
the same change for face sets. The benefits are general
consistency, nicer code, and more support in newer areas
that deal with attributes like geometry nodes.

The RNA API is replaced with one created in Python. The new
API only presents a single layer as an attribute class, so it
should be simpler to use in general:
- Before: `object.data.vertex_paint_masks[0].data[0].value`
- After: `object.data.vertex_paint_mask.data[0].value`

Pull Request: https://projects.blender.org/blender/blender/pulls/115119
2023-11-20 17:42:01 +01:00
Miguel Pozo 4dc1c23384 Fix #114742: Draw: Buffers never shrink
The buffers from the new Draw Manager increase their size as needed,
but they never shrink.

Add `StorageArrayBuffer::trim_to_next_power_of_2` function that can
downsize the buffer following the same heuristic as `get_or_resize`.
Add `StorageVectorBuffer::trim_and_clear`, which calls
`trim_to_next_power_of_2` automatically.

Pull Request: https://projects.blender.org/blender/blender/pulls/114857
2023-11-20 12:23:12 +01:00
Jason Fielder b8c84d03cd Fix #107025: Resolve incorrect UV stretch color on macOS
Modify `UVStretchAngle` vertex struct alignment to match
4-byte struct alignment for Metal. This includes reordering
array elements to the front and adding additional padding
to the struct in Metal such that the raw-data write size
matches the padded vertex format.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/114923
2023-11-20 08:45:56 +01:00
Hans Goudey dd902d97ab Cleanup: Add missing forward struct declaration 2023-11-19 17:31:37 -05:00
Hans Goudey 3d57bc4397 Cleanup: Move several blenkernel headers to C++
Mostly focus on areas where we're already using C++ features,
where combining C and C++ APIs is getting in the way.

Pull Request: https://projects.blender.org/blender/blender/pulls/114972
2023-11-16 11:41:55 +01:00
Hans Goudey 4bcdc57fc8 Refactor: Move object runtime data to separate allocation
Move object runtime data to a separate header and allocate it separately
as `blender::bke::ObjectRuntime`. This is how node, mesh, curves, and
point cloud runtime data is stored.

Benefits:
- Allow using C++ types in object runtime data
- Reduce space required for Object struct in files
- Increase conceptual separation between DNA and runtime data
- Remove the need to add manual padding in runtime data
- Include runtime struct definition only in files that require it

Pull Request: https://projects.blender.org/blender/blender/pulls/113957
2023-11-15 18:46:07 +01:00
Hans Goudey 6d18fe76b5 Fix: Incorrect default used when retrieving material indices 2023-11-15 16:16:22 +01:00
Hans Goudey 1a8b5bcd43 Fix #114841: Sculpt Multires drawing broken with no mask
The GPU buffer type was replaced with `float` in 4151691552,
but the "no mask" case wasn't changed. We still assigned a `uchar` value
to a `float` pointer, which made the drawing look random. Instead do the
same fill we use for other PBVH types.

Pull Request: https://projects.blender.org/blender/blender/pulls/114846
2023-11-14 16:28:46 +01:00
Hans Goudey 7b51d32dd9 Cleanup: Move BKE_modifier.h to C++ 2023-11-14 09:30:40 +01:00
Hans Goudey 583bd9662e Cleanup: Remove C header from C++ math header
Remove some redundancy between headers, more fully
separate the C++ headers from the older C headers.

Pull Request: https://projects.blender.org/blender/blender/pulls/114705
2023-11-11 21:09:54 +01:00
Martijn Versteegh 596aab27bd Merge branch 'blender-v4.0-release' 2023-11-08 21:32:30 +01:00
Martijn Versteegh aaf6937631 Fix #112697: Skip non-existing UV maps on VBO upload
Fix #112697: Skip unavaliable UV maps on VBO upload

The list of available UV maps is generated for the evaluated object,
however if any modifier generates UV maps (for example Geometry
Nodes) it is possible the evaluated object contains UV maps which are
not present in the base mesh. So when only the base mesh is uploaded,
for example in the UV editor, UV maps present in the list are not
guaranteed to exist.

Pull Request: https://projects.blender.org/blender/blender/pulls/114558
2023-11-08 21:31:22 +01:00
Hans Goudey ece4b6e84d Cleanup: Remove unused functions
See 7b89a0a580, ae1b4a6a28
2023-11-08 10:18:37 +01:00
Sergey Sharybin 7b89a0a580 Cleanup: Mark unused arguments as such
Pull Request: https://projects.blender.org/blender/blender/pulls/114619
2023-11-08 09:44:58 +01:00
Miguel Pozo 7c68e9a94c Fix #114524: EEVEE-Next: Wrong normal map node result
The new draw manager stores the object scale as a regular flag.
Update `node_normal_map` to read it correctly.

Pull Request: https://projects.blender.org/blender/blender/pulls/114587
2023-11-07 18:58:31 +01:00
Miguel Pozo b4316445a8 EEVEE-Next: Add Max Displacement option
Add a Max Displacement option to Material settings, so frustum culling
can work correctly with vertex displacement.

Pull Request: https://projects.blender.org/blender/blender/pulls/114200
2023-11-07 15:28:07 +01:00
Jeroen Bakker adb2164191 Draw: Add Region Info Debug Group
Adding a deug group for draw manager region info so it is easier
to find inside tools like renderdoc.

Pull Request: https://projects.blender.org/blender/blender/pulls/114578
2023-11-07 14:53:48 +01:00
Hans Goudey 17b875fccf Fix: Windows build error from missing template argument deduction 2023-11-07 11:19:43 +01:00
Hans Goudey ae1b4a6a28 Cleanup: Consolidate draw attribute extraction
Use the same attribute conversion class for PBVH and regular
mesh attribute extraction. This makes the GPU formats we use
for each attribute type more explicit and centralizes the conversions
from the attribute types to the GPU types. It's also a bit more aligned
to how we could use implicit sharing for GPU vertex buffer data.

Unfortunately it isn't possible to use this same code for curves
and point clouds because they use textures for their evaluated data,
and 3-wide vectors (e.g. `float3`) aren't supported on GPUs with our
current texture abstraction. For generic attributes, the long term
approach will probably be to use an SSBO instead.

Pull Request: https://projects.blender.org/blender/blender/pulls/114340
2023-11-07 10:05:13 +01:00
Campbell Barton 611930e5a8 Cleanup: use std::min/max instead of MIN2/MAX2 macros 2023-11-07 16:33:19 +11:00
Campbell Barton aaf05c2497 Cleanup: various C++ changes (use nullptr, function style casts) 2023-11-07 11:35:16 +11:00
Falk David 91db8fc5a0 GPv3: Multi-frame editing
Adds a new scene tool setting `use_grease_pencil_multi_frame_editing`.

The `foreach_*_drawing` functions are moved to the `ed::greasepencil` namespace in the editor, since they are now context sensitive and depend on the toolsetting. They are now named `retrieve_editable_drawings` and `retrieve_visible_drawings` and return
an array of drawings instead of calling a callback function.

Pull Request: https://projects.blender.org/blender/blender/pulls/114283
2023-11-02 17:10:59 +01:00
Gilberto Rodrigues dfd1b63cc7 UI: improve mesh edge highlighting
Changes to edit mode mesh overlays, use hue shift instead of color
fading/darkening for selection mode visual differentiation, and some
theme changes to improve the display of mesh edges and faces with good
selection visibility.

- Removed "edge" toggle from edit mode overlays panel.
- No longer halves the edge and face alpha depending on selection mode.
  Half the face alpha in wire-frame mode. For better visibility on most
  themes.

Ref !111431
2023-11-02 22:09:17 +11:00
Hans Goudey d6be6339f1 Fix: Incorrect PBVH mask drawing after recent change
The `COMPONENT_LEN_SCALAR` workaround isn't used for
masks which are drawn in a more hard-coded way.
2023-10-31 18:17:26 +01:00
Hans Goudey acbab3550f Merge branch 'blender-v4.0-release' 2023-10-31 18:12:18 +01:00
Hans Goudey e05c36f56d Fix #113496: PBVH draw crashes and unsupported attribute types
Use more modern approaches for supporting all generic attribute types,
rather than hardcoding all of the types and mistakenly correlating types
and domains.

A "Converter" template class handles conversion to GPU data and
describing the GPU format. The class is based on recent work in Cycles
attribute upload and is meant to replace the `AttributeTypeConverter`
class in `extract_vbo_attributes.cc`. I will do that as a separate step.
This structure will give build errors if new attribute types are added
but not supported here, preventing the situation described in the
report.

All generic attribute types are supported now, consistently with non
sculpt mode drawing. The edge domain isn't supported though.
Typically edges are more costly and complex to access, and interpolation
is less well defined anyway.

Pull Request: https://projects.blender.org/blender/blender/pulls/114334
2023-10-31 17:33:15 +01:00
Brecht Van Lommel 39107b3133 Revert changes from main commits that were merged into blender-v4.0-release
The last good commit was 8474716abb.

After this commits from main were pushed to blender-v4.0-release. These are
being reverted.

Commits a4880576dc from to b26f176d1a that happend afterwards were meant for
4.0, and their contents is preserved.
2023-10-30 21:40:35 +01:00
Hans Goudey e52b269283 Cleanup: Use simpler copying with begin iterator and count 2023-10-20 20:07:02 +02:00
Jason Fielder 1b0ddfa6cb GPU: Add explicit API to sync storage buffer back to host
PR Introduces GPU_storagebuf_sync_to_host as an explicit routine to
flush GPU-resident storage buffer memory back to the host within the
GPU command stream.

The previous implmentation relied on implicit synchronization of
resources using OpenGL barriers which does not match the
paradigm of explicit APIs, where indiviaul resources may need
to be tracked.

This patch ensures GPU_storagebuf_read can be called without
stalling the GPU pipeline while work finishes executing. There are
two possible use cases:

1) If GPU_storagebuf_read is called AFTER an explicit call to
GPU_storagebuf_sync_to_host, the read will be synchronized.
If the dependent work is still executing on the GPU, the host
will stall until GPU work has completed and results are available.

2) If GPU_storagebuf_read is called WITHOUT an explicit call to
GPU_storagebuf_sync_to_host, the read will be asynchronous
and whatever memory is visible to the host at that time will be used.
(This is the same as assuming a sync event has already been signalled.)

This patch also addresses a gap in the Metal implementation where
there was missing read support for GPU-only storage buffers.
This routine now uses a staging buffer to copy results if no
host-visible buffer was available.

Reading from a GPU-only storage buffer will always stall
the host, as it is not possible to pre-flush results, as no
host-resident buffer is available.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/113456
2023-10-20 17:04:36 +02:00
Hans Goudey 89e3ba4e25 Mesh: Replace auto smooth with node group
Design task: #93551

This PR replaces the auto smooth option with a geometry nodes modifier
that sets the sharp edge attribute. This solves a fair number of long-
standing problems related to auto smooth, simplifies the process of
normal computation, and allows Blender to automatically choose between
face, vertex, and face corner normals based on the sharp edge and face
attributes.

Versioning adds a geometry node group to objects with meshes that had
auto-smooth enabled. The modifier can be applied, which also improves
performance.

Auto smooth is now unnecessary to get a combination of sharp and smooth
edges. In general workflows are changed a bit. Separate procedural and
destructive workflows are available. Custom normals can be used
immediately without turning on the removed auto smooth option.

**Procedural**

The node group asset "Smooth by Angle" is the main way to set sharp
normals based on the edge angle. It can be accessed directly in the add
modifier menu. Of course the modifier can be reordered, muted, or
applied like any other, or changed internally like any geometry nodes
modifier.

**Destructive**
Often the sharp edges don't need to be dynamic. This can give better
performance since edge angles don't need to be recalculated. In edit
mode the two operators "Select Sharp Edges" and "Mark Sharp" can be
used. In other modes, the "Shade Smooth by Angle" controls the edge
sharpness directly.

### Breaking API Changes
- `use_auto_smooth` is removed. Face corner normals are now used
  automatically   if there are mixed smooth vs. not smooth tags. Meshes
  now always use custom normals if they exist.
- In Cycles, the lack of the separate auto smooth state makes normals look
  triangulated when all faces are shaded smooth.
- `auto_smooth_angle` is removed. Replaced by a modifier (or operator)
  controlling the sharp edge attribute. This means the mesh itself
  (without an object) doesn't know anything about automatically smoothing
  by angle anymore.
- `create_normals_split`, `calc_normals_split`, and `free_normals_split`
  are removed, and are replaced by the simpler `Mesh.corner_normals`
  collection property. Since it gives access to the normals cache, it
  is automatically updated when relevant data changes.

Addons are updated here: https://projects.blender.org/blender/blender-addons/pulls/104609

### Tests
- `geo_node_curves_test_deform_curves_on_surface` has slightly different
   results because face corner normals are used instead of interpolated
   vertex normals.
- `bf_wavefront_obj_tests` has different export results for one file
  which mixed sharp and smooth faces without turning on auto smooth.
- `cycles_mesh_cpu` has one object which is completely flat shaded.
  Previously every edge was split before rendering, now it looks triangulated.

Pull Request: https://projects.blender.org/blender/blender/pulls/108014
2023-10-20 16:54:08 +02:00
Sergey Sharybin 85c557ffa2 Cleanup: Rename BLI_string_utils.h to BLI_string_utils.hh
All users of it are now C++, which opens doors to add C++ to the
public API.
2023-10-20 10:27:26 +02:00
Hans Goudey 1cbd0f5a85 Refactor: Improve access to object data bounds
Currently object bounds (`object.runtime.bb`) are lazily initialized
when accessed. This access happens from arbitrary threads, and
is unprotected by a mutex. This can cause access to stale data at
best, and crashes at worst. Eager calculation is meant to keep this
working, but it's fragile.

Since e8f4010611, geometry bounds are cached in the geometry
itself, which makes this object-level cache redundant. So, it's clearer
to build the  `BoundBox` from those cached bounds and return it by
value, without interacting with the object's cached bounding box.

The code change is is mostly a move from `const BoundBox *` to
`std::optional<BoundBox>`. This is only one step of a larger change
described in #96968. Followup steps would include switching to
a simpler and smaller `Bounds` type, removing redundant object-
level access, and eventually removing `object.runtime.bb`.

Access of bounds from the object for mesh, curves, and point cloud
objects should now be thread-safe. Other object types still lazily
initialize the object `BoundBox` cache since they don't have
a data-level cache.

Pull Request: https://projects.blender.org/blender/blender/pulls/113465
2023-10-19 14:18:40 +02:00
Hans Goudey 40080f618c Sculpt: Use C++ Set to store PBVH Node BMesh elements
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
2023-10-19 14:18:15 +02:00
Falk David 6281d9a039 Fix: GPv3 depth buffer
Resolves #113422.

The depth buffer was rendered to, but not correctly merged
with the scene depth buffer. This lead to, e.g. the object appearing
behind the grid.

This fixes the issue by rendering a "merge" pass.

Pull Request: https://projects.blender.org/blender/blender/pulls/113779
2023-10-19 13:22:38 +02:00
Campbell Barton e7e4e63313 Cleanup: spelling in comments, white-space in comments 2023-10-19 18:53:16 +11:00
Jeroen Bakker 62f721467b Merge branch 'blender-v4.0-release' 2023-10-19 08:03:51 +02:00
Jason Fielder 62219f8da9 Metal: Re-enable workbench NEXT shadows
With the shift to GPU-driven rendering pipeline,
the SSBO vertex fetch paradigm used to
implement workbench shadows on Metal
instead of utilising the geometry shader
path no longer worked correctly.

This is because the draw submission
required vertex amplification up-front,
based on the expected output geometry
amount for a given input geometry.

This patch aims to resolve this
issue through addition of API to
enable the features within the
GPU driven pipeline.

Co-authored-by: Michael Parkin-White <mparkinwhite@apple.com>
Pull Request: https://projects.blender.org/blender/blender/pulls/113498
2023-10-19 08:01:17 +02:00
Campbell Barton 6ed3b4a5a6 Cleanup: format, quiet unused argument warning 2023-10-18 22:09:27 +11:00
Hans Goudey e1fd7a8a7b Cleanup: Simplify grease pencil line overlay size counting
Avoid the need to iterate over every curve, and only iterate over the
cyclic attribute if it exists. This removes the check that avoided
creating cyclic segments for curves with only two points. If that
was necessary, some of the complexity would return, but the
new `array_utils` function wouldn't be necessary.

Pull Request: https://projects.blender.org/blender/blender/pulls/113814
2023-10-17 18:29:17 +02:00
Falk David 07749b389d GPv3: Convert radius to blender units
Previously, Grease Pencil used a radius convention where
1 "px" = 0.001 units. This "px" was the brush size which would be
stored in the stroke thickness and then scaled by the point pressure
factor. Finally, the render engine would divide this thickness value by
2000 (we're going from a thickness to a radius, hence the factor of
two) to convert back into blender units.

Store the radius now directly in blender units. This makes it
consistent with how hair curves handle the radius.

* Removes the scaling in the render engine.
* Makes sure the grease pencil primitives use the correct radii
* Changes the drawing tool to work with screen space radius
* Draws the drawing tool cursor in screen space
* Makes sure the scaling is done when converting from legacy
grease pencil objects
* Makes sure the scaling is done when loading previous files

Consequences for the draw tool:
* Since the tool has a radius input in pixels, it now works in screen space. This is a pretty big change to how it works by default before, so a new option will have to be added that allows the brush to be in "Scene" space. This is similar to how it works in sculpt mode. But this is a bigger change, so I would like to split that into a separate PR.

Pull Request: https://projects.blender.org/blender/blender/pulls/113770
2023-10-17 17:00:35 +02:00
Miguel Pozo 6f125661e6 GPU: Add Texture::debug_clear
Clear uninitialized textures to NaN/debug values.
Enabled for `--debug-gpu` only.

Pull Request: https://projects.blender.org/blender/blender/pulls/113781
2023-10-17 15:54:09 +02:00
Hans Goudey 57c27b47b9 Cleanup: Avoid unnecessary check for empty curves
In `CurvesGeometry`, curves should never be empty. We shouldn't have
to check for that in the drawing code.
2023-10-16 19:51:12 +02:00
Hans Goudey 2528b6da9b Cleanup: Use const in grease pencil drawing code 2023-10-16 19:51:12 +02:00
casey bianco-davis 0508e81b79 GPv3: Add edit mode lines to overlay
Adds lines in edit mode to the overlay.

Pull Request: https://projects.blender.org/blender/blender/pulls/111596
2023-10-16 13:59:26 +02:00
Campbell Barton 2e0b844b36 Cleanup: spelling in comments 2023-10-14 13:53:00 +11:00