Commit Graph

99305 Commits

Author SHA1 Message Date
Sergey Sharybin
2e7b896928 Fix strict compiler warning in ImBuf
Solves the warning C4060: switch statement contains no 'case'
or 'default' labels warning with lite builds.

Pull Request: https://projects.blender.org/blender/blender/pulls/107619
2023-05-04 15:51:24 +02:00
Hans Goudey
d0705bd697 Mesh: Split MLoopTri poly indices into a separate array
For derived mesh triangulation information, currently the three face
corner indices are stored in the same struct as index of the mesh
polygon the triangle is part of. While those pieces of information are
often used together, they often aren't, and combining them prevents
the indices from being used with generic utilities. It also means that
1/3 more memory has to be written when recalculating the triangulation
after deforming the mesh, and that the entire triangle data has to be
read when only the polygon indices are needed.

This commit splits the polygon index into a separate cache on `Mesh`.
The triangulation data isn't saved to files, so this doesn't affect
.blend files at all.

In a simple test deforming a mesh with geometry nodes, the time used
to recalculate the triangulation reduced from 2.0 ms to 1.6 ms,
increasing overall FPS from 14.6 to 15.

Pull Request: https://projects.blender.org/blender/blender/pulls/106774
2023-05-04 15:39:10 +02:00
Julian Eisel
bf77d3436d Cleanup: Comment formatting for preview image enums definitions 2023-05-04 15:22:49 +02:00
Julian Eisel
9d422f2fbc Cleanup: Avoid nesting (use early exit) in icon code
Conditional blocks introduce scopes that need to be kept track of,
linear code is easier to follow. So use early exiting to reduce
cognitive load, a number of devs (including myself) consider this good
practice.
2023-05-04 15:05:49 +02:00
YimingWu
1049f11cc0 Fix #107566: Gesture face set respect hidden faces
Gesture face set selection (box and lasso selection) didn't respect hidden
faces, causing selection to bleed unexpectedly, now fixed.

Pull Request: https://projects.blender.org/blender/blender/pulls/107575
2023-05-04 14:51:36 +02:00
Jeroen Bakker
22e4e97310 macOS: Reduce Edit Mode Drawing Artifacts
Apple Silicon uses tile rendering and can discard tiles if it
is covered. The retopology overlay made some changes to the
shader that introduced some blocking and striping artifacts when
the overlay was disabled.

This PR changes the minimum used offset to reduce the drawing
artifacts. Tweaking the GLSL shader itself didn't work.

Fix #105830

Pull Request: https://projects.blender.org/blender/blender/pulls/107611
2023-05-04 12:42:37 +02:00
Jacques Lucke
e674e32aa1 Fix: missing null check leads to crash when rendering
The simulation cache is allocated lazily during evaluation when the
depsgraph is active. However, during rendering, the depsgraph is not
active, so it's not created.
2023-05-04 11:04:42 +02:00
Clément Foucault
9d6659bf07 Metal: Shader: Remove assertion of compilation success
This allow the compilation tests to finish even on failure.
2023-05-04 10:59:26 +02:00
Clément Foucault
2815f46883 Metal: ShaderLog: Add initial implementation
This is a really rough implementation. Since the MSL sources
do not correspond 1:1 to the GLSL sources, some mapping is
needed to retreive the GLSL source file for a given generated
line. This will be implemented in a later commit.
2023-05-04 10:59:26 +02:00
Clément Foucault
e39c3c600c GPU: ShaderLog: Add more const correctness & notes supports
The metal shader compiler can produce `note` reports.
Treat them as warnings.
2023-05-04 10:59:26 +02:00
Jeroen Bakker
b0c7e83805 Cleanup: formatting
In recent changes to vulkan.
2023-05-04 10:23:15 +02:00
Jacques Lucke
1c57ac6ce7 Cleanup: remove unused member variable 2023-05-04 10:19:40 +02:00
Nathan Vegdahl
10a93aebf1 Fix #95855: prioritize selecting keys on active fcurve
This addresses #95855 by prioritizing the selection of keys in the following order:

1. Keys on the active curve.
2. Keys on any selected curve.
3. Other keys.

Additionally, this fixes an as-yet unreported issue where you couldn't select the main vertex of a key if it was overlapping with another one and one or more of its handle vertices were already selected.  This was due to the selection status of a key and its handles not being properly considered separately.

Pull Request: https://projects.blender.org/blender/blender/pulls/107223
2023-05-04 10:10:34 +02:00
Jeroen Bakker
f428fd8229 Vulkan: Share Device Between Contexts
Previous GHOST_ContextVK would create a logical device for each
context. Blender uses multiple contexts at the same time and wasn't able
to share resources between them as the logical device where different.

This patch will create a single logical device and share them between
multiple contexts. This allows sharing memory/shaders between contexts
and make sure that all memory allocations are freed from the device it
was allocated from.

Some allocations in Blender are freed when there isn't a context, this
was failing in the previous implementation. We didn't noticed it before
as we didn't test multiple contexts.

This patch also moves device specific data structures from VKContext to
VKDevice like the descriptor pools, debug layers etc.

Pull Request: https://projects.blender.org/blender/blender/pulls/107606
2023-05-04 10:06:48 +02:00
Campbell Barton
93b6463113 Assert ImBuf & Main paths never use blend-file relative prefix
Add assertion on free because the final path isn't always known on
creation.
2023-05-04 13:43:28 +10:00
Campbell Barton
4395a35641 Cleanup: reduce indentation with early returns in allocimbuf 2023-05-04 13:18:42 +10:00
Campbell Barton
cf16eab370 Cleanup: avoid calling stat twice in BLI_dir_create_recursive 2023-05-04 13:12:35 +10:00
Campbell Barton
aa7d7c8e4b Cleanup: naming in BLI_path, reserve len for string length
- Names ending with len sometimes referred to the buffer size.
  The same names were used for both buffer size and string length
  depending on the function in some cases.

- Rename str/string to path for generic path functions.

- Rename BLI_path_rel arguments (file, relfile) to (path, basename)
  as it wasn't so clear which is being made relative, `file` can be a
  directory so rename to `path` (matches naming for BLI_path_abs).
2023-05-04 13:09:28 +10:00
Campbell Barton
c891dbd162 RNA: replace BLI_strncpy with strcpy when when the size isn't meaningful
The size limit used in RNA string access wasn't meaningful as the size
of buffers passed into these functions is defined by the length+1 which
uses strlen, unterminated strings would already cause a buffer overflow.
Note that strcpy for accessing RNA is already widely used,
there were just some cases that used BLI_strncpy too.

This also removes use of BLI_strncpy_utf8 in texture slot access as
names are expected to be utf8, sanitizing when copying in this
particular case doesn't make sense and isn't done elsewhere.
2023-05-04 13:09:28 +10:00
Campbell Barton
069db83152 BLI_string: move DEBUG_STRSIZE check into a macro, check sizes after nil
- Avoid inline ifdef checks for DEBUG_STRSIZE
- Add BLI_string_debug_size_after_nil to ensure strings to manipulate
  have the expected buffer size after the nil terminator.
- Add checks to more string manipulation functions.

Further changes are required for this to be enabled during regular
development as the RNA currently allocates the strings length but
passes in the buffer size as a limit which conflicts with DEBUG_STRSIZE.
2023-05-04 13:09:28 +10:00
Campbell Barton
40ff2cfdc5 BLI_path: correct buffer size argument
Pass the size of the string passed in, although in practice
this didn't cause any problems.
2023-05-04 13:09:28 +10:00
Hong Shin
54e397cc78 Cleanup: convert node_exec.h to C++
Ref: #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/107591
2023-05-04 00:09:29 +02:00
Hans Goudey
2390abf1d3 Cleanup: Reduce indentation when setting custom normals 2023-05-03 16:53:00 -04:00
Hans Goudey
96f9930de1 Cleanup: Miscellaneous changes in corner fan normal calculation
- Use C++ float3 type, and math function
- Remove non-helpful braces, comment
- Use slightly longer variable name
2023-05-03 16:21:08 -04:00
Sietse Brouwer
a7d652e459 Fix Unreported: GPencil grab tool doesn't work on strokes changed by modifiers
The grab tool in Grease Pencil sculpt mode doesn't work correctly on strokes affected by modifiers.
You had to grab over the original vertex positions to see any effect.

Pull Request: https://projects.blender.org/blender/blender/pulls/106744
2023-05-03 21:48:19 +02:00
Hans Goudey
367145209c Cleanup: Move attribute_math to proper blenkernel namespace
The fact that blenlib doesn't know about the set of attribute types is
actually an important detail right now that can influence how things
are designed. Longer term it would be good to consolidate many of
these attribute propagation algorithms anyway.
2023-05-03 12:10:54 -04:00
Hans Goudey
d9a7f1285f Cleanup: Rename field input classes to match UI names 2023-05-03 12:10:54 -04:00
Hans Goudey
7f040099e3 Cleanup: Deduplicate sampling at index in geometry nodes
The "Evaluate at Index" and "Sample Index" nodes are exactly the same
once they retrieve the values to copy and the indices (apart from the
clamping option anyway). This also allows devirtualizing the index input
in the evaluate at index node like the sample index node.
2023-05-03 12:10:54 -04:00
Hans Goudey
09c1a93c21 Cleanup: Simplify CurvesGeometry deletion copying
Use span slicing instead of the POINTER_OFFSET macro
2023-05-03 12:10:54 -04:00
Hans Goudey
1f76863f80 BLI: Remove clamping from generic span slicing
Similar to a5e7657cee
2023-05-03 12:10:54 -04:00
Sergey Sharybin
42cdd39618 Fix return of stack memory
The fix is suggested by Jacques.

Pull Request: https://projects.blender.org/blender/blender/pulls/107586
2023-05-03 17:59:12 +02:00
Bastien Montagne
ac1ac6be9a Fix #107573: Purging orphan data deletes used data.
The logic in the initial commit (97dd107070) was broken in some cases,
and would end up tagging as unused IDs that had valid usages. It is
reverted by this commit..

For this new solution to #98029 (deleting unused archipelagos of data),
the logic handling dependency loops detection is reworked to rely on a
new tag in the relations entry of the relevant IDs, instead of
pre-tagging as unused the ID itself.

Further more, when a dependency loop is detected, the IDs in it cannot
be immediately tagged as unused, since it may be that the entry point
of that loop is later detected as actually used. So their relations
entries are not tagged as processed, and only the entry point of the
potential archipelago can be checked in that case, outside of the
recursive processing of dependencies.

The other IDs of the archipelago will then be processed again later, in
a state where at least one ID in the archipelago has a known state for
sure, which then allows for a safe evaluation of the other related data.

This commit should be backported to 3.3LTS.
2023-05-03 16:32:33 +02:00
Michael Kowalski
109c1b92cd Fix #105621: USD export: incorrect texture alpha mapping
Fixed bug where texture alpha was incorrectly remapped to red when exporting material shaders.

Now connecting the UsdPreviewSurface 'opacity' input to the UsdUVTexture 'a' output if the Blender texture image node source socket identifier is 'Alpha'.

Changes include the following:

The InputSpec::source_name struct member was removed, as the connection source name is now determined at runtime based on the Blender node input socket identifier.

The traverse_channel() utility function now returns a bNodeLink*, so that the source socket identifier can be queried from the link.

In create_usd_preview_surface_materia(), the code for creating and connecting a UsdUVTexture shader was reorganized to group it within one conditional block, to make it easier to follow.  Also replaced a call to a deprecated version of UsdShadeInput::ConnectToSource().

Pull Request: https://projects.blender.org/blender/blender/pulls/107022
2023-05-03 16:12:52 +02:00
Hans Goudey
7ff752b789 Cleanup: Unify mesh sampling multifunctions
Change the implementation of the raycast and sample nearest surface
node to split separate loops into separate multi-functions. This
clarifies the task of each function, gives more information to the
field evaluator, and gives more opportunity for memory reuse.

Sampling mesh attributes with triangle barycentric weights is now
implemented in a single place. Two other new multi-functions
handle conversion of sampled positions into barycentric weights.
Normalizing the ray directions for the raycast node is split out
too, so it can be skipped in some cases in the future.

The mesh attribute interpolator helper class is also removed,
since it didn't give much benefit over a more functional approach.

I didn't notice a performance improvement from this change.

Pull Request: https://projects.blender.org/blender/blender/pulls/107563
2023-05-03 15:07:16 +02:00
Hong Shin
743f57e95e Cleanup: Move draw_manager_profiling to C++
See: #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/107508
2023-05-03 14:30:58 +02:00
Hong Shin
642e18e889 Cleanup: Move node_util.h to C++
Ref: #103343

Pull Request: https://projects.blender.org/blender/blender/pulls/107569
2023-05-03 14:21:14 +02:00
Jacques Lucke
0de54b84c6 Geometry Nodes: add simulation support
This adds support for building simulations with geometry nodes. A new
`Simulation Input` and `Simulation Output` node allow maintaining a
simulation state across multiple frames. Together these two nodes form
a `simulation zone` which contains all the nodes that update the simulation
state from one frame to the next.

A new simulation zone can be added via the menu
(`Simulation > Simulation Zone`) or with the node add search.

The simulation state contains a geometry by default. However, it is possible
to add multiple geometry sockets as well as other socket types. Currently,
field inputs are evaluated and stored for the preceding geometry socket in
the order that the sockets are shown. Simulation state items can be added
by linking one of the empty sockets to something else. In the sidebar, there
is a new panel that allows adding, removing and reordering these sockets.

The simulation nodes behave as follows:
* On the first frame, the inputs of the `Simulation Input` node are evaluated
  to initialize the simulation state. In later frames these sockets are not
  evaluated anymore. The `Delta Time` at the first frame is zero, but the
  simulation zone is still evaluated.
* On every next frame, the `Simulation Input` node outputs the simulation
  state of the previous frame. Nodes in the simulation zone can edit that
  data in arbitrary ways, also taking into account the `Delta Time`. The new
  simulation state has to be passed to the `Simulation Output` node where it
  is cached and forwarded.
* On a frame that is already cached or baked, the nodes in the simulation
  zone are not evaluated, because the `Simulation Output` node can return
  the previously cached data directly.

It is not allowed to connect sockets from inside the simulation zone to the
outside without going through the `Simulation Output` node. This is a necessary
restriction to make caching and sub-frame interpolation work. Links can go into
the simulation zone without problems though.

Anonymous attributes are not propagated by the simulation nodes unless they
are explicitly stored in the simulation state. This is unfortunate, but
currently there is no practical and reliable alternative. The core problem
is detecting which anonymous attributes will be required for the simulation
and afterwards. While we can detect this for the current evaluation, we can't
look into the future in time to see what data will be necessary. We intend to
make it easier to explicitly pass data through a simulation in the future,
even if the simulation is in a nested node group.

There is a new `Simulation Nodes` panel in the physics tab in the properties
editor. It allows baking all simulation zones on the selected objects. The
baking options are intentially kept at a minimum for this MVP. More features
for simulation baking as well as baking in general can be expected to be added
separately.

All baked data is stored on disk in a folder next to the .blend file. #106937
describes how baking is implemented in more detail. Volumes can not be baked
yet and materials are lost during baking for now. Packing the baked data into
the .blend file is not yet supported.

The timeline indicates which frames are currently cached, baked or cached but
invalidated by user-changes.

Simulation input and output nodes are internally linked together by their
`bNode.identifier` which stays the same even if the node name changes. They
are generally added and removed together. However, there are still cases where
"dangling" simulation nodes can be created currently. Those generally don't
cause harm, but would be nice to avoid this in more cases in the future.

Co-authored-by: Hans Goudey <h.goudey@me.com>
Co-authored-by: Lukas Tönne <lukas@blender.org>

Pull Request: https://projects.blender.org/blender/blender/pulls/104924
2023-05-03 13:18:59 +02:00
Thomas Dinges
8775cf804e Fix compilation on Windows after f30434ac99. 2023-05-03 11:55:24 +02:00
Jason Fielder
88ace032a6 Metal: Storage buffer and explicit bind location support
Adds support for Storage buffers, including changes to the resource
binding model to ensure explicit resource bind locations are supported
for all resource types.

Storage buffer support also includes required changes for shader
source generation and SSBO wrapper support for other resource
types such as GPUVertBuf, GPUIndexBuf and GPUUniformBuf.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/107175
2023-05-03 11:46:30 +02:00
Campbell Barton
bcedbdcf6f Cleanup: improve code-comments, naming, use defines, correct spelling 2023-05-03 17:34:27 +10:00
Campbell Barton
5f0a5c9b15 Cleanup: remove redundant path splitting in font loading
BLI_path_split_file_part ran for every filename comparison,
replace with BLI_path_basename and run once.

Also rename FaceDetails::name -> filename.
2023-05-03 17:23:19 +10:00
Campbell Barton
e5e17c5a81 Cleanup: rename "name" to "filepath"
Missed in recent cleanup.
2023-05-03 17:13:42 +10:00
Campbell Barton
7ec1456b43 Cleanup: remove BLI_path_abs call on ImBuf path when saving a sequence 2023-05-03 17:12:25 +10:00
Campbell Barton
d824030782 Fix blend file relative path being copied into ImBuf::filepath
ImBuf paths don't support blend file relative prefix,
make absolute after copying.
2023-05-03 16:54:30 +10:00
Campbell Barton
f9fbbd8f80 Cleanup: expand on code-comments
Rename layout_old to layout_ref as the layout is a reference
(the old layout has been freed).
Also use boolean for save_copy argument.
2023-05-03 16:31:37 +10:00
Campbell Barton
b690b8c16f Fix incorrect buffer size copying to StudioLight::filepath
Use STRNCPY macro so these don't get out of sync.
2023-05-03 16:26:42 +10:00
Campbell Barton
d770fd5ac4 Cleanup: remove unused BLI_dir_* functions
Loading a font in BLF would search a list of directory presets
however these presets were never used.
Remove them as all callers pass in full paths.

Also rename FontBLF::name to mem_name as it's only needed as an ID
for in-memory fonts (to prevent them being loaded multiple times).

Non-unique font loading now compares against the filepath or mem_name
when loading from files or memory (before both used `name` which was
often the filepath, sometimes the full ID-name).
2023-05-03 16:08:31 +10:00
Campbell Barton
6b9a500a3a Cleanup: disambiguate terms "name", "file" & "str" / "string"
- Rename name/filename/path to filepath when it's used for full paths.
- Rename name/path to dirpath when it refers to a directory.
- Rename file to filepath or path (when it may be a file or dir).
- Rename ImBuf::name & anim::name to filepath.
2023-05-03 15:26:14 +10:00
Campbell Barton
1f96fa1129 Cleanup: rename BLI_make_existing_file for clarity
Rename BLI_make_existing_file to BLI_file_ensure_parent_dir_exists.
The previous name read as if it would make (touch) the file,
where as it ensures the directory component of the path exists.

Move from BLI_path to BLI_fileops as path utilities should only
manipulate paths and not deal with file IO creation
(this has more in common with BLI_file_touch for e.g.).
2023-05-03 11:49:47 +10:00
Campbell Barton
bb341eaf12 BLI_path: use module prefix for BLI_filename_make_safe
Rename BLI_filename_make_safe -> BLI_path_make_safe_filename.
2023-05-03 11:48:52 +10:00