From 075a70e167e37af612ed4af49054427d52958944 Mon Sep 17 00:00:00 2001 From: Katelyn Gadd Date: Sat, 20 Jan 2024 12:39:49 -0800 Subject: [PATCH] Add FNA3D_REDUCED_FRAME_LATENCY support for D3D11 --- src/FNA3D_Driver_D3D11.c | 25 +++++++++++++++++++++++++ src/FNA3D_Driver_D3D11.h | 1 + 2 files changed, 26 insertions(+) diff --git a/src/FNA3D_Driver_D3D11.c b/src/FNA3D_Driver_D3D11.c index b9eab7bd..f2f68f8d 100644 --- a/src/FNA3D_Driver_D3D11.c +++ b/src/FNA3D_Driver_D3D11.c @@ -2537,6 +2537,7 @@ static void D3D11_INTERNAL_CreateSwapChain( HWND dxgiHandle; void* factory4; IDXGISwapChain3 *swapchain3; + IDXGIDevice1 *dxgiDevice; DXGI_COLOR_SPACE_TYPE colorSpace; HRESULT res; @@ -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)); diff --git a/src/FNA3D_Driver_D3D11.h b/src/FNA3D_Driver_D3D11.h index 165e3125..de2a88a8 100644 --- a/src/FNA3D_Driver_D3D11.h +++ b/src/FNA3D_Driver_D3D11.h @@ -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}};