no frames in flight

main
Benjamin Kraft 2 weeks ago
parent 7c85f8efaa
commit da97341c07
  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() {
vkWaitForFences(Instance::instance->device, 1, &inFlightFences[currentFrame], VK_TRUE, UINT64_MAX);
vkWaitForFences(Instance::instance->device, 1, &inFlightFence, VK_TRUE, UINT64_MAX);
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){
swapchain->recreateSwapchain();
return;
}
vkResetFences(Instance::instance->device, 1, &inFlightFences[currentFrame]);
vkResetFences(Instance::instance->device, 1, &inFlightFence);
vkResetCommandBuffer(commandPool->buffers[currentFrame], 0);
recordCommandBuffer(commandPool->buffers[currentFrame], imageIndex);
vkResetCommandBuffer(commandPool->buffer, 0);
recordCommandBuffer(commandPool->buffer, imageIndex);
updateUniformBuffer();
VkSubmitInfo submitInfo {};
submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
VkSemaphore waitSemaphores[] = {imageAvailableSemaphores[currentFrame]};
VkSemaphore waitSemaphores[] = {imageAvailableSemaphore};
VkPipelineStageFlags waitStages[] = {VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT};
submitInfo.waitSemaphoreCount = 1;
submitInfo.pWaitSemaphores = waitSemaphores;
submitInfo.pWaitDstStageMask = waitStages;
submitInfo.commandBufferCount = 1;
submitInfo.pCommandBuffers = &commandPool->buffers[currentFrame];
submitInfo.pCommandBuffers = &commandPool->buffer;
VkSemaphore signalSemaphores[] = {renderFinishedSemaphores[currentFrame]};
VkSemaphore signalSemaphores[] = {renderFinishedSemaphore};
submitInfo.signalSemaphoreCount = 1;
submitInfo.pSignalSemaphores = signalSemaphores;
vkQueueSubmit(Instance::instance->graphicsQueue, 1, &submitInfo, inFlightFences[currentFrame]);
vkQueueSubmit(Instance::instance->graphicsQueue, 1, &submitInfo, inFlightFence);
VkPresentInfoKHR presentInfo {};
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
@ -154,15 +154,9 @@ void Application::drawFrame() {
swapchain->recreateSwapchain();
return;
}
currentFrame = (currentFrame + 1) % MAX_FRAMES_IN_FLIGHT;
}
void Application::createSyncObjects() {
imageAvailableSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
renderFinishedSemaphores.resize(MAX_FRAMES_IN_FLIGHT);
inFlightFences.resize(MAX_FRAMES_IN_FLIGHT);
VkSemaphoreCreateInfo semaphoreInfo {};
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
@ -170,11 +164,9 @@ void Application::createSyncObjects() {
fenceInfo.sType = VK_STRUCTURE_TYPE_FENCE_CREATE_INFO;
fenceInfo.flags = VK_FENCE_CREATE_SIGNALED_BIT;
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++){
vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &imageAvailableSemaphores[i]);
vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &renderFinishedSemaphores[i]);
vkCreateFence(Instance::instance->device, &fenceInfo, nullptr, &inFlightFences[i]);
}
vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &imageAvailableSemaphore);
vkCreateSemaphore(Instance::instance->device, &semaphoreInfo, nullptr, &renderFinishedSemaphore);
vkCreateFence(Instance::instance->device, &fenceInfo, nullptr, &inFlightFence);
}
void Application::mainLoop() {
@ -187,11 +179,9 @@ void Application::mainLoop() {
Application::~Application() {
delete swapchain;
for (size_t i = 0; i < MAX_FRAMES_IN_FLIGHT; i++){
vkDestroySemaphore(Instance::instance->device, imageAvailableSemaphores[i], nullptr);
vkDestroySemaphore(Instance::instance->device, renderFinishedSemaphores[i], nullptr);
vkDestroyFence(Instance::instance->device, inFlightFences[i], nullptr);
}
vkDestroySemaphore(Instance::instance->device, imageAvailableSemaphore, nullptr);
vkDestroySemaphore(Instance::instance->device, renderFinishedSemaphore, nullptr);
vkDestroyFence(Instance::instance->device, inFlightFence, nullptr);
delete commandPool;
delete vertexBuffer;
delete indexBuffer;

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

@ -16,18 +16,16 @@ CommandPool::CommandPool() {
}
void CommandPool::createBuffers() {
buffers.resize(MAX_FRAMES_IN_FLIGHT);
VkCommandBufferAllocateInfo allocateInfo {};
allocateInfo.sType = VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO;
allocateInfo.commandPool = handle;
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() {
vkFreeCommandBuffers(Instance::instance->device, handle, buffers.size(), buffers.data());
vkFreeCommandBuffers(Instance::instance->device, handle, 1, &buffer);
vkDestroyCommandPool(Instance::instance->device, handle, nullptr);
}

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

Loading…
Cancel
Save