Commit Graph

4377 Commits

Author SHA1 Message Date
Clément Foucault
8fb6b51410 GPU: Fix false positive include of debug_draw
This created unfulfilled resources binds that would
trigger an assert when running with Metal Backend.
2023-05-16 12:54:29 +02:00
Iliya Katueshenock
f7388e3be5 Cleanup: Move BKE_node.h to C++
See: https://projects.blender.org/blender/blender/issues/103343

Changes:
1. Added `BKE_node.hh` file. New file includes old one.
2. Functions moved to new file. Redundant `(void)`, `struct` are removed.
3. All cpp includes replaced from `.h` on `.hh`.
4. Everything in `BKE_node.hh` is on `blender::bke` namespace.
5. All implementation functions moved in namespace.
6. Function names (`BKE_node_*`) changed to `blender::bke::node_*`.
7. `eNodeSizePreset` now is a class, with renamed items.

Pull Request: https://projects.blender.org/blender/blender/pulls/107790
2023-05-15 15:14:22 +02:00
Omar Emara
d91f0bf8d2 Realtime Compositor: Implement Convert Color Space node
This patch implements the Convert Color Space node for the realtime
compositor. A custom OCIO GpuShaderCreator was implemented to use the
ShaderCreateInfo in constructing the OCIO GPU processor shader. That
shader is then cached inside the cache manager and is invalidated when
the OCIO configuration changes.

Pull Request: https://projects.blender.org/blender/blender/pulls/107878
2023-05-15 07:20:08 +02:00
Chris Blackbourn
654cfc06c5 Cleanup: format 2023-05-13 11:03:59 +12:00
Marino Toscano
a05a7988dc Fix #106929: Gap in node links when sockets are aligned
Fix an issue when drawing node links that caused gaps, when sockets were
horizontally or vertically aligned.

When the inner and outer points of the node link's bezier control
polygon overlap, the link's tangent can be a zero vector. The shader
didn't check for this before normalizing the tangent leading to an
undefined vector which prevented the outermost segments of the link
from being drawn.
Since this only happens when the end points of the node link are
horizontally or vertically aligned, we can use the vector between the
link's end points instead of the tangent.

Fix #106929
Fix #89282

Pull Request: https://projects.blender.org/blender/blender/pulls/107636
2023-05-12 20:35:22 +02: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
a9c1d47255 GPU: Added Tests For Blend state And Immediate Mode
This PR adds several tests to GTest for testing blend states
and immediate mode. The immediate mode test are basic and will
be extended in the near future.

The tests have been developed in order to get the first pixel on
screen for the Vulkan backend. In the first phase of this goal we
had to validate that everything was working as expected without
being able to validate it by starting Blender.

Pull Request: https://projects.blender.org/blender/blender/pulls/107834
2023-05-11 09:15:39 +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
Jeroen Bakker
43bee6ea69 Vulkan: Ensure Minimum Size of VKBuffer
In Vulkan it is not allowed to allocate a buffer of zero bytes. This
would generate an error. In Blender it is possible that a buffer is zero
bytes. For example when the draw manager is drawing instances and there
are no instanced in the scene.

This PR ensures that at least a single byte is allocated in order to not
fail later on.

Co-authored-by: Jeroen Bakker <j.bakker@atmind.nl>
Pull Request: https://projects.blender.org/blender/blender/pulls/107731
2023-05-09 10:20:54 +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
Campbell Barton
c49a0fa474 Cleanup: remove redundant use of BLI_snprintf (no formatting args given)
The SNPRINTF macro isn't usable as it expectes at least one argument.
2023-05-09 14:08:19 +10:00
Campbell Barton
3958ae7241 Cleanup: use STRNCPY, SNPRINTF macros 2023-05-09 14:08:19 +10:00
Jeroen Bakker
8759ae1760 GPU: Initialize SRGB In TestCases
Vulkan test cases uses SRGB conversion. These test cases where failing
as the conversion table wasn't initialized.

This PR initializes the conversion table and fix the Vulkan data
conversion tests.
2023-05-08 15:32:15 +02:00
Jeroen Bakker
1f3fda16e6 Vulkan: Extract Correct UniformBuf Name From Interface
Fixes an issue as the uniformbuf name was incorrectly extracted
from the shader interface.

Pull Request: https://projects.blender.org/blender/blender/pulls/107736
2023-05-08 13:01:10 +02:00
Clément Foucault
c796cbebef Metal: Add atomicExchange and mat3x4 support 2023-05-05 16:18:24 +02:00
Chris Blackbourn
48abc09d84 Cleanup: format 2023-05-05 23:44:56 +12:00
Clément Foucault
c11ac86e03 Cleanup: Metal: Better function name and comments for buffer bindings 2023-05-05 12:52:47 +02:00
Campbell Barton
ba3d7499fa Cleanup: spelling, use term polygons in polygon callbacks 2023-05-05 09:46:28 +10:00
Hans Goudey
d0705bd697 Mesh: Split MLoopTri poly indices into a separate array
For derived mesh triangulation information, currently the three face
corner indices are stored in the same struct as index of the mesh
polygon the triangle is part of. While those pieces of information are
often used together, they often aren't, and combining them prevents
the indices from being used with generic utilities. It also means that
1/3 more memory has to be written when recalculating the triangulation
after deforming the mesh, and that the entire triangle data has to be
read when only the polygon indices are needed.

This commit splits the polygon index into a separate cache on `Mesh`.
The triangulation data isn't saved to files, so this doesn't affect
.blend files at all.

In a simple test deforming a mesh with geometry nodes, the time used
to recalculate the triangulation reduced from 2.0 ms to 1.6 ms,
increasing overall FPS from 14.6 to 15.

Pull Request: https://projects.blender.org/blender/blender/pulls/106774
2023-05-04 15:39:10 +02:00
Clément Foucault
9d6659bf07 Metal: Shader: Remove assertion of compilation success
This allow the compilation tests to finish even on failure.
2023-05-04 10:59:26 +02:00
Clément Foucault
2815f46883 Metal: ShaderLog: Add initial implementation
This is a really rough implementation. Since the MSL sources
do not correspond 1:1 to the GLSL sources, some mapping is
needed to retreive the GLSL source file for a given generated
line. This will be implemented in a later commit.
2023-05-04 10:59:26 +02:00
Clément Foucault
e39c3c600c GPU: ShaderLog: Add more const correctness & notes supports
The metal shader compiler can produce `note` reports.
Treat them as warnings.
2023-05-04 10:59:26 +02:00
Jeroen Bakker
b0c7e83805 Cleanup: formatting
In recent changes to vulkan.
2023-05-04 10:23:15 +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
Jason Fielder
88ace032a6 Metal: Storage buffer and explicit bind location support
Adds support for Storage buffers, including changes to the resource
binding model to ensure explicit resource bind locations are supported
for all resource types.

Storage buffer support also includes required changes for shader
source generation and SSBO wrapper support for other resource
types such as GPUVertBuf, GPUIndexBuf and GPUUniformBuf.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/107175
2023-05-03 11:46:30 +02:00
Jeroen Bakker
96dcdbfc51 Vulkan: Correct Aspectbits for Depth Textures
Vulkan spec only wants to have a single aspect bit when a texture
contains both a stencil and a depth part. As for Blender depth
is more used than stencil we standardize to depth aspect.

Pull Request: https://projects.blender.org/blender/blender/pulls/107542
2023-05-02 16:20:25 +02:00
Jeroen Bakker
17201752d9 Vulkan: Add FLOAT to SRGB and Depth24 Conversion
This PR adds support to convert host/device data from floats
to GPU_SRGB8_A8 and GPU_DEPTH_COMPONENT24.

Pull Request: https://projects.blender.org/blender/blender/pulls/107544
2023-05-02 15:57:17 +02:00
Jeroen Bakker
13fe6d0170 Vulkan: Silence Compilation Warnings
This PR silences some compilation warnings in the command buffer.

Pull Request: https://projects.blender.org/blender/blender/pulls/107541
2023-05-02 15:52:53 +02:00
Campbell Barton
a0db0a5580 Cleanup: move comments wrapped with MultiLine control statements
In some cases comments at the end of control statements were wrapped
onto new lines which made it read as if they applied to the next line
instead of the (now) previous line.

Relocate comments to the previous line or in some cases the end of the
line (before the brace) to avoid confusion.

Note that in quite a few cases these blocks didn't read well
even before MultiLine was used as comments after the brace caused
wrapping across multiple lines in a way that didn't follow
formatting used everywhere else.
2023-05-02 09:54:48 +10:00
Campbell Barton
6859bb6e67 Cleanup: format (with BraceWrapping::AfterControlStatement "MultiLine") 2023-05-02 09:37:49 +10:00
Jason Fielder
36e1ebc78d Metal: Resolve runtime issues with texture views
When creating a texture view, Metal may require that the original
GPUTexture state is modified in some way. This may be a result
of deferred creation, or, to cache the texture view against the
source.

As a result, GPUTexture passed into GPU_texture_create_view
cannot be const.

Small fixes have also been made in the Metal texture
implementation to ensure correct function of texture views.

Authored by Apple: Michael Parkin-White

Pull Request: https://projects.blender.org/blender/blender/pulls/107167
2023-05-01 09:14:00 +02:00
Jeroen Bakker
89afdd6f24 Vulkan: Texture Unpacking
This PR adds support for `GPU_unpack_row_length_set` to the vulkan
backend.

Texture unpacking is used when uploading a part of a texture from
host memory to device memory.

Pull Request: https://projects.blender.org/blender/blender/pulls/107360
2023-04-26 09:23:58 +02:00
Campbell Barton
db1af0e325 Cleanup: spelling in comments 2023-04-26 16:14:07 +10:00
Jeroen Bakker
7691d19ad2 Vulkan: Index Buffer
This PR adds the binding of index buffers.

Pull Request: https://projects.blender.org/blender/blender/pulls/107358
2023-04-26 08:09:28 +02:00
Jeroen Bakker
f0e768c198 Vulkan: Conversions between Blender and Vulkan Enums
Add conversions to convert from Blender enums to their Vulkan
counterpart.

Pull Request: https://projects.blender.org/blender/blender/pulls/107336
2023-04-26 07:56:35 +02:00
Brecht Van Lommel
ca52f0fae3 Cleanup: make format 2023-04-25 20:19:43 +02:00
Jeroen Bakker
d5cd51f089 Vulkan: Add streaming buffers.
Add support for streaming buffers.

Pull Request: https://projects.blender.org/blender/blender/pulls/107335
2023-04-25 15:48:52 +02:00
Jeroen Bakker
a813b65c7d Vulkan: Command Buffer.
Changes to the internal workings of the VKCommandBuffer:
- Use state engine to track correct usage.
- Switch between render pass/no render pass automatically.

Eventually the command buffer should be rewritten to use custom command
encoding to improve performance.

Pull Request: https://projects.blender.org/blender/blender/pulls/107337
2023-04-25 15:32:41 +02:00
Jeroen Bakker
468a152fe1 Vulkan: Uniform Buffer
Add implementation to clear and bind uniform buffers.

Pull Request: https://projects.blender.org/blender/blender/pulls/107334
2023-04-25 15:30:55 +02:00
Jeroen Bakker
fd7f21af8c Vulkan: Shader Interface Attribute Extraction.
Add extraction of attributes from shader interface.

Pull Request: https://projects.blender.org/blender/blender/pulls/107333
2023-04-25 15:09:25 +02:00
Jacques Lucke
a57584e40d BLI: extract MapItem type to simplify iterating over map items 2023-04-25 12:15:02 +02:00
Jeroen Bakker
5fde2b34ba GPU: Ensure Absolute Ratio During SDF-Widget Drawing
In the GPU_SHADER_2D_WIDGET_BASE the deriviates were assumed to be
positive. This is not always the case. In Vulkan this leads to
incorrect rendering of the widgets due to incorrect SDF values.

This change will ensure that the shader make the ratio variable
absolute.

Pull Request: https://projects.blender.org/blender/blender/pulls/107327
2023-04-25 12:08:43 +02:00
Jeroen Bakker
d9621add55 Vulkan: Initialize Device Capabilities.
Load the device capabilities into the context. This makes sure
that GPU framework already takes care of the capabilities.

Pull Request: https://projects.blender.org/blender/blender/pulls/107302
2023-04-24 15:35:27 +02:00
Jeroen Bakker
26147b29a7 Vulkan: Construct a Vulkan 1.2 Context.
Apparently we always constructed a Vulkan 1.0 Context, although we
are targetting Vulkan 1.2. This also lead to incorrect expectations
when using the Vulkan Memory allocator.

Pull Request: https://projects.blender.org/blender/blender/pulls/107300
2023-04-24 15:32:17 +02:00