Skip to content

Commit

Permalink
Prefer DX11 renderer if running on windows with vsync active
Browse files Browse the repository at this point in the history
This works around a bug in DX9 on Win11.
  • Loading branch information
ephphatha authored and AJenbo committed Dec 17, 2021
1 parent 0d44d95 commit 530604c
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions Source/utils/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -269,11 +269,25 @@ void ReinitializeRenderer()
rendererFlags |= SDL_RENDERER_PRESENTVSYNC;
}

#ifdef _WIN32
// On Windows 11 the directx9 VSYNC timer doesn't get recreated properly, see https://github.com/libsdl-org/SDL/issues/5099
// Attempt to use the directx11 driver instead if we have vsync active.
const char *const renderHint = SDL_GetHint(SDL_HINT_RENDER_DRIVER);
if ((rendererFlags & SDL_RENDERER_PRESENTVSYNC) != 0 && SDL_SetHint(SDL_HINT_RENDER_DRIVER, "direct3d11") != SDL_TRUE) {
Log("Error when trying to set hint for direct3d11, using default render driver");
}
#endif

renderer = SDL_CreateRenderer(ghMainWnd, -1, rendererFlags);
if (renderer == nullptr) {
ErrSdl();
}

#ifdef _WIN32
// Restore any system/user defined hint just in case they turn off upscale/vsync.
SDL_SetHint(SDL_HINT_RENDER_DRIVER, renderHint);
#endif

auto quality = fmt::format("{}", static_cast<int>(*sgOptions.Graphics.scaleQuality));
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, quality.c_str());

Expand Down

0 comments on commit 530604c

Please sign in to comment.