Skip to content

Commit

Permalink
Added a hint to create the D3D device in thread-safe mode: SDL_HINT_R…
Browse files Browse the repository at this point in the history
…ENDER_DIRECT3D_THREADSAFE
  • Loading branch information
slouken committed Sep 28, 2013
1 parent 803965b commit cf5e5a8
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 7 deletions.
11 changes: 11 additions & 0 deletions include/SDL_hints.h
Expand Up @@ -94,6 +94,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
*
Expand Down
22 changes: 15 additions & 7 deletions src/render/direct3d/SDL_render_d3d.c
Expand Up @@ -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;
Expand Down Expand Up @@ -589,8 +591,6 @@ D3D_CreateRenderer(SDL_Window * window, Uint32 flags)
}
}



if (!data->d3d || !data->matrixStack) {
SDL_free(renderer);
SDL_free(data);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit cf5e5a8

Please sign in to comment.