no frames in flight

main
Benjamin Kraft 2 weeks ago
parent 7c85f8efaa
commit 689de18da7
  1. 40
      src/vulkan/application.cpp
  2. 8
      src/vulkan/application.hpp
  3. 8
      src/vulkan/command_pool.cpp
  4. 2
      src/vulkan/command_pool.hpp

@ -106,38 +106,38 @@ void Application::recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t im
} }
void Application::drawFrame() { void Application::drawFrame() {
vkWaitForFences(Instance::instance->device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX); vkWaitForFences(Instance::instance->device, 1, &inFlightFence, VK_TRUE, UINT64_MAX);
uint32_t imageIndex; uint32_t imageIndex;
VkResult result = vkAcquireNextImageKHR(Instance::instance->device, swapchain->handle, UINT64_MAX, imageAvailableSemaphores[currentFrame], VK_NULL_HANDLE, &imageIndex); VkResult result = vkAcquireNextImageKHR(Instance::instance->device, swapchain->handle, UINT64_MAX, imageAvailableSemaphore, VK_NULL_HANDLE, &imageIndex);
if (result == VK_ERROR_OUT_OF_DATE_KHR){ if (result == VK_ERROR_OUT_OF_DATE_KHR){
swapchain->recreateSwapchain(); swapchain->recreateSwapchain();
return; return;
} }
vkResetFences(Instance::instance->device, 1, &inFlightFences[currentFrame]); vkResetFences(Instance::instance->device, 1, &inFlightFence);
vkResetCommandBuffer(commandPool->buffers[currentFrame], 0); vkResetCommandBuffer(commandPool->buffer, 0);
recordCommandBuffer(commandPool->buffers[currentFrame], imageIndex); recordCommandBuffer(commandPool->buffer, imageIndex);
updateUniformBuffer(); updateUniformBuffer();
VkSubmitInfo submitInfo {}; VkSubmitInfo submitInfo {};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO; submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
VkSemaphore waitSemaphores[] = {imageAvailableSemaphores[currentFrame]}; VkSemaphore waitSemaphores[] = {imageAvailableSemaphore};
VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT}; VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};
submitInfo.waitSemaphoreCount = 1; submitInfo.waitSemaphoreCount = 1;
submitInfo.pWaitSemaphores = waitSemaphores; submitInfo.pWaitSemaphores = waitSemaphores;
submitInfo.pWaitDstStageMask = waitStages; submitInfo.pWaitDstStageMask = waitStages;
submitInfo.commandBufferCount = 1; submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &commandPool->buffers[currentFrame]; submitInfo.pCommandBuffers = &commandPool->buffer;
VkSemaphore signalSemaphores[] = {renderFinishedSemaphores[currentFrame]}; VkSemaphore signalSemaphores[] = {renderFinishedSemaphore};
submitInfo.signalSemaphoreCount = 1; submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = signalSemaphores; submitInfo.pSignalSemaphores = signalSemaphores;
vkQueueSubmit(Instance::instance->graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]); vkQueueSubmit(Instance::instance->graphicsQueue, 1, &submitInfo, inFlightFence);
VkPresentInfoKHR presentInfo {}; VkPresentInfoKHR presentInfo {};
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR; presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
@ -154,15 +154,9 @@ void Application::drawFrame() {
swapchain->recreateSwapchain(); swapchain->recreateSwapchain();
return; return;
} }
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
} }
void Application::createSyncObjects() { void Application::createSyncObjects() {
imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
renderFinishedSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
inFlightFences.resize(MAX_FRAMES_IN_FLIGHT);
VkSemaphoreCreateInfo semaphoreInfo {}; VkSemaphoreCreateInfo semaphoreInfo {};
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO; semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
@ -170,11 +164,9 @@ void Application::createSyncObjects() {
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO; fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT; fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++){ vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &imageAvailableSemaphore);
vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &imageAvailableSemaphores[i]); vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &renderFinishedSemaphore);
vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &renderFinishedSemaphores[i]); vkCreateFence(Instance::instance->device, &fenceInfo, nullptr, &inFlightFence);
vkCreateFence(Instance::instance->device, &fenceInfo, nullptr, &inFlightFences[i]);
}
} }
void Application::mainLoop() { void Application::mainLoop() {
@ -187,11 +179,9 @@ void Application::mainLoop() {
Application::~Application() { Application::~Application() {
delete swapchain; delete swapchain;
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++){ vkDestroySemaphore(Instance::instance->device, imageAvailableSemaphore, nullptr);
vkDestroySemaphore(Instance::instance->device, imageAvailableSemaphores[i], nullptr); vkDestroySemaphore(Instance::instance->device, renderFinishedSemaphore, nullptr);
vkDestroySemaphore(Instance::instance->device, renderFinishedSemaphores[i], nullptr); vkDestroyFence(Instance::instance->device, inFlightFence, nullptr);
vkDestroyFence(Instance::instance->device, inFlightFences[i], nullptr);
}
delete commandPool; delete commandPool;
delete vertexBuffer; delete vertexBuffer;
delete indexBuffer; delete indexBuffer;

@ -55,11 +55,9 @@ private:
void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex); void recordCommandBuffer(VkCommandBuffer commandBuffer, uint32_t imageIndex);
std::vector<VkSemaphore> imageAvailableSemaphores; VkSemaphore imageAvailableSemaphore;
std::vector<VkSemaphore> renderFinishedSemaphores; VkSemaphore renderFinishedSemaphore;
std::vector<VkFence> inFlightFences; VkFence inFlightFence;
size_t currentFrame = 0;
void drawFrame(); void drawFrame();
void createSyncObjects(); void createSyncObjects();

@ -16,18 +16,16 @@ CommandPool::CommandPool() {
} }
void CommandPool::createBuffers() { void CommandPool::createBuffers() {
buffers.resize(MAX_FRAMES_IN_FLIGHT);
VkCommandBufferAllocateInfo allocateInfo {}; VkCommandBufferAllocateInfo allocateInfo {};
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO; allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocateInfo.commandPool = handle; allocateInfo.commandPool = handle;
allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY; allocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
allocateInfo.commandBufferCount = buffers.size(); allocateInfo.commandBufferCount = 1;
vkAllocateCommandBuffers(Instance::instance->device, &allocateInfo, buffers.data()); vkAllocateCommandBuffers(Instance::instance->device, &allocateInfo, &buffer);
} }
CommandPool::~CommandPool() { CommandPool::~CommandPool() {
vkFreeCommandBuffers(Instance::instance->device, handle, buffers.size(), buffers.data()); vkFreeCommandBuffers(Instance::instance->device, handle, 1, &buffer);
vkDestroyCommandPool(Instance::instance->device, handle, nullptr); vkDestroyCommandPool(Instance::instance->device, handle, nullptr);
} }

@ -9,7 +9,7 @@ class CommandPool {
public: public:
explicit CommandPool(); explicit CommandPool();
~CommandPool(); ~CommandPool();
std::vector<VkCommandBuffer> buffers; VkCommandBuffer buffer = VK_NULL_HANDLE;
VkCommandPool handle = VK_NULL_HANDLE; VkCommandPool handle = VK_NULL_HANDLE;
private: private:

Loading…
Cancel
Save