[Bf-blender-cvs] [0e6f2d9fe0f] master: GPU: Add placeholder for Vulkan backend.

Jeroen Bakker noreply at git.blender.org
Mon Oct 31 16:01:24 CET 2022


Commit: 0e6f2d9fe0f49de658414bf16a9babab61f1895a
Author: Jeroen Bakker
Date:   Mon Oct 31 16:01:02 2022 +0100
Branches: master
https://developer.blender.org/rB0e6f2d9fe0f49de658414bf16a9babab61f1895a

GPU: Add placeholder for Vulkan backend.

This patch adds a placeholder for the vulkan backend.
When activated (`WITH_VULKAN_BACKEND=On` and `--gpu-backend vulkan`)
it might open a blender screen, but nothing should be visible as
none of the functions are implemented or otherwise crash on a nullptr.

This is expected as this is just a placeholder. The goal is to add shader compilation
+validation to this backend as one of the next steps so we can validate
changes to existing shaders on OpenGL, Metal and Vulkan at the same time.

Reviewed By: fclem

Differential Revision: https://developer.blender.org/D16338

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

M	CMakeLists.txt
M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_platform.h
M	source/blender/gpu/intern/gpu_context.cc
A	source/blender/gpu/vulkan/vk_backend.cc
A	source/blender/gpu/vulkan/vk_backend.hh
A	source/blender/gpu/vulkan/vk_batch.cc
A	source/blender/gpu/vulkan/vk_batch.hh
A	source/blender/gpu/vulkan/vk_context.cc
A	source/blender/gpu/vulkan/vk_context.hh
A	source/blender/gpu/vulkan/vk_drawlist.cc
A	source/blender/gpu/vulkan/vk_drawlist.hh
A	source/blender/gpu/vulkan/vk_framebuffer.cc
A	source/blender/gpu/vulkan/vk_framebuffer.hh
A	source/blender/gpu/vulkan/vk_index_buffer.cc
A	source/blender/gpu/vulkan/vk_index_buffer.hh
A	source/blender/gpu/vulkan/vk_query.cc
A	source/blender/gpu/vulkan/vk_query.hh
A	source/blender/gpu/vulkan/vk_shader.cc
A	source/blender/gpu/vulkan/vk_shader.hh
A	source/blender/gpu/vulkan/vk_storage_buffer.cc
A	source/blender/gpu/vulkan/vk_storage_buffer.hh
A	source/blender/gpu/vulkan/vk_texture.cc
A	source/blender/gpu/vulkan/vk_texture.hh
A	source/blender/gpu/vulkan/vk_uniform_buffer.cc
A	source/blender/gpu/vulkan/vk_uniform_buffer.hh
A	source/blender/gpu/vulkan/vk_vertex_buffer.cc
A	source/blender/gpu/vulkan/vk_vertex_buffer.hh
M	source/blender/python/gpu/gpu_py_platform.c
M	source/blender/windowmanager/intern/wm_window.c
M	source/creator/creator_args.c

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

diff --git a/CMakeLists.txt b/CMakeLists.txt
index 3c5fa8a63f6..7e89943714a 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -569,6 +569,12 @@ mark_as_advanced(
   WITH_GPU_BUILDTIME_SHADER_BUILDER
 )
 
+# Vulkan
+option(WITH_VULKAN_BACKEND "Enable Vulkan as graphics backend (only for development)" OFF)
+mark_as_advanced(
+  WITH_VULKAN_BACKEND
+)
+
 # Metal
 
 if(APPLE)
@@ -1222,6 +1228,13 @@ if(WITH_OPENGL)
 endif()
 
 
+# -----------------------------------------------------------------------------
+# Configure Vulkan.
+
+if(WITH_VULKAN_BACKEND)
+  add_definitions(-DWITH_VULKAN_BACKEND)
+endif()
+
 # -----------------------------------------------------------------------------
 # Configure Metal
 
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 58b1cd0a50b..bfbbf1be225 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -12,6 +12,7 @@ endif()
 set(INC
   .
   intern
+  vulkan
   metal
   opengl
   ../blenkernel
@@ -184,6 +185,34 @@ set(OPENGL_SRC
   opengl/gl_vertex_buffer.hh
 )
 
+set(VULKAN_SRC
+  vulkan/vk_backend.cc
+  vulkan/vk_batch.cc
+  vulkan/vk_context.cc
+  vulkan/vk_drawlist.cc
+  vulkan/vk_framebuffer.cc
+  vulkan/vk_index_buffer.cc
+  vulkan/vk_query.cc
+  vulkan/vk_shader.cc
+  vulkan/vk_storage_buffer.cc
+  vulkan/vk_texture.cc
+  vulkan/vk_uniform_buffer.cc
+  vulkan/vk_vertex_buffer.cc
+
+  vulkan/vk_backend.hh
+  vulkan/vk_batch.hh
+  vulkan/vk_context.hh
+  vulkan/vk_drawlist.hh
+  vulkan/vk_framebuffer.hh
+  vulkan/vk_index_buffer.hh
+  vulkan/vk_query.hh
+  vulkan/vk_shader.hh
+  vulkan/vk_storage_buffer.hh
+  vulkan/vk_texture.hh
+  vulkan/vk_uniform_buffer.hh
+  vulkan/vk_vertex_buffer.hh
+)
+
 set(METAL_SRC
   metal/mtl_backend.mm
   metal/mtl_batch.mm
@@ -235,6 +264,10 @@ if(WITH_OPENGL)
   list(APPEND SRC ${OPENGL_SRC})
 endif()
 
+if(WITH_VULKAN_BACKEND)
+  list(APPEND SRC ${VULKAN_SRC})
+endif()
+
 if(WITH_METAL_BACKEND)
   list(APPEND SRC ${METAL_SRC})
 endif()
diff --git a/source/blender/gpu/GPU_platform.h b/source/blender/gpu/GPU_platform.h
index b63fe4c0580..657b45df1a5 100644
--- a/source/blender/gpu/GPU_platform.h
+++ b/source/blender/gpu/GPU_platform.h
@@ -16,6 +16,7 @@ typedef enum eGPUBackendType {
   GPU_BACKEND_NONE = 0,
   GPU_BACKEND_OPENGL = 1 << 0,
   GPU_BACKEND_METAL = 1 << 1,
+  GPU_BACKEND_VULKAN = 1 << 3,
   GPU_BACKEND_ANY = 0xFFFFFFFFu
 } eGPUBackendType;
 
diff --git a/source/blender/gpu/intern/gpu_context.cc b/source/blender/gpu/intern/gpu_context.cc
index f6b88c4231c..7e94538892a 100644
--- a/source/blender/gpu/intern/gpu_context.cc
+++ b/source/blender/gpu/intern/gpu_context.cc
@@ -33,6 +33,9 @@
 #  include "gl_backend.hh"
 #  include "gl_context.hh"
 #endif
+#ifdef WITH_VULKAN_BACKEND
+#  include "vk_backend.hh"
+#endif
 #ifdef WITH_METAL_BACKEND
 #  include "mtl_backend.hh"
 #endif
@@ -244,6 +247,12 @@ bool GPU_backend_supported(void)
       return true;
 #else
       return false;
+#endif
+    case GPU_BACKEND_VULKAN:
+#ifdef WITH_VULKAN_BACKEND
+      return true;
+#else
+      return false;
 #endif
     case GPU_BACKEND_METAL:
 #ifdef WITH_METAL_BACKEND
@@ -268,6 +277,11 @@ static void gpu_backend_create()
       g_backend = new GLBackend;
       break;
 #endif
+#ifdef WITH_VULKAN_BACKEND
+    case GPU_BACKEND_VULKAN:
+      g_backend = new VKBackend;
+      break;
+#endif
 #ifdef WITH_METAL_BACKEND
     case GPU_BACKEND_METAL:
       g_backend = new MTLBackend;
diff --git a/source/blender/gpu/vulkan/vk_backend.cc b/source/blender/gpu/vulkan/vk_backend.cc
new file mode 100644
index 00000000000..00bc43333d6
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_backend.cc
@@ -0,0 +1,107 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#include "vk_backend.hh"
+
+#include "vk_batch.hh"
+#include "vk_context.hh"
+#include "vk_drawlist.hh"
+#include "vk_framebuffer.hh"
+#include "vk_index_buffer.hh"
+#include "vk_query.hh"
+#include "vk_shader.hh"
+#include "vk_storage_buffer.hh"
+#include "vk_texture.hh"
+#include "vk_uniform_buffer.hh"
+#include "vk_vertex_buffer.hh"
+
+namespace blender::gpu {
+
+void VKBackend::delete_resources()
+{
+}
+
+void VKBackend::samplers_update()
+{
+}
+
+void VKBackend::compute_dispatch(int /*groups_x_len*/, int /*groups_y_len*/, int /*groups_z_len*/)
+{
+}
+
+void VKBackend::compute_dispatch_indirect(StorageBuf * /*indirect_buf*/)
+{
+}
+
+Context *VKBackend::context_alloc(void * /*ghost_window*/, void * /*ghost_context*/)
+{
+  return new VKContext();
+}
+
+Batch *VKBackend::batch_alloc()
+{
+  return new VKBatch();
+}
+
+DrawList *VKBackend::drawlist_alloc(int /*list_length*/)
+{
+  return new VKDrawList();
+}
+
+FrameBuffer *VKBackend::framebuffer_alloc(const char *name)
+{
+  return new VKFrameBuffer(name);
+}
+
+IndexBuf *VKBackend::indexbuf_alloc()
+{
+  return new VKIndexBuffer();
+}
+
+QueryPool *VKBackend::querypool_alloc()
+{
+  return new VKQueryPool();
+}
+
+Shader *VKBackend::shader_alloc(const char *name)
+{
+  return new VKShader(name);
+}
+
+Texture *VKBackend::texture_alloc(const char *name)
+{
+  return new VKTexture(name);
+}
+
+UniformBuf *VKBackend::uniformbuf_alloc(int size, const char *name)
+{
+  return new VKUniformBuffer(size, name);
+}
+
+StorageBuf *VKBackend::storagebuf_alloc(int size, GPUUsageType /*usage*/, const char *name)
+{
+  return new VKStorageBuffer(size, name);
+}
+
+VertBuf *VKBackend::vertbuf_alloc()
+{
+  return new VKVertexBuffer();
+}
+
+void VKBackend::render_begin()
+{
+}
+
+void VKBackend::render_end()
+{
+}
+
+void VKBackend::render_step()
+{
+}
+
+}  // namespace blender::gpu
\ No newline at end of file
diff --git a/source/blender/gpu/vulkan/vk_backend.hh b/source/blender/gpu/vulkan/vk_backend.hh
new file mode 100644
index 00000000000..549478586e8
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_backend.hh
@@ -0,0 +1,42 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#pragma once
+
+#include "gpu_backend.hh"
+
+namespace blender::gpu {
+
+class VKBackend : public GPUBackend {
+ public:
+  void delete_resources() override;
+
+  void samplers_update() override;
+  void compute_dispatch(int groups_x_len, int groups_y_len, int groups_z_len) override;
+  void compute_dispatch_indirect(StorageBuf *indirect_buf) override;
+
+  Context *context_alloc(void *ghost_window, void *ghost_context) override;
+
+  Batch *batch_alloc() override;
+  DrawList *drawlist_alloc(int list_length) override;
+  FrameBuffer *framebuffer_alloc(const char *name) override;
+  IndexBuf *indexbuf_alloc() override;
+  QueryPool *querypool_alloc() override;
+  Shader *shader_alloc(const char *name) override;
+  Texture *texture_alloc(const char *name) override;
+  UniformBuf *uniformbuf_alloc(int size, const char *name) override;
+  StorageBuf *storagebuf_alloc(int size, GPUUsageType usage, const char *name) override;
+  VertBuf *vertbuf_alloc() override;
+
+  /* Render Frame Coordination --
+   * Used for performing per-frame actions globally */
+  void render_begin() override;
+  void render_end() override;
+  void render_step() override;
+};
+
+}  // namespace blender::gpu
\ No newline at end of file
diff --git a/source/blender/gpu/vulkan/vk_batch.cc b/source/blender/gpu/vulkan/vk_batch.cc
new file mode 100644
index 00000000000..a25f98a2e24
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_batch.cc
@@ -0,0 +1,27 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#include "vk_batch.hh"
+
+namespace blender::gpu {
+
+void VKBatch::draw(int /*v_first*/, int /*v_count*/, int /*i_first*/, int /*i_count*/)
+{
+}
+
+void VKBatch::draw_indirect(GPUStorageBuf * /*indirect_buf*/, intptr_t /*offset*/)
+{
+}
+
+void VKBatch::multi_draw_indirect(GPUStorageBuf * /*indirect_buf*/,
+                                  int /*count*/,
+                                  intptr_t /*offset*/,
+                                  intptr_t /*stride*/)
+{
+}
+
+}  // namespace blender::gpu
\ No newline at end of file
diff --git a/source/blender/gpu/vulkan/vk_batch.hh b/source/blender/gpu/vulkan/vk_batch.hh
new file mode 100644
index 00000000000..0f6df41606d
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_batch.hh
@@ -0,0 +1,24 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#pragma once
+
+#include "gpu_batch_private.hh"
+
+namespace blender::gpu {
+
+class VKBatch : public Batch {
+ public:
+  void draw(int v_first, int v_count, int i_first, int i_count) override;
+  void draw_indirect(GPUStorageBuf *indirect_buf, intptr_t offset) override;
+  void multi_draw_indirect(GPUStorageBuf *indirect_buf,
+                           int count,
+                           intptr_t offset,
+                           intptr_t stride) override;
+};
+
+}  // namespace blender::gpu
\ No newline at end of file
diff --git a/source/blender/gpu/vulkan/vk_context.cc b/source/blender/gpu/vulkan/vk_context.cc
new file mode 100644
index 00000000000..55b29ea4e2f
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_context.cc
@@ -0,0 +1,48 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later
+ * Copyright 2022 Blender Foundation. All rights reserved. */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#include "vk_context.hh"
+
+namespace blender::gpu {
+
+void VKContext::activate()
+{
+}
+
+void VKContext::deactivate()
+{
+}
+
+void VKContext::begin_frame()
+{
+}
+
+void VKContext::end_frame()
+{
+}
+
+void VKContext::flush()
+{
+}
+
+void VKContext::finish()
+{
+}
+
+void VKContext::memory_statistics_get(int * /*total_mem*/, int * /*free_mem*/)
+{
+}
+
+void VKContext::debug_group_begin(const char *, int)
+{
+}
+
+void VKContext::debug_group_end()
+{
+}
+
+}  // namespace blender::gpu
\ No newline at end of file
diff --git a/source/blender/gpu/vulkan/vk_context.hh b/source/blender/gpu/vulkan/vk_context.hh
new file mode 100644
index 00000000000..17292b891b6
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_context.hh
@@ -0,0 +1,34 @@
+

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list