Commit Graph

33 Commits

Author SHA1 Message Date
Jeroen Bakker
c4feddefd7 Refactor: Vulkan: Split VKWorkarounds
VKWorkarounds adds double negation. This PR splits
the struct into workarounds and extensions to reduce
confusing code.

Pull Request: https://projects.blender.org/blender/blender/pulls/136064
2025-03-17 09:06:47 +01:00
Jeroen Bakker
33fd027dc5 Cleanup: Remove unused attribute 2024-12-02 08:29:46 +01:00
Jeroen Bakker
c2695e2dcc Vulkan: Add support for legacy platforms
Dynamic rendering is a Vulkan 1.3 feature. Most platforms have support
for them, but there are several legacy platforms that don't support dynamic
rendering or have driver bugs that don't allow us to use it.

This change will make dynamic rendering optional allowing legacy
platforms to use Vulkan.

**Limitations**

`GPU_LOADACTION_CLEAR` is implemented as clear attachments.
Render passes do support load clear, but adding support to it would
add complexity as it required multiple pipeline variations to support
suspend/resume rendering. It isn't clear when which variation should
be used what lead to compiling to many pipelines and branches in the
codebase. Using clear attachments doesn't require the complexity
for what is expected to be only used by platforms not supported by
the GPU vendors.

Subpass inputs and dual source blending are not supported as
Subpass inputs can alter the exact binding location of attachments.
Fixing this would add code complexity that is not used.

Ref: #129063

**Current state**

![image](/attachments/9ce012e5-2d88-4775-a636-2b74de812826)

Pull Request: https://projects.blender.org/blender/blender/pulls/129062
2024-11-19 16:30:31 +01:00
Jeroen Bakker
8b9b67f2d3 Cleanup: Vulkan: Don't over-allocate render areas/viewports
In multiple parts (framebuffer and shader) the render areas/viewport could be
copied in an array of 16 structs, when only one is needed. This PR will use builder
patters so we don't over-allocate. Would spend less CPU cycles when constructing
render info, render passes/framebuffers, shaders.

Cleanup was part of !129062

Pull Request: https://projects.blender.org/blender/blender/pulls/130515
2024-11-19 13:40:12 +01:00
Jeroen Bakker
272403a6cb Vulkan: Remove empty attachments
Some Vulkan platforms don't support framebuffers with gaps between the
color attachments. Workbench framebuffers can create gaps.
(`in_front_fb`, `main_fb` when used for wire frame drawing).

This PR implements a detection mechanism to detect gaps. It also disables
features that are not able to comply to this requirement.

Detected when working on #129062

Pull Request: https://projects.blender.org/blender/blender/pulls/130258
2024-11-14 13:55:33 +01: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
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
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
5d5cbca7ed Vulkan: Refactor image views
Move ownership of image views to VKTexture. VKFramebuffer can request
access to the image views. This allows reconfiguring framebuffers when
the previous configuration is still in use by the render graph.

Pull Request: https://projects.blender.org/blender/blender/pulls/121727
2024-05-14 10:46:12 +02:00
Jeroen Bakker
40f2df1a81 Vulkan: Render graph clear attachments
Adds support for clear attachments to the render graph.
Clearing attachments require that the command buffer is
being set for rendering (vkCmdBeginRendering).

**What works**

- Clear attachments are working with dynamic rendering and the render graph
- `GPUVulkanTest.framebuffer_clear_color_single_attachment`
- `GPUVulkanTest.framebuffer_clear_color_multiple_attachments`
- `GPUVulkanTest.framebuffer_clear_multiple_color_multiple_attachments`
- `GPUVulkanTest.framebuffer_scissor_test`
- `GPUVulkanTest.framebuffer_clear_depth`

**What still needs to be addressed**

When a command buffer is rendering it cannot do any pipeline
barriers. For clearing attachments this isn't needed, but when
we address drawing we might need to register drawing resource
dependencies to the dependency list of the begin rendering node.
This will be solved when drawing will be implemented. [#121648]

The begin rendering node is large as it has to store data for
framebuffers with 8 color attachments as well. This might
become an overhead and we could solve this by splicing the
data of larger nodes into 2 lists. This will be addressed
after we are able to draw a screen so we can collect data
on this topic. [#121649]

Pull Request: https://projects.blender.org/blender/blender/pulls/121073
2024-05-10 15:39:56 +02:00
Hans Goudey
61e61ce0e1 Cleanup: Use Span instead of Vector const reference
Span is preferrable since it's agnostic of the source container,
makes it clearer that there is no ownership, is 8 bytes smaller,
and can be passed by value.
2024-02-14 17:23:01 -05:00
Miguel Pozo
333a5b513b GPU: Assert framebuffer operations match attachment layout
Ensure attachment states and load/store configs don't get out of sync
with the framebuffer layout.
In theory, a Framebuffer could have empty attachments interleaved with
valid ones so checking just the attachments "length" is not enough.
What this does instead is to ensure that valid attachments have a valid
config and that null attachments either don't have a matching config or
have an IGNORE/DONT_CARE one.

Pull Request: https://projects.blender.org/blender/blender/pulls/117073
2024-01-15 13:25:20 +01:00
Campbell Barton
7a4f7a1d51 Cleanup: spelling in comments, comment blocks 2024-01-11 16:46:46 +11:00
Jeroen Bakker
f9aca93a47 Vulkan: Add Support for sRGB Framebuffer Enablement
Allow binding of framebuffers without sRGB to linear transform.
`GPU_framebuffer_bind_no_srgb`. This Patch removes color transform
artifacts in node, image and sequence editor.

When the framebuffer is an srgb framebuffer and it is bound without
the transformation, the SRGB textures are bound as UNORM variants.

As framebuffer, render pass and subpass recreation is ensured by
`VKCommandBuffer` we don't need to mark the framebuffer dirty at
this time. Later on we can optimize this by adding a state changed
detection for framebuffers and render passes.

Pull Request: https://projects.blender.org/blender/blender/pulls/113838
2023-10-19 14:41:18 +02:00
Campbell Barton
b4504c7840 Cleanup: spelling in comments 2023-10-12 16:03:18 +11:00
Jeroen Bakker
d67ec32747 Vulkan: Support for Framebuffer with Missing Attachments
Wireframe mode wasn't working and viewport had flickering artifacts.
Reason was that the render pass creation failed for its framebuffer as
the input data was filled with garbage for attachments that were unused.

Vulkan requires every attachment to be filled upto the highest used attachment
slot. This PR fills missing attachments with a dummy texture.

Pull Request: https://projects.blender.org/blender/blender/pulls/113141
2023-10-10 09:27:07 +02:00
Clément Foucault
4a4b1482cd GL: Add subpass input emulation
This adds basic emulation of the subpass input feature
of vulkan and to a lower extend Raster Order Group on Metal.

This help test paths that might use this feature in the future
(like shadow rendering) on all platform and or simplify higher
level code for supporting older hardware.

This add clear description to the load/store ops and to the
new `GPUAttachementState`.

The OpenGL backend will correctly mask un-writable
attachments and will bind as texture readable attachments.

Even if possible by the vulkan standard, the GPU API prohibit
the read and write to the same attachment inside the same
subpass.

In the GL backend, this is implemented using `glTextureBarrier`
and `texelFetch` as it is described in the ARB_texture_barrier
extension.
https://registry.khronos.org/OpenGL/extensions/ARB/ARB_texture_barrier.txt

Pull Request: https://projects.blender.org/blender/blender/pulls/112051
2023-10-01 15:27:21 +02:00
Jason Fielder
503bdbf777 GPU: Add clear color support to explicit FB LoadStore state
Enhance custom framebuffer binding state to allow
specification of clear color as part of the loadstore
state at framebuffer bind time.

This ensures all parameters controlling attachment
loading and storage behaviour can be explicitly
specified when binding a framebuffer.

This change enables optimizations which leverage
explicit framebuffer load store state to also specify
a clear color without prematurely triggering a
clear which may occur independently to
render work when using GPU_framebuffer_clear(..).

Authored by Apple: Michael Parkin-White.

Pull Request: https://projects.blender.org/blender/blender/pulls/111810
2023-09-04 18:30:54 +02:00
Campbell Barton
3d607be572 Cleanup: spelling in comments 2023-08-30 10:57:12 +10:00
Jeroen Bakker
bee3f645d8 Vulkan: Rewrite GHOST_ContextVK
This is a rewrite of GHOST_ContextVK to align with Metal backend as described
in #111389 - solution 3 with the adaptation that GHOST is still responsible
for presenting the swap chain image and a post callback is still needed in
case the swapchain is recreated.

This PR also includes some smaller improvements in stability.

Technical documentation: https://developer.blender.org/docs/eevee_and_viewport/gpu/vulkan/swap_chain/

* Renderpasses and framebuffers are not owned anymore by GHOST_ContextVK
* VKFramebuffer doesn't contain a swap chain image.
* Swapchain images can only be used as a blit destination or present source.
  Not as an attachment.
* GHOST_ContextVK::swapBuffers would call a callback with the image the
  GPU module needs to blit the results to.
* Clearing of depth/stencil attachments when no depth write state is set.
* Enable VK_KHR_maintenance4 to relax the stage interface mapping.
* Removes most vulkan validation warnings/errors.
* Detection of frame buffer changes that needs to be applied before
  performing a command requiring render pass (draw/clear attachment)

**Benefits**

* Late retrieval of a swap chain image results in better overall performance as
  Blender doesn't need to wait until the image is presented on the screen.
* Easier API and clearer state (transitions)
* More control over Image layouts and command buffer states. (Better alignment with
  Vulkan API)

Pull Request: https://projects.blender.org/blender/blender/pulls/111473
2023-08-29 15:05:08 +02:00
Campbell Barton
e955c94ed3 License Headers: Set copyright to "Blender Authors", add AUTHORS
Listing the "Blender Foundation" as copyright holder implied the Blender
Foundation holds copyright to files which may include work from many
developers.

While keeping copyright on headers makes sense for isolated libraries,
Blender's own code may be refactored or moved between files in a way
that makes the per file copyright holders less meaningful.

Copyright references to the "Blender Foundation" have been replaced with
"Blender Authors", with the exception of `./extern/` since these this
contains libraries which are more isolated, any changed to license
headers there can be handled on a case-by-case basis.

Some directories in `./intern/` have also been excluded:

- `./intern/cycles/` it's own `AUTHORS` file is planned.
- `./intern/opensubdiv/`.

An "AUTHORS" file has been added, using the chromium projects authors
file as a template.

Design task: #110784

Ref !110783.
2023-08-16 00:20:26 +10:00
Clément Foucault
983ff8e616 GPU: Framebuffer: Add multi viewport support
This add the possibility to define different
viewports inside a single framebuffer and
let the vertex shader decide which viewport
to render to.

This only contain the GL and VK implementation.
The Vulkan implementation works but still
has a validation error related to shader features
and extension. The test passes nonetheless.

Pull Request: https://projects.blender.org/blender/blender/pulls/110923
2023-08-08 17:12:49 +02:00
Jeroen Bakker
513250051e Vulkan: Image Views
The ownership of image views depends on how they are used. When used as
an framebuffer attachment the image view is owned by the framebuffer.
When used as a image/texture in a shader the ownership of the image view
is the texture itself.

Pull Request: https://projects.blender.org/blender/blender/pulls/108765
2023-06-08 16:07:38 +02:00
Campbell Barton
9b97123bf9 Cleanup: spelling in comments, odd comment block spacing 2023-06-02 10:16:16 +10:00
Sergey Sharybin
c1bc70b711 Cleanup: Add a copyright notice to files and use SPDX format
A lot of files were missing copyright field in the header and
the Blender Foundation contributed to them in a sense of bug
fixing and general maintenance.

This change makes it explicit that those files are at least
partially copyrighted by the Blender Foundation.

Note that this does not make it so the Blender Foundation is
the only holder of the copyright in those files, and developers
who do not have a signed contract with the foundation still
hold the copyright as well.

Another aspect of this change is using SPDX format for the
header. We already used it for the license specification,
and now we state it for the copyright as well, following the
FAQ:

    https://reuse.software/faq/
2023-05-31 16:19:06 +02:00
Jeroen Bakker
821b53942e Vulkan: Color Blend State for Multi Attachment Framebuffer
Current implementation of the Color Blend State worked for framebuffers
with a single attachment. This PR adds support for Color Blend State for
multiple attachments. It is assumed that the Blend State is the same for
all attachments.

NOTE: Integer based attachments aren't yet supported. In OpenGL it is
assumed that Integer based attachments aren't blended. It is currently
to early to tell if this is also the case for Vulkan. If this assumption
is incorrect we should use multi blend state.

Pull Request: https://projects.blender.org/blender/blender/pulls/108419
2023-05-30 13:46:11 +02:00
Campbell Barton
bf36a61e62 Cleanup: spelling in comments & some corrections 2023-05-20 21:17:09 +10:00
Jeroen Bakker
63cc5a1e61 Vulkan: Frame Buffer Flipping
Vulkan coordinate system is flipped compared to OpenGL. This PR
flips the drawing when drawn to the on-screen frame buffer.
Offscreen frame buffers are still drawn upside down.

The flipping is done by making the viewport of the framebuffer negative.

Pull Request: https://projects.blender.org/blender/blender/pulls/107743
2023-05-09 09:22:26 +02:00
Sergey Sharybin
a12a8a71bb Remove "All Rights Reserved" from Blender Foundation copyright code
The goal is to solve confusion of the "All rights reserved" for licensing
code under an open-source license.

The phrase "All rights reserved" comes from a historical convention that
required this phrase for the copyright protection to apply. This convention
is no longer relevant.

However, even though the phrase has no meaning in establishing the copyright
it has not lost meaning in terms of licensing.

This change makes it so code under the Blender Foundation copyright does
not use "all rights reserved". This is also how the GPL license itself
states how to apply it to the source code:

    <one line to give the program's name and a brief idea of what it does.>
    Copyright (C) <year>  <name of author>

    This program is free software ...

This change does not change copyright notice in cases when the copyright
is dual (BF and an author), or just an author of the code. It also does
mot change copyright which is inherited from NaN Holding BV as it needs
some further investigation about what is the proper way to handle it.
2023-03-30 10:51:59 +02:00
Jeroen Bakker
aa69ec7f80 Vulkan: Clearing Framebuffer + Scissors
This PR adds support for clearing framebuffers and scissor testing.
Tweaks had to be made to VKTexture to keep track of its layout
on the device. Based on the actual call the layout can switch
to a more optimum layout.

For example during upload of a texture the texture will be converted
to a transfer destination optimized layout. When reading from the
texture it will be converted to a transfer source optimized layout.

The order of the attachments in the framebuffer follows the next rules

- When only color attachments are there the color attachments will
  be placed in the slot they are defined. This way it will match
  the ShaderCreateInfo binding location.
- When a stencil/depth attachment is added it will be placed
  right after the color attachments. When there isn't a color
  attachment it will be the first attachment.

Pull Request: https://projects.blender.org/blender/blender/pulls/106044
2023-03-28 11:51:32 +02:00
Jeroen Bakker
3cba2911e0 Vulkan: Add Initial VKFrameBuffer.
This was backported from tmp-vulkan. When disabling the fence check
in ghost it is able to start blender. It will show a black screen
so not usable for users.
2023-02-28 06:20:12 +01:00
Campbell Barton
79c82fc1c5 Cleanup: trailing space 2023-01-31 15:49:04 +11:00
Jeroen Bakker
0e6f2d9fe0 GPU: Add placeholder for Vulkan backend.
This patch adds a placeholder for the vulkan backend.
When activated (`WITH_VULKAN_BACKEND=On` and `--gpu-backend vulkan`)
it might open a blender screen, but nothing should be visible as
none of the functions are implemented or otherwise crash on a nullptr.

This is expected as this is just a placeholder. The goal is to add shader compilation
+validation to this backend as one of the next steps so we can validate
changes to existing shaders on OpenGL, Metal and Vulkan at the same time.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D16338
2022-10-31 16:01:15 +01:00