[Bf-blender-cvs] [ec40ef19c7d] temp-vulkan-descriptor-sets: Create compute command buffer.

Jeroen Bakker noreply at git.blender.org
Mon Feb 6 15:59:22 CET 2023


Commit: ec40ef19c7d6f6cb9784318c363d466b94a888dd
Author: Jeroen Bakker
Date:   Mon Feb 6 15:59:15 2023 +0100
Branches: temp-vulkan-descriptor-sets
https://developer.blender.org/rBec40ef19c7d6f6cb9784318c363d466b94a888dd

Create compute command buffer.

===================================================================

M	intern/ghost/GHOST_C-api.h
M	intern/ghost/GHOST_IContext.h
M	intern/ghost/intern/GHOST_C-api.cpp
M	intern/ghost/intern/GHOST_Context.h
M	intern/ghost/intern/GHOST_ContextVK.cpp
M	intern/ghost/intern/GHOST_ContextVK.h
M	source/blender/gpu/vulkan/vk_context.cc
M	source/blender/gpu/vulkan/vk_context.hh
M	source/blender/gpu/vulkan/vk_shader.cc
M	source/blender/gpu/vulkan/vk_shader.hh

===================================================================

diff --git a/intern/ghost/GHOST_C-api.h b/intern/ghost/GHOST_C-api.h
index cf810caf778..025dd3045db 100644
--- a/intern/ghost/GHOST_C-api.h
+++ b/intern/ghost/GHOST_C-api.h
@@ -1201,6 +1201,7 @@ void GHOST_GetVulkanHandles(GHOST_ContextHandle context,
                             void *r_instance,
                             void *r_physical_device,
                             void *r_device,
+                            void *r_compute_command_buffer,
                             uint32_t *r_graphic_queue_family);
 
 /**
diff --git a/intern/ghost/GHOST_IContext.h b/intern/ghost/GHOST_IContext.h
index 52863e8c061..14477b96315 100644
--- a/intern/ghost/GHOST_IContext.h
+++ b/intern/ghost/GHOST_IContext.h
@@ -40,7 +40,7 @@ class GHOST_IContext {
 
   virtual unsigned int getDefaultFramebuffer() = 0;
 
-  virtual GHOST_TSuccess getVulkanHandles(void *, void *, void *, uint32_t *) = 0;
+  virtual GHOST_TSuccess getVulkanHandles(void *, void *, void *, void *, uint32_t *) = 0;
 
   /**
    * Gets the Vulkan framebuffer related resource handles associated with the Vulkan context.
diff --git a/intern/ghost/intern/GHOST_C-api.cpp b/intern/ghost/intern/GHOST_C-api.cpp
index a3c1eedc9c0..56385ed1dbb 100644
--- a/intern/ghost/intern/GHOST_C-api.cpp
+++ b/intern/ghost/intern/GHOST_C-api.cpp
@@ -1203,10 +1203,12 @@ void GHOST_GetVulkanHandles(GHOST_ContextHandle contexthandle,
                             void *r_instance,
                             void *r_physical_device,
                             void *r_device,
+                            void *r_compute_command_buffer,
                             uint32_t *r_graphic_queue_family)
 {
   GHOST_IContext *context = (GHOST_IContext *)contexthandle;
-  context->getVulkanHandles(r_instance, r_physical_device, r_device, r_graphic_queue_family);
+  context->getVulkanHandles(
+      r_instance, r_physical_device, r_device, r_compute_command_buffer, r_graphic_queue_family);
 }
 
 void GHOST_GetVulkanBackbuffer(GHOST_WindowHandle windowhandle,
diff --git a/intern/ghost/intern/GHOST_Context.h b/intern/ghost/intern/GHOST_Context.h
index d4cc0d18e55..b3529dc73b0 100644
--- a/intern/ghost/intern/GHOST_Context.h
+++ b/intern/ghost/intern/GHOST_Context.h
@@ -142,6 +142,7 @@ class GHOST_Context : public GHOST_IContext {
   virtual GHOST_TSuccess getVulkanHandles(void * /*r_instance*/,
                                           void * /*r_physical_device*/,
                                           void * /*r_device*/,
+                                          void * /*r_compute_command_buffer*/,
                                           uint32_t * /*r_graphic_queue_family*/) override
   {
     return GHOST_kFailure;
diff --git a/intern/ghost/intern/GHOST_ContextVK.cpp b/intern/ghost/intern/GHOST_ContextVK.cpp
index b14ae40df2e..b81a4cac894 100644
--- a/intern/ghost/intern/GHOST_ContextVK.cpp
+++ b/intern/ghost/intern/GHOST_ContextVK.cpp
@@ -192,6 +192,9 @@ GHOST_TSuccess GHOST_ContextVK::destroySwapchain()
   if (m_render_pass != VK_NULL_HANDLE) {
     vkDestroyRenderPass(m_device, m_render_pass, NULL);
   }
+  if (m_compute_command_buffer != VK_NULL_HANDLE) {
+    vkFreeCommandBuffers(m_device, m_command_pool, 1, &m_compute_command_buffer);
+  }
   for (auto command_buffer : m_command_buffers) {
     vkFreeCommandBuffers(m_device, m_command_pool, 1, &command_buffer);
   }
@@ -311,11 +314,13 @@ GHOST_TSuccess GHOST_ContextVK::getVulkanBackbuffer(void *image,
 GHOST_TSuccess GHOST_ContextVK::getVulkanHandles(void *r_instance,
                                                  void *r_physical_device,
                                                  void *r_device,
+                                                 void *r_compute_command_buffer,
                                                  uint32_t *r_graphic_queue_family)
 {
   *((VkInstance *)r_instance) = m_instance;
   *((VkPhysicalDevice *)r_physical_device) = m_physical_device;
   *((VkDevice *)r_device) = m_device;
+  *((VkCommandBuffer *)r_compute_command_buffer) = m_compute_command_buffer;
   *r_graphic_queue_family = m_queue_family_graphic;
 
   return GHOST_kSuccess;
@@ -619,16 +624,34 @@ static GHOST_TSuccess selectPresentMode(VkPhysicalDevice device,
   return GHOST_kFailure;
 }
 
-GHOST_TSuccess GHOST_ContextVK::createCommandBuffers()
+GHOST_TSuccess GHOST_ContextVK::createCommandPools()
 {
-  m_command_buffers.resize(m_swapchain_image_views.size());
-
   VkCommandPoolCreateInfo poolInfo = {};
   poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO;
   poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
   poolInfo.queueFamilyIndex = m_queue_family_graphic;
 
   VK_CHECK(vkCreateCommandPool(m_device, &poolInfo, NULL, &m_command_pool));
+  return GHOST_kSuccess;
+}
+
+GHOST_TSuccess GHOST_ContextVK::createComputeCommandBuffer()
+{
+  assert(m_command_pool != VK_NULL_HANDLE);
+  VkCommandBufferAllocateInfo alloc_info = {};
+  alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
+  alloc_info.commandPool = m_command_pool;
+  alloc_info.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
+  alloc_info.commandBufferCount = 1;
+
+  VK_CHECK(vkAllocateCommandBuffers(m_device, &alloc_info, &m_compute_command_buffer));
+  return GHOST_kSuccess;
+}
+
+GHOST_TSuccess GHOST_ContextVK::createGraphicsCommandBuffers()
+{
+  assert(m_command_pool != VK_NULL_HANDLE);
+  m_command_buffers.resize(m_swapchain_image_views.size());
 
   VkCommandBufferAllocateInfo alloc_info = {};
   alloc_info.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
@@ -637,7 +660,6 @@ GHOST_TSuccess GHOST_ContextVK::createCommandBuffers()
   alloc_info.commandBufferCount = static_cast<uint32_t>(m_command_buffers.size());
 
   VK_CHECK(vkAllocateCommandBuffers(m_device, &alloc_info, m_command_buffers.data()));
-
   return GHOST_kSuccess;
 }
 
@@ -776,7 +798,7 @@ GHOST_TSuccess GHOST_ContextVK::createSwapchain()
     VK_CHECK(vkCreateFence(m_device, &fence_info, NULL, &m_in_flight_fences[i]));
   }
 
-  createCommandBuffers();
+  createGraphicsCommandBuffers();
 
   return GHOST_kSuccess;
 }
@@ -976,6 +998,9 @@ GHOST_TSuccess GHOST_ContextVK::initializeDrawingContext()
 
   VK_CHECK(vkCreateDevice(m_physical_device, &device_create_info, NULL, &m_device));
 
+  createCommandPools();
+  createComputeCommandBuffer();
+
   vkGetDeviceQueue(m_device, m_queue_family_graphic, 0, &m_graphic_queue);
 
   if (use_window_surface) {
diff --git a/intern/ghost/intern/GHOST_ContextVK.h b/intern/ghost/intern/GHOST_ContextVK.h
index 1a2d38bc701..396c922172c 100644
--- a/intern/ghost/intern/GHOST_ContextVK.h
+++ b/intern/ghost/intern/GHOST_ContextVK.h
@@ -113,6 +113,7 @@ class GHOST_ContextVK : public GHOST_Context {
   GHOST_TSuccess getVulkanHandles(void *r_instance,
                                   void *r_physical_device,
                                   void *r_device,
+                                  void *r_compute_command_buffer,
                                   uint32_t *r_graphic_queue_family);
   /**
    * Gets the Vulkan framebuffer related resource handles associated with the Vulkan context.
@@ -182,6 +183,7 @@ class GHOST_ContextVK : public GHOST_Context {
   std::vector<VkImage> m_swapchain_images;
   std::vector<VkImageView> m_swapchain_image_views;
   std::vector<VkFramebuffer> m_swapchain_framebuffers;
+  VkCommandBuffer m_compute_command_buffer;
   std::vector<VkCommandBuffer> m_command_buffers;
   VkRenderPass m_render_pass;
   VkExtent2D m_render_extent;
@@ -200,6 +202,8 @@ class GHOST_ContextVK : public GHOST_Context {
   GHOST_TSuccess pickPhysicalDevice(std::vector<const char *> required_exts);
   GHOST_TSuccess createSwapchain();
   GHOST_TSuccess destroySwapchain();
-  GHOST_TSuccess createCommandBuffers();
+  GHOST_TSuccess createCommandPools();
+  GHOST_TSuccess createGraphicsCommandBuffers();
+  GHOST_TSuccess createComputeCommandBuffer();
   GHOST_TSuccess recordCommandBuffers();
 };
diff --git a/source/blender/gpu/vulkan/vk_context.cc b/source/blender/gpu/vulkan/vk_context.cc
index a8142bc71bc..bafd8547170 100644
--- a/source/blender/gpu/vulkan/vk_context.cc
+++ b/source/blender/gpu/vulkan/vk_context.cc
@@ -24,13 +24,14 @@ VKContext::VKContext(void *ghost_window, void *ghost_context)
                          &instance_,
                          &physical_device_,
                          &device_,
+                         &compute_command_buffer_,
                          &graphic_queue_family_);
 
   /* Initialize the memory allocator. */
   VmaAllocatorCreateInfo info = {};
   /* Should use same vulkan version as GHOST, but set to 1.0 for now. Raising it to 1.2 requires
-   * correct extensions and functions to be found, which doesn't out-of-the-box. We should fix this,
-   * but to continue the development at hand we lower the API to 1.0.*/
+   * correct extensions and functions to be found, which doesn't out-of-the-box. We should fix
+   * this, but to continue the development at hand we lower the API to 1.0.*/
   info.vulkanApiVersion = VK_API_VERSION_1_0;
   info.physicalDevice = physical_device_;
   info.device = device_;
diff --git a/source/blender/gpu/vulkan/vk_context.hh b/source/blender/gpu/vulkan/vk_context.hh
index c9370d41d0a..fca9082f9fd 100644
--- a/source/blender/gpu/vulkan/vk_context.hh
+++ b/source/blender/gpu/vulkan/vk_context.hh
@@ -27,6 +27,7 @@ class VKContext : public Context {
   VkInstance instance_ = VK_NULL_HANDLE;
   VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
   VkDevice device_ = VK_NULL_HANDLE;
+  VkCommandBuffer compute_command_buffer_ = VK_NULL_HANDLE;
   uint32_t graphic_queue_family_ = 0;
 
   /** Allocator used for texture and buffers and other resources. */
@@ -59,6 +60,11 @@ class VKContext : public Context {
   {
     return device_;
   }
+  
+  VkCommandBuffer compute_command_buffer_get() const
+  {
+    return compute_command_buffer_;
+  }
 
   const uint32_t *queue_family_ptr_get() const
   {
diff --git a/source/blender/gpu/vulkan/vk_shader.cc b/source/blender/gpu/vulkan/vk_shader.cc
index 8297041ea08..6a244861a76 100644
--- a/source/blender/gpu/vulkan/vk_shader.cc
+++ b/source/blender/gpu/vulkan/vk_shader.cc
@@ -605,8 +605,8 @@ VKShader::~VKShader()
   for (VkDescriptorSetLayout &l

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list