Commit Graph

43 Commits

Author SHA1 Message Date
Jeroen Bakker
d28474e404 Vulkan: Render graph - VKFramebuffer blitting
Implement framebuffer blitting using the render graph.

Pull Request: https://projects.blender.org/blender/blender/pulls/122143
2024-05-23 11:37:58 +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
Jeroen Bakker
cd8218d9e4 Vulkan: Fix Image Range Validation Error
Co-authored-by: vnapdv <kaz380@hotmail.co.jp>
Pull Request: https://projects.blender.org/blender/blender/pulls/117024
2024-01-11 12:47:11 +01:00
Jeroen Bakker
cc04bcd792 Vulkan: Reusing Textures from Pool
This PR solves an issue when using texture pools with textures that are not
natively supported by the device. In the previous implementation the
internal `Texture::format_` was changed. Any check if the texture could
be reused would fail as its format would be different that the requested one.

This PR fixes this by separating the requested format `Texture::format_` and
how it is stored on the GPU `VKTexture::device_format_`.

This solves the next artifacts:
* Workbench flickering artifacts on AMD/Intel GPUs
* Workbench TAA on AMD/Intel GPUs
* Overlays were not always drawn fully solid

Pull Request: https://projects.blender.org/blender/blender/pulls/114697
2023-11-10 12:52:34 +01:00
Jeroen Bakker
8c7f927ec8 Vulkan: Workbench Shadow Drawing
There were some issues with workbench shadow drawing. This PR
does some tweaks to fix the shadow drawing on vulkan.

* Framebuffer stencil clearing when write stencil is disabled
* Tweaks to stencil operation and tests
* Disable restart for line adjacency

Pull Request: https://projects.blender.org/blender/blender/pulls/114673
2023-11-09 16:07:26 +01:00
Jeroen Bakker
e77cf08b02 Cleanup: Vulkan: Replace FlagBits with Flags
Vulkan API uses Flags and FlagBits for enumerations. The FlagBits
contains the options that can be hold with the Flags data type.

This wasn't well understood at the beginning of the project and
the FlagBits where used where Flags should have been used. This cleanup
fixes this, improving the readability of the code where bit
manipulations where used.

Pull Request: https://projects.blender.org/blender/blender/pulls/114459
2023-11-03 14:42:12 +01:00
Jeroen Bakker
0f5abc5a8b Vulkan: Readback Texture Views
When using EEVEE-Next the final render data is readback from texture
views. This wasn't implemented yet.

This PR adds support for reading back texture views. It also makes sure
the correct layer is read when reading back data from framebuffers and
adds internal support to read back a partial texture.

Pull Request: https://projects.blender.org/blender/blender/pulls/114411
2023-11-02 15:55:05 +01:00
Jeroen Bakker
f35b0373d6 Vulkan: Separate DataTransfer, Compute, Graphics Commands
Goal is to reduce the number of command buffer flushes by tracking what is
happening in the different command queues. This is an initial step towards
advanced queue-ing strategies.

The new (intermediate) strategy records commands to different command
buffers based on what they do. There is a command buffer for data transfers,
compute pipelines and graphics pipelines.

When a compute command is recorded it ensures that all graphic commands
are finished. When a graphic command is recorded it ensures all compute
commands are finished. When a graphic or compute command is scheduled
all recorded data transfer commands are scheduled as well.

Some improvements are expected as multiple compute and data transfers
commands can now be scheduled at the same time and don't need to unbind
and rebind render passes. Especially when using EEVEE-Next which is
compute centric the performance change is visible for the user.

Pull Request: https://projects.blender.org/blender/blender/pulls/114104
2023-10-30 14:21:14 +01: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
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
Jeroen Bakker
f97a56eedd Vulkan: Fix Blitting Extents
During Blitting it is not allowed to read/write outside
the texture bounds. This patch ensures that the bounds
(called extents in Vulkan) are inside the expected range.

Pull Request: https://projects.blender.org/blender/blender/pulls/113050
2023-09-29 11:44:50 +02:00
Jeroen Bakker
ad93324580 Vulkan: Add support for Framebuffer Depth Blit
This PR adds support for `GPU_framebuffer_blit` When used with `GPU_DEPTH_BIT`.
The challenge with is that not all GPUs support using a depth texture as a blit destination.

An AMD GPU doesn't support a depth buffer with stencil buffer as blit destination.
![image](/attachments/130e7e38-2dbc-4653-950c-2234bd5bad52)
> NOTE: AMD GPUs don't support 24 bit unsigned normalized depth textures at all.

In all cases when we use depth blitting we are blitting the whole texture
and in stead we can use a texture copy.

A negative effect is that we need to unbind the framebuffer when copying
depth textures, but a positive effect is that we can use a data transfer function what should
theoretically be faster.

This should be revisited when we are investigating in areas to improve the
performance of the Vulkan backend.

Pull Request: https://projects.blender.org/blender/blender/pulls/112674
2023-09-28 10:00:24 +02:00
Jeroen Bakker
e5a33b3b2c Vulkan: Rework Initializing/Allocating Textures
When initialy adding textures it wasn't possible to allocate during
initialization as its usage wasn't known. Bot Metal and Vulkan would do
a delayed allocation adding more checks when using textures.

Recently the behavior of setting texture usage was changed and now is
known when initializing textures. This PR makes advantage of this to
give correct feedback to the calling code if the texture can be created
and remove all the delayed allocating of textures.

Pull Request: https://projects.blender.org/blender/blender/pulls/112997
2023-09-28 09:38:52 +02:00
Jeroen Bakker
f7ccec2bcc Vulkan: Fix Generate Mipmaps for Array Textures
Array textures stores the array length inside the size of the image. In
vulkan the size mustn't contain the array length, but it should be set
as a separate parameter. This logic wasn't implemented when updating
the mipmap chain.

Patch also includes some smaller fixes where textures would not yet be
allocated on the device, but was expected to be.

Pull Request: https://projects.blender.org/blender/blender/pulls/112518
2023-09-18 13:45:53 +02:00
Jeroen Bakker
1daecc24d0 Vulkan: Postpone Resource Destruction
Resources can still be in use inside the vulkan command queue, when
they are destroyed. Especially as Vulkan doesn't allow resetting
bindings to nothing.

This PR will collect the resources that needs to be destroyed inside
the VKDevice and actually destroy the resources when on frame end.

The resources currently include:
* VkBuffer
* VkImage
* VkImageView
* VkFramebuffer
* VkRenderPass

Pull Request: https://projects.blender.org/blender/blender/pulls/112514
2023-09-18 13:42:17 +02:00
Jeroen Bakker
ded7d96ba1 Vulkan: Texture View
Adding support for Texture View in Vulkan backend.

When a VKTexture is a texture view many options become
irrelevant, but isn't actually clear via its API. Added
asserts to make sure that the usage is supported.

This patch allows rendering simple workbench-next scenes
without any validation errors.

Pull Request: https://projects.blender.org/blender/blender/pulls/110887
2023-09-12 11:18:38 +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
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
Jeroen Bakker
2af2a11651 Vulkan: Use Correct Image Aspects
Depending on the usage of an image/image view different image aspect
requirements need to be used. When changing the layout of an image
all aspects needs to be included. When using it as a sampler or
framebuffer attachment only one aspect can be used.

This change also remove duplicated code when creating image views.

Pull Request: https://projects.blender.org/blender/blender/pulls/111349
2023-08-22 11:00:43 +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
2ee2ae93fb Vulkan: Initial Cube(Array) Support
This PR adds initial cube (array) support. Depending on how the texture
is used a different image view is created. When used as a framebuffer
attachment only a single side of the cubemap is attached. The image
view is attached as a 2d texture array. When used as a shader resource
the image view is a cubemap.

Also adds test cases to test both scenarios.

Pull Request: https://projects.blender.org/blender/blender/pulls/108794
2023-06-09 16:09:54 +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
a08652b56c Vulkan: Area Readback of Framebuffer Textures
This PR adds the ability to only read back an area of a framebuffer
texture. It also adds the ability to read back from the depth
attachment.

Also reduces the amount of needed memory and reduces the CPU cycles
by reading back directly into the memory provided by the user. The
previous implementation wasn't able to do so as the `VKTexture::read`
function always returned a new buffer. The introduced
`VKTexture::read_sub` works on a pre-allocated buffer.

Pull Request: https://projects.blender.org/blender/blender/pulls/108418
2023-05-30 13:47:55 +02:00
Jeroen Bakker
809a5aa418 Vulkan: Initial Graphics Pipeline
Initial graphic pipeline targeting. The goal of this PR is to have an initial
graphics pipeline with missing features. It should help identifying
areas that requires engineering.

Current state is that developers of the GPU module can help with the many
smaller pieces that needs to be engineered in order to get it working. It is not
intended for users or developers from other modules, but your welcome to learn
and give feedback on the code and engineering part.

We do expect that large parts of the code still needs to be re-engineered into
a more future-proof implementation.

**Some highlights**:
- In Vulkan the state is kept in the pipeline. Therefore the state is tracked
  per pipeline. In the near future this could be used as a cache. More research
  is needed against the default pipeline cache that vulkan already provides.
- This PR is based on the work that Kazashi Yoshioka already did. And include
  work from him in the next areas
  - Vertex attributes
  - Vertex data conversions
  - Pipeline state
- Immediate support working.
- This PR modifies the VKCommandBuffer to keep track of the framebuffer and its
  binding state(render pass). Some Vulkan commands require no render pass to be
  active, other require a render pass. As the order of our commands on API level
  can not be separated this PR introduces a state engine to keep track of the
  current state and desired state. This is a temporary solution, the final
  solution will be proposed when we have a pixel on the screen. At that time
  I expect that we can design a command encoder that supports all the cases
  we need.

**Notices**:
- This branch works on NVIDIA GPUs and has been validated on a Linux system. AMD
  is known not to work (stalls) and Intel GPUs have not been tested at all. Windows might work
  but hasn't been validated yet.
- The graphics pipeline is implemented with pixels in mind, not with performance. Currently
  when a draw call is scheduled it is flushed and waited until it is finished drawing, before
  other draw calls can be scheduled. We expected the performance to be worse that it actually
  is, but we expect huge performance gains in the future.
- Any advanced drawing (that is used by the image editor, compositor or 3d viewport) isn't
  implemented and might crash when used.
- Using multiple windows or resizing of window isn't supported and will stall the system.

Pull Request: https://projects.blender.org/blender/blender/pulls/106224
2023-05-11 13:01:56 +02: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
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
6859bb6e67 Cleanup: format (with BraceWrapping::AfterControlStatement "MultiLine") 2023-05-02 09:37:49 +10:00
Campbell Barton
37b7702d74 Cleanup: comment blocks, #if 0 commented code 2023-04-14 13:51:38 +10:00
Campbell Barton
440cccecdc Cleanup: spelling in comments 2023-04-05 14:39:51 +10:00
Jeroen Bakker
d030d12d7b Vulkan: Fix Compilation Error on Windows Platforms.
Automatically conversion not working. Replacing `begin` with
`data` would solve this issue.

Pull Request: https://projects.blender.org/blender/blender/pulls/106539
2023-04-04 12:13:01 +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
Campbell Barton
5a90bbf716 Cleanup: format 2022-11-02 11:20:06 +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