Added a hint to create the D3D device in thread-safe mode: SDL_HINT_RENDER_DIRECT3D_THREADSAFE
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
diff --git a/include/SDL_hints.h b/include/SDL_hints.h
index 9dc9cfe..dac928e 100644
--- a/include/SDL_hints.h
+++ b/include/SDL_hints.h
@@ -95,6 +95,17 @@ extern "C" {
#define SDL_HINT_RENDER_OPENGL_SHADERS "SDL_RENDER_OPENGL_SHADERS"
/**
+ * \brief A variable controlling whether the Direct3D device is initialized for thread-safe operations.
+ *
+ * This variable can be set to the following values:
+ * "0" - Thread-safety is not enabled (faster)
+ * "1" - Thread-safety is enabled
+ *
+ * By default the Direct3D device is created with thread-safety disabled.
+ */
+#define SDL_HINT_RENDER_DIRECT3D_THREADSAFE "SDL_RENDER_DIRECT3D_THREADSAFE"
+
+/**
* \brief A variable controlling the scaling quality
*
* This variable can be set to the following values:
diff --git a/src/render/direct3d/SDL_render_d3d.c b/src/render/direct3d/SDL_render_d3d.c
index 2ac5974..fdaf796 100644
--- a/src/render/direct3d/SDL_render_d3d.c
+++ b/src/render/direct3d/SDL_render_d3d.c
@@ -544,9 +544,11 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
D3D_RenderData *data;
SDL_SysWMinfo windowinfo;
HRESULT result;
+ const char *hint;
D3DPRESENT_PARAMETERS pparams;
IDirect3DSwapChain9 *chain;
D3DCAPS9 caps;
+ DWORD device_flags;
Uint32 window_flags;
int w, h;
SDL_DisplayMode fullscreen_mode;
@@ -589,8 +591,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
}
}
-
-
if (!data->d3d || !data->matrixStack) {
SDL_free(renderer);
SDL_free(data);
@@ -667,14 +667,22 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps);
+ device_flags = D3DCREATE_FPU_PRESERVE;
+ if (caps.DevCaps & D3DDEVCAPS_HWTRANSFORMANDLIGHT) {
+ device_flags |= D3DCREATE_HARDWARE_VERTEXPROCESSING;
+ } else {
+ device_flags |= D3DCREATE_SOFTWARE_VERTEXPROCESSING;
+ }
+
+ hint = SDL_GetHint(SDL_HINT_RENDER_DIRECT3D_THREADSAFE);
+ if (hint && SDL_atoi(hint)) {
+ device_flags |= D3DCREATE_MULTITHREADED;
+ }
+
result = IDirect3D9_CreateDevice(data->d3d, data->adapter,
D3DDEVTYPE_HAL,
pparams.hDeviceWindow,
- D3DCREATE_FPU_PRESERVE | ((caps.
- DevCaps &
- D3DDEVCAPS_HWTRANSFORMANDLIGHT) ?
- D3DCREATE_HARDWARE_VERTEXPROCESSING :
- D3DCREATE_SOFTWARE_VERTEXPROCESSING),
+ device_flags,
&pparams, &data->device);
if (FAILED(result)) {
D3D_DestroyRenderer(renderer);