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
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
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
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
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
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
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
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
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
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
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
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/
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
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
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
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
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
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
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
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
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
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
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
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
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