Changeset 9c0a614 in opengl-game for vulkan-game.cpp
- Timestamp:
- Feb 14, 2021, 2:15:18 AM (4 years ago)
- Branches:
- feature/imgui-sdl
- Children:
- 4e2c709
- Parents:
- 9067efc
- git-author:
- Dmitry Portnoy <dportnoy@…> (02/14/21 02:06:31)
- git-committer:
- Dmitry Portnoy <dportnoy@…> (02/14/21 02:15:18)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
vulkan-game.cpp
r9067efc r9c0a614 219 219 createRenderPass(); 220 220 createResourceCommandPool(); 221 createCommandPool ();221 createCommandPools(); 222 222 223 223 createImageResources(); … … 1229 1229 1230 1230 vkDestroyCommandPool(device, resourceCommandPool, nullptr); 1231 vkDestroyCommandPool(device, commandPool, nullptr);1232 1231 1233 1232 vkDestroyDevice(device, nullptr); … … 1632 1631 } 1633 1632 1634 void VulkanGame::createCommandPool() { 1635 QueueFamilyIndices queueFamilyIndices = VulkanUtils::findQueueFamilies(physicalDevice, surface); 1636 1637 VkCommandPoolCreateInfo poolInfo = {}; 1638 poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; 1639 poolInfo.queueFamilyIndex = queueFamilyIndices.graphicsFamily.value(); 1640 poolInfo.flags = 0; 1641 1642 if (vkCreateCommandPool(device, &poolInfo, nullptr, &commandPool) != VK_SUCCESS) { 1643 throw runtime_error("failed to create graphics command pool!"); 1633 void VulkanGame::createCommandPools() { 1634 commandPools.resize(swapChainImageCount); 1635 1636 QueueFamilyIndices indices = VulkanUtils::findQueueFamilies(physicalDevice, surface); 1637 1638 for (size_t i = 0; i < swapChainImageCount; i++) { 1639 VkCommandPoolCreateInfo poolInfo = {}; 1640 poolInfo.sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO; 1641 poolInfo.queueFamilyIndex = indices.graphicsFamily.value(); 1642 poolInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; 1643 1644 VKUTIL_CHECK_RESULT(vkCreateCommandPool(device, &poolInfo, nullptr, &commandPools[i]), 1645 "failed to create graphics command pool!"); 1644 1646 } 1645 1647 } … … 1731 1733 commandBuffers.resize(swapChainImageCount); 1732 1734 1733 VkCommandBufferAllocateInfo allocInfo = {}; 1734 allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; 1735 allocInfo.commandPool = commandPool; 1736 allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; 1737 allocInfo.commandBufferCount = (uint32_t) commandBuffers.size(); 1738 1739 if (vkAllocateCommandBuffers(device, &allocInfo, commandBuffers.data()) != VK_SUCCESS) { 1740 throw runtime_error("failed to allocate command buffers!"); 1735 for (size_t i = 0; i < swapChainImageCount; i++) { 1736 VkCommandBufferAllocateInfo allocInfo = {}; 1737 allocInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; 1738 allocInfo.commandPool = commandPools[i]; 1739 allocInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; 1740 allocInfo.commandBufferCount = 1; 1741 1742 if (vkAllocateCommandBuffers(device, &allocInfo, &commandBuffers[i]) != VK_SUCCESS) { 1743 throw runtime_error("failed to allocate command buffer!"); 1744 } 1741 1745 } 1742 1746 … … 2140 2144 createRenderPass(); 2141 2145 2146 createCommandPools(); 2147 2148 // The depth buffer does need to be recreated with the swap chain since its dimensions depend on the window size 2149 // and resizing the window is a common reason to recreate the swapchain 2142 2150 VulkanUtils::createDepthImage(device, physicalDevice, resourceCommandPool, findDepthFormat(), swapChainExtent, 2143 2151 depthImage, graphicsQueue); … … 2205 2213 } 2206 2214 2207 vkFreeCommandBuffers(device, commandPool, static_cast<uint32_t>(commandBuffers.size()), commandBuffers.data()); 2215 for (uint32_t i = 0; i < swapChainImageCount; i++) { 2216 vkFreeCommandBuffers(device, commandPools[i], 1, &commandBuffers[i]); 2217 vkDestroyCommandPool(device, commandPools[i], nullptr); 2218 } 2208 2219 2209 2220 overlayPipeline.cleanup();
Note:
See TracChangeset
for help on using the changeset viewer.