Commit Graph

139 Commits

Author SHA1 Message Date
Campbell Barton
6fbe467021 Cleanup: replace BLI_dynstr with a call to BLI_vsprintfN 2023-07-03 14:15:07 +10:00
Campbell Barton
472c461816 Cleanup: spelling in comments 2023-06-21 11:28:58 +10:00
Campbell Barton
6a75ff7afa Cleanup: use function style casts, trailing space 2023-06-16 12:20:31 +10:00
Jeroen Bakker
d84a64900f Vulkan: Device Context Resource Management
The current Vulkan resource management has some issues as context that
are not active can still use resources that are freed via another
context.

When this happens incorrect data can be read on the GPU and even crash
Blender. When trying to bind something that now contains other memory
pointers.

This change introduces that contexts are tracked via the device.
Context will be registered/unregistered with the device instance.
Unbinding of resources must pass the device and the device will check
all registered contexts. Binding of resources will happen via the active
context only.

On user perspective this now allowes:
- Opening/switching files
- Switching workspaces
- Switching render engines

Pull Request: https://projects.blender.org/blender/blender/pulls/108968
2023-06-15 08:14:37 +02:00
Campbell Barton
65f99397ec License headers: use SPDX-FileCopyrightText in all sources 2023-06-15 13:35:34 +10:00
Hans Goudey
1f0e206da6 Cleanup: Use nullptr, clang format 2023-06-14 14:55:44 -04:00
Campbell Barton
ffdce441ee License headers: use SPDX-FileCopyrightText for source/
There are still some files that need to be manually updated due to
missing copyright dates.
2023-06-14 23:36:23 +10:00
Campbell Barton
d4b23cae8f Cleanup: use C-style comments for descriptive text 2023-06-14 12:20:06 +10:00
Jeroen Bakker
ccbab842b7 Vulkan: Indirect Compute
This PR adds support for indirect compute.
Indirect compute is almost the same as regular compute. The
only difference is that the parameters for the compute dispatch
isn't passed as a parameter, but that these parameters are part
of a buffer.

Pull Request: https://projects.blender.org/blender/blender/pulls/108879
2023-06-12 14:56:38 +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
f5dd7d5e6c Vulkan: Fix Workbench Normals
Workbench normals where inverted resulting to drawing artifacts like:
- Black pixels during matcaps (normals contained NAN values)
- Studio light inverted

The root cause for this was that Vulkan default to determine if a
primitive is facing the camera should be switched. The default was still
incorrect.

Although this fixes it, a better solution is to determine the front
facing based on if the viewport should be switched. As all rendering
occurs when the viewport is inverted it doesn't matter at this moment.

Pull Request: https://projects.blender.org/blender/blender/pulls/108797
2023-06-09 11:54:06 +02:00
Campbell Barton
2f1899a7fa Cleanup: spelling in comments 2023-06-09 11:40:50 +10: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
Jeroen Bakker
b6f8b50dd9 Fix using incorrect struct when unbinding images. 2023-06-08 09:49:50 +02:00
Jeroen Bakker
4faee0b26e Vulkan: Set Debug Name For Descriptor Layout
This makes tracking shaders easier across the pipeline. Durring logging
and debugging the vulkan driver now remembers the shader associate to
the descriptor and provides this information in its messages.

Pull Request: https://projects.blender.org/blender/blender/pulls/108743
2023-06-08 09:47:17 +02:00
Jeroen Bakker
db4cd61001 Vulkan: Unbind Uniform Buffers When Destroyed
When Uniform buffers are destroyed they need to be removed from the
state manager. Otherwise Vulkan points to unallocated memory and leads
to artifacts.

Pull Request: https://projects.blender.org/blender/blender/pulls/108742
2023-06-08 09:46:00 +02:00
Jeroen Bakker
8f988206de Vulkan: UBYTE to SRGBA8 Texture Format
Adds support to create SRGBA8 textures using UBYTE as input data.
It is assumed that the UBYTE are already converted to SRGB and no
conversion actually needs to happen.

Pull Request: https://projects.blender.org/blender/blender/pulls/108741
2023-06-08 09:44:51 +02:00
Jeroen Bakker
0a0a451b4d Vulkan: Fix Unbinding All Images
When unbinding all images, all textures where unbound. This was
incorrect. This PR fixes this.

Pull Request: https://projects.blender.org/blender/blender/pulls/108740
2023-06-08 09:42:39 +02:00
Jeroen Bakker
c71d198dfd Vulkan: Mipmap Generation
Implement Mipmap generation for the Vulkan backend.
This patch implements `GPU_texture_update_mipmap_chain`.

Pull Request: https://projects.blender.org/blender/blender/pulls/108699
2023-06-08 09:15:07 +02:00
Jeroen Bakker
2231b819a5 Vulkan: Workaround for 24bit depth component
Some vulkan platforms don't support 24bit depth components. In this
case we will allocate float depth component. During readback the data
should be converted back to what is expected.

Pull Request: https://projects.blender.org/blender/blender/pulls/108698
2023-06-08 08:53:12 +02:00
Campbell Barton
6704881708 Cleanup: spelling in comments 2023-06-07 21:47:45 +10:00
Jeroen Bakker
b7963d247c Vulkan: Low Precision Float Conversion
This PR adds conversion template to convert between Low Precision float
formats. These include Binary32 floats and lower. It also adds support
to convert between unsigned and signed float formats and float formats
with different mantissa and exponents.

Additionally overflows (values that don't fit in the target float
format) will be clamped to the maximum value.

**Reasoning**:
Up to now the Vulkan backend only supported float and half float
formats, but to support workbench, 11 and 10 unsigned floats have to be
supported as well. The available libraries that support those float
formats targets scientific applications. Where the final code couldn't
be optimized that well by the compiler.

Data conversion for color pixels have different requirements about
clamping and sign, what could eliminate some clamping code in other
areas in Blender as well. Also could fix some undesired overflow when
using pixels with high intensity that didn't fit in the texture format
leading to known artifects in Eevee and slow-down in the image editor.

**Future**
In the future we might want to move this to the public part of the GPU
module so we can use this as well in other areas (Metal backend), Imbuf clamping
See 3c658d2c2e69e9cf97dfaa7a3c164262aefb9e76 for a commit that uses
this and improves image editor massively as it doesn't need to reiterate over
the image buffer to clamp the values into a known range.

Pull Request: https://projects.blender.org/blender/blender/pulls/108168
2023-06-07 07:50:04 +02:00
Campbell Barton
05b8242e45 Cleanup: use \n for line endings (run dos2unix) 2023-06-06 11:52:25 +10:00
Campbell Barton
493a1dd7c8 Cleanup: remove NULL literals in C++ (including comments & strings) 2023-06-04 18:35:12 +10:00
Jeroen Bakker
c8bd998944 Vulkan: Fix Debug Messenging
In the specification of validation layers it is mentioned that
the messenger should always return VK_FALSE. When this isn't the
case VK_ERROR_VALIDATION_FAILED_EXT will be returned and the
API command will fail.

This PR will always return false.

Pull Request: https://projects.blender.org/blender/blender/pulls/108545
2023-06-02 15:41:09 +02:00
Jeroen Bakker
30de07199a Vulkan: Some tweaks to the messenger
- Removal of Vulkan version number
- Removal of object counts
- Put objects next under the message

Pull Request: https://projects.blender.org/blender/blender/pulls/108531
2023-06-02 10:12:32 +02:00
Kazashi Yoshioka
a4249588cd Vulkan: Debug Messages
This change will register a callback to Vulkan debug messaging
allowing us to filter out messages and log them using CLog.

This change only provides the initial changes, and more tweaks
are expected to on formatting and filtering.

Pull Request: https://projects.blender.org/blender/blender/pulls/107635
2023-06-02 09:50:30 +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
004ce8fc4e Vulkan: Add Support For Texture Buffers
Texture buffers are vbos that can be sampled as textures inside shaders.
This adds support for them to the Vulkan Backend.

Pull Request: https://projects.blender.org/blender/blender/pulls/108193
2023-05-30 13:54:51 +02:00
Jeroen Bakker
3f89ec2866 Vulkan: Copy Between Textures
This PR adds support for copying between two textures.

Pull Request: https://projects.blender.org/blender/blender/pulls/108413
2023-05-30 13:50:35 +02:00
Jeroen Bakker
2cc0f94d68 Vulkan: Fix Out of Resources Crash
When a descriptor pool cannot allocate a descriptor set in stead
of resulting `VK_ERROR_OUT_OF_POOL_MEMORY` it is adviced that
drivers will return `VK_ERROR_FRAGMENTED_POOL`.

Before this PR the Vulkan Backend crashed as it only checked the
out of pool memory. According to the Vulkan specification it is
adviced to driver developers to report fragmented pool.

The crash happened as no new pool was allocated and no descriptor
set could be allocated anymore.

This change improved the reliability of the vulkan backend to be
able draw an animation in the 3d viewport for half an hour without
crashing. Before this change Blender would crash in a few seconds.

Pull Request: https://projects.blender.org/blender/blender/pulls/108416
2023-05-30 13:48:17 +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
589044a637 Vulkan: Detect AMD Vendor
This PR improves the vendor detection for AMD GPUs. Previously only
older AMD GPUs where detected (ATI). This PR adds support for newer
cards as well.

Pull Request: https://projects.blender.org/blender/blender/pulls/108417
2023-05-30 13:46:36 +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
Jeroen Bakker
84cb112b4e Vulkan: Restart Index
This PR adds support for restart indices. Restart indices are for
example used during hair rendering where an index buffer contains
multiple hair strands. When in the index buffer a restart index is
added, a new line will start, instead of continuing extending the
previous line.

Pull Request: https://projects.blender.org/blender/blender/pulls/108421
2023-05-30 13:45:41 +02:00
Campbell Barton
2708317b25 Merge branch 'blender-v3.6-release' 2023-05-25 20:34:06 +10:00
Jeroen Bakker
f5d159b2a4 Vulkan: Extract Vendor/Driver/Device Information
Extract vendor, driver and device information from the physical device
properties.

Note that driver version is implementation dependent and might fail as
it is unclear which driver is being used. An open source driver could
store the driver version in a different way than a closed source driver.
But as it is not clear which driver version is being used it might
extract the incorrect version.

To solve this issue we check if the extracted version makes sense
depending on the version schema of the driver and if they don't match we
use another approach.

Pull Request: https://projects.blender.org/blender/blender/pulls/107872
2023-05-25 11:55:47 +02:00
Jason Fielder
03e4325fa9 Fix: High resolution textures in Metal from Integer overflow
Resolve an issue where a high resolution texutre 16k x 8k
did not update in metal due to integer overflow of size parameter.

This patch contains several changes to address size correctness
across multiple use cases within the Metal backend.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/108238
2023-05-25 08:50:14 +02:00
Jason Fielder
ae405639e7 Metal: Stencil texture view support
Adds stencil texture view support for Metal, allowing reading of
stencil component during texture sample/read.

Stencil view creation refactored to use additional parameter in
textureview creation function, due to deferred stencil parameter
causing double texture view creation in Metal, when this should
ideally be provided upfront.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/107971
2023-05-22 20:40:38 +02:00
Campbell Barton
bf36a61e62 Cleanup: spelling in comments & some corrections 2023-05-20 21:17:09 +10:00
Chris Blackbourn
654cfc06c5 Cleanup: format 2023-05-13 11:03:59 +12:00
Jeroen Bakker
4cf7b95a15 Vulkan: Fix Compilation Issues on Windows
VKVertexAttributeObject was both defined as a class and a struct.
Settled on being a class.

Also removed an assert that is currently failing as workbench has
more attributes defined than actually used.

Pull Request: https://projects.blender.org/blender/blender/pulls/107874
2023-05-12 12:38:42 +02:00
Jeroen Bakker
7a52ad1161 Vulkan: Fix Incorrect Vertex Buffer State
After uploading the vertex buffer the state got corrupted.
Reason of this corruption is an assign-compare operation that should
just be an compare operation.

Pull Request: https://projects.blender.org/blender/blender/pulls/107875
2023-05-12 12:33:37 +02:00
Jeroen Bakker
83a2904d1a Vulkan: IndexBuffer as Subrange
Add support for index buffers as subrange. When an index buffer
is a subrange it should bind the source buffer and use the index start
as an offset in the buffer.

Pull Request: https://projects.blender.org/blender/blender/pulls/107871
2023-05-12 12:12:43 +02:00
Jeroen Bakker
f9d094ba9e Vulkan: Initial Draw List
Dummy implementation of the VKDrawList that isn't caching the draw calls
but just execute them when they are appended to the list.

Pull Request: https://projects.blender.org/blender/blender/pulls/107873
2023-05-12 12:09:41 +02:00
Chris Blackbourn
eb273143c6 Cleanup: format 2023-05-12 11:00:26 +12: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
8aff713270 Vulkan: Convert VertexBuffer to Contain Supported Attributes
Vulkan doesn't have a conversion from uint32_t/int32_t to float. It does
have conversions from 16/8 bits. Main reason is that Vulkan expects that
there is no benefit when converting 32 bits from one type to the other
and should be solved by passing the right data type.

In Blender however this isn't the case as there are benefits on other
GPU backends (OpenGL for example).

This PR adds helper function to check if conversion is needed and
perform any conversions in place. It also implements the function to
upload vertex buffers to the GPU.

NOTE: Test cases have been added to validate this, but they are not
able to run on the Vulkan backend just yet, because they require the
graphics pipeline to be available.

Pull Request: https://projects.blender.org/blender/blender/pulls/107733
2023-05-11 12:23:23 +02:00
Jeroen Bakker
a0ea40034b Vulkan: Make ShaderInput Optional
ShaderInput lookup used to be explicit as in we know for sure that the
shader input exists. This was guarded by a assert. During development
of the graphics pipeline we came to the conclusion that this isn't
always the case due to its late bindings of resources.

This PR Makes the shader input lookup return an optional result.
This result can then be checked depending on the area where it is used
to validate the existence.

Pull Request: https://projects.blender.org/blender/blender/pulls/107735
2023-05-11 08:44:57 +02:00