Commit Graph

379 Commits

Author SHA1 Message Date
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
Jeroen Bakker
615f4a7d4e Cleanup: Vulkan: Remove unused variable
Detected when compiled with clang.

Pull Request: https://projects.blender.org/blender/blender/pulls/124480
2024-07-10 21:44:19 +02:00
Jeroen Bakker
6471b715b2 Vulkan: Remove performance warning about depth clearing
When clearing depth attachment the write depth state should be enabled.
When this isn't the case a clear texture is being performed. Before
the render graph this used to be a performance issue as the rendering
would be suspended.

The render graph currently reorders these texture clears before of
the rendering context and therefore isn't seen as a performance issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/124340
2024-07-08 14:00:40 +02:00
Jeroen Bakker
180a257eef Cleanup: Vulkan: Use stamp in stead of version
Pull Request: https://projects.blender.org/blender/blender/pulls/124339
2024-07-08 12:56:21 +02:00
Jeroen Bakker
08d365b810 Vulkan: Cleanup barrier state
Try to reduce the barrier state so we can be more flexible when adding
support for sub resource tracking.

Pull Request: https://projects.blender.org/blender/blender/pulls/124237
2024-07-08 12:28:11 +02:00
Campbell Barton
cd1dbab348 Cleanup: spelling in comments 2024-07-07 00:29:39 +10:00
Campbell Barton
48383cf20e Cleanup: avoid shadowing, redundant assignment & minor changes
Quiet cppecheck warnings, use const pointers, ELEM(..) macro,
replace NULL -> nullptr, unsigned int -> uint.
2024-07-07 00:18:00 +10:00
Jeroen Bakker
89daa19f57 Vulkan: Device statistics
This PR adds device statistics which can be printed to the console.
By default nothing is printed, but developer can choose to enable
it during development.

Pull Request: https://projects.blender.org/blender/blender/pulls/124150
2024-07-04 13:47:54 +02:00
Jeroen Bakker
b6c078a28f Vulkan: Fix image bind space collision
EEVEE Eval light shader could still make a collision between
texture and image bind space making rendering glitch
when not using `--debug-gpu`. The problem was that the bind space
wasn't aware of the offset that the shader interface was using.

Pull Request: https://projects.blender.org/blender/blender/pulls/124140
2024-07-04 10:41:43 +02:00
Jeroen Bakker
4394b87012 Vulkan: Add support for barycentric coordinates
Barycentric coordinates are used for the wireframe shader. It was
already implemented, but was made broken or when we change the depth
range or when we added support for fallback of shader viewport/layer
rendering. The previous implementation didn't use the correct
EmitVertex leading to incorrect depths. Also the shader layouts where
not Vulkan compliant.

![image](/attachments/39fbfd9e-16fd-42d8-9520-3d8fa839e7de)

Pull Request: https://projects.blender.org/blender/blender/pulls/124048
2024-07-02 15:59:16 +02:00
Jeroen Bakker
88f04e95c3 Vulkan: Fix HiZ synchronization
HiZ update performs a read/write on different buffers, this lead
to write-after-write hazards as the resources where added multiple
times in the same pipeline barrier with different access masks.
This is fixed by merging pipeline barriers based on their resource.

Pull Request: https://projects.blender.org/blender/blender/pulls/124036
2024-07-02 14:06:49 +02:00
Jeroen Bakker
bf3c6a3480 Vulkan: Improve debugging render graph
Adds debug print function to output a node with its inputs and outputs.
Also keep track of the name of the resource (only images) what will
be presented. Tracking of the resource name is only done in debug builds.

Pull Request: https://projects.blender.org/blender/blender/pulls/124033
2024-07-02 13:29:34 +02:00
Jeroen Bakker
7fcc4e5374 Vulkan: Add Render graph support to VKDrawList
Resources of the draw list were overwritten, before used. Fixed by
using resource tracking.

Pull Request: https://projects.blender.org/blender/blender/pulls/124024
2024-07-02 09:20:34 +02:00
Jeroen Bakker
3434260874 Vulkan: Add support for Cycles CPU
Other Cycles backend might also work. Not sure about or Optix/Cuda
as they require GPU synchronization.

Pull Request: https://projects.blender.org/blender/blender/pulls/123895
2024-06-28 13:51:51 +02:00
Jeroen Bakker
da4746fe96 Vulkan: Fix copy depth images with stencil
When copying the depth aspect of a depth+stencil image the incorrect
barriers where created. The barrier needs to have the full aspect, even
when we only copy a single aspect from the image.

Pull Request: https://projects.blender.org/blender/blender/pulls/123890
2024-06-28 13:13:33 +02:00
Jeroen Bakker
e72e538fdd Vulkan: Fix sequential read hazard
When a buffer resource was read, and after that read from another
shader stage it would not generate the appropriate pipeline barrier.

This is fixed by keeping the last write action around and check
if the shader stage was already included in the previous barriers.

Pull Request: https://projects.blender.org/blender/blender/pulls/123845
2024-06-27 15:53:14 +02:00
Jeroen Bakker
3009c98d5f Vulkan: Fix read-after-write hazard in draw manager visibility
Draw Manager visibility compute shader triggered a read-after-write
hazard. This root cause was that the incorrect access was read from
the shader interface. It was set to none, skipping the needed pipeline
barrier.

Pull Request: https://projects.blender.org/blender/blender/pulls/123839
2024-06-27 14:55:15 +02:00
Jeroen Bakker
02a45fb60d Vulkan: Add read dependency for push constants fallback
When a shader uses push constants fallback the push constants are
stored inside a uniform buffer. The uniform buffer needs to be guarded
with a read barrier.

Pull Request: https://projects.blender.org/blender/blender/pulls/123777
2024-06-26 14:38:08 +02:00
Jeroen Bakker
ee0b7b9a95 Vulken: Mix array aspect of image views
The image views type can change depending based on how they are bound
to shaders. When a shader accesses a view without array operations,
the image view should not be an array. This was previously ignored.

Pull Request: https://projects.blender.org/blender/blender/pulls/123726
2024-06-25 15:15:18 +02:00
Jeroen Bakker
78f37fe331 Vulkan: Fix incorrect image aspect
When clearing only the depth of a depth/stencil only the depth
part of the image aspect was stored in the node. This is invalid
when the image needed to be transitioned.

Pull Request: https://projects.blender.org/blender/blender/pulls/123713
2024-06-25 11:05:24 +02:00
Jeroen Bakker
f5b173188e Vulkan: Fix incorrect read image barrier
When having a sequential read image barriers for the same resource
and the second one requires an image layout transition the incorrect
barriers where generated.

This was fixed by aligning the implementation with write image barriers.

Pull Request: https://projects.blender.org/blender/blender/pulls/123712
2024-06-25 11:05:07 +02:00
Jeroen Bakker
55ac7fd6fd Vulkan: Early exit clearing stencils
Adds an early exit when clearing stencils on textures that don't have
a stencil aspect. This is the case when rendering EEVEE planar probes.

Pull Request: https://projects.blender.org/blender/blender/pulls/123668
2024-06-24 14:19:24 +02:00
Jeroen Bakker
34a679d19f Vulkan: Read out of bound when using many resources
Internally the image and texture resources where kept in a vector
where the elements were referenced. When using more than 16 images
this vector is reallocated and previous references become invalid.

This is a quick fix and should be changed with something more
stable.

Pull Request: https://projects.blender.org/blender/blender/pulls/123656
2024-06-24 11:50:38 +02:00
Jeroen Bakker
0c39a75634 Vulkan: Fix binding collision when mixing textures and images
Due to incompatible binding namespaces between Vulkan and OpenGL we
offset the images in the ubo list. In the previous implementation
this could still go wrong as the images and textures bindings where
sequential. When EEVEE binds resources it can also try to bind resources
that aren't valid for the current shader. In this case it was still
possible that the incorrect binding was chosen.

This is fixed by offsetting the images by a large number.

Pull Request: https://projects.blender.org/blender/blender/pulls/123649
2024-06-24 09:27:13 +02:00
Jeroen Bakker
dbd04310c7 Vulkan: Fix incorrect layout transition
When many text using BLF the glymp texture could be re-written.
In this case the new upload should be done in a separate render
graph node group. This wasn't the case and resulted in
validation warnings about the glyph texture being in an layout
that wasn't expected.

This PR simplifies the group extraction a bit by looking ahead
when the group ends.

Pull Request: https://projects.blender.org/blender/blender/pulls/123547
2024-06-21 13:26:52 +02:00
Jeroen Bakker
4c8de4aedd Vulkan: Fix multi viewport framebuffers
Due to incorrect logic any multi viewport setup could be cleaned
when dynamic rendering begins. This patch moves the clearing
of the viewport/scissor setup when binding.

This issue fixes shadow rendering in EEVEE.

Pull Request: https://projects.blender.org/blender/blender/pulls/123484
2024-06-20 14:46:48 +02:00
Jeroen Bakker
faf0171c36 Vulkan: Make stencil export optional
`VK_EXT_shader_stencil_export` isn't supported by NVIDIA devices.
This extension was recently added to support EEVEE PBR layer selection.

This PR makes this extension optional and selects the work around
when not supported by the physical device.

Fixes #114385

Pull Request: https://projects.blender.org/blender/blender/pulls/123470
2024-06-20 14:12:07 +02:00
Jeroen Bakker
4353b7ffba Vulkan: Remove unused code
Vulkan backend has recently switched to a render graph approach. Many
code was left so we could develop the render graph beside the previous
implementation. Last week we removed the switch. This PR will remove
most of the unused code. There might be some left and will be removed
when detected.

Pull Request: https://projects.blender.org/blender/blender/pulls/123422
2024-06-20 11:34:19 +02:00
Campbell Barton
a9447cf09a Cleanup: spelling in comments 2024-06-19 10:03:37 +10:00
Hans Goudey
79416a8b96 Refactor: GPU: Simplify access to vertex buffer data
Add a `.data<T>()` method that retrieves a mutable span. This is useful
more and more as we change to filling in vertex buffer data arrays
directly, and compared to raw pointers it's safer too because of asserts
in debug builds.

Pull Request: https://projects.blender.org/blender/blender/pulls/123338
2024-06-18 21:10:45 +02:00
Jeroen Bakker
0643f495cd Vulkan: Fix incorrect write access mask in pipeline barriers
By adding the previous mask, masks could be used in pipeline
stages that don't support the mask. Fixed by limiting the
mask to the current node.

Pull Request: https://projects.blender.org/blender/blender/pulls/123381
2024-06-18 17:17:20 +02:00
Jeroen Bakker
71c716d8c0 Vulkan: Fix incorrect texture update
Texture update ignored layered based offsets and extents. This was
an oversight due to misintepreting the API. This fixes uploading the
utility texture of EEVEE and enables correct material shading.

Pull Request: https://projects.blender.org/blender/blender/pulls/123371
2024-06-18 14:58:41 +02:00
Jacques Lucke
8b7cde3efc Merge branch 'blender-v4.2-release' 2024-06-14 20:19:03 +02:00
Miguel Pozo
a22a4810c7 GPU: Use size_t for GPU buffer sizes
Update all GPU buffer size-related functions to use `size_t` for
consistency.

Pull Request: https://projects.blender.org/blender/blender/pulls/123240
2024-06-14 19:27:33 +02:00
Campbell Barton
f529b0f115 Cleanup: compiler warning with enum mis-match 2024-06-15 00:31:17 +10:00
Jeroen Bakker
7a8831ba13 Vulkan: Fix clamp to edge samplers
When using GPU_SAMPLER_EXTEND_MODE_EXTEND the incorrect sampler
was created, making the OCIO shader fail. This PR selects the
correct wrapping mode (CLAMP_TO_EDGE).

Pull Request: https://projects.blender.org/blender/blender/pulls/123234
2024-06-14 15:36:48 +02:00
Jeroen Bakker
11218f2fca Vulkan: Fix clang compiler warning
_No response_

Pull Request: https://projects.blender.org/blender/blender/pulls/123233
2024-06-14 15:26:25 +02:00
Jeroen Bakker
58ecfb869d Vulkan: Remove render graph switch
As render graph is now the default, we can remove the
render graph switch. This allows us to cleanup unused
functions and classes.

Pull Request: https://projects.blender.org/blender/blender/pulls/123219
2024-06-14 09:44:59 +02:00
Jeroen Bakker
07ea6a5c23 Vulkan: Enable render graph
This PR hooks up the vulkan backend with the render graph
for drawing. It can run Blender better than the previous
implementation so we also flipped it to be the default
implementation.

**Some highlights**
- Adds support for framebuffer load/store operations
- Adds support for framebuffer subpass transitions
- Fixes workbench shadows
- Performance is just below OpenGL performance when comparing
  fps. But the screen feels more fluent when using complex
  scenes.
- Current performance is without doing any optimizations so
  will improve in the future.
- EEVEE will not crash but has artifacts and many parts that
  require more work.

**Related to**
- #121648
- #118330

**Known Limitation**
- Similar to previous implementation resources can be freed when
  still in use crashing Blender. This is typically the case when
  playing back an animation or updating a material icon.

**Next steps**
- Remove old implementation
- Get EEVEE to work
- Fix double resource freeing
- Improve performance by identifying hotspots and change them

Pull Request: https://projects.blender.org/blender/blender/pulls/121787
2024-06-14 08:46:33 +02:00
Jeroen Bakker
22d352dacc Vulkan: Render graph drawing
This PR adds drawing support to the render graph. It adds support for
draw, indirect draw, indexed draw and indexed indirect draw.

Draw commands can only be executed within a rendering scope. Data
transfer commands and dispatch commands cannot be executed within a
rendering scope. Blender can still send in commands in any order and
the render graph needs to find out the best order to minimize context
switches (rendering/begin/end). This is the responsibility of the
scheduler.

The scheduler will push data transfer and dispatch commands outside the
rendering scope:
- data transfer and dispatch commands at the beginning are done before
  the rendering begin.
- data transfer and dispatch commands at the end are done after the
  rendering end.
- data transfer and dispatches in between draw commands will be pushed
  to the beginning if they are not yet being used.
- for all other data transfer and dispatch commands the rendering is
  suspenderd and will be continued afterwards.

Within a rendering context it is not allowed to perform synchronization
commands. Any synchronization commands inside a rendering scope will be
performed before the rendering scope begins. Nodes are now organized
in groups to simplify the code around this area.

Pull Request: https://projects.blender.org/blender/blender/pulls/123168
2024-06-13 09:37:17 +02:00
Miguel Pozo
83db9cc7b4 Merge branch 'blender-v4.2-release' 2024-06-07 18:47:47 +02:00
Miguel Pozo
22652b305e GPU: Add GPU_shaders_precompile_specializations
Allow precompiling specialization constants variations in parallel.
Only supported in OpenGL as the rest of the batch compilation API,
on the other backends the function is a no-op.
This also moves the `SpecializationConstant` from
`gpu_shader_create_info` (private API) into`GPU_common_types`
(public API).

Pull Request: https://projects.blender.org/blender/blender/pulls/122796
2024-06-07 18:45:31 +02:00
Lukas Stockner
5891a73785 Merge branch 'blender-v4.2-release' 2024-06-05 20:25:50 +02:00
Hans Goudey
84c4ddbbb9 Cleanup: GPU: Use references for some vertex buffer functions
Pull Request: https://projects.blender.org/blender/blender/pulls/122784
2024-06-05 18:47:22 +02:00
Miguel Pozo
74224b25a5 GPU: Add GPU_shader_batch_create_from_infos
This is the first commit of the several required to support
subprocess-based parallel compilation on OpenGL.
This provides the base API and implementation, and exposes the max
subprocesses setting on the UI, but it's not used by any code yet.

More information and the rest of the code can be found in #121925.

This one includes:
- A new `GPU_shader_batch` API that allows requesting the compilation
  of multiple shaders at once, allowing GPU backed to compile them in
  parallel and asynchronously without blocking the Blender UI.
- A virtual `ShaderCompiler` class that backends can use to add their
  own implementation.
- A `ShaderCompilerGeneric` class that implements synchronous/blocking
  compilation of batches for backends that don't have their own
  implementation yet.
- A `GLShaderCompiler` that supports parallel compilation using
  subprocesses.
- A new `BLI_subprocess` API, including IPC (required for the
  `GLShaderCompiler` implementation).
- The implementation of the subprocess program in
  `GPU_compilation_subprocess`.
- A new `Max Shader Compilation Subprocesses` option in
  `Preferences > System > Memory & Limits` to enable parallel shader
  compilation and the max number of subprocesses to allocate (each
  subprocess has a relatively high memory footprint).

Implementation Overview:
There's a single `GLShaderCompiler` shared by all OpenGL contexts.
This class stores a pool of up to `GCaps.max_parallel_compilations`
subprocesses that can be used for compilation.
Each subprocess has a shared memory pool used for sending the shader
source code from the main Blender process and for receiving the already
compiled shader binary from the subprocess. This is synchronized using
a series of shared semaphores.
The subprocesses maintain a shader cache on disk inside a
`BLENDER_SHADER_CACHE` folder at the OS temporary folder.
Shaders that fail to compile are tried to be compiled again locally for
proper error reports.
Hanged subprocesses are currently detected using a timeout of 30s.

Pull Request: https://projects.blender.org/blender/blender/pulls/122232
2024-06-05 18:45:57 +02:00
Jeroen Bakker
6ec64cb039 Vulkan: Fix sample count when uploading layered textures
When uploading layered textures it was assumed that the data uploaded
had the data for all layers and ignored the given extent.
2024-06-03 13:51:11 +02:00
Jeroen Bakker
8077411d59 Vulkan: Disable barriers when using render graph
Barriers should be automatically extracted from the render graph.
GPU_issue_barrier will become a no-op.
2024-06-03 13:48:56 +02:00
Jeroen Bakker
049d84d36d Vulkan: Texture view clearing
EEVEE-Next requires clearing texture views. This PR adds that.

Pull Request: https://projects.blender.org/blender/blender/pulls/122650
2024-06-03 13:47:15 +02:00
Jeroen Bakker
ac4ab3a209 Vulkan: Debug name for staging buffer
Staging buffers didn't had a name this PR adds a name so they
are easier to track in debug tools.

Pull Request: https://projects.blender.org/blender/blender/pulls/122649
2024-06-03 11:14:27 +02:00