[Bf-blender-cvs] [2474810aa0b] temp-vulkan-descriptor-sets: Vulkan: Added initial compute pipeline.
Jeroen Bakker
noreply at git.blender.org
Fri Feb 3 15:23:46 CET 2023
Commit: 2474810aa0b979f1b910a6a124d0fc16385b1dfa
Author: Jeroen Bakker
Date: Tue Jan 31 15:45:21 2023 +0100
Branches: temp-vulkan-descriptor-sets
https://developer.blender.org/rB2474810aa0b979f1b910a6a124d0fc16385b1dfa
Vulkan: Added initial compute pipeline.
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/vulkan/vk_context.hh
A source/blender/gpu/vulkan/vk_descriptor_pools.cc
A source/blender/gpu/vulkan/vk_descriptor_pools.hh
M source/blender/gpu/vulkan/vk_shader.cc
M source/blender/gpu/vulkan/vk_shader.hh
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 6804c63d4e4..0285e8e674c 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -191,6 +191,7 @@ set(VULKAN_SRC
vulkan/vk_backend.cc
vulkan/vk_batch.cc
vulkan/vk_context.cc
+ vulkan/vk_descriptor_pools.cc
vulkan/vk_drawlist.cc
vulkan/vk_fence.cc
vulkan/vk_framebuffer.cc
@@ -207,6 +208,7 @@ set(VULKAN_SRC
vulkan/vk_backend.hh
vulkan/vk_batch.hh
vulkan/vk_context.hh
+ vulkan/vk_descriptor_pools.hh
vulkan/vk_drawlist.hh
vulkan/vk_fence.hh
vulkan/vk_framebuffer.hh
diff --git a/source/blender/gpu/vulkan/vk_context.hh b/source/blender/gpu/vulkan/vk_context.hh
index 6a5b5cb0034..d516b459b20 100644
--- a/source/blender/gpu/vulkan/vk_context.hh
+++ b/source/blender/gpu/vulkan/vk_context.hh
@@ -9,6 +9,8 @@
#include "gpu_context_private.hh"
+#include "vk_descriptor_pools.hh"
+
#include "vk_mem_alloc.h"
#ifdef __APPLE__
@@ -29,6 +31,7 @@ class VKContext : public Context {
/** Allocator used for texture and buffers and other resources. */
VmaAllocator mem_allocator_ = VK_NULL_HANDLE;
+ VKDescriptorPools descriptor_pools_;
public:
VKContext(void *ghost_window, void *ghost_context);
diff --git a/source/blender/gpu/vulkan/vk_descriptor_pools.cc b/source/blender/gpu/vulkan/vk_descriptor_pools.cc
new file mode 100644
index 00000000000..0ea3a94c9cb
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_descriptor_pools.cc
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#include "vk_descriptor_pools.hh"
+
+namespace blender::gpu {
+VKDescriptorPools::VKDescriptorPools()
+{
+}
+
+VKDescriptorPools::~VKDescriptorPools()
+{
+}
+
+void VKDescriptorPools::new_pool(VkDevice vk_device)
+{
+ Vector<VkDescriptorPoolSize> pool_sizes = {
+ {VK_DESCRIPTOR_TYPE_UNIFORM_BUFFER, POOL_SIZE_UNIFORM_BUFFER},
+ };
+ VkDescriptorPoolCreateInfo pool_info = {};
+ pool_info.sType = VK_STRUCTURE_TYPE_DESCRIPTOR_POOL_CREATE_INFO;
+ pool_info.flags = 0;
+ pool_info.maxSets = POOL_SIZE_DESCRIPTOR_SETS;
+ pool_info.poolSizeCount = pool_sizes.size();
+ pool_info.pPoolSizes = pool_sizes.data();
+ VkDescriptorPool descriptor_pool = VK_NULL_HANDLE;
+ VkResult result = vkCreateDescriptorPool(vk_device, &pool_info, nullptr, &descriptor_pool);
+ UNUSED_VARS(result);
+ pools_.append(descriptor_pool);
+}
+
+} // namespace blender::gpu
\ No newline at end of file
diff --git a/source/blender/gpu/vulkan/vk_descriptor_pools.hh b/source/blender/gpu/vulkan/vk_descriptor_pools.hh
new file mode 100644
index 00000000000..fdca3c68b7a
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_descriptor_pools.hh
@@ -0,0 +1,41 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#pragma once
+
+#include "BLI_vector.hh"
+
+#ifdef __APPLE__
+# include <MoltenVK/vk_mvk_moltenvk.h>
+#else
+# include <vulkan/vulkan.h>
+#endif
+
+namespace blender::gpu {
+
+/**
+ * List of VkDescriptorPools.
+ *
+ * In Vulkan a pool is constructed with a certain size. When more is needed it is adviced to
+ * construct a second pool. VKDescriptorPools will keep track of those pools and construct
+ * new pools when the previous one is exhausted.
+ */
+class VKDescriptorPools {
+ /** Number of pool sizes */
+ static constexpr uint32_t POOL_SIZE_UNIFORM_BUFFER = 1000;
+ static constexpr uint32_t POOL_SIZE_DESCRIPTOR_SETS = 1000;
+
+ Vector<VkDescriptorPool> pools_;
+
+ public:
+ VKDescriptorPools();
+ ~VKDescriptorPools();
+
+ private:
+ void new_pool(VkDevice vk_device);
+};
+} // namespace blender::gpu
\ No newline at end of file
diff --git a/source/blender/gpu/vulkan/vk_shader.cc b/source/blender/gpu/vulkan/vk_shader.cc
index 17c06fb42e6..29f7253413a 100644
--- a/source/blender/gpu/vulkan/vk_shader.cc
+++ b/source/blender/gpu/vulkan/vk_shader.cc
@@ -641,52 +641,195 @@ bool VKShader::finalize(const shader::ShaderCreateInfo *info)
return false;
}
- if (vertex_module_ != VK_NULL_HANDLE) {
+ VkDevice vk_device = context_->device_get();
+ if (!finalize_descriptor_set_layouts(vk_device, info)) {
+ return false;
+ }
+ if (!finalize_pipeline_layout(vk_device, info)) {
+ return false;
+ }
+
+ /* TODO we might need to move the actual pipeline construction to a later stage as the graphics
+ * pipeline requires more data before it can be constructed.*/
+ const bool is_graphics_shader = vertex_module_ != VK_NULL_HANDLE;
+ if (is_graphics_shader) {
BLI_assert((fragment_module_ != VK_NULL_HANDLE && info->tf_type_ == GPU_SHADER_TFB_NONE) ||
(fragment_module_ == VK_NULL_HANDLE && info->tf_type_ != GPU_SHADER_TFB_NONE));
BLI_assert(compute_module_ == VK_NULL_HANDLE);
-
- VkPipelineShaderStageCreateInfo vertex_stage_info = {};
- vertex_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
- vertex_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT;
- vertex_stage_info.module = vertex_module_;
- vertex_stage_info.pName = "main";
- pipeline_infos_.append(vertex_stage_info);
-
- if (geometry_module_ != VK_NULL_HANDLE) {
- VkPipelineShaderStageCreateInfo geo_stage_info = {};
- geo_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
- geo_stage_info.stage = VK_SHADER_STAGE_GEOMETRY_BIT;
- geo_stage_info.module = geometry_module_;
- geo_stage_info.pName = "main";
- pipeline_infos_.append(geo_stage_info);
- }
- if (fragment_module_ != VK_NULL_HANDLE) {
- VkPipelineShaderStageCreateInfo fragment_stage_info = {};
- fragment_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
- fragment_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
- fragment_stage_info.module = fragment_module_;
- fragment_stage_info.pName = "main";
- pipeline_infos_.append(fragment_stage_info);
- }
+ return finalize_graphics_pipeline(vk_device);
}
else {
BLI_assert(vertex_module_ == VK_NULL_HANDLE);
BLI_assert(geometry_module_ == VK_NULL_HANDLE);
BLI_assert(fragment_module_ == VK_NULL_HANDLE);
BLI_assert(compute_module_ != VK_NULL_HANDLE);
+ return finalize_compute_pipeline(vk_device);
+ }
+}
- VkPipelineShaderStageCreateInfo compute_stage_info = {};
- compute_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
- compute_stage_info.stage = VK_SHADER_STAGE_GEOMETRY_BIT;
- compute_stage_info.module = compute_module_;
- compute_stage_info.pName = "main";
- pipeline_infos_.append(compute_stage_info);
+bool VKShader::finalize_graphics_pipeline(VkDevice /*vk_device */)
+{
+ Vector<VkPipelineShaderStageCreateInfo> pipeline_stages;
+ VkPipelineShaderStageCreateInfo vertex_stage_info = {};
+ vertex_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ vertex_stage_info.stage = VK_SHADER_STAGE_VERTEX_BIT;
+ vertex_stage_info.module = vertex_module_;
+ vertex_stage_info.pName = "main";
+ pipeline_stages.append(vertex_stage_info);
+
+ if (geometry_module_ != VK_NULL_HANDLE) {
+ VkPipelineShaderStageCreateInfo geo_stage_info = {};
+ geo_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ geo_stage_info.stage = VK_SHADER_STAGE_GEOMETRY_BIT;
+ geo_stage_info.module = geometry_module_;
+ geo_stage_info.pName = "main";
+ pipeline_stages.append(geo_stage_info);
+ }
+ if (fragment_module_ != VK_NULL_HANDLE) {
+ VkPipelineShaderStageCreateInfo fragment_stage_info = {};
+ fragment_stage_info.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ fragment_stage_info.stage = VK_SHADER_STAGE_FRAGMENT_BIT;
+ fragment_stage_info.module = fragment_module_;
+ fragment_stage_info.pName = "main";
+ pipeline_stages.append(fragment_stage_info);
}
-#ifdef NDEBUG
- UNUSED_VARS(info);
-#endif
+ /*
+ VkGraphicsPipelineCreateInfo pipeline_info = {};
+ pipeline_info.sType = VK_STRUCTURE_TYPE_GRAPHICS_PIPELINE_CREATE_INFO;
+ pipeline_info.flags = 0;
+ pipeline_info.stageCount = pipeline_stages.size();
+ pipeline_info.pStages = pipeline_stages.data();
+ pipeline_info.layout = pipeline_layout_;
+ */
+
+ /* TODO: Graphics pipeline should be added. Note that it requries rendered passes and might need
+ * some more refactorings, when it should be used. TODO: Research what is a vulkan renderpass.
+ * As we are currently focussing on Compute pipeline we will not spent to much effort in this at
+ * the current time.
+ *
+ * It seems like we will not be able to construct the graphics pipeline at this moment as it
+ * would be part of the binding process. */
+
+ return true;
+}
+
+bool VKShader::finalize_compute_pipeline(VkDevice vk_device)
+{
+
+ VkComputePipelineCreateInfo pipeline_info = {};
+ pipeline_info.sType = VK_STRUCTURE_TYPE_COMPUTE_PIPELINE_CREATE_INFO;
+ pipeline_info.flags = 0;
+ pipeline_info.stage = {};
+ pipeline_info.stage.sType = VK_STRUCTURE_TYPE_PIPELINE_SHADER_STAGE_CREATE_INFO;
+ pipeline_info.stage.flags = 0;
+ pipeline_info.stage.stage = VK_SHADER_STAGE_COMPUTE_BIT;
+ pipeline_info.stage.module = compute_module_;
+ pipeline_info.layout = pipeline_layout_;
+ pipeline_info.stage.pName = "main";
+
+ if (vkCreateComputePipelines(vk_device, nullptr, 1, &pipeline_info, nullptr, &pipeline_) !=
+ VK_SUCCESS) {
+ return false;
+ }
+
+ return true;
+}
+
+bool VKShader::finalize_pipeline_layout(VkDevice vk_device,
+ const shader::ShaderCreateInfo * /*info*/)
+{
+ VkPipelineLayoutCreateInfo pipeline_info = {};
+ pipeline_info.sType = VK_STRUCTURE_TYPE_PIPELINE_LAYOUT_CREATE_INFO;
+ pipeline_info.flags = 0;
+ pipeline_info.setLayoutCount = layouts_.size();
+ pipeline_info.pSetLayouts = layouts_.data();
+
+ if (vkCreatePipelineLayout(vk_device, &pipeline_info, nullptr, &pipeline_layout_) !=
+ VK_SUCCESS) {
+ return false;
+ };
+
+ return true;
+}
+
+static VkDescriptorType descriptor_type(
+ const shader::ShaderCreateInfo::Resource::BindType bind_type
@@ Diff output truncated at 10240 characters. @@
More information about the Bf-blender-cvs
mailing list