Commit Graph

187 Commits

Author SHA1 Message Date
Campbell Barton
b4504c7840 Cleanup: spelling in comments 2023-10-12 16:03:18 +11:00
Miguel Pozo
3f72c62be6 GPU: Add GPU_max_storage_buffer_size
Needed for #113509.

Using a `size_t` since some GPUs should support >4GB buffers,
but Vulkan exposes the value as a `uint` and Metal as an `int`.

Pull Request: https://projects.blender.org/blender/blender/pulls/113516
2023-10-11 19:26:40 +02:00
Jeroen Bakker
f361cfa361 Vulkan: Bundle Immediate Mode Calls
When using Immediate mode emulation the data is stored in a ring buffer.
As data isn't overwritten it is safe to call multiple draw commands in
a single command buffer.

This improves drawing performance when immediate mode is being used, it
mostly improves the readability of the GPU traces in renderdoc.

Pull Request: https://projects.blender.org/blender/blender/pulls/113482
2023-10-10 09:54:35 +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
Jason Fielder
e64db67fa5 GPU: Add platform parameter for GPU architecture
Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/112566
2023-09-28 12:49:55 +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
7dbe689b63 Vulkan: Use Point Shaders When Drawing Points
In Vulkan (and Metal) it is not possible to use a global as point
size. It needs to be set for each vertex when drawing points. Blender
has specialized shaders for that, but not all code respect those
shaders.

This PR will add an assert inside the vulkan backend when incorrect
usage of shaders are detected.

Pull Request: https://projects.blender.org/blender/blender/pulls/112906
2023-09-26 16:04:08 +02:00
Jeroen Bakker
dd3e23e812 Vulkan: Show Missing Implementations
This PR will print a message when a vulkan method isn't implemented.
So we can keep track of what still needs to be implemented.

Pull Request: https://projects.blender.org/blender/blender/pulls/112671
2023-09-21 15:21:32 +02:00
Jeroen Bakker
6d91d36161 GPU: Remove GPU_shader_storage_buffer_objects_support
Blender 4.0 requires OpenGL 4.3 which always support SSBO's.
Platforms that don't support enough SSBO bind points will be marked
as unsupported.

Users who start Blender on those platforms will be informed via a
dialog. This PR also updates the `--debug-gpu-force-workarounds`
to match our minimum requirements. Note that some bugs are still
there that should be solved in other PRs:

* Workbench only renders the object using a unit matrix this is because
  there is a bug in the workaround for shader_draw_parameters
* Navigating with middle mouse button is not working. Unsure what the
  cause is, but might be a missing feature check in the OpenGL backend.

Related to #112224

Pull Request: https://projects.blender.org/blender/blender/pulls/112572
2023-09-21 12:55:51 +02:00
Jeroen Bakker
2d70f46265 Fix: Vulkan Grid Overlay
In Vulkan the grid overlay wasn't rendering correctly. The reason was
a mis alignment in the std430 layout. This PR fixes the std430 layout
so the grid overlay (and perhaps also other sections) would work.

Root cause is that the reserve size if an nVec3 is different when used
as an array versus a single attribute. This was not taken into account
where the overlay flag was read from uninitialized memory.

Pull Request: https://projects.blender.org/blender/blender/pulls/112564
2023-09-19 11:52:59 +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
231f1a6076 Vulkan: Implement GPU_storagebuf_copy_sub_from_vertbuf
This PR implements `GPU_storagebuf_copy_sub_from_vertbuf`. It can be
used to copy a part of a vertex buffer to a storage buffer.

Pull Request: https://projects.blender.org/blender/blender/pulls/112516
2023-09-18 13:44:03 +02:00
Jeroen Bakker
a54495b347 Vulkan: Upload Uniform Buffer Attached Data
Uniform buffers can have data provided during construction, or as
attached data. Attached data should be uploaded during bind.

This PR implements `GPU_uniformbuf_create_from_list`.

Pull Request: https://projects.blender.org/blender/blender/pulls/112517
2023-09-18 13:43:16 +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
0e47a13e3e Vulkan: Fix Namespace Collision Between Shader Resources
Previous implemetation had some limitations that were not working
for complex shaders. This limitations included:

* All bindings should be bound to a location < 16.
* Collision could happen when image locations where read that
  overlapped with the texture locations.

This PR replaces the fixed binding locations with a dynamic vector.
When allocating locations for images the image offset is determined
that it is always clear if the requested locations is already
offsetted or not. This is done by ensuring the offset to larger than
the max slot of samplers, but also of image slots.

When using Eevee-next materials the slot numbers can be very high
as the location of the first material texture is set to
`GPU_max_textures_frag()` On current NVIDIA drivers this number is
set to 1K. Images are stored after the textures slots upwards.

In the future driver could set this to MAX_INT which will not work
with the new implementation. This isn't the case at this moment
and perhaps also not realistic. We don't check for this situation yet.

Pull Request: https://projects.blender.org/blender/blender/pulls/112511
2023-09-18 13:41:50 +02:00
Jeroen Bakker
80dda1168f Vulkan: Submit after Compute Dispatch
This PR adds command submission after performing any compute dispatch.
This is a work around as the vulkan backend doesn't support memory
barriers yet.

Pull Request: https://projects.blender.org/blender/blender/pulls/112505
2023-09-18 13:41:19 +02:00
Campbell Barton
b7f3e0d84e Cleanup: spelling & punctuation in comments
Also remove some unhelpful/redundant comments.
2023-09-14 13:25:24 +10:00
Jeroen Bakker
6920c690f1 Vulkan: Implement Component Swizzling
Component swizzling is part of an image view and localized in the code.
With component swizzling a different channel (or 0 or 1) can be read
when the component is accessed.

Pull Request: https://projects.blender.org/blender/blender/pulls/112273
2023-09-12 11:54:57 +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
Jeroen Bakker
65a88c3d60 Vulkan: Fix Incorrect UINT formats.
When `COMP_U*` is used together with a `GPU_FETCH_INT` the backend
tried to convert them to floats. What is of course not what should
happen.

Issue was that these cases were never correctly tested. With this
change the `data` attribute of the `overlay_edit_mesh` shaders are
transferred correctly and can draw some pixels as intended.

Pull Request: https://projects.blender.org/blender/blender/pulls/112270
2023-09-12 11:15:51 +02:00
Jeroen Bakker
81c6eb9c7f Vulkan: Enable Shader Draw Parameters Support
Shader draw parameter support is needed for Workbench-next. (Almost) All
devices that we support also supports shader draw parameters. This PR
doesn't include a workaround for devices that don't have support.

For end-users this PR will allow workbench-next to render the object on
the correct location. Before this patch they were always drawn on the origin.

The catch is that OpenGL uses gl_InstanceID which always starts counting at 0.
Vulkan has gl_InstanceIndex which holds the correct instance number. By
subtracting the gl_InstanceIndex from gl_BaseInstance will get the correct
gl_InstanceID.

This patch also activates some device extensions to perform in shader printf
statements inside a shader. Documentation for this will be added to the dev
docs how to use them.

Pull Request: https://projects.blender.org/blender/blender/pulls/111461
2023-09-11 15:04:54 +02:00
Jeroen Bakker
b6bc53760a Vulkan: Add recent introduced types
Recently shader::Type::SHORT/USHORT types have been added.
This will add them to the vulkan backend as well

Pull Request: https://projects.blender.org/blender/blender/pulls/111962
2023-09-05 10:47:58 +02:00
Campbell Barton
bedfc68e3f Cleanup: use function style integer casts, modernize headers 2023-09-05 11:10:44 +10: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
0026d20c8c Cleanup: quiet compiler warnings, correct doxy section 2023-08-30 10:57:17 +10: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
Jeroen Bakker
bce23aa0f5 Fix: Crash On Exit When Using Vulkan
Vulkan device was deallocated, but when destroying the GHOST context
the GPU context is reactivated and want to allocate buffers lazilly.

This is solved by de-initializing the device on platform exit, resetting
buffer pointers so double free can be detected.

Pull Request: https://projects.blender.org/blender/blender/pulls/111462
2023-08-24 10:23:21 +02:00
Jeroen Bakker
d9ae608c87 Fix: Crash when using Vulkan backend.
Command buffer was not availble at the time dummy buffers are
initialized. Resulting in undefined behavior.
2023-08-22 13:46:48 +02:00
Jeroen Bakker
4ebd7d84d1 Vulkan: Bind Dummy Vertex Attributes
Batches don't always provide all required resources for a shader.
This can happen when the resource is defined in the shader, but
not used in a specific variant. The definition is still there and
needs to be filled.

This PR adds a dummy buffer to fill the missing attributes.
It also fixes an issue when using vertex attributes that
uses multiple binding locations (mat4).

Pull Request: https://projects.blender.org/blender/blender/pulls/111350
2023-08-22 13:35:01 +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
Jeroen Bakker
785e03b13f Cleanup: Reduce VKDebug Messenger Complexity
Reduces the complexity of VKDebug messenger_callback.
2023-08-21 15:03:33 +02:00
Jeroen Bakker
9df5f2c495 Vulkan: Indirect Drawing
This PR implements indirect drawing for the Vulkan backend. Indirect
drawing is a requirement for workbench-next.

NOTE: that this is one of multiple changes needed to get to the same
support level. With this patch only objects at the center of the world
are drawn correctly.

Pull Request: https://projects.blender.org/blender/blender/pulls/111334
2023-08-21 08:55:55 +02:00
Jeroen Bakker
82c1b9f684 Vulkan: Remove Unneeded Workaround for Shader Interfaces
All shaders have been patched and an error will be generated when using
incompatible shaders, no need to have workaround in the code anymore.
2023-08-18 08:57:37 +02:00
Jeroen Bakker
8477f62ba1 Vulkan: Detect Vulkan Incompatibility When Running OpenGL/MTL
Now that all shaders have been converted to be Vulkan Compatible it is
safe to test for incompatibility when running in OpenGL or MTL.

This detection is only done when blender is compiled in debug mode.
2023-08-18 08:48:22 +02:00
Jeroen Bakker
074f10470c Vulkan: Add Workaround for Mixed Interpolation Attributes
shaderc generates an error when a struct containing an int type
isn't qualified as flat. We work around this issue by changing the
interpolation mode to flat during code generation.

Pull Request: https://projects.blender.org/blender/blender/pulls/111211
2023-08-17 10:53:05 +02:00
Jeroen Bakker
f44447a628 Vulkan: Use Correct Interpolation Qualifier in Stage Interfaces
This PR cleans up the Stage Interface code generation and use the
correct interpolation qualifier. This is a cleanup/fix before we can
start converting shaders stage interfaces to be compatible with vulkan.

Ref: #111138 for more information about vulkan compatibility
Pull Request: https://projects.blender.org/blender/blender/pulls/111207
2023-08-17 09:40:34 +02:00
Jeroen Bakker
6f9c3b1bd5 Vulkan: Report Incompatible Shaders
A difference was detected between stage interfaces between OpenGL and Vulkan
that are not compatible with our current API.

**OpenGL**

In OpenGL an stage interface struct can have different interpolation qualifiers
per attribute.

```glsl
struct MyStageInterface {
    smooth vec4 color;
    flat int face_flag;
};
layout(..) MyStageInterface interp;
```

**Vulkan**

In vulkan the interpolation qualifier isn't supported on attribute
level and needs to be added to the struct.

```glsl
struct MyStageInterface {
    vec4 color;
};
struct MyStageInterface_flat {
    int face_flag;
};
layout(..) smooth MyStageInterface interp;
layout(..) flat MyStageInterface_flat interp_flat;
```

This patch reports shaders that are incompatible with Vulkan so they can be
patched. Report is only done in debug mode and when using the vulkan backend.
After all shaders are patched an error will be raised so developers will
known immediately when incompatibility are created.

Making the shaders compatible and adding the error will be done in future
patches.

**Python**

Via Python gpu module (gpu.types.GPUShaderCreateInfo) it isn't possible
to construct an incompatible shader as instance names cannot be set
via the API. So this isn't a breaking change.

Pull Request: https://projects.blender.org/blender/blender/pulls/111138
2023-08-17 08:59:03 +02:00
Jeroen Bakker
bbe4f6cf74 Fix: Compilation Error When Compiling with Vulkan
This PR fixes an compilation error where sstream used to be included
on a higher level, but has been removed and we need to include them
where they are actually used.

This wasn't detected as most developers don't have the vulkan backend
active.

Pull Request: https://projects.blender.org/blender/blender/pulls/111203
2023-08-17 08:24:29 +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
Jeroen Bakker
616e0c8c1d Vulkan: Set Geometry Shader Capability
Vulkan already used geometry stages, but it wasn't set as backend
capability. This resulted that the shader builder didn't validate
shaders that uses geometry stages.

Pull Request: https://projects.blender.org/blender/blender/pulls/111139
2023-08-15 15:53:56 +02:00
Jeroen Bakker
d20f26aeb6 Fix: Memory Reserve Issue in Vulkan/Std140
This PR solves a memory reserve issue when a nvec3 was followed by
a int, bool, float.

Also adds a debug_print method to the push constants for checking
the structure against data in renderdoc.

Pull Request: https://projects.blender.org/blender/blender/pulls/111109
2023-08-15 14:16:26 +02:00
Jeroen Bakker
ab3ae2be4d Fix: Vulkan Use Resource After Free
When immediate mode is used with a temp texture the
draw command was executed after the texture was freed.

This PR ensures that the draw command is executed before
the texture is freed.

Pull Request: https://projects.blender.org/blender/blender/pulls/111111
2023-08-15 14:15:46 +02: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
Campbell Barton
9ea8477c23 Cleanup: various non-functional C++ changes 2023-08-05 13:57:29 +10:00
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