/* SPDX-License-Identifier: GPL-2.0-or-later * Copyright 2023 Blender Foundation */ /** \file * \ingroup gpu */ #include "vk_device.hh" #include "vk_backend.hh" #include "vk_memory.hh" #include "GHOST_C-api.h" namespace blender::gpu { void VKDevice::deinit() { vmaDestroyAllocator(mem_allocator_); mem_allocator_ = VK_NULL_HANDLE; debugging_tools_.deinit(); vk_instance_ = VK_NULL_HANDLE; vk_physical_device_ = VK_NULL_HANDLE; vk_device_ = VK_NULL_HANDLE; vk_queue_family_ = 0; vk_queue_ = VK_NULL_HANDLE; vk_physical_device_limits_ = {}; } bool VKDevice::is_initialized() const { return vk_device_ != VK_NULL_HANDLE; } void VKDevice::init(void *ghost_context) { BLI_assert(!is_initialized()); GHOST_GetVulkanHandles((GHOST_ContextHandle)ghost_context, &vk_instance_, &vk_physical_device_, &vk_device_, &vk_queue_family_, &vk_queue_); init_physical_device_limits(); init_capabilities(); init_debug_callbacks(); init_memory_allocator(); init_descriptor_pools(); debug::object_label(device_get(), "LogicalDevice"); debug::object_label(queue_get(), "GenericQueue"); } void VKDevice::init_debug_callbacks() { debugging_tools_.init(vk_instance_); } void VKDevice::init_physical_device_limits() { BLI_assert(vk_physical_device_ != VK_NULL_HANDLE); VkPhysicalDeviceProperties properties = {}; vkGetPhysicalDeviceProperties(vk_physical_device_, &properties); vk_physical_device_limits_ = properties.limits; } void VKDevice::init_capabilities() { VKBackend::capabilities_init(); } void VKDevice::init_memory_allocator() { VK_ALLOCATION_CALLBACKS; VmaAllocatorCreateInfo info = {}; info.vulkanApiVersion = VK_API_VERSION_1_2; info.physicalDevice = vk_physical_device_; info.device = vk_device_; info.instance = vk_instance_; info.pAllocationCallbacks = vk_allocation_callbacks; vmaCreateAllocator(&info, &mem_allocator_); } void VKDevice::init_descriptor_pools() { descriptor_pools_.init(vk_device_); } } // namespace blender::gpu