[Bf-blender-cvs] [0bc4eb987c4] temp-vulkan-shader: GPU: add vulkan memory allocator to VKContext.
Jeroen Bakker
noreply at git.blender.org
Tue Nov 22 17:01:39 CET 2022
Commit: 0bc4eb987c4e27eb6c30b52386f99953cd1abade
Author: Jeroen Bakker
Date: Tue Nov 22 13:06:52 2022 +0100
Branches: temp-vulkan-shader
https://developer.blender.org/rB0bc4eb987c4e27eb6c30b52386f99953cd1abade
GPU: add vulkan memory allocator to VKContext.
===================================================================
M source/blender/gpu/CMakeLists.txt
M source/blender/gpu/vulkan/vk_backend.cc
M source/blender/gpu/vulkan/vk_context.cc
M source/blender/gpu/vulkan/vk_context.hh
===================================================================
diff --git a/source/blender/gpu/CMakeLists.txt b/source/blender/gpu/CMakeLists.txt
index 67c8cbc1185..abc8640af36 100644
--- a/source/blender/gpu/CMakeLists.txt
+++ b/source/blender/gpu/CMakeLists.txt
@@ -268,6 +268,15 @@ endif()
if(WITH_VULKAN_BACKEND)
list(APPEND SRC ${VULKAN_SRC})
+ list(APPEND INC_SYS
+ ${VULKAN_INCLUDE_DIRS}
+ ${MOLTENVK_INCLUDE_DIRS}
+ )
+
+ list(APPEND INC
+ ../../../extern/vulkan_memory_allocator/
+ )
+
add_definitions(-DWITH_VULKAN_BACKEND)
endif()
@@ -279,7 +288,7 @@ set(LIB
${Epoxy_LIBRARIES}
)
-if(WITH_VULKAN)
+if(WITH_VULKAN_BACKEND)
list(APPEND LIB
extern_vulkan_memory_allocator
)
diff --git a/source/blender/gpu/vulkan/vk_backend.cc b/source/blender/gpu/vulkan/vk_backend.cc
index d22275cebef..7e8d08f9ca9 100644
--- a/source/blender/gpu/vulkan/vk_backend.cc
+++ b/source/blender/gpu/vulkan/vk_backend.cc
@@ -65,9 +65,9 @@ void VKBackend::compute_dispatch_indirect(StorageBuf * /*indirect_buf*/)
{
}
-Context *VKBackend::context_alloc(void * /*ghost_window*/, void * /*ghost_context*/)
+Context *VKBackend::context_alloc(void *ghost_window, void *ghost_context)
{
- return new VKContext();
+ return new VKContext(ghost_window, ghost_context);
}
Batch *VKBackend::batch_alloc()
diff --git a/source/blender/gpu/vulkan/vk_context.cc b/source/blender/gpu/vulkan/vk_context.cc
index 55b29ea4e2f..349d78d94db 100644
--- a/source/blender/gpu/vulkan/vk_context.cc
+++ b/source/blender/gpu/vulkan/vk_context.cc
@@ -7,8 +7,34 @@
#include "vk_context.hh"
+#include "GHOST_C-api.h"
+
namespace blender::gpu {
+VKContext::VKContext(void *ghost_window, void *ghost_context)
+{
+ ghost_window_ = ghost_window;
+ if (ghost_window) {
+ ghost_context = GHOST_GetDrawingContext((GHOST_WindowHandle)ghost_window);
+ }
+
+ GHOST_GetVulkanHandles((GHOST_ContextHandle)ghost_context,
+ &instance_,
+ &physical_device_,
+ &device_,
+ &graphic_queue_familly_);
+
+ {
+ VmaAllocatorCreateInfo info = {};
+ /* TODO use same vulkan version as GHOST. */
+ info.vulkanApiVersion = VK_API_VERSION_1_1;
+ info.physicalDevice = physical_device_;
+ info.device = device_;
+ info.instance = instance_;
+ vmaCreateAllocator(&info, &mem_allocator_);
+ }
+}
+
void VKContext::activate()
{
}
diff --git a/source/blender/gpu/vulkan/vk_context.hh b/source/blender/gpu/vulkan/vk_context.hh
index 17292b891b6..05f4bba18cb 100644
--- a/source/blender/gpu/vulkan/vk_context.hh
+++ b/source/blender/gpu/vulkan/vk_context.hh
@@ -9,13 +9,29 @@
#include "gpu_context_private.hh"
+#include "vk_mem_alloc.h"
+
+#ifdef __APPLE__
+# include <MoltenVK/vk_mvk_moltenvk.h>
+#else
+# include <vulkan/vulkan.h>
+#endif
+
namespace blender::gpu {
class VKContext : public Context {
+ private:
+ /** Copies of the handles owned by the GHOST context. */
+ VkInstance instance_ = VK_NULL_HANDLE;
+ VkPhysicalDevice physical_device_ = VK_NULL_HANDLE;
+ VkDevice device_ = VK_NULL_HANDLE;
+ uint32_t graphic_queue_familly_ = 0;
+
+ /** Allocator used for texture and buffers. */
+ VmaAllocator mem_allocator_ = VK_NULL_HANDLE;
+
public:
- VKContext()
- {
- }
+ VKContext(void *ghost_window, void *ghost_context);
void activate() override;
void deactivate() override;
More information about the Bf-blender-cvs
mailing list