Commit Graph

5413 Commits

Author SHA1 Message Date
Jeroen Bakker
2b43900ccc Vulkan: Reading subtexture
Subtexture reading is supported via GPUFramebuffer. The input
parameters was an rect, but is called an area which includes
width and height.

Due to inconsistent naming the area was assumed to be a region leading
to incorrect sub texture being downloaded or crashes due to out of
bound writes.

This fix crashes when selecting in edit mode.

Pull Request: https://projects.blender.org/blender/blender/pulls/127229
2024-09-06 11:55:36 +02:00
Jeroen Bakker
458faa6486 Preferences: GPU backend selection
This PR allows users to select a GPU backend.

In the system tab of the user preferences the GPU backend can be selected in the `Display Graphics` panel.
It will require a restart of Blender before the changes become effective.

During startup minimum requirements are checked. Blender will switch automatically
to OpenGL when no compatible Vulkan device could be detected. A dialog will be shown
to inform the user.

The setting of the in the `Display Graphics` panel are still overridden when blender is started
using the `--gpu-backend` option. When starting blender with `--debug-gpu` the backend
detection will print to the console.

See PR for detailed information and screenshots of the UI.

Implements #126504
Pull Request: https://projects.blender.org/blender/blender/pulls/126545
2024-09-06 08:28:41 +02:00
Jeroen Bakker
b2fdae6f0e Vulkan: GPU depth picking
GPU depth picking was not working on all GPUs. When a GPU requires a
DEPTH32F to store depths the conversion to unsigned normalized could
wrap around. Making depths of 1.0 become 0. In stead of MAX_DEPTH.

This solves depth picking issues on Intel and AMD GPUs.
2024-09-05 15:14:40 +02:00
Jeroen Bakker
98feb87f40 Vulkan: Disk cache for static pipelines
This PR introduces disk cache for static pipelines. The pipelines are
stored in `<cache folder>/vk-pipeline-caches/static-shaders.bin`.

Due to limitations in some drivers we add a custom header to the
cache file to identify if the cache file was created by the same driver
for the same GPU for the same Blender.

Reading/writing the cache is skipped when running blender with
`--debug-gpu` as that would generate different shader modules. For
now that isn't a problem, but the final implementation would check
before compiling a shader if a certain key is in the pipeline cache if
that is the case the compilation step is skipped and the cached shader
module is used.

Reference: #126229
Pull Request: https://projects.blender.org/blender/blender/pulls/127110
2024-09-05 13:02:40 +02:00
Jeroen Bakker
52a84b6c01 Vulkan: Don't overwrite pipeline base when already set
Base pipelines are used to optimize the vulkan pipeline creation.
Instead of building each pipeline from scratch a base pipeline can
be used to share resources and faster code-paths.

We used to overwrite the base pipeline with the last created pipeline.
This PR doesn't overwrite the base pipeline after it was initially set
giving less confusion when working with base pipelines.

Pull Request: https://projects.blender.org/blender/blender/pulls/127181
2024-09-05 13:00:39 +02:00
Anthony Roberts
5f34338296 Windows: Disable shader draw parameter support on certain Qualcomm GPUs
This works around an issue where eevee was rendering a pure black cube in certain shader configurations in the default scene (#122837). This only affects X Elite devices (8cx Gen3 is unaffected).

Pull Request: https://projects.blender.org/blender/blender/pulls/127148
2024-09-04 18:19:54 +02:00
Miguel Pozo
6f81cb7c63 Fix #126194: Parallel shader compilation crash 2024-09-03 18:13:19 +02:00
Jeroen Bakker
b2a0d29345 Vulkan: Separate pipeline caches for (non)static shaders
This change does some preparations before we implement persistent
caching for static shaders.

- Move ownership of pipeline cache to the pipeline pool.
- Use two pools. one is only used for static shaders
  other for non static shaders.

Related to #126229

Pull Request: https://projects.blender.org/blender/blender/pulls/127100
2024-09-03 15:25:50 +02:00
Campbell Barton
e34d9eeac7 Cleanup: use C-style comments, double quote Python text 2024-09-03 21:22:34 +10:00
Weizhen Huang
77035192c9 Fix #126799: undefined behavior of shader node Arctan2 at (0, 0)
`atan2(0, 0)` is undefined on many platforms. To ensure consistent
result across platforms, we return `0` in this case.

Note only the behavior of the shader node `Artan2` is changed here.
During shading, we might still produce `atan2(0, 0)` internally and
cause different results across platforms, but that usually happens with
single samples and is not obvious, plus checking this condition all the
time is costly. If later we find out it's indeed necessary to change all
the invocation of `atan2(0, 0)`, we could change the wrapper functions
in `metal/compat.h` and `mtl_shader_defines.msl`.

Pull Request: https://projects.blender.org/blender/blender/pulls/126951
2024-09-03 11:44:59 +02:00
Aras Pranckevicius
4c8f22447f VSE: Faster timeline thumbnail drawing
VSE timeline, when many (hundreds/thousands) of thumbnails were visible, was
very slow to redraw. This PR makes them 3-10x faster to redraw, by stopping
doing things that are slow :) Part of #126087 thumbnail improvements task.

- No longer do mute semitransparency or corner rounding on the CPU, do it in
  shader instead.
- Stop creating a separate GPU texture for each thumbnail, on every repaint,
  and drawing each thumbnail as a separate draw call. Instead, put thumbnails
  into a single texture atlas (using a simple shelf packing algorithm), and
  draw them in batch, passing data via UBO. The atlas is still re-created every
  frame, but that does not seem to be a performance issue. Thumbnails are
  cropped horizontally based on how much of their parts are visible (e.g. a
  narrow strip on screen), so realistically the atlas size is kinda
  proportional to screen size, and ends up being just several megabytes of data
  transfer between CPU -> GPU each frame.

On this Sprite Fright edit timeline view (612 visible thumbnails), time taken
to repaint the timeline window:

- Mac (M1 Max, Metal): 68.1ms -> 4.7ms
- Windows (Ryzen 5950X, RTX 3080Ti, OpenGL): 23.7ms -> 6.8ms

This also fixes a visual issue with thumbnails, where when strips are very
tall, the "rounded corners" that were poked right into the thumbnail bitmap
on the CPU were showing up due to actual bitmap being scaled up a lot.

Pull Request: https://projects.blender.org/blender/blender/pulls/126972
2024-09-03 08:25:15 +02:00
Clément FOUCAULT
b13593e0be GPU: Silence warnings when not building with renderdoc support 2024-09-01 13:15:56 +02:00
Aras Pranckevicius
4b76b398d5 Fix: Vulkan code build failure when Renderdoc is enabled
8ae0264459 broke the build when both Vulkan and Renderdoc options
are on
2024-09-01 12:32:02 +03:00
Clément FOUCAULT
870d664e31 Overlay-Next: Edit Curves
Straightforward Port

Rel #102179

Pull Request: https://projects.blender.org/blender/blender/pulls/126892
2024-08-30 16:03:44 +02:00
Clément FOUCAULT
8ae0264459 GPU: Add debug scope capture support for Renderdoc
This adds a new launch argument when building with
renderdoc support. It allows to trigger the capture
of a specific capture scope. This allows selective
capture of some commonly captured parts.

Pull Request: https://projects.blender.org/blender/blender/pulls/126791
2024-08-30 15:14:58 +02:00
Jeroen Bakker
e8e89b751d Vulkan: Fix incorrect reordering when copying attachment
Solved by not supporting complex reordering at this moment. It
is currently better to focus on quality and add back performance
later. During tests I didn't detect any user noticeable performance
degradation. Could also be because we support rendering
suspending/resuming.

Fixes artifacts in EEVEE volumes and raytracing.

Pull Request: https://projects.blender.org/blender/blender/pulls/126974
2024-08-30 13:24:57 +02:00
Jeroen Bakker
509123c877 Vulkan: Initial support for multiple windows
- Resource pools are shared between multiple swap chains to reduce
  code complexity
- Fix issue where activating a new graphical context could still leave
  the previous context rendering.
- Known issue: opening files with more windows require a redraw.

Reference: #126499
Pull Request: https://projects.blender.org/blender/blender/pulls/126961
2024-08-30 10:01:56 +02:00
Jeroen Bakker
e82ba8d495 Vulkan: Incorrect buffer size when allocating large buffers
When 'really' large buffers are allocated the incorrect clamping
function was used and the actual buffer allocated was smaller than
expected.

This was detected during investigation of #126863.

Pull Request: https://projects.blender.org/blender/blender/pulls/126915
2024-08-29 08:55:02 +02:00
Clément Foucault
25b2c5f170 BLI: Add reduce_mul 2024-08-28 09:48:17 +02:00
Alaska
6ccb33e9fe Shader: Add Metallic BSDF Node
Add Metallic BSDF Node to the shader editor.

This node can primarily be used to create more realistic looking
metallic materials than the existing Glossy BSDF node.

This commit does not add any new closures to Cycles, it simply exposes
existing closures that were previous hard to access on their own.

- Exposes the F82 fresnel type that is currently used by the
metallic component of the Principled BSDF. Results should match
between the Metallic BSDF and Principled BSDF when using the same
settings.
- Exposes the Physical Conductor fresnel type that was previously
limited to custom OSL scripts. The Conductor fresnel type accepts
IOR and Extinction coefficients to define the appearance of the
material based off real life measurements.

EEVEE only supports the F82 fresnel type with internal code to convert
the the physical conductor inputs in to a colour format for F82,
which can lead to noticeable rendering differences with
some configurations.

Pull Request: https://projects.blender.org/blender/blender/pulls/114958
2024-08-27 17:20:46 +02:00
Jeroen Bakker
f19675ffca Vulkan: Incorrect default for missing orco
When orcos are not available in the geometry data it is bound with
a default buffer. This buffer was initialized with only zeros. But
orcos required to read the 0, 0, 0, 1.

Fixes `render/shader/tex_voronoi.blend` render test.

Pull Request: https://projects.blender.org/blender/blender/pulls/126838
2024-08-27 16:00:00 +02:00
Jeroen Bakker
660e571969 Vulkan: Recycle resources when rendering in background
When rendering in background there is no swap chain in play and
resources would never be collected. Resulting in out of resources and
crashes.

This PR is an initial fix what cycles resource pools every time a layer
has been rendered. It counts the render hierarchy
(GPU_rendering_begin/end) to identify if the background render is
completed and if so would cycle to the next resource pool.

Pull Request: https://projects.blender.org/blender/blender/pulls/126819
2024-08-27 10:09:53 +02:00
Jeroen Bakker
78af1722cf Fix #123787: EEVEE: RDNA2 shadow of tiny geom
Workaround for RDNA2 shadow rendering when the geometry it needs
to render is to tiny. In this case the rasterizer can skip triangles
leading to incorrect shadow.

This issue has been forwarded to AMD, but this is a temp workaround
for the current drivers. Note that this workaround adds a performance
penalty of around 50% in selected scenes.

Pull Request: https://projects.blender.org/blender/blender/pulls/126693
2024-08-26 12:45:18 +02:00
Campbell Barton
40f96afa61 Cleanup: various non-functional changes
- Use const arguments.
- Remove redundant cast.
- Use ELEM macro.
- Use boolean & nullptr literals.
2024-08-26 11:50:12 +10:00
Clément Foucault
e673e89630 GPU: Add support for shader printf inside tests 2024-08-23 16:11:28 +02:00
Jeroen Bakker
d48986eec9 Fix: Vulkan: EEVEE irradiance baking
Fix crash when using EEVEE irradiance baking. When reading back the
intermediate result the active rendering was not ended, resulting
in an assert as the rendergraph is cleared and assumed to be in an
initial state (not rendering).

Pull Request: https://projects.blender.org/blender/blender/pulls/126688
2024-08-23 14:45:40 +02:00
Jeroen Bakker
529c720457 Fix #126412: Metal default alpha value
Metal doesn't support RGB textures and the backend converts them to RGBA textures.
During the conversion missing RGB components should be set to 0 and missing A
component should be set to 1.

In the current implementation this was not the case and A components where also set
to 0.

PR should be backported to 4.2

Pull Request: https://projects.blender.org/blender/blender/pulls/126630
2024-08-22 11:52:34 +02:00
Jeroen Bakker
d16806bc17 Fix: Vulkan: Incorrect Depth Retargetting
Vulkan has different depth limits then opengl. We fix this by
retargetting the opengl limits into the limits that vulkan supports.

This is done in the vertex shader, or in the geometry shader. When
viewport index or layer isn't supported a geometry shader is added to
workaround these missing features. In this case the depth range was
could be done twice (vertex shader and geometry shader).

Pull Request: https://projects.blender.org/blender/blender/pulls/126634
2024-08-22 11:29:55 +02:00
Jeroen Bakker
7f1812e335 Vulkan: Fix multi view layer selection
When using multi view only the first layer could be selected as the
rendering info only had a single layer in its main struct.
- Add failsafe for unsupported platforms
2024-08-20 16:02:32 +02:00
Jeroen Bakker
8acb2f363e Cleanup: Remove solved comment 2024-08-20 15:31:54 +02:00
Jeroen Bakker
2c6b1eb2e5 GPU: Fix static shader tests for NVIDIA
Skipping tests when workarounds are enabled due to GLSL restrictions in
the NVIDIA driver.
2024-08-20 14:52:35 +02:00
Jeroen Bakker
242271237a Vulkan: Ensure rendering ends when deleting attached framebuffer
When a frame buffer that is attached is being deleted the rendering end
event will never happen which leads to inconsistent render graphs.
2024-08-20 14:50:18 +02:00
Jeroen Bakker
df910f2417 GPU: Fix draw test on NVIDIA/OpenGL
Some workarounds cannot work on NVIDIA but are tested leading to
segfaults. Fixed by skipping in these cases.
2024-08-20 13:37:00 +02:00
Jeroen Bakker
7a7ae5defe Vulkan: Occlusion Queries
Implements occlusion queries using VkQueryPools.

Pull Request: https://projects.blender.org/blender/blender/pulls/123883
2024-08-20 11:27:33 +02:00
Jeroen Bakker
994e14b000 OpenGL: Enable HQ normals workaround for more AMD drivers
Allows EEVEE to be used on Legacy platforms. Fixes rendering black geometry in some cases.

Pull Request: https://projects.blender.org/blender/blender/pulls/126540
2024-08-20 08:46:55 +02:00
Campbell Barton
908d004fcc Cleanup: spelling in comments 2024-08-20 14:25:52 +10:00
Iliya Katueshenock
1b67be14c6 Cleanup: BKE: Nodes: Functions renaming
Use snake style naming for all the kernel nodes functions.
Omit kernel prefix in the names since of the using namespace.
Use full forms of the terms
('iter' -> 'iterator', 'ntree' -> 'node_tree', 'rem' -> 'remove', ...).

Pull Request: https://projects.blender.org/blender/blender/pulls/126416
2024-08-19 20:27:37 +02:00
Jeroen Bakker
ef3ceb3629 Vulkan: Resource Pools
This PR implements #126353; In short: keep discard list as part of swap chain images. This allows
better determination when resources are actually not in use anymore.

## Resource pool

Resource pools keep track of the resources for a swap chain image.

In Blender this is a bit more complicated due to the way GPUContext work. A single thread can have
multiple contexts. Some of them have a swap chain (GHOST Window) other don't (draw manager). The
resource pool should be shared between the contexts running on the same thread.

When opening multiple windows there are also multiple swap chains to consider.

### Discard pile

Resource handles that are deleted and stored in the discard pile. When we are sure that these
resources are not used on the GPU anymore these are destroyed.

### Reusable resources

There are other resources as well like:
- Descriptor sets
- Descriptor pools

## Open issues

There are some limitations that require future PRs to fix including:
- Background rendering
- Handling multiple windows
- Improve CPU/GPU synchronization
- Reuse staging buffers

Pull Request: https://projects.blender.org/blender/blender/pulls/126353
2024-08-19 15:37:48 +02:00
Jeroen Bakker
975dcea23f OpenGL: Enable High Quality Normals for Legacy AMD Drivers
On Legacy AMD devices EEVEE doesn't render any geometry. During testing
we found that it was based on reading normal attribute. Further testing
it was detected that enabling the high quality normals would solve the
rendering.

This is a known issue on legacy AMD drivers. This PR updates the check
to enable the high quality normals workaround for the latest known AMD
legacy drivers (22.6.1/21.Q1.2). Both drivers still have this issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/126483
2024-08-19 09:42:52 +02:00
Campbell Barton
b5e0b59736 Cleanup: remove space around identifiers in C-style comments 2024-08-15 20:46:00 +10:00
Jeroen Bakker
925753c83b Fix #125618: EEVEE: Cryptomatte Material Layer Incorrect
Missing oversight in previous fix where incorrect name size where
used to generate the cryptomatte hash.

Pull Request: https://projects.blender.org/blender/blender/pulls/126352
2024-08-15 08:41:12 +02:00
Omar Emara
075bdbcd63 Nodes: Improve isotropic Gabor noise UI controls
This patch improves the isotropic Gabor noise UI controls such that
variations happen in both directions of the base orientation, as opposed
to being biased in the positive direction only.

Thanks to Charlie Jolly for suggesting this improvement.
2024-08-14 15:26:03 +03:00
Omar Emara
ce89d7949c Nodes: Optimize Gabor noise variance estimation
This patch optimizes the Gabor noise standard deviation estimation by
computing the upper limit of the integral as the frequency approaches
infinity, since the integral is mostly constant for the relevant
frequency range. The limits are 0.25 for the 2D case and 1 / 4 * sqrt2
for the 3D case.

This also improves normalization for low frequencies, possibly due to
the effect of windowing.

Thanks to Charlie Jolly for spotting the optimization.
2024-08-14 14:27:23 +03:00
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