31
31
#include "FNA3D_Driver_D3D11.h"
32
32
#include "FNA3D_Driver_D3D11_shaders.h"
33
33
34
+ #ifdef USE_SDL3
35
+ #include <SDL3/SDL.h>
36
+ #else
34
37
#include <SDL.h>
35
38
#ifndef FNA3D_DXVK_NATIVE
36
39
#include <SDL_syswm.h>
37
40
#endif /* !FNA3D_DXVK_NATIVE */
41
+ #define SDL_Mutex SDL_mutex
42
+ #endif
38
43
39
44
/* D3D11 Libraries */
40
45
@@ -213,7 +218,7 @@ typedef struct D3D11Renderer /* Cast FNA3D_Renderer* to this! */
213
218
IDXGIAdapter1 * adapter ;
214
219
ID3DUserDefinedAnnotation * annotation ;
215
220
BOOL supportsTearing ;
216
- SDL_mutex * ctxLock ;
221
+ SDL_Mutex * ctxLock ;
217
222
SDL_iconv_t iconv ;
218
223
219
224
/* Window surfaces */
@@ -1067,11 +1072,18 @@ static void D3D11_DestroyDevice(FNA3D_Device *device)
1067
1072
swapchainData = renderer -> swapchainDatas [i ];
1068
1073
ID3D11RenderTargetView_Release (swapchainData -> swapchainRTView );
1069
1074
IDXGISwapChain_Release (swapchainData -> swapchain );
1075
+ #if SDL_MAJOR_VERSION >= 3
1076
+ SDL_ClearProperty (
1077
+ SDL_GetWindowProperties (swapchainData -> windowHandle ),
1078
+ WINDOW_SWAPCHAIN_DATA
1079
+ );
1080
+ #else
1070
1081
SDL_SetWindowData (
1071
1082
(SDL_Window * ) swapchainData -> windowHandle ,
1072
1083
WINDOW_SWAPCHAIN_DATA ,
1073
1084
NULL
1074
1085
);
1086
+ #endif
1075
1087
SDL_free (renderer -> swapchainDatas [i ]);
1076
1088
}
1077
1089
SDL_free (renderer -> swapchainDatas );
@@ -1532,10 +1544,18 @@ static void D3D11_SwapBuffers(
1532
1544
}
1533
1545
}
1534
1546
1547
+ #if SDL_MAJOR_VERSION >= 3
1548
+ swapchainData = (D3D11SwapchainData * ) SDL_GetProperty (
1549
+ SDL_GetWindowProperties (overrideWindowHandle ),
1550
+ WINDOW_SWAPCHAIN_DATA ,
1551
+ NULL
1552
+ );
1553
+ #else
1535
1554
swapchainData = (D3D11SwapchainData * ) SDL_GetWindowData (
1536
1555
(SDL_Window * ) overrideWindowHandle ,
1537
1556
WINDOW_SWAPCHAIN_DATA
1538
1557
);
1558
+ #endif
1539
1559
if (swapchainData == NULL )
1540
1560
{
1541
1561
D3D11_INTERNAL_CreateSwapChain (
@@ -1544,10 +1564,18 @@ static void D3D11_SwapBuffers(
1544
1564
(SDL_Window * ) overrideWindowHandle ,
1545
1565
NULL
1546
1566
);
1567
+ #if SDL_MAJOR_VERSION >= 3
1568
+ swapchainData = (D3D11SwapchainData * ) SDL_GetProperty (
1569
+ SDL_GetWindowProperties (overrideWindowHandle ),
1570
+ WINDOW_SWAPCHAIN_DATA ,
1571
+ NULL
1572
+ );
1573
+ #else
1547
1574
swapchainData = (D3D11SwapchainData * ) SDL_GetWindowData (
1548
1575
(SDL_Window * ) overrideWindowHandle ,
1549
1576
WINDOW_SWAPCHAIN_DATA
1550
1577
);
1578
+ #endif
1551
1579
D3D11_INTERNAL_UpdateSwapchainRT (
1552
1580
renderer ,
1553
1581
swapchainData ,
@@ -2544,11 +2572,19 @@ static void D3D11_INTERNAL_CreateSwapChain(
2544
2572
2545
2573
#ifdef FNA3D_DXVK_NATIVE
2546
2574
dxgiHandle = (HWND ) windowHandle ;
2575
+ #else
2576
+ #if SDL_MAJOR_VERSION >= 3
2577
+ dxgiHandle = (HWND ) SDL_GetProperty (
2578
+ SDL_GetWindowProperties (windowHandle ),
2579
+ SDL_PROP_WINDOW_WIN32_HWND_POINTER ,
2580
+ NULL
2581
+ );
2547
2582
#else
2548
2583
SDL_SysWMinfo info ;
2549
2584
SDL_VERSION (& info .version );
2550
2585
SDL_GetWindowWMInfo ((SDL_Window * ) windowHandle , & info );
2551
2586
dxgiHandle = info .info .win .window ;
2587
+ #endif
2552
2588
#endif /* FNA3D_DXVK_NATIVE */
2553
2589
2554
2590
/* Initialize swapchain buffer descriptor */
@@ -2676,7 +2712,11 @@ static void D3D11_INTERNAL_CreateSwapChain(
2676
2712
swapchainData -> windowHandle = windowHandle ;
2677
2713
swapchainData -> swapchainRTView = NULL ;
2678
2714
swapchainData -> format = backBufferFormat ;
2715
+ #if SDL_MAJOR_VERSION >= 3
2716
+ SDL_SetProperty (SDL_GetWindowProperties (windowHandle ), WINDOW_SWAPCHAIN_DATA , swapchainData );
2717
+ #else
2679
2718
SDL_SetWindowData ((SDL_Window * ) windowHandle , WINDOW_SWAPCHAIN_DATA , swapchainData );
2719
+ #endif
2680
2720
if (growSwapchains )
2681
2721
{
2682
2722
if (renderer -> swapchainDataCount >= renderer -> swapchainDataCapacity )
@@ -2771,10 +2811,18 @@ static void D3D11_INTERNAL_CreateBackbuffer(
2771
2811
/* Create or update the swapchain */
2772
2812
if (parameters -> deviceWindowHandle != NULL )
2773
2813
{
2814
+ #if SDL_MAJOR_VERSION >= 3
2815
+ swapchainData = (D3D11SwapchainData * ) SDL_GetProperty (
2816
+ SDL_GetWindowProperties (parameters -> deviceWindowHandle ),
2817
+ WINDOW_SWAPCHAIN_DATA ,
2818
+ NULL
2819
+ );
2820
+ #else
2774
2821
swapchainData = (D3D11SwapchainData * ) SDL_GetWindowData (
2775
2822
(SDL_Window * ) parameters -> deviceWindowHandle ,
2776
2823
WINDOW_SWAPCHAIN_DATA
2777
2824
);
2825
+ #endif
2778
2826
if (swapchainData == NULL )
2779
2827
{
2780
2828
D3D11_INTERNAL_CreateSwapChain (
@@ -2783,10 +2831,18 @@ static void D3D11_INTERNAL_CreateBackbuffer(
2783
2831
parameters -> deviceWindowHandle ,
2784
2832
NULL
2785
2833
);
2834
+ #if SDL_MAJOR_VERSION >= 3
2835
+ swapchainData = (D3D11SwapchainData * ) SDL_GetProperty (
2836
+ SDL_GetWindowProperties (parameters -> deviceWindowHandle ),
2837
+ WINDOW_SWAPCHAIN_DATA ,
2838
+ NULL
2839
+ );
2840
+ #else
2786
2841
swapchainData = (D3D11SwapchainData * ) SDL_GetWindowData (
2787
2842
(SDL_Window * ) parameters -> deviceWindowHandle ,
2788
2843
WINDOW_SWAPCHAIN_DATA
2789
2844
);
2845
+ #endif
2790
2846
}
2791
2847
else
2792
2848
{
@@ -2796,7 +2852,7 @@ static void D3D11_INTERNAL_CreateBackbuffer(
2796
2852
/* Surface format changed, recreate entirely */
2797
2853
IDXGISwapChain_Release (swapchainData -> swapchain );
2798
2854
2799
- /*
2855
+ /*
2800
2856
* DXGI will crash in some cases if we don't flush deferred swapchain destruction:
2801
2857
*
2802
2858
* DXGI ERROR: IDXGIFactory::CreateSwapChain: Only one flip model swap chain can be
@@ -5212,7 +5268,9 @@ static uint8_t D3D11_PrepareWindowAttributes(uint32_t *flags)
5212
5268
}
5213
5269
5214
5270
/* No window flags required */
5271
+ #if SDL_MAJOR_VERSION < 3
5215
5272
SDL_SetHint (SDL_HINT_VIDEO_EXTERNAL_CONTEXT , "1" );
5273
+ #endif
5216
5274
#ifdef FNA3D_DXVK_NATIVE
5217
5275
/* ... unless this is DXVK */
5218
5276
* flags = SDL_WINDOW_VULKAN ;
@@ -5544,7 +5602,7 @@ static FNA3D_Device* D3D11_CreateDevice(
5544
5602
{
5545
5603
res = D3D11CreateDeviceFunc (
5546
5604
(driverType == D3D_DRIVER_TYPE_WARP ) ? NULL : (IDXGIAdapter * ) renderer -> adapter ,
5547
- driverType ,
5605
+ driverType ,
5548
5606
NULL ,
5549
5607
flags ,
5550
5608
& levels [i ],
0 commit comments