Skip to content

Commit 4e88504

Browse files
committed
Fix Vulkan build
1 parent 436db65 commit 4e88504

File tree

1 file changed

+97
-2
lines changed

1 file changed

+97
-2
lines changed

src/FNA3D_Driver_Vulkan.c

+97-2
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@
4545
#include <SDL_vulkan.h>
4646
#define SDL_AtomicInt SDL_atomic_t
4747
#define SDL_Mutex SDL_mutex
48+
#define SDL_IOStream SDL_RWops
49+
#define SDL_IOFromFile SDL_RWFromFile
50+
#define SDL_WriteIO(file, data, size) \
51+
file->write( \
52+
file, \
53+
data, \
54+
sizeof(uint8_t), \
55+
size \
56+
)
57+
#define SDL_CloseIO(file) file->close(file)
58+
#define SDL_CreateWindow(title, w, h, flags) SDL_CreateWindow(title, 0, 0, w, h, flags)
59+
#define SDL_Vulkan_CreateSurface(windowHandle, instance, callbacks, surface) SDL_Vulkan_CreateSurface(windowHandle, instance, surface)
4860
#endif
4961

5062
#define VULKAN_INTERNAL_clamp(val, min, max) SDL_max(min, SDL_min(val, max))
@@ -2283,7 +2295,9 @@ static uint8_t VULKAN_INTERNAL_CreateInstance(
22832295
) {
22842296
VkResult vulkanResult;
22852297
VkApplicationInfo appInfo;
2298+
#ifdef USE_SDL3
22862299
char const* const* inferredExtensionNames;
2300+
#endif
22872301
const char **instanceExtensionNames;
22882302
uint32_t instanceExtensionCount;
22892303
VkInstanceCreateInfo createInfo;
@@ -2298,6 +2312,7 @@ static uint8_t VULKAN_INTERNAL_CreateInstance(
22982312
appInfo.engineVersion = FNA3D_COMPILED_VERSION;
22992313
appInfo.apiVersion = VK_MAKE_VERSION(1, 0, 0);
23002314

2315+
#ifdef USE_SDL3
23012316
inferredExtensionNames = SDL_Vulkan_GetInstanceExtensions(&instanceExtensionCount);
23022317

23032318
if (inferredExtensionNames == NULL)
@@ -2322,6 +2337,41 @@ static uint8_t VULKAN_INTERNAL_CreateInstance(
23222337
{
23232338
instanceExtensionNames[i] = inferredExtensionNames[i];
23242339
}
2340+
#else
2341+
if (!SDL_Vulkan_GetInstanceExtensions(
2342+
(SDL_Window*) presentationParameters->deviceWindowHandle,
2343+
&instanceExtensionCount,
2344+
NULL
2345+
)) {
2346+
FNA3D_LogWarn(
2347+
"SDL_Vulkan_GetInstanceExtensions(): getExtensionCount: %s",
2348+
SDL_GetError()
2349+
);
2350+
2351+
return 0;
2352+
}
2353+
2354+
/* Extra space for the following extensions:
2355+
* VK_KHR_get_physical_device_properties2
2356+
* VK_EXT_debug_utils
2357+
*/
2358+
instanceExtensionNames = SDL_stack_alloc(
2359+
const char*,
2360+
instanceExtensionCount + 2
2361+
);
2362+
2363+
if (!SDL_Vulkan_GetInstanceExtensions(
2364+
(SDL_Window*) presentationParameters->deviceWindowHandle,
2365+
&instanceExtensionCount,
2366+
instanceExtensionNames
2367+
)) {
2368+
FNA3D_LogWarn(
2369+
"SDL_Vulkan_GetInstanceExtensions(): %s",
2370+
SDL_GetError()
2371+
);
2372+
goto create_instance_fail;
2373+
}
2374+
#endif
23252375

23262376
if (!VULKAN_INTERNAL_CheckInstanceExtensions(
23272377
renderer->debugMode,
@@ -4282,8 +4332,14 @@ static void VULKAN_INTERNAL_SubmitCommands(
42824332
VulkanSwapchainData *swapchainData = NULL;
42834333
uint32_t swapchainImageIndex;
42844334
VulkanCommandBuffer *commandBufferToSubmit;
4335+
int32_t refreshRate;
42854336

4337+
#ifdef USE_SDL3
42864338
const SDL_DisplayMode *mode;
4339+
#else
4340+
SDL_DisplayMode mode;
4341+
#endif
4342+
42874343
VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
42884344
VkPresentInfoKHR presentInfo;
42894345
struct
@@ -4298,13 +4354,31 @@ static void VULKAN_INTERNAL_SubmitCommands(
42984354

42994355
if (present)
43004356
{
4357+
#ifdef USE_SDL3
43014358
mode = SDL_GetCurrentDisplayMode(
43024359
SDL_GetDisplayForWindow(
43034360
(SDL_Window*) windowHandle
43044361
)
43054362
);
4363+
refreshRate = mode->refresh_rate;
43064364

4307-
swapchainData = (VulkanSwapchainData *)SDL_GetProperty(SDL_GetWindowProperties(windowHandle), WINDOW_SWAPCHAIN_DATA, NULL);
4365+
swapchainData = (VulkanSwapchainData*) SDL_GetProperty(SDL_GetWindowProperties(windowHandle), WINDOW_SWAPCHAIN_DATA, NULL);
4366+
#else
4367+
SDL_GetCurrentDisplayMode(
4368+
SDL_GetWindowDisplayIndex(
4369+
(SDL_Window*) windowHandle
4370+
),
4371+
&mode
4372+
);
4373+
refreshRate = mode.refresh_rate;
4374+
if (refreshRate == 0)
4375+
{
4376+
/* Needs to be _something_ */
4377+
refreshRate = 60;
4378+
}
4379+
4380+
swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
4381+
#endif
43084382

43094383
if (swapchainData == NULL)
43104384
{
@@ -4320,7 +4394,11 @@ static void VULKAN_INTERNAL_SubmitCommands(
43204394
}
43214395
else
43224396
{
4397+
#ifdef USE_SDL3
43234398
swapchainData = (VulkanSwapchainData *)SDL_GetProperty(SDL_GetWindowProperties(windowHandle), WINDOW_SWAPCHAIN_DATA, NULL);
4399+
#else
4400+
swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
4401+
#endif
43244402
validSwapchainExists = 1;
43254403
}
43264404
}
@@ -4335,7 +4413,7 @@ static void VULKAN_INTERNAL_SubmitCommands(
43354413
acquireResult = renderer->vkAcquireNextImageKHR(
43364414
renderer->logicalDevice,
43374415
swapchainData->swapchain,
4338-
10000000000 / mode->refresh_rate, /* ~10 frames, so we'll progress even if throttled to zero. */
4416+
10000000000 / refreshRate, /* ~10 frames, so we'll progress even if throttled to zero. */
43394417
swapchainData->imageAvailableSemaphore,
43404418
VK_NULL_HANDLE,
43414419
&swapchainImageIndex
@@ -4491,7 +4569,11 @@ static void VULKAN_INTERNAL_SubmitCommands(
44914569
{
44924570
if (renderer->supports.GGP_frame_token)
44934571
{
4572+
#ifdef USE_SDL3
44944573
const void *token = SDL_GetProperty(SDL_GetWindowProperties(windowHandle), "GgpFrameToken", NULL);
4574+
#else
4575+
const void *token = SDL_GetWindowData((SDL_Window*) windowHandle, "GgpFrameToken");
4576+
#endif
44954577
presentInfoGGP.sType = VK_STRUCTURE_TYPE_PRESENT_FRAME_TOKEN_GGP;
44964578
presentInfoGGP.pNext = NULL;
44974579
presentInfoGGP.frameToken = (uint64_t) (size_t) token;
@@ -5011,7 +5093,11 @@ static CreateSwapchainResult VULKAN_INTERNAL_CreateSwapchain(
50115093

50125094
swapchainData->fence = VK_NULL_HANDLE;
50135095

5096+
#ifdef USE_SDL3
50145097
SDL_SetProperty(SDL_GetWindowProperties(windowHandle), WINDOW_SWAPCHAIN_DATA, swapchainData);
5098+
#else
5099+
SDL_SetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA, swapchainData);
5100+
#endif
50155101

50165102
if (renderer->swapchainDataCount >= renderer->swapchainDataCapacity)
50175103
{
@@ -5043,7 +5129,11 @@ static void VULKAN_INTERNAL_DestroySwapchain(
50435129
uint32_t i;
50445130
VulkanSwapchainData *swapchainData;
50455131

5132+
#ifdef USE_SDL3
50465133
swapchainData = (VulkanSwapchainData*) SDL_GetProperty(SDL_GetWindowProperties(windowHandle), WINDOW_SWAPCHAIN_DATA, NULL);
5134+
#else
5135+
swapchainData = (VulkanSwapchainData*) SDL_GetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA);
5136+
#endif
50475137

50485138
if (swapchainData == NULL)
50495139
{
@@ -5110,7 +5200,12 @@ static void VULKAN_INTERNAL_DestroySwapchain(
51105200
}
51115201
}
51125202

5203+
#ifdef USE_SDL3
51135204
SDL_ClearProperty(SDL_GetWindowProperties(windowHandle), WINDOW_SWAPCHAIN_DATA);
5205+
#else
5206+
SDL_SetWindowData(windowHandle, WINDOW_SWAPCHAIN_DATA, NULL);
5207+
#endif
5208+
51145209
SDL_free(swapchainData);
51155210
}
51165211

0 commit comments

Comments
 (0)