Bläddra i källkod

Add command pool

Kajetan Johannes Hammerle 3 månader sedan
förälder
incheckning
b8d4bd5856
2 ändrade filer med 14 tillägg och 10 borttagningar
  1. 0 7
      src/VulkanUtils.c
  2. 14 3
      src/VulkanWrapper.c

+ 0 - 7
src/VulkanUtils.c

@@ -483,11 +483,6 @@ void destroyVulkanFramebuffers(VkFramebuffer** f, u32 amount, VkDevice d) {
 }
 
 /*static bool initCommandBuffers() {
-    VkCommandPoolCreateInfo info = {
-        .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
-        .queueFamilyIndex = vk.device.graphicsFamily};
-    VK_ASSERT(vkCreateCommandPool(
-        vk.device.logical, &info, nullptr, &vk.swapchain.commandPool));
     vk.swapchain.commandsBuffers =
         coreAllocate(sizeof(VkCommandBuffer) * vk.swapchain.amount);
     VkCommandBufferAllocateInfo a = {
@@ -506,8 +501,6 @@ static void destroyCommandBuffers() {
 vk.swapchain.amount, vk.swapchain.commandsBuffers);
     }
     coreFree(vk.swapchain.commandsBuffers);
-    vkDestroyCommandPool(vk.device.logical, vk.swapchain.commandPool,
-nullptr);
 }
 
 static bool fillCommandBuffer(u32 index) {

+ 14 - 3
src/VulkanWrapper.c

@@ -6,7 +6,6 @@
 #include "GLFW.h"
 #include "VulkanUtils.h"
 
-// VkCommandPool commandPool;
 // VkCommandBuffer* commandsBuffers;
 // VkSemaphore semaphore;
 // VkSemaphore renderSemaphore;
@@ -28,6 +27,7 @@ static VkPipelineLayout pipelineLayout;
 static VkRenderPass renderPass;
 static VkPipeline pipeline;
 static VkFramebuffer* framebuffers;
+static VkCommandPool commandPool;
 
 static int getSurfaceFormatPoints(const VkSurfaceFormatKHR* sf) {
     if(sf->format == VK_FORMAT_B8G8R8A8_UNORM &&
@@ -343,6 +343,15 @@ static bool initRenderPass() {
     return false;
 }
 
+static bool initCommandPool() {
+    VkCommandPoolCreateInfo info = {
+        .sType = VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO,
+        .flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT,
+        .queueFamilyIndex = graphicsFamily};
+    VK_ASSERT(vkCreateCommandPool(device, &info, nullptr, &commandPool));
+    return false;
+}
+
 bool initVulkan() {
     return initVulkanInstance() || initVulkanDebugging() ||
            initVulkanSurface(&surface, getWindow()) || initPhysicalDevice() ||
@@ -351,9 +360,10 @@ bool initVulkan() {
            initRenderPass() || initPipeline() ||
            initVulkanFramebuffers(
                &framebuffers, &images, device, renderPass, swapchainSize.width,
-               swapchainSize.height);
+               swapchainSize.height) ||
+           initCommandPool();
     /*  || initSemaphore(&vk.semaphore) ||
-       initSemaphore(&vk.renderSemaphore) || initCommandBuffers() ||
+       initSemaphore(&vk.renderSemaphore)
      */
 }
 
@@ -365,6 +375,7 @@ void destroyVulkan(void) {
         //     destroyCommandBuffers();
         //     destroySemaphore(vk.semaphore);
         //     destroySemaphore(vk.renderSemaphore);
+        vkDestroyCommandPool(device, commandPool, nullptr);
         destroyVulkanFramebuffers(&framebuffers, images.amount, device);
         vkDestroyPipeline(device, pipeline, nullptr);
         vkDestroyRenderPass(device, renderPass, nullptr);