Vulkan: Initial Graphics Pipeline #106224

Merged
Jeroen Bakker merged 104 commits from Jeroen-Bakker/blender:vulkan-offscreen-rendering into main 2023-05-11 13:02:03 +02:00
Member

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.
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.
Jeroen Bakker added 3 commits 2023-03-28 16:03:33 +02:00
Jeroen Bakker added the
Interest
Vulkan
label 2023-03-28 16:03:42 +02:00
Jeroen Bakker added this to the 3.6 LTS milestone 2023-03-28 16:03:44 +02:00
Jeroen Bakker added this to the EEVEE & Viewport project 2023-03-28 16:03:48 +02:00
Jeroen Bakker self-assigned this 2023-03-28 16:03:53 +02:00
Hans Goudey changed title from WIP: Vulkan: Initial Graphics Pipeline. to WIP: Vulkan: Initial Graphics Pipeline 2023-03-28 16:11:05 +02:00
Jeroen Bakker added 1 commit 2023-03-29 08:07:58 +02:00
Jeroen Bakker added 3 commits 2023-04-06 16:21:58 +02:00
Jeroen Bakker added 3 commits 2023-04-07 12:10:11 +02:00
Jeroen Bakker changed title from WIP: Vulkan: Initial Graphics Pipeline to Vulkan: Initial Graphics Pipeline 2023-04-07 12:25:00 +02:00
Jeroen Bakker added the
Module
EEVEE & Viewport
label 2023-04-07 12:26:14 +02:00
Jeroen Bakker requested review from Clément Foucault 2023-04-07 12:26:53 +02:00
Jeroen Bakker requested review from Bastien Montagne 2023-04-07 12:33:11 +02:00
Jeroen Bakker added 1 commit 2023-04-07 12:33:42 +02:00
Jeroen Bakker added 2 commits 2023-04-07 14:14:24 +02:00
Jeroen Bakker added 1 commit 2023-04-07 15:01:47 +02:00
Jeroen Bakker changed title from Vulkan: Initial Graphics Pipeline to WIP: Vulkan: Initial Graphics Pipeline 2023-04-13 13:27:06 +02:00
Jeroen Bakker added a new dependency 2023-04-13 13:46:18 +02:00
Jeroen Bakker added 5 commits 2023-04-13 15:35:37 +02:00
29cc37cf22 GPU: Add texture usage parameter to GPUOffscreen.
Currently the Textures used for offscreen rendering don't have
the `GPU_TEXTURE_USAGE_HOST_READ` flag. But some cases it is
needed. This PR adds a parameter when creating an offscreen
buffer.

Other solution could be to add this flag to all textures, but
we chose not to do this as that reduces the amount of fine-tuning
options for Metal/Vulkan backends. GPU can store textures
differently based on its actual usage.

This option isn't available in the python API as we don't expect
add-on developers to fine-tune texture usages to this extent.
Jeroen Bakker changed title from WIP: Vulkan: Initial Graphics Pipeline to Vulkan: Initial Graphics Pipeline 2023-04-13 15:35:45 +02:00
Jeroen Bakker added 3 commits 2023-04-13 15:44:32 +02:00
Jeroen Bakker added 1 commit 2023-04-13 16:15:01 +02:00
Jeroen Bakker added 2 commits 2023-04-14 09:30:26 +02:00
Jeroen Bakker reviewed 2023-04-14 16:01:06 +02:00
@ -73,0 +94,4 @@
VkShaderModule vertex_module,
VkShaderModule fragment_module,
VkPipelineLayout &pipeline_layout,
const VKBatch &batch,
Author
Member

Don't pass VKBatch, but GPUPrimType. This makes the function also usable when using immediate mode.

Don't pass VKBatch, but `GPUPrimType`. This makes the function also usable when using immediate mode.
Jeroen Bakker changed title from Vulkan: Initial Graphics Pipeline to WIP: Vulkan: Initial Graphics Pipeline 2023-04-16 09:13:44 +02:00
Jeroen Bakker added 4 commits 2023-04-17 08:52:41 +02:00
Jeroen Bakker added 1 commit 2023-04-17 14:15:44 +02:00
Jeroen Bakker added 1 commit 2023-04-17 15:25:11 +02:00
Jeroen Bakker added 2 commits 2023-04-17 16:13:57 +02:00
Jeroen Bakker added 2 commits 2023-04-18 10:15:34 +02:00
Jeroen Bakker added 1 commit 2023-04-18 15:51:11 +02:00
Jeroen Bakker added 5 commits 2023-04-20 15:55:28 +02:00
Jeroen Bakker added 1 commit 2023-04-20 16:35:00 +02:00
Jeroen Bakker added 2 commits 2023-04-21 10:10:09 +02:00
Jeroen Bakker added 1 commit 2023-04-21 12:23:45 +02:00
Jeroen Bakker added 1 commit 2023-04-21 12:56:27 +02:00
Jeroen Bakker added 1 commit 2023-04-21 14:32:30 +02:00
Jeroen Bakker added 1 commit 2023-04-21 15:44:40 +02:00
Jeroen Bakker added 3 commits 2023-04-24 14:59:42 +02:00
Jeroen Bakker added 1 commit 2023-04-24 15:38:26 +02:00
Jeroen Bakker added 1 commit 2023-04-25 09:44:53 +02:00
Jeroen Bakker added 1 commit 2023-04-25 10:07:18 +02:00
Jeroen Bakker added 5 commits 2023-04-25 13:32:19 +02:00
Jeroen Bakker added 3 commits 2023-04-25 14:24:21 +02:00
Jeroen Bakker added 1 commit 2023-04-26 08:14:49 +02:00
Jeroen Bakker added 1 commit 2023-04-26 08:22:00 +02:00
Jeroen Bakker added 3 commits 2023-04-26 09:29:27 +02:00
Jeroen Bakker added 2 commits 2023-04-26 15:25:00 +02:00
Jeroen Bakker added 2 commits 2023-05-01 14:25:31 +02:00
Jeroen Bakker added 1 commit 2023-05-01 14:32:56 +02:00
Jeroen Bakker added 1 commit 2023-05-01 14:46:18 +02:00
Jeroen Bakker reviewed 2023-05-01 20:06:19 +02:00
@ -344,7 +344,6 @@ static void gpu_backend_create()
void gpu_backend_delete_resources()
{
BLI_assert(g_backend);
Author
Member

Revert this change. It is not intended

Revert this change. It is not intended
Jeroen-Bakker marked this conversation as resolved
Jeroen Bakker added 2 commits 2023-05-02 13:50:53 +02:00
Jeroen Bakker added 1 commit 2023-05-02 14:45:05 +02:00
Jeroen Bakker added 1 commit 2023-05-02 14:57:34 +02:00
Jeroen Bakker reviewed 2023-05-02 15:27:25 +02:00
@ -124,0 +155,4 @@
void wait_idle()
{
if (device) {
Author
Member

!= VK_NULL_HANDLE)

`!= VK_NULL_HANDLE)`
Author
Member

!= VK_NULL_HANDLE)

`!= VK_NULL_HANDLE)`
@ -170,3 +386,1 @@
if (m_device) {
vkDeviceWaitIdle(m_device);
}
// TODO: see if we can use a usage counter to free the global device.
Author
Member

Remove comment

Remove comment
@ -121,3 +126,3 @@
void VKCommandBuffer::end_render_pass(const VKFrameBuffer &framebuffer)
{
UNUSED_VARS_NDEBUG(framebuffer)
UNUSED_VARS_NDEBUG(framebuffer);
Author
Member

Commit directly to main.

Commit directly to main.
Jeroen-Bakker marked this conversation as resolved
@ -136,1 +160,3 @@
image_info.imageLayout = VK_IMAGE_LAYOUT_GENERAL;
image_info.sampler = binding.vk_sampler;
image_info.imageView = binding.texture->vk_image_view_handle();
/* TODO: use the correct one from the texture. */
Author
Member

Remove comment

Remove comment
Jeroen Bakker added 1 commit 2023-05-02 15:28:11 +02:00
Jeroen Bakker added 1 commit 2023-05-04 08:02:18 +02:00
Jeroen Bakker added 2 commits 2023-05-04 10:37:57 +02:00
Jeroen Bakker added 1 commit 2023-05-04 16:00:38 +02:00
Jeroen Bakker added 2 commits 2023-05-05 08:38:36 +02:00
Jeroen Bakker added 3 commits 2023-05-05 12:13:27 +02:00
Jeroen Bakker added 1 commit 2023-05-05 12:36:01 +02:00
Jeroen Bakker added 2 commits 2023-05-05 14:55:31 +02:00
Jeroen Bakker changed title from WIP: Vulkan: Initial Graphics Pipeline to Vulkan: Initial Graphics Pipeline 2023-05-05 15:44:26 +02:00
Jeroen Bakker reviewed 2023-05-05 16:18:29 +02:00
@ -1622,6 +1623,7 @@ void DRW_draw_view(const bContext *C)
{
View3D *v3d = CTX_wm_view3d(C);
if (v3d) {
GPU_debug_capture_begin();
Author
Member

Revert these changes. Draw manager support will be added later as it requires more features to be added to the VKBackend.

Revert these changes. Draw manager support will be added later as it requires more features to be added to the VKBackend.
Jeroen-Bakker marked this conversation as resolved
Jeroen Bakker reviewed 2023-05-05 16:26:18 +02:00
@ -304,6 +322,24 @@ bool VKTexture::allocate()
return result == VK_SUCCESS;
}
// TODO: move texture/image bindings to shader.
Author
Member

This should be done as part of this change.

This should be done as part of this change.
Jeroen Bakker reviewed 2023-05-08 12:45:41 +02:00
@ -318,0 +360,4 @@
void VKTexture::unbind()
{
VKContext &context = *VKContext::get();
/* TODO get a list of shaders this texture is bound to. */
Author
Member

Remove comment. The solution is to remove the informative warning from vulkan validation layers using message utils. The reason is that due to the dynamic and extensible character of Blender it isn't possible to keep textures alive until the next time the pipeline is being used. Other solutions like filling it with an dummy textures would add more complexity just to remove an informative message. The complexity is that the texture requires similar formats/usages and might be a larger set than expected.

Remove comment. The solution is to remove the informative warning from vulkan validation layers using message utils. The reason is that due to the dynamic and extensible character of Blender it isn't possible to keep textures alive until the next time the pipeline is being used. Other solutions like filling it with an dummy textures would add more complexity just to remove an informative message. The complexity is that the texture requires similar formats/usages and might be a larger set than expected.
Jeroen-Bakker marked this conversation as resolved
Jeroen Bakker reviewed 2023-05-08 13:30:13 +02:00
@ -39,3 +39,3 @@
const VKDescriptorSet::Location descriptor_set_location(
const shader::ShaderCreateInfo::Resource &resource) const;
const VKDescriptorSet::Location descriptor_set_location(
const std::optional<VKDescriptorSet::Location> descriptor_set_location(
Author
Member

Need to re-evaluate if this change is still needed, or has been fixed by using late resource binding via the VKStateManager

Need to re-evaluate if this change is still needed, or has been fixed by using late resource binding via the VKStateManager
Jeroen Bakker reviewed 2023-05-08 13:33:24 +02:00
@ -513,0 +481,4 @@
VkDevice device = vulkan_device->device;
if (m_currentFrame != m_lastFrame) {
vkResetFences(device, 1, &m_in_flight_fences[m_currentFrame]);
}
Author
Member

Add early exit when m_currentFrame == m_lastFrame. In this case swapChain is triggered without anything being rendered.

Add early exit when `m_currentFrame == m_lastFrame`. In this case swapChain is triggered without anything being rendered.
Jeroen Bakker reviewed 2023-05-08 13:34:29 +02:00
@ -848,3 +839,3 @@
/* Driver can stall if only using minimal image count. */
uint32_t image_count = capabilities.minImageCount;
uint32_t image_count = capabilities.minImageCount + 1;
Author
Member

According to vulkan it is better to allocate one extra.

According to vulkan it is better to allocate one extra.
Jeroen-Bakker marked this conversation as resolved
Jeroen Bakker reviewed 2023-05-08 13:38:09 +02:00
@ -10,3 +15,3 @@
namespace blender::gpu {
void VKBatch::draw(int /*v_first*/, int /*v_count*/, int /*i_first*/, int /*i_count*/) {}
void VKBatch::draw(int v_first, int v_count, int i_first, int i_count)
Author
Member

Use full names to make a difference between indexed and instanced.

Use full names to make a difference between indexed and instanced.
Jeroen-Bakker marked this conversation as resolved
Jeroen Bakker reviewed 2023-05-08 13:41:15 +02:00
@ -0,0 +16,4 @@
/**
* Helper struct to enable buffers to be bound with an offset.
*/
struct VKBufferWithOffset {
Author
Member

This is specifically added to support VKImmediate where internally an VKBuffer is used, and can have multiple layouts. This should be mentioned in the comments.

It was added in its own file as it needs to be included to the command buffer. We might want to move this to the VKBuffer as for now I don't see other specific subtypes being added.

This is specifically added to support VKImmediate where internally an VKBuffer is used, and can have multiple layouts. This should be mentioned in the comments. It was added in its own file as it needs to be included to the command buffer. We might want to move this to the VKBuffer as for now I don't see other specific subtypes being added.
Jeroen-Bakker marked this conversation as resolved
Jeroen Bakker reviewed 2023-05-08 14:19:36 +02:00
@ -510,3 +478,3 @@
submit_info.pSignalSemaphores = &m_render_finished_semaphores[m_currentFrame];
vkResetFences(device, 1, &m_in_flight_fences[m_currentFrame]);
assert(vulkan_device.has_value() && vulkan_device->device != VK_NULL_HANDLE);
Author
Member

Describe the swapchan in a technical document.

Describe the swapchan in a technical document.
Jeroen Bakker reviewed 2023-05-08 14:31:13 +02:00
@ -65,3 +65,3 @@
{
VKContext &context = *VKContext::get();
VKShader *shader = static_cast<VKShader *>(context.shader);
context.bind_compute_pipeline();
Author
Member

Add late binding of compute pipeline

Add late binding of compute pipeline
Jeroen-Bakker marked this conversation as resolved
Jeroen Bakker force-pushed vulkan-offscreen-rendering from 9cab0604f5 to 3fc7d631af 2023-05-11 08:58:35 +02:00 Compare
Jeroen Bakker added 2 commits 2023-05-11 09:05:16 +02:00
Jeroen Bakker added 2 commits 2023-05-11 10:00:06 +02:00
Jeroen Bakker added 2 commits 2023-05-11 10:14:12 +02:00
Jeroen Bakker added 2 commits 2023-05-11 12:35:30 +02:00
Jeroen Bakker added 4 commits 2023-05-11 12:52:35 +02:00
Jeroen Bakker merged commit 809a5aa418 into main 2023-05-11 13:02:03 +02:00
Jeroen Bakker deleted branch vulkan-offscreen-rendering 2023-05-11 13:02:05 +02:00
Howard Trickey referenced this issue from a commit 2023-05-29 02:51:40 +02:00
Sign in to join this conversation.
No Label
Interest
Alembic
Interest
Animation & Rigging
Interest
Asset Browser
Interest
Asset Browser Project Overview
Interest
Audio
Interest
Automated Testing
Interest
Blender Asset Bundle
Interest
BlendFile
Interest
Collada
Interest
Compatibility
Interest
Compositing
Interest
Core
Interest
Cycles
Interest
Dependency Graph
Interest
Development Management
Interest
EEVEE
Interest
EEVEE & Viewport
Interest
Freestyle
Interest
Geometry Nodes
Interest
Grease Pencil
Interest
ID Management
Interest
Images & Movies
Interest
Import Export
Interest
Line Art
Interest
Masking
Interest
Metal
Interest
Modeling
Interest
Modifiers
Interest
Motion Tracking
Interest
Nodes & Physics
Interest
OpenGL
Interest
Overlay
Interest
Overrides
Interest
Performance
Interest
Physics
Interest
Pipeline, Assets & IO
Interest
Platforms, Builds & Tests
Interest
Python API
Interest
Render & Cycles
Interest
Render Pipeline
Interest
Sculpt, Paint & Texture
Interest
Text Editor
Interest
Translations
Interest
Triaging
Interest
Undo
Interest
USD
Interest
User Interface
Interest
UV Editing
Interest
VFX & Video
Interest
Video Sequencer
Interest
Virtual Reality
Interest
Vulkan
Interest
Wayland
Interest
Workbench
Interest: X11
Legacy
Blender 2.8 Project
Legacy
Milestone 1: Basic, Local Asset Browser
Legacy
OpenGL Error
Meta
Good First Issue
Meta
Papercut
Meta
Retrospective
Meta
Security
Module
Animation & Rigging
Module
Core
Module
Development Management
Module
EEVEE & Viewport
Module
Grease Pencil
Module
Modeling
Module
Nodes & Physics
Module
Pipeline, Assets & IO
Module
Platforms, Builds & Tests
Module
Python API
Module
Render & Cycles
Module
Sculpt, Paint & Texture
Module
Triaging
Module
User Interface
Module
VFX & Video
Platform
FreeBSD
Platform
Linux
Platform
macOS
Platform
Windows
Priority
High
Priority
Low
Priority
Normal
Priority
Unbreak Now!
Status
Archived
Status
Confirmed
Status
Duplicate
Status
Needs Info from Developers
Status
Needs Information from User
Status
Needs Triage
Status
Resolved
Type
Bug
Type
Design
Type
Known Issue
Type
Patch
Type
Report
Type
To Do
No Milestone
No Assignees
1 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Reference: blender/blender#106224
No description provided.