[Bf-blender-cvs] [99fc68bf6ae] tmp-vulkan: GPU: Add Vulkan empty implementation

Clément Foucault noreply at git.blender.org
Sun Sep 13 00:44:36 CEST 2020


Commit: 99fc68bf6ae88e19274adec6775adafb3e644081
Author: Clément Foucault
Date:   Sun Sep 13 00:44:15 2020 +0200
Branches: tmp-vulkan
https://developer.blender.org/rB99fc68bf6ae88e19274adec6775adafb3e644081

GPU: Add Vulkan empty implementation

This does not even builds! WHY?

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

M	source/blender/gpu/CMakeLists.txt
M	source/blender/gpu/GPU_context.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.hh
A	source/blender/gpu/vulkan/vk_context.hh
A	source/blender/gpu/vulkan/vk_drawlist.hh
A	source/blender/gpu/vulkan/vk_framebuffer.hh
A	source/blender/gpu/vulkan/vk_immediate.hh
A	source/blender/gpu/vulkan/vk_index_buffer.hh
A	source/blender/gpu/vulkan/vk_primitive.hh
A	source/blender/gpu/vulkan/vk_query.hh
A	source/blender/gpu/vulkan/vk_shader.hh
A	source/blender/gpu/vulkan/vk_shader_interface.hh
A	source/blender/gpu/vulkan/vk_state.hh
A	source/blender/gpu/vulkan/vk_texture.hh
A	source/blender/gpu/vulkan/vk_uniform_buffer.hh
A	source/blender/gpu/vulkan/vk_vertex_buffer.hh

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

diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index b7ffa59538a..2638178fc96 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -30,6 +30,7 @@ set(INC
   .
   intern
   opengl
+  vulkan
   ../blenkernel
   ../blenlib
   ../bmesh
@@ -175,6 +176,28 @@ set(SRC
   opengl/gl_vertex_buffer.hh
 )
 
+if(WITH_VULKAN)
+  list(APPEND SRC
+    vulkan/vk_backend.cc
+
+    vulkan/vk_backend.hh
+    vulkan/vk_batch.hh
+    vulkan/vk_context.hh
+    vulkan/vk_drawlist.hh
+    vulkan/vk_framebuffer.hh
+    vulkan/vk_immediate.hh
+    vulkan/vk_index_buffer.hh
+    vulkan/vk_primitive.hh
+    vulkan/vk_query.hh
+    vulkan/vk_shader_interface.hh
+    vulkan/vk_shader.hh
+    vulkan/vk_state.hh
+    vulkan/vk_texture.hh
+    vulkan/vk_uniform_buffer.hh
+    vulkan/vk_vertex_buffer.hh
+  )
+endif()
+
 set(LIB
   ${BLENDER_GL_LIBRARIES}
 )
diff --git a/source/blender/gpu/GPU_context.h b/source/blender/gpu/GPU_context.h
index 82f13424502..29bb5c10a08 100644
--- a/source/blender/gpu/GPU_context.h
+++ b/source/blender/gpu/GPU_context.h
@@ -35,6 +35,9 @@ extern "C" {
 typedef enum eGPUBackendType {
   GPU_BACKEND_NONE = 0,
   GPU_BACKEND_OPENGL,
+#ifdef WITH_VULKAN
+  GPU_BACKEND_VULKAN,
+#endif
 } eGPUBackendType;
 
 void GPU_backend_init(eGPUBackendType backend);
diff --git a/source/blender/gpu/intern/gpu_context.cc b/source/blender/gpu/intern/gpu_context.cc
index 119c1ef9c55..0bc737b7fbe 100644
--- a/source/blender/gpu/intern/gpu_context.cc
+++ b/source/blender/gpu/intern/gpu_context.cc
@@ -34,6 +34,8 @@
 #include "BLI_assert.h"
 #include "BLI_utildefines.h"
 
+#include "BKE_global.h"
+
 #include "GPU_context.h"
 #include "GPU_framebuffer.h"
 
@@ -49,6 +51,11 @@
 #  include "gl_context.hh"
 #endif
 
+#ifdef WITH_VULKAN
+#  include "vk_backend.hh"
+#  include "vk_context.hh"
+#endif
+
 #include <mutex>
 #include <vector>
 
@@ -100,7 +107,13 @@ GPUContext *GPU_context_create(void *ghost_window)
 {
   if (GPUBackend::get() == NULL) {
     /* TODO move where it make sense. */
-    GPU_backend_init(GPU_BACKEND_OPENGL);
+    eGPUBackendType type = GPU_BACKEND_OPENGL;
+#ifdef WITH_VULKAN
+    if (G.debug & G_DEBUG_VK_CONTEXT) {
+      type = GPU_BACKEND_OPENGL;
+    }
+#endif
+    GPU_backend_init(type);
   }
 
   Context *ctx = GPUBackend::get()->context_alloc(ghost_window);
@@ -173,6 +186,11 @@ void GPU_backend_init(eGPUBackendType backend_type)
     case GPU_BACKEND_OPENGL:
       g_backend = new GLBackend;
       break;
+#endif
+#if WITH_VULKAN
+    case GPU_BACKEND_VULKAN:
+      g_backend = new VKBackend;
+      break;
 #endif
     default:
       BLI_assert(0);
diff --git a/source/blender/gpu/vulkan/vk_backend.cc b/source/blender/gpu/vulkan/vk_backend.cc
new file mode 100644
index 00000000000..bf8dabfd41c
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_backend.cc
@@ -0,0 +1,79 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2020, Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#include "BKE_global.h"
+
+#include "gpu_capabilities_private.hh"
+#include "gpu_platform_private.hh"
+
+#include "vk_backend.hh"
+#include "vk_framebuffer.hh"
+
+namespace blender::gpu {
+
+/* -------------------------------------------------------------------- */
+/** \name Platform
+ * \{ */
+
+void VKBackend::platform_init(void)
+{
+  BLI_assert(!GPG.initialized);
+  GPG.initialized = true;
+
+#ifdef _WIN32
+  GPG.os = GPU_OS_WIN;
+#elif defined(__APPLE__)
+  GPG.os = GPU_OS_MAC;
+#else
+  GPG.os = GPU_OS_UNIX;
+#endif
+}
+
+void VKBackend::platform_exit(void)
+{
+  BLI_assert(GPG.initialized);
+  GPG.clear();
+}
+
+/** \} */
+
+/* -------------------------------------------------------------------- */
+/** \name Capabilities
+ * \{ */
+
+void VKBackend::capabilities_init(void)
+{
+  /* Common Capabilities. */
+  GCaps.max_texture_size = 0;
+  GCaps.max_texture_layers = 0;
+  GCaps.max_textures_frag = 0;
+  GCaps.max_textures_vert = 0;
+  GCaps.max_textures_geom = 0;
+  GCaps.max_textures = 0;
+  GCaps.mem_stats_support = false;
+  GCaps.shader_image_load_store_support = false;
+}
+
+/** \} */
+
+}  // namespace blender::gpu
diff --git a/source/blender/gpu/vulkan/vk_backend.hh b/source/blender/gpu/vulkan/vk_backend.hh
new file mode 100644
index 00000000000..f58e24408ef
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_backend.hh
@@ -0,0 +1,121 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2020, Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup gpu
+ */
+
+#pragma once
+
+#include "gpu_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_texture.hh"
+#include "vk_uniform_buffer.hh"
+#include "vk_vertex_buffer.hh"
+
+namespace blender {
+namespace gpu {
+
+class VKBackend : public GPUBackend {
+ public:
+  VKBackend()
+  {
+    /* platform_init needs to go first. */
+    VKBackend::platform_init();
+
+    VKBackend::capabilities_init();
+  }
+  ~VKBackend()
+  {
+    VKBackend::platform_exit();
+  }
+
+  static VKBackend *get(void)
+  {
+    return nullptr;
+  };
+
+  void samplers_update(void) override{};
+
+  Context *context_alloc(void *ghost_window) override
+  {
+    return new VKContext(ghost_window);
+  };
+
+  Batch *batch_alloc(void) override
+  {
+    return new VKBatch();
+  };
+
+  DrawList *drawlist_alloc(int list_length) override
+  {
+    return new VKDrawList(list_length);
+  };
+
+  FrameBuffer *framebuffer_alloc(const char *name) override
+  {
+    return new VKFrameBuffer(name);
+  };
+
+  IndexBuf *indexbuf_alloc(void) override
+  {
+    return new VKIndexBuf();
+  };
+
+  QueryPool *querypool_alloc(void) override
+  {
+    return new VKQueryPool();
+  };
+
+  Shader *shader_alloc(const char *name) override
+  {
+    return new VKShader(name);
+  };
+
+  Texture *texture_alloc(const char *name) override
+  {
+    return new VKTexture(name);
+  };
+
+  UniformBuf *uniformbuf_alloc(int size, const char *name) override
+  {
+    return new VKUniformBuf(size, name);
+  };
+
+  VertBuf *vertbuf_alloc(void) override
+  {
+    return new VKVertBuf();
+  };
+
+ private:
+  static void platform_init(void);
+  static void platform_exit(void);
+
+  static void capabilities_init(void);
+};
+
+}  // namespace gpu
+}  // namespace blender
diff --git a/source/blender/gpu/vulkan/vk_batch.hh b/source/blender/gpu/vulkan/vk_batch.hh
new file mode 100644
index 00000000000..84be5a91b0b
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_batch.hh
@@ -0,0 +1,64 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+ * Copyright 2020, Blender Foundation.
+ * All rights reserved.
+ */
+
+/** \file
+ * \ingroup gpu
+ *
+ * GPU geometry batch
+ * Contains VAOs + VBOs + Shader representing a drawable entity.
+ */
+
+#pragma once
+
+#include "MEM_guardedalloc.h"
+
+#include "gpu_batch_private.hh"
+
+#include "vk_index_buffer.hh"
+#include "vk_vertex_buffer.hh"
+
+namespace blender {
+namespace gpu {
+
+class VKBatch : public Batch {
+ public:
+  VKBatch(){};
+  ~VKBatch(){};
+
+  void draw(int v_first, int v_count, int i_first, int i_count) override{};
+
+  /* Convenience getters. */
+  VKIndexBuf *elem_(void) const
+  {
+    return static_cast<VKIndexBuf *>(unwrap(elem));
+  }
+  VKVertBuf *verts_(const int index) const
+  {
+    return static_cast<VKVertBuf *>(unwrap(verts[index]));
+  }
+  VKVertBuf *inst_(const int index) const
+  {
+    return static_cast<VKVertBuf *>(unwrap(inst[index]));
+  }
+
+  MEM_CXX_CLASS_ALLOC_FUNCS("VKBatch");
+};
+
+}  // namespace gpu
+}  // namespace blender
diff --git a/source/blender/gpu/vulkan/vk_context.hh b/source/blender/gpu/vulkan/vk_context.hh
new file mode 100644
index 00000000000..e4664bf5e85
--- /dev/null
+++ b/source/blender/gpu/vulkan/vk_context.hh
@@ -0,0 +1,60 @@
+/*
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your

@@ Diff output truncated at 10240 characters. @@



More information about the Bf-blender-cvs mailing list