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

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