Skip to content

Commit

Permalink
One more...
Browse files Browse the repository at this point in the history
  • Loading branch information
flibitijibibo committed Mar 20, 2024
1 parent 4e88504 commit 3c5bf97
Showing 1 changed file with 27 additions and 22 deletions.
49 changes: 27 additions & 22 deletions src/FNA3D_Driver_Vulkan.c
Original file line number Diff line number Diff line change
Expand Up @@ -2295,7 +2295,7 @@ static uint8_t VULKAN_INTERNAL_CreateInstance(
) {
VkResult vulkanResult;
VkApplicationInfo appInfo;
#ifdef USE_SDL3
#if SDL_MAJOR_VERSION >= 3
char const* const* inferredExtensionNames;
#endif
const char **instanceExtensionNames;
Expand All @@ -2312,7 +2312,7 @@ static uint8_t VULKAN_INTERNAL_CreateInstance(
appInfo.engineVersion = FNA3D_COMPILED_VERSION;
appInfo.apiVersion = VK_MAKE_VERSION(1, 0, 0);

#ifdef USE_SDL3
#if SDL_MAJOR_VERSION >= 3
inferredExtensionNames = SDL_Vulkan_GetInstanceExtensions(&instanceExtensionCount);

if (inferredExtensionNames == NULL)
Expand Down Expand Up @@ -4332,13 +4332,7 @@ static void VULKAN_INTERNAL_SubmitCommands(
VulkanSwapchainData *swapchainData = NULL;
uint32_t swapchainImageIndex;
VulkanCommandBuffer *commandBufferToSubmit;
int32_t refreshRate;

#ifdef USE_SDL3
const SDL_DisplayMode *mode;
#else
SDL_DisplayMode mode;
#endif

VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
VkPresentInfoKHR presentInfo;
Expand All @@ -4354,32 +4348,43 @@ static void VULKAN_INTERNAL_SubmitCommands(

if (present)
{
#ifdef USE_SDL3
mode = SDL_GetCurrentDisplayMode(
#if SDL_MAJOR_VERSION >= 3
const SDL_DisplayMode *curMode = SDL_GetCurrentDisplayMode(
SDL_GetDisplayForWindow(
(SDL_Window*) windowHandle
)
);
refreshRate = mode->refresh_rate;
SDL_memcpy(&mode, curMode, sizeof(SDL_DisplayMode));

swapchainData = (VulkanSwapchainData*) SDL_GetProperty(SDL_GetWindowProperties(windowHandle), WINDOW_SWAPCHAIN_DATA, NULL);
#else
SDL_GetCurrentDisplayMode(
SDL_GetWindowDisplayIndex(
(SDL_Window*) windowHandle
),
&mode
);
refreshRate = mode.refresh_rate;
if (refreshRate == 0)
#endif

if (mode.refresh_rate == 0)
{
/* Needs to be _something_ */
refreshRate = 60;
mode.refresh_rate = 60;
}

swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
#if SDL_MAJOR_VERSION >= 3
swapchainData = (VulkanSwapchainData*) SDL_GetProperty(
SDL_GetWindowProperties(windowHandle),
WINDOW_SWAPCHAIN_DATA,
NULL
);
#else
swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(
windowHandle,
WINDOW_SWAPCHAIN_DATA
);
#endif


if (swapchainData == NULL)
{
createSwapchainResult = VULKAN_INTERNAL_CreateSwapchain(renderer, windowHandle);
Expand All @@ -4394,7 +4399,7 @@ static void VULKAN_INTERNAL_SubmitCommands(
}
else
{
#ifdef USE_SDL3
#if SDL_MAJOR_VERSION >= 3
swapchainData = (VulkanSwapchainData *)SDL_GetProperty(SDL_GetWindowProperties(windowHandle), WINDOW_SWAPCHAIN_DATA, NULL);
#else
swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
Expand All @@ -4413,7 +4418,7 @@ static void VULKAN_INTERNAL_SubmitCommands(
acquireResult = renderer->vkAcquireNextImageKHR(
renderer->logicalDevice,
swapchainData->swapchain,
10000000000 / refreshRate, /* ~10 frames, so we'll progress even if throttled to zero. */
10000000000 / mode.refresh_rate, /* ~10 frames, so we'll progress even if throttled to zero. */
swapchainData->imageAvailableSemaphore,
VK_NULL_HANDLE,
&swapchainImageIndex
Expand Down Expand Up @@ -4569,7 +4574,7 @@ static void VULKAN_INTERNAL_SubmitCommands(
{
if (renderer->supports.GGP_frame_token)
{
#ifdef USE_SDL3
#if SDL_MAJOR_VERSION >= 3
const void *token = SDL_GetProperty(SDL_GetWindowProperties(windowHandle), "GgpFrameToken", NULL);
#else
const void *token = SDL_GetWindowData((SDL_Window*) windowHandle, "GgpFrameToken");
Expand Down Expand Up @@ -5093,7 +5098,7 @@ static CreateSwapchainResult VULKAN_INTERNAL_CreateSwapchain(

swapchainData->fence = VK_NULL_HANDLE;

#ifdef USE_SDL3
#if SDL_MAJOR_VERSION >= 3
SDL_SetProperty(SDL_GetWindowProperties(windowHandle), WINDOW_SWAPCHAIN_DATA, swapchainData);
#else
SDL_SetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA, swapchainData);
Expand Down Expand Up @@ -5129,7 +5134,7 @@ static void VULKAN_INTERNAL_DestroySwapchain(
uint32_t i;
VulkanSwapchainData *swapchainData;

#ifdef USE_SDL3
#if SDL_MAJOR_VERSION >= 3
swapchainData = (VulkanSwapchainData*) SDL_GetProperty(SDL_GetWindowProperties(windowHandle), WINDOW_SWAPCHAIN_DATA, NULL);
#else
swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
Expand Down Expand Up @@ -5200,7 +5205,7 @@ static void VULKAN_INTERNAL_DestroySwapchain(
}
}

#ifdef USE_SDL3
#if SDL_MAJOR_VERSION >= 3
SDL_ClearProperty(SDL_GetWindowProperties(windowHandle), WINDOW_SWAPCHAIN_DATA);
#else
SDL_SetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA, NULL);
Expand Down

0 comments on commit 3c5bf97

Please sign in to comment.