limit max frames in flight
continuous-integration/drone/push Build is passing Details

pull/51/head
cosmonaut 2024-03-01 15:38:18 -08:00
parent a3249404bc
commit 42d62d423a
1 changed files with 19 additions and 0 deletions

View File

@ -80,6 +80,7 @@ typedef struct VulkanExtensions
#define UBO_BUFFER_SIZE 16777216 /* 16MB */ #define UBO_BUFFER_SIZE 16777216 /* 16MB */
#define MAX_UBO_SECTION_SIZE 4096 /* 4KB */ #define MAX_UBO_SECTION_SIZE 4096 /* 4KB */
#define DESCRIPTOR_POOL_STARTING_SIZE 128 #define DESCRIPTOR_POOL_STARTING_SIZE 128
#define MAX_FRAMES_IN_FLIGHT 3
#define WINDOW_DATA "Refresh_VulkanWindowData" #define WINDOW_DATA "Refresh_VulkanWindowData"
#define IDENTITY_SWIZZLE \ #define IDENTITY_SWIZZLE \
@ -875,6 +876,8 @@ typedef struct VulkanSwapchainData
/* Synchronization primitives */ /* Synchronization primitives */
VkSemaphore imageAvailableSemaphore; VkSemaphore imageAvailableSemaphore;
VkSemaphore renderFinishedSemaphore; VkSemaphore renderFinishedSemaphore;
uint32_t submissionsInFlight;
} VulkanSwapchainData; } VulkanSwapchainData;
typedef struct WindowData typedef struct WindowData
@ -4639,6 +4642,7 @@ static uint8_t VULKAN_INTERNAL_CreateSwapchain(
uint32_t i; uint32_t i;
swapchainData = SDL_malloc(sizeof(VulkanSwapchainData)); swapchainData = SDL_malloc(sizeof(VulkanSwapchainData));
swapchainData->submissionsInFlight = 0;
/* Each swapchain must have its own surface. */ /* Each swapchain must have its own surface. */
@ -9616,6 +9620,12 @@ static Refresh_Texture* VULKAN_AcquireSwapchainTexture(
swapchainData = windowData->swapchainData; swapchainData = windowData->swapchainData;
/* Drop frames if too many submissions in flight */
if (swapchainData->submissionsInFlight >= MAX_FRAMES_IN_FLIGHT)
{
return NULL;
}
/* Window is claimed but swapchain is invalid! */ /* Window is claimed but swapchain is invalid! */
if (swapchainData == NULL) if (swapchainData == NULL)
{ {
@ -10057,6 +10067,11 @@ static void VULKAN_INTERNAL_CleanCommandBuffer(
/* Reset presentation data */ /* Reset presentation data */
for (i = 0; i < commandBuffer->presentDataCount; i += 1)
{
commandBuffer->presentDatas[i].windowData->swapchainData->submissionsInFlight -= 1;
}
commandBuffer->presentDataCount = 0; commandBuffer->presentDataCount = 0;
commandBuffer->waitSemaphoreCount = 0; commandBuffer->waitSemaphoreCount = 0;
commandBuffer->signalSemaphoreCount = 0; commandBuffer->signalSemaphoreCount = 0;
@ -10255,6 +10270,10 @@ static void VULKAN_Submit(
presentData->windowData presentData->windowData
); );
} }
else
{
presentData->windowData->swapchainData->submissionsInFlight += 1;
}
} }
/* Check if we can perform any cleanups */ /* Check if we can perform any cleanups */