Skip to content

Commit

Permalink
Add FNA3D_REDUCED_FRAME_LATENCY support for D3D11
Browse files Browse the repository at this point in the history
  • Loading branch information
kg committed Jan 20, 2024
1 parent 880ca67 commit 075a70e
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
25 changes: 25 additions & 0 deletions src/FNA3D_Driver_D3D11.c
Original file line number Diff line number Diff line change
Expand Up @@ -2537,6 +2537,7 @@ static void D3D11_INTERNAL_CreateSwapChain(
HWND dxgiHandle;
void* factory4;
IDXGISwapChain3 *swapchain3;
IDXGIDevice1 *dxgiDevice;
DXGI_COLOR_SPACE_TYPE colorSpace;
HRESULT res;

Expand Down Expand Up @@ -2668,6 +2669,30 @@ static void D3D11_INTERNAL_CreateSwapChain(
}
}

if (SDL_GetHintBoolean("FNA3D_REDUCED_FRAME_LATENCY", SDL_FALSE))
{
/*
If possible, limit queued frames to 1. (The default is 3.)
This significantly reduces rendering latency, especially in windowed mode.
Note that this will reduce maximum framerate somewhat.
*/
if (SUCCEEDED(IDXGIDevice1_QueryInterface(
renderer->device,
&D3D_IID_IDXGIDevice1,
(void**)&dxgiDevice
)))
{
if (!SUCCEEDED(IDXGIDevice1_SetMaximumFrameLatency(dxgiDevice, 1)))
{
FNA3D_LogWarn("IDXGIDevice1_SetMaximumFrameLatency failed");
}
}
else
{
FNA3D_LogWarn("IDXGIDevice1_QueryInterface failed");
}
}

if (growSwapchains)
{
swapchainData = (D3D11SwapchainData*) SDL_malloc(sizeof(D3D11SwapchainData));
Expand Down
1 change: 1 addition & 0 deletions src/FNA3D_Driver_D3D11.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ static const IID D3D_IID_IDXGIFactory4 = {0x7632e1f5,0xee65,0x4dca,{0x87,0xfd,0x
static const IID D3D_IID_IDXGIFactory6 = {0xc1b6694f,0xff09,0x44a9,{0xb0,0x3c,0x77,0x90,0x0a,0x0a,0x1d,0x17}};
static const IID D3D_IID_IDXGIFactory5 = {0x7632e1f5,0xee65,0x4dca,{0x87,0xfd,0x84,0xcd,0x75,0xf8,0x83,0x8d}};
static const IID D3D_IID_IDXGIAdapter1 = {0x29038f61,0x3839,0x4626,{0x91,0xfd,0x08,0x68,0x79,0x01,0x1a,0x05}};
static const IID D3D_IID_IDXGIDevice1 = {0x77db970f,0x6276,0x48ba,{0xba,0x28,0x07,0x01,0x43,0xb4,0x39,0x2c}};
static const IID D3D_IID_IDXGISwapChain3 = {0x94d99bdb,0xf1f8,0x4ab0,{0xb2,0x36,0x7d,0xa0,0x17,0x0e,0xda,0xb1}};
static const IID D3D_IID_ID3D11Texture2D = {0x6f15aaf2,0xd208,0x4e89,{0x9a,0xb4,0x48,0x95,0x35,0xd3,0x4f,0x9c}};
static const IID D3D_IID_ID3DUserDefinedAnnotation = {0xb2daad8b,0x03d4,0x4dbf,{0x95,0xeb,0x32,0xab,0x4b,0x63,0xd0,0xab}};
Expand Down

0 comments on commit 075a70e

Please sign in to comment.