45
45
#include <SDL_vulkan.h>
46
46
#define SDL_AtomicInt SDL_atomic_t
47
47
#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)
48
60
#endif
49
61
50
62
#define VULKAN_INTERNAL_clamp (val , min , max ) SDL_max(min, SDL_min(val, max))
@@ -2283,7 +2295,9 @@ static uint8_t VULKAN_INTERNAL_CreateInstance(
2283
2295
) {
2284
2296
VkResult vulkanResult ;
2285
2297
VkApplicationInfo appInfo ;
2298
+ #ifdef USE_SDL3
2286
2299
char const * const * inferredExtensionNames ;
2300
+ #endif
2287
2301
const char * * instanceExtensionNames ;
2288
2302
uint32_t instanceExtensionCount ;
2289
2303
VkInstanceCreateInfo createInfo ;
@@ -2298,6 +2312,7 @@ static uint8_t VULKAN_INTERNAL_CreateInstance(
2298
2312
appInfo .engineVersion = FNA3D_COMPILED_VERSION ;
2299
2313
appInfo .apiVersion = VK_MAKE_VERSION (1 , 0 , 0 );
2300
2314
2315
+ #ifdef USE_SDL3
2301
2316
inferredExtensionNames = SDL_Vulkan_GetInstanceExtensions (& instanceExtensionCount );
2302
2317
2303
2318
if (inferredExtensionNames == NULL )
@@ -2322,6 +2337,41 @@ static uint8_t VULKAN_INTERNAL_CreateInstance(
2322
2337
{
2323
2338
instanceExtensionNames [i ] = inferredExtensionNames [i ];
2324
2339
}
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
2325
2375
2326
2376
if (!VULKAN_INTERNAL_CheckInstanceExtensions (
2327
2377
renderer -> debugMode ,
@@ -4282,8 +4332,14 @@ static void VULKAN_INTERNAL_SubmitCommands(
4282
4332
VulkanSwapchainData * swapchainData = NULL ;
4283
4333
uint32_t swapchainImageIndex ;
4284
4334
VulkanCommandBuffer * commandBufferToSubmit ;
4335
+ int32_t refreshRate ;
4285
4336
4337
+ #ifdef USE_SDL3
4286
4338
const SDL_DisplayMode * mode ;
4339
+ #else
4340
+ SDL_DisplayMode mode ;
4341
+ #endif
4342
+
4287
4343
VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT ;
4288
4344
VkPresentInfoKHR presentInfo ;
4289
4345
struct
@@ -4298,13 +4354,31 @@ static void VULKAN_INTERNAL_SubmitCommands(
4298
4354
4299
4355
if (present )
4300
4356
{
4357
+ #ifdef USE_SDL3
4301
4358
mode = SDL_GetCurrentDisplayMode (
4302
4359
SDL_GetDisplayForWindow (
4303
4360
(SDL_Window * ) windowHandle
4304
4361
)
4305
4362
);
4363
+ refreshRate = mode -> refresh_rate ;
4306
4364
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
4308
4382
4309
4383
if (swapchainData == NULL )
4310
4384
{
@@ -4320,7 +4394,11 @@ static void VULKAN_INTERNAL_SubmitCommands(
4320
4394
}
4321
4395
else
4322
4396
{
4397
+ #ifdef USE_SDL3
4323
4398
swapchainData = (VulkanSwapchainData * )SDL_GetProperty (SDL_GetWindowProperties (windowHandle ), WINDOW_SWAPCHAIN_DATA , NULL );
4399
+ #else
4400
+ swapchainData = (VulkanSwapchainData * ) SDL_GetWindowData (windowHandle , WINDOW_SWAPCHAIN_DATA );
4401
+ #endif
4324
4402
validSwapchainExists = 1 ;
4325
4403
}
4326
4404
}
@@ -4335,7 +4413,7 @@ static void VULKAN_INTERNAL_SubmitCommands(
4335
4413
acquireResult = renderer -> vkAcquireNextImageKHR (
4336
4414
renderer -> logicalDevice ,
4337
4415
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. */
4339
4417
swapchainData -> imageAvailableSemaphore ,
4340
4418
VK_NULL_HANDLE ,
4341
4419
& swapchainImageIndex
@@ -4491,7 +4569,11 @@ static void VULKAN_INTERNAL_SubmitCommands(
4491
4569
{
4492
4570
if (renderer -> supports .GGP_frame_token )
4493
4571
{
4572
+ #ifdef USE_SDL3
4494
4573
const void * token = SDL_GetProperty (SDL_GetWindowProperties (windowHandle ), "GgpFrameToken" , NULL );
4574
+ #else
4575
+ const void * token = SDL_GetWindowData ((SDL_Window * ) windowHandle , "GgpFrameToken" );
4576
+ #endif
4495
4577
presentInfoGGP .sType = VK_STRUCTURE_TYPE_PRESENT_FRAME_TOKEN_GGP ;
4496
4578
presentInfoGGP .pNext = NULL ;
4497
4579
presentInfoGGP .frameToken = (uint64_t ) (size_t ) token ;
@@ -5011,7 +5093,11 @@ static CreateSwapchainResult VULKAN_INTERNAL_CreateSwapchain(
5011
5093
5012
5094
swapchainData -> fence = VK_NULL_HANDLE ;
5013
5095
5096
+ #ifdef USE_SDL3
5014
5097
SDL_SetProperty (SDL_GetWindowProperties (windowHandle ), WINDOW_SWAPCHAIN_DATA , swapchainData );
5098
+ #else
5099
+ SDL_SetWindowData (windowHandle , WINDOW_SWAPCHAIN_DATA , swapchainData );
5100
+ #endif
5015
5101
5016
5102
if (renderer -> swapchainDataCount >= renderer -> swapchainDataCapacity )
5017
5103
{
@@ -5043,7 +5129,11 @@ static void VULKAN_INTERNAL_DestroySwapchain(
5043
5129
uint32_t i ;
5044
5130
VulkanSwapchainData * swapchainData ;
5045
5131
5132
+ #ifdef USE_SDL3
5046
5133
swapchainData = (VulkanSwapchainData * ) SDL_GetProperty (SDL_GetWindowProperties (windowHandle ), WINDOW_SWAPCHAIN_DATA , NULL );
5134
+ #else
5135
+ swapchainData = (VulkanSwapchainData * ) SDL_GetWindowData (windowHandle , WINDOW_SWAPCHAIN_DATA );
5136
+ #endif
5047
5137
5048
5138
if (swapchainData == NULL )
5049
5139
{
@@ -5110,7 +5200,12 @@ static void VULKAN_INTERNAL_DestroySwapchain(
5110
5200
}
5111
5201
}
5112
5202
5203
+ #ifdef USE_SDL3
5113
5204
SDL_ClearProperty (SDL_GetWindowProperties (windowHandle ), WINDOW_SWAPCHAIN_DATA );
5205
+ #else
5206
+ SDL_SetWindowData (windowHandle , WINDOW_SWAPCHAIN_DATA , NULL );
5207
+ #endif
5208
+
5114
5209
SDL_free (swapchainData );
5115
5210
}
5116
5211
0 commit comments