Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions src/command_buffer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1260,16 +1260,12 @@ void CommandBuffer::start() {
auto &state = vulkan::commandBufferState(this);
auto &deviceState = vulkan::deviceState(device);

if (state.imageAvailableSemaphore == VK_NULL_HANDLE ||
state.renderFinishedSemaphore == VK_NULL_HANDLE) {
if (state.imageAvailableSemaphore == VK_NULL_HANDLE) {
VkSemaphoreCreateInfo semaphoreInfo{};
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
VULKAN_GUARD(vkCreateSemaphore(deviceState.device, &semaphoreInfo,
nullptr, &state.imageAvailableSemaphore),
"Failed to create Vulkan image available semaphore");
VULKAN_GUARD(vkCreateSemaphore(deviceState.device, &semaphoreInfo,
nullptr, &state.renderFinishedSemaphore),
"Failed to create Vulkan render finished semaphore");
}

if (state.inFlightFence == VK_NULL_HANDLE) {
Expand Down Expand Up @@ -2114,7 +2110,10 @@ void CommandBuffer::commit() {
VkSemaphoreSubmitInfo signalInfo{};
signalInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_SUBMIT_INFO;

signalInfo.semaphore = state.renderFinishedSemaphore;
signalInfo.semaphore = state.needsPresent
? contextState.renderFinishedSemaphores.at(
state.imageIndex)
: VK_NULL_HANDLE;

signalInfo.stageMask = VK_PIPELINE_STAGE_2_ALL_COMMANDS_BIT;

Expand Down Expand Up @@ -2142,7 +2141,7 @@ void CommandBuffer::commit() {
VkPresentInfoKHR presentInfo{};
presentInfo.sType = VK_STRUCTURE_TYPE_PRESENT_INFO_KHR;
presentInfo.waitSemaphoreCount = 1;
presentInfo.pWaitSemaphores = &state.renderFinishedSemaphore;
presentInfo.pWaitSemaphores = &signalInfo.semaphore;
presentInfo.swapchainCount = 1;
presentInfo.pSwapchains = &contextState.swapchain;
presentInfo.pImageIndices = &state.imageIndex;
Expand Down Expand Up @@ -2185,7 +2184,7 @@ void CommandBuffer::waitForSubmittedWork() {
state.inFlightResources.clear();
#elif defined(VULKAN)
auto &state = vulkan::commandBufferState(this);
if (state.inFlightFence == VK_NULL_HANDLE) {
if (state.inFlightFence == VK_NULL_HANDLE || !state.submitted) {
return;
}

Expand Down
15 changes: 15 additions & 0 deletions src/vulkan/vulkan_image.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,19 @@ void createSwapchainImages(ContextState &contextState,
contextState.swapchainImages.data());

contextState.swapchainImageViews.resize(swapchainImageCount);
contextState.renderFinishedSemaphores.resize(swapchainImageCount,
VK_NULL_HANDLE);
contextState.swapchainImageLayouts.resize(swapchainImageCount,
VK_IMAGE_LAYOUT_UNDEFINED);

for (size_t i = 0; i < swapchainImageCount; i++) {
VkSemaphoreCreateInfo semaphoreInfo{};
semaphoreInfo.sType = VK_STRUCTURE_TYPE_SEMAPHORE_CREATE_INFO;
VULKAN_GUARD(
vkCreateSemaphore(deviceState.device, &semaphoreInfo, nullptr,
&contextState.renderFinishedSemaphores[i]),
"Failed to create Vulkan presentation semaphore");

VkImageViewCreateInfo viewInfo{};
viewInfo.sType = VK_STRUCTURE_TYPE_IMAGE_VIEW_CREATE_INFO;
viewInfo.image = contextState.swapchainImages[i];
Expand Down Expand Up @@ -190,6 +199,12 @@ void destroySwapchain(ContextState &contextState, DeviceState &deviceState) {
vkDestroyImageView(deviceState.device, imageView, nullptr);
}
}
for (VkSemaphore semaphore : contextState.renderFinishedSemaphores) {
if (semaphore != VK_NULL_HANDLE) {
vkDestroySemaphore(deviceState.device, semaphore, nullptr);
}
}
contextState.renderFinishedSemaphores.clear();
contextState.swapchainImageViews.clear();
contextState.swapchainImages.clear();
contextState.swapchainImageLayouts.clear();
Expand Down
9 changes: 0 additions & 9 deletions src/vulkan/vulkan_state.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,6 @@ void releaseDeviceState(Device *device) {
commandState.imageAvailableSemaphore,
nullptr);
}
if (commandState.renderFinishedSemaphore != VK_NULL_HANDLE) {
vkDestroySemaphore(state.device,
commandState.renderFinishedSemaphore,
nullptr);
}
if (commandState.inFlightFence != VK_NULL_HANDLE) {
vkDestroyFence(state.device, commandState.inFlightFence,
nullptr);
Expand Down Expand Up @@ -361,10 +356,6 @@ void releaseCommandBufferState(CommandBuffer *commandBuffer) {
vkDestroySemaphore(state.device, state.imageAvailableSemaphore,
nullptr);
}
if (state.renderFinishedSemaphore != VK_NULL_HANDLE) {
vkDestroySemaphore(state.device, state.renderFinishedSemaphore,
nullptr);
}
if (state.inFlightFence != VK_NULL_HANDLE) {
vkDestroyFence(state.device, state.inFlightFence, nullptr);
}
Expand Down
2 changes: 1 addition & 1 deletion src/vulkan/vulkan_state.h
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ struct ContextState {

std::vector<VkImage> swapchainImages;
std::vector<VkImageView> swapchainImageViews;
std::vector<VkSemaphore> renderFinishedSemaphores;

uint32_t currentSwapchainImageIndex = UINT32_MAX;

Expand Down Expand Up @@ -155,7 +156,6 @@ struct CommandBufferState {
bool submitted = false;

VkSemaphore imageAvailableSemaphore = VK_NULL_HANDLE;
VkSemaphore renderFinishedSemaphore = VK_NULL_HANDLE;
VkFence inFlightFence = VK_NULL_HANDLE;

bool clearColorPending = false;
Expand Down
Loading