Added a hint to create the D3D device in thread-safe mode: SDL_HINT_RENDER_DIRECT3D_THREADSAFE

Sam Lantinga 2013-09-28 14:07:08 -07:00
parent 803965bcc2
commit cf5e5a8360
2 changed files with 26 additions and 7 deletions

View File

@ -94,6 +94,17 @@ extern "C" {
*/ */
#define SDL_HINT_RENDER_OPENGL_SHADERS "SDL_RENDER_OPENGL_SHADERS" #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 * \brief A variable controlling the scaling quality
* *

View File

@ -544,9 +544,11 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
D3D_RenderData *data; D3D_RenderData *data;
SDL_SysWMinfo windowinfo; SDL_SysWMinfo windowinfo;
HRESULT result; HRESULT result;
const char *hint;
D3DPRESENT_PARAMETERS pparams; D3DPRESENT_PARAMETERS pparams;
IDirect3DSwapChain9 *chain; IDirect3DSwapChain9 *chain;
D3DCAPS9 caps; D3DCAPS9 caps;
DWORD device_flags;
Uint32 window_flags; Uint32 window_flags;
int w, h; int w, h;
SDL_DisplayMode fullscreen_mode; SDL_DisplayMode fullscreen_mode;
@ -589,8 +591,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
} }
} }
if (!data->d3d || !data->matrixStack) { if (!data->d3d || !data->matrixStack) {
SDL_free(renderer); SDL_free(renderer);
SDL_free(data); SDL_free(data);
@ -667,14 +667,22 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
IDirect3D9_GetDeviceCaps(data->d3d, data->adapter, D3DDEVTYPE_HAL, &caps); 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, result = IDirect3D9_CreateDevice(data->d3d, data->adapter,
D3DDEVTYPE_HAL, D3DDEVTYPE_HAL,
pparams.hDeviceWindow, pparams.hDeviceWindow,
D3DCREATE_FPU_PRESERVE | ((caps. device_flags,
DevCaps &
D3DDEVCAPS_HWTRANSFORMANDLIGHT) ?
D3DCREATE_HARDWARE_VERTEXPROCESSING :
D3DCREATE_SOFTWARE_VERTEXPROCESSING),
&pparams, &data->device); &pparams, &data->device);
if (FAILED(result)) { if (FAILED(result)) {
D3D_DestroyRenderer(renderer); D3D_DestroyRenderer(renderer);