Commit Graph

5370 Commits

Author SHA1 Message Date
Omar Emara
847a3a7ea3 Nodes: Optimize Gabor noise with early exit
Optimize the Gabor noise texture code with an early exit for points that
are further away from the kernel center. This was already done for the
kernel, but is now being done earlier before computing the weight, so
its computation is now skipped.

Thanks to Charlie Jolly for the suggestion.
2024-08-14 12:12:34 +03:00
Jeroen Bakker
7fc55c0ad8 OpenGL: Remove conservative depth extension check
No need to enable the GL_ARB_conservative_depth extension as it is
core in GLSL 4.20. Some drivers still complain that the
extension was explicitly enabled.

Detected on AMD 21.Q2.1 (27.20.21026.2006) legacy driver.

Pull Request: https://projects.blender.org/blender/blender/pulls/126223
2024-08-13 12:10:00 +02:00
Jeroen Bakker
c4e90eddcb Fix #125618: EEVEE: Cryptomatte Material Layer Incorrect
The encoded material names used by cryptomatte were incorrect. Reason
was that it used the name including the object type.

NOTE: reference images needs to be updated

Pull Request: https://projects.blender.org/blender/blender/pulls/126267
2024-08-13 11:28:45 +02:00
Jesse Yurkovich
5835ea1eaf Build: C++20: Properly implement some definitions of operator==
Several `operator==` methods were mis-implemented; they were not defined
as `const` when implemented as part of the class rather than as friends.
C++20 is more strict about this now.

Example errors: https://godbolt.org/z/h8G5jaoha

Ref #125881

Pull Request: https://projects.blender.org/blender/blender/pulls/126121
2024-08-09 19:48:05 +02:00
Clément Foucault
2c275aec87 Overlay-Next: Mesh Edit Mode
This includes the port of the edit edge shader to the new
primitive expansion API, removing split codepath and
code duplication.

Some of the shader code is duplicated for keeping the
legacy engine untouched.

Rel #102179

Pull Request: https://projects.blender.org/blender/blender/pulls/125921
2024-08-09 16:29:59 +02:00
Omar Emara
149825bc2a Fix #125946: Crash when adding compositor node
Blender crashes when adding any Color compositor node when both the
viewport and the interactive compositors are active at the same time.
This is caused by a threading issue where both threads try to compile
the same GPU material at the same time.

To fix this, we protects GPU material pass compilation using a mutex.

Pull Request: https://projects.blender.org/blender/blender/pulls/126084
2024-08-08 13:54:22 +02:00
Harley Acheson
b63d691570 UI: Allow Changing Alpha for Multicolor Icons
When we use icons that are multi-color, like for Tool icons, we'll
still need the ability to change their alpha at runtime. We do this
for hover effects, and as a theme setting.

Pull Request: https://projects.blender.org/blender/blender/pulls/126063
2024-08-07 23:28:17 +02:00
Clément Foucault
f98bf61eac Fix: GL: IndexBuf: Out of bound copy during indices upload
The padded size was using for the data upload.
Now decouple the data specification and the upload.
2024-08-07 17:26:55 +02:00
Clément Foucault
04ae9ffd7f GPU: Add assert on zero sized VBOs
These can create GL errors that are not reported
appropriately.
2024-08-07 16:31:44 +02:00
Clément Foucault
e7c20e99df GPU: Add padding bytes to VBO and IBO
This is to avoid any issue with buffer alignement
and out of bounds reads when using these buffers
in compute shader or with vertex attribute fetch.
2024-08-07 16:31:44 +02:00
Clément Foucault
1e83d2f3ea Cleanup: GPU: Silence implicit narrowing warning 2024-08-05 10:36:36 +02:00
Campbell Barton
c071030ac3 Cleanup: spelling in comments 2024-08-04 13:45:06 +10:00
Clément FOUCAULT
d712f91881 DRW: Primitive Expansion
This PR introduces the concept of primitive expansion draws.
This allows to create a drawcall that will generate N amount of new
primitive for an original primitive in a `gpu::Batch`. The intent is to
phase out the use of geometry shader for this purpose.

This adds a new `Frequency::GEOMETRY` only available for SSBOs.
The resources using this will be fed the current `gpu::Batch` VBOs
using name matching.

A dedicated slot is reserved for the index buffer, which has its own
internal  lib to decode the index buffer content.

A new attribute lib is added to ease the loading of unaligned attribute.
This should be revisited and made obsolete once more refactor
lands.

It is similar to the Metal backend SSBO vertex fetch path but it is
defined on a different level. The main difference is that this PR is
backend independant and modify the draw module instead of the GPU
module. However, it doesn't cover all possible attribute conversion
cases. This will only be added if needed.

This system is less automatic than the Metal backend one and needs
more care to make sure the data matches what the shader expects.
The Metal system will be removed once all its usage have been
converted.

This PR only shows example usage for workbench shadows. Cleanup PRs
will follow this one.

Rel #105221

Pull Request: https://projects.blender.org/blender/blender/pulls/125782
2024-08-03 11:06:17 +02:00
Alaska
ba5d76e7e2 Fix: Shader: Align vector math node reflect mode with OSL
Align Cycles SVM and EEVEE's rendering of the vector math node
in reflect mode with OSL when the normal vector is 0,0,0.

This is done by using safe_normalize rather than normalize on the
normal vector. Which also fixes a NaN in the reflect mode in this
specific configuration.

Pull Request: https://projects.blender.org/blender/blender/pulls/125688
2024-08-02 11:20:57 +02:00
Alaska
be50c96c00 Fix #125643: Mismatch between Cycles EEVEE Vector Math Refract
Fixes a mismatch between Cycles and EEVEE when rendering a
Vector Math node in Refract mode with a normal vector of 0,0,0.

This mismatch first appeared after 8650068f0c which changed the
behaviour in Cycles, but not EEVEE.

Pull Request: https://projects.blender.org/blender/blender/pulls/125644
2024-07-30 17:33:39 +02:00
Campbell Barton
d8c2301ee8 Cleanup: use const arguments 2024-07-30 12:23:09 +10:00
Miguel Pozo
0bd1b92133 Fix: APIENTRY redefinition warning 2024-07-29 12:49:42 +02:00
Campbell Barton
4afb3aff35 Cleanup: pass const arguments, use r_ prefixed return arg 2024-07-29 13:01:12 +10:00
Campbell Barton
004c247670 Cleanup: different declaration names, use r_ prefix for return args 2024-07-29 13:01:10 +10:00
Jacques Lucke
f600d5681b Fix #125346: wrong transparency for dashed node links
This changed accidentally in 3410d0bf3f.
2024-07-26 14:40:03 +02:00
Sergey Sharybin
3ae945c34a Cleanup: Strict compiler warnings
Happens in release builds or when GPU_FORCE_ENABLE_SHADER_PRINTF=1.
2024-07-26 11:29:50 +02:00
Miguel Pozo
a83348fbdc GPU: Improve the shader cache behavior
Move the shader cache to `BKE_appdir_folder_caches`, since the
temporary folder is reset on Linux on every system restart.
Manually delete shader cache files on Blender exit if they have not
been used for more than 30 days.

Pull Request: https://projects.blender.org/blender/blender/pulls/125010
2024-07-25 19:22:36 +02:00
Miguel Pozo
4919221456 GPU: Batch Compilation: Show compiled GPUMaterials as soon as possible
Request one separate compilation batch for each GPUPass so users can
get a better sense of the compilation progress, and to better distribute
texture loading over time.

Pull Request: https://projects.blender.org/blender/blender/pulls/125012
2024-07-25 19:18:07 +02:00
Campbell Barton
8418ec4952 CMake: include headers in source lists 2024-07-25 11:24:11 +10:00
Campbell Barton
547b63b69b Cleanup: sort cmake file lists 2024-07-25 11:24:10 +10:00
Campbell Barton
2edc2393d2 Cleanup: spelling in comments 2024-07-25 10:17:42 +10:00
Aras Pranckevicius
527e55239b Fix #125061: VSE timeline pixel rounding/snapping issues at large frames
VSE timeline widget drawing is done in "timeline space" (x: frames,
y: channels), but that can have precision issues at large frames,
when "pixel size features" (outlines, borders) need to get evaluated
inside a shader.

This can lead to inconsistent border sizes between neighboring strips,
e.g. sometimes it would be 2 pixels, but sometiems 3 pixels. I've seen
this mostly happen when frames get into 100'000+ range.

To address this, switch timeline widget drawing to be in window pixel
space. This avoids the issue since coordinates to draw the strip
widgets become "up to several thousand" range, not arbitrarily large.

Pull Request: https://projects.blender.org/blender/blender/pulls/125220
2024-07-22 16:08:07 +02:00
Campbell Barton
f1e5263423 Cleanup: spelling in comments 2024-07-22 10:16:55 +10:00
Campbell Barton
5794913fb8 Cleanup: CMake file indentation, wrap long lines 2024-07-22 09:58:45 +10:00
Jesse Yurkovich
ec4fc2d34a CMake: Modernize the optional TBB dependency
This continues the cmake modernization effort and introduces support for
allowing our optional dependencies to integrate properly. TBB is added
here as it's proven troublesome to maintain correctly.

Currently the only Blender project which uses the TBB headers directly
is `blenlib`.  However, all downstream projects which require blenlib as
their dependency, and wish to properly make use of its threading
facilities, needed to define various TBB items in their CMake files. Not
only is this unnecessary and arcane, but several projects didn't do this
and ended up not using threading as well as producing ODR violations
along the way[1].

This PR makes TBB a modern dependency and exposes it PUBLIC'ly from
`blenlib`.  All downstream projects which depend on blenlib will now
receive everything they require from TBB automatically. This includes
the `WITH_TBB` define, the headers, and the library itself.

[1] blender/blender@05241f47f5

Pull Request: https://projects.blender.org/blender/blender/pulls/124916
2024-07-19 23:30:56 +02:00
Sebastian Parborg
c09ed8a04f Fix: GPU resourses were not set to nullptr after deleting, resulting in heap-use-after-free
The code has nullptr checks to make sure it doesn't try to use freed or unitiallized variables.
However the when freeing the data, the code doesn't assign the pointer to be null.
Now set them to be null

Pull Request: https://projects.blender.org/blender/blender/pulls/125090
2024-07-19 17:44:22 +02:00
Clément Foucault
d2fdb22b93 GPU: Add support for in shader printf
This allows much easier debugging of shader programs.

Usage is as simple as adding `printf` calls inside shaders.
example: `printf("Formating %d\n", my_var);`

Contrary to the `drw_print`, this is not limited
to draw manager shader dispatch/draws. It is compatible
with any shader inside blender.
Most notably, this doesn't need a viewport to display.
So this can be used to debug render pipeline.

Data formating is currently limited to only `%x`, `%d`,
`%u` and `%f`. This could be easily extended if this is
really needed.

There is no type checking, so values are directly reinterpreted
as specified by the printf format.

The current approach for making this work is to bind a
storage buffer inside `GPU_shader_bind`, making it
available to any shader that needs it. The storage buffer
is downloaded back to CPU after a frame or a render
step and the content printed to the console.

This scheduling means that you cannot rely on these printfs
to detect crashes. We could add a mode to force flushing
at shader binding to avoid this limitation.

The values are written from the shaders in binary form and
only formated on the CPU. This avoid issues with manual
printing like with `drw_print`.

Pull Request: https://projects.blender.org/blender/blender/pulls/125071
2024-07-19 15:48:00 +02:00
Harley Acheson
6145920a0d UI: Allow Use of Full-Color UI Icons
Allow the optional use of SVG UI icons shown in full color by
changing their definition from DEF_ICON to DEF_ICON_COLOR.

Pull Request: https://projects.blender.org/blender/blender/pulls/124696
2024-07-17 20:13:17 +02:00
Laurynas Duburas
a412268980 Fix: Overlay-Next when multiple objects are click selected
Fixes Overlay-Next selection when multiple objects are hit.

To reproduce:
- enable "Ovlay Next" in Preferences>Experimental
- create any Empty object and duplicate it without moving
- try to select by clicking them

Crash occurs because `mixed_bones_object_selectbuffer` in `view3d_select.cc` expects that `view3d_opengl_select_ex` will append results to `buffer`. Depending on situation after several `view3d_opengl_select_ex`calls with decreasing radius it tries to `slice` results from buffer:
```c
has_bones9 = selectbuffer_has_bones(storage.as_span().slice(ofs, hits9));
```

Pull Request: https://projects.blender.org/blender/blender/pulls/124154
2024-07-17 16:07:15 +02:00
Jeroen Bakker
31a045ba15 Vulkan: Faster hashing of fragment shader
Improving performance as hashing the fragment shader was visible
in performance analysis. This PR calculates the hash once and stores
it inside the struct for quick access.

Pull Request: https://projects.blender.org/blender/blender/pulls/124882
2024-07-17 15:23:21 +02:00
Jeroen Bakker
1497e37728 Cleanup: Vulkan: Descriptor set allocations
During descriptor set update several internal buffers where reallocated
over and over. As descriptor set updates are done very often (1000s
times per frame) some performance could be gained by keeping the
previous allocated buffers around.

Pull Request: https://projects.blender.org/blender/blender/pulls/124877
2024-07-17 14:38:44 +02:00
Weizhen Huang
c7c55894e4 Fix: EEVEE principled coat has tint when the weight is zero
caused by 26eb5d9899

Pull Request: https://projects.blender.org/blender/blender/pulls/124856
2024-07-17 13:54:26 +02:00
Jeroen Bakker
823de4b3b8 Vulkan: Add support for colored particle hair
When using particle hair the optional generated color buffer was bound
as a texture (texel buffer), however in Vulkan texel buffers aren't
textures but buffers.

This change will create a texture, that will pass the needed calls to
the source vertex buffer. Only particle hair does uses
`GPU_texture_create_from_vertbuf`. I would expect that we will phase
this out eventually when particle hair is removed.

This fixes crashes with scenes using particle hair where materials use color
or uv attributes.
![image](/attachments/d5511eee-4db0-4241-bf00-472834c4ca7b)

Pull Request: https://projects.blender.org/blender/blender/pulls/124854
2024-07-17 13:32:06 +02:00
Jeroen Bakker
ca0e1d696a Vulkan: Layer tracking during render scope
EEVEE can bind layers of a texture that is also used as an attachment. When binding
the image layout of these specific layers can be different that the image layout of
the whole image.

This fixes the known synchronization issues inside EEVEE. wasp_bot, tree_creature and
wanderer scenes can be rendered without any synchronization issue reported by the
Vulkan validation layers.

Design task: #124214

When beginning to render the attachments are being evaluated. If there is an arrayed
texture (with multiple layers) the individual layers of that texture can be tracked
during until the rendering is ended.

When the same texture is bound to a shader it will be a different layer (otherwise
there is a feedback loop, which isn't allowed). The bound layers will typically need
a different layout the transition to the new layout is executed and recorded. When
the rendering ends, the layers are transitioned back to the layout the texture is
expected in.

It can happen that a layer is used multiple times during the same rendering. In
that case the rendering should be suspended to perform the transition. Image layout
transitions are not allowed during rendering.

There is one place where a layer needs to be transited multiple times that is when
EEVEE wants to extract the thickness from the shadow. The thickness is stored inside
the gbuffer_normal which is also used as an attachment. Eval then samples the thickness
from the gbuffer_normal as a sampler. To work around this issue we suspend the rendering
when a `GPU_BARRIER_SHADER_IMAGE_ACCESS` is signaled.

Pull Request: https://projects.blender.org/blender/blender/pulls/124407
2024-07-16 16:39:18 +02:00
Iliya Katueshenock
9a2ff022a7 Fix: Nodes: Lack of dash on fields links
Regression after 24dc9a21b1.

Pull Request: https://projects.blender.org/blender/blender/pulls/124740
2024-07-16 09:47:15 +02:00
Weizhen Huang
3fcd80db68 Fix #124621: EEVEE closure reservoir sampling not considering color weight
color was not taken into consideration when picking a closure using
reservoir sampling, giving closures with dark color much higher weights
than they should have.
This fix multiplies the weight by the average color when picking the
closure, similar as what has been done in principled BSDF.

Pull Request: https://projects.blender.org/blender/blender/pulls/124730
2024-07-15 17:00:51 +02:00
Jeroen Bakker
0d71d83d47 Vulkan: Share rendergraphs on context inside same thread
This PR will share render graphs between all contexts that run in
the same thread. This allows the draw manager commands to be added
to the same render graph as the UI.

- Fixes debug groups hiearchy. Draw manager would restart a hierarchy as
  it wasn't aware of the debug groups already added by the UI
- Removes cpu sync when switching between contexts.

In a future change this is needed to improve discarding resources.

Pull Request: https://projects.blender.org/blender/blender/pulls/124715
2024-07-15 16:03:51 +02:00
Campbell Barton
8fdb190278 Cleanup: typos in comments (duplicate words) 2024-07-14 18:55:43 +10:00
Jeroen Bakker
14fb537eca Merge branch 'blender-v4.2-release' 2024-07-12 15:41:39 +02:00
Jeroen Bakker
8ac023da61 Fix #124530: EEVEE: Math wrap function not working
Due to incorrect check the result was always returning the min
parameter.

Found issue by comparing the implementation with cycles.
Regression introduced by 7fe7b2eed0

Pull Request: https://projects.blender.org/blender/blender/pulls/124604
2024-07-12 15:40:12 +02:00
Jeroen Bakker
d953f6b6f7 Vulkan: Reset command buffer
Previously we create a new command buffer when the render graph is being
submitted. This PR changes that by resetting the command buffer for
reuse.

Pull Request: https://projects.blender.org/blender/blender/pulls/124596
2024-07-12 14:38:42 +02:00
Jeroen Bakker
0cbc354b54 Fix: Vulkan: Texture Views ignored array length
The array-length of a texture view isn't stored at the same location as
the array-base and was forgotten that it was a feature what had to be
supported.

Detected when testing `monster.blend` where the SSS object id wasn't
set and lead to missing materials.

**Before**
![image](/attachments/e503a48a-d365-459b-901d-7b72f224e163)

**After**
![image](/attachments/a321494b-042a-4534-a4e0-b864babbd5aa)

Pull Request: https://projects.blender.org/blender/blender/pulls/124590
2024-07-12 12:50:50 +02:00
Jeroen Bakker
a730454c8a Vulkan: Add test case for render graph draw
Pull Request: https://projects.blender.org/blender/blender/pulls/124507
2024-07-11 11:38:36 +02:00
Richard Antalik
af1a6d048d VSE: Simplify outline parameters definition and usage
Function `strip_data_outline_params_set()` was simplified, so setting
color and outline parameters are not mixed and overwriting as code flows
and so the function is better readable.

Shader code is changed, so that when strip overlaps other strip, it gets
2 px red outline regardless of whether it is active or selected. This
makes it more consistent when strip is not active or selected.

Pull Request: https://projects.blender.org/blender/blender/pulls/124442
2024-07-11 07:38:02 +02:00
Jesse Yurkovich
57544887d0 CMake: Add WITH_TBB definition to prevent ODR violation for BLI_spin API
The BLI_spin APIs use a `SpinLock` typedef whose underlying type is
contingent on the precense of `WITH_TBB`. Since our projects did not
consistently define the `WITH_TBB` definition, multiple `SpinLock` types
would end up in our final binary creating ODR violations.

Pull Request: https://projects.blender.org/blender/blender/pulls/124285
2024-07-10 23:02:17 +02:00