[Fix] (MG_Backend/DirectVulkan): create command pool and command buffer

This commit is contained in:
2026-02-14 10:21:25 +08:00
parent 0ce95894a3
commit 5f94f72be5
2 changed files with 29 additions and 0 deletions
@@ -61,10 +61,16 @@ namespace MobileGL::MG_Backend::DirectVulkan {
CreateLogicalDeviceAndQueues(); CreateLogicalDeviceAndQueues();
CreateSwapchain(); CreateSwapchain();
CreateSwapchainImageViews(); CreateSwapchainImageViews();
CreateCommandPool();
MGLOG_D("VulkanRenderer initialized"); MGLOG_D("VulkanRenderer initialized");
} }
void VulkanRenderer::Shutdown() { void VulkanRenderer::Shutdown() {
if (m_commandPool != VK_NULL_HANDLE) {
vkDestroyCommandPool(m_device, m_commandPool, nullptr);
m_commandPool = VK_NULL_HANDLE;
}
for (auto imageView : m_swapChainImageViews) { for (auto imageView : m_swapChainImageViews) {
vkDestroyImageView(m_device, imageView, nullptr); vkDestroyImageView(m_device, imageView, nullptr);
} }
@@ -836,6 +842,24 @@ namespace MobileGL::MG_Backend::DirectVulkan {
MGLOG_I("Swapchain image views created"); MGLOG_I("Swapchain image views created");
} }
void VulkanRenderer::CreateCommandPool() {
VkCommandPoolCreateInfo createInfo{VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO};
createInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT;
createInfo.queueFamilyIndex = m_physicalDevice.queueFamilies.graphicsFamily;
VK_VERIFY(vkCreateCommandPool(m_device, &createInfo, nullptr, &m_commandPool));
MGLOG_I("Command pool created");
}
void VulkanRenderer::CreateCommandBuffer() {
VkCommandBufferAllocateInfo allocInfo{};
allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocInfo.commandPool = m_commandPool;
allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocInfo.commandBufferCount = 1;
VK_VERIFY(vkAllocateCommandBuffers(m_device, &allocInfo, &m_commandBuffer));
MGLOG_I("Command buffer created");
}
void VulkanRenderer::CreateSurface() { void VulkanRenderer::CreateSurface() {
#if defined VK_USE_PLATFORM_ANDROID_KHR #if defined VK_USE_PLATFORM_ANDROID_KHR
auto* nativeWindow = static_cast<ANativeWindow*>(m_window); auto* nativeWindow = static_cast<ANativeWindow*>(m_window);
@@ -93,6 +93,9 @@ namespace MobileGL::MG_Backend::DirectVulkan {
VkQueue m_graphicsQueue = VK_NULL_HANDLE; VkQueue m_graphicsQueue = VK_NULL_HANDLE;
VkQueue m_presentQueue = VK_NULL_HANDLE; VkQueue m_presentQueue = VK_NULL_HANDLE;
VkCommandPool m_commandPool = VK_NULL_HANDLE;
VkCommandBuffer m_commandBuffer = VK_NULL_HANDLE;
void CreateInstance(); void CreateInstance();
VkResult SetupDebugMessenger(); VkResult SetupDebugMessenger();
VkResult DestroyDebugMessenger(); VkResult DestroyDebugMessenger();
@@ -102,6 +105,8 @@ namespace MobileGL::MG_Backend::DirectVulkan {
void CreateLogicalDeviceAndQueues(); void CreateLogicalDeviceAndQueues();
void CreateSwapchain(); void CreateSwapchain();
void CreateSwapchainImageViews(); void CreateSwapchainImageViews();
void CreateCommandPool();
void CreateCommandBuffer();
static Int GetPresentQueueFamilyIndex( static Int GetPresentQueueFamilyIndex(
const PhysicalDevice& physicalDevice, VkSurfaceKHR surface, const PhysicalDevice& physicalDevice, VkSurfaceKHR surface,