DirectX11 supported?

Hi there,
I search the web and the SDL site for an answer, but it’s still not clear to me : does SDL2 support DirectX11 ?

  • a call to SDL_SetHint(SDL_HINT_RENDER_DRIVER, “direct3d11”) return true on my PC, but some forum posts seems to say that it’s not relevant…
  • and if I look into the SDL2 code, I can see for example that in file SDL_render_d3d11.c , at line 23, the #if SDL_VIDEO_RENDER_D3D11 && !SDL_RENDER_DISABLED is disabled because SDL_VIDEO_RENDER_D3D11 has a 0 value…

So is it still based on DirectX9 as the name of the function SDL_RenderGetD3D9Device() seems to suggest ?

Because I’d like to use, in the same window, the SDL2 DX renderer with another graphical API (imgui) that can have either a DX9, DX10, DX11 or DX12 backend… So I wonder what to do to improve compatibility between both worlds…

Both D3D9 and D3D11 are supported by libsdl. Are you getting precompiled libraries (and from where?) or do you build yourself?

If you’re building yourself, whether SDL_VIDEO_RENDER_D3D11 is enabled or not is up to how you configure your build and what’s visible in the system (CMake, for example, is looking for D3D11 header to check if you’ve got appropriate SDK installed).

The SDL_HINT_RENDER_DRIVER hint should trigger D3D11 when available if "direct3d11" hint is used. To check if you’ve got D3D11 support built in, you can use a pair of SDL_GetNumRenderDrivers and SDL_GetRenderDriverInfo calls.

The imgui support is discussed in several other threads and it’s pretty independent from libsdl operation. The sample SDL backend imgui provides uses SDL input controls but you still need some renderer support to accompany it (sample D3D9 and D3D11 renderers are provided). I’m not sure what sort of improved compatibility you’re talking about.

Both libraries just generate command queues in their internal formats that typically end up being pushed to the GPU. There’s an intersection of rendering APIs both libraries support (again: imgui doesn’t support any API internally; it is input and renderer agnostic, but provides samples for several popular options) and there are renderers that one has support/sample for and the other doesn’t (there’s no software renderer sample bundled with imgui for example; libsdl does contain a software renderer).

1 Like

thx for your answer @DominikD .
I use libraries built by myself, with the VisualC solution provided (so not the Cmake).
So I don’t know where I can change this SDL_VIDEO_RENDER_D3D11 settings in the VC++ project…

The name of the driver retruned by SDL_GetNumRenderDrivers and SDL_GetRenderDriverInfo is just “direct3d”, ad then “opengl”. No more precisions…

The SDL_HINT_RENDER_DRIVER return a bool “true” on "direct3d11"

By compatibility I mean that I would like to use on the same DX window some graphics drawn by SDL_Renderer functions AND on the top of that, some IMGUI widgets. But I cannot manage how to do that. Someway the imgui DX backend already has its function to create a DX renderer and SDL has its own function too : but they create 2 separated “contexts”, not shared. I cannot figure out how to share the same DX device…

Have a look at SDL\include\SDL_config_windows.h and search for SDL_VIDEO_RENDER_D3D11. Whether it’s sufficient for the included vcxproj to work - I don’t know, but it should help you start.

The way you can introduce this preprocessor macro is by adding it to the project settings C/C++ -> Preprocessor -> Preprocessor Definitions. Make sure it’s in all configuration on all platforms.

Combining SDL with imgui is slightly more involved. :slight_smile: