From f1c34cf4a2e6f152f98f2ba941a6f20cb0832b4b Mon Sep 17 00:00:00 2001 From: Fabrice Desclaux Date: Wed, 14 Dec 2022 11:08:17 +0100 Subject: [PATCH] Set dxgi latency to 1 frame --- sanzu/src/server_windows.rs | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/sanzu/src/server_windows.rs b/sanzu/src/server_windows.rs index 036edf2..1720db9 100644 --- a/sanzu/src/server_windows.rs +++ b/sanzu/src/server_windows.rs @@ -332,6 +332,34 @@ fn d3d11_get_device_idxgidevice(device: &d3d11::ID3D11Device) -> Result<&dxgi::I unsafe { p_idxgidevice.as_ref() }.context("Null idxgiadapter") } +fn d3d11_get_device_idxgidevice1(device: &d3d11::ID3D11Device) -> Result<&dxgi::IDXGIDevice1> { + /* GUID_ENTRY(0x77db970f,0x6276,0x48ba,0xba,0x28,0x07,0x01,0x43,0xb4,0x39,0x2c,IID_IDXGIDevice1) */ + let riid_idxgidevice1 = GUID { + Data1: 0x77db970f, + Data2: 0x6276, + Data3: 0x48ba, + Data4: [0xba, 0x28, 0x07, 0x01, 0x43, 0xb4, 0x39, 0x2c], + }; + + let mut p_idxgidevice1: *mut c_void = null_mut(); + + let ret = unsafe { + device.QueryInterface( + &riid_idxgidevice1 as *const _, + &mut p_idxgidevice1 as *mut _, + ) + }; + + if SUCCEEDED(ret) { + info!("Query interface success {:?}", p_idxgidevice1); + } else { + error!("Error in queryinterface"); + return Err(anyhow!("Error in query interface idxgidevice1")); + } + let p_idxgidevice1: *mut dxgi::IDXGIDevice1 = unsafe { std::mem::transmute(p_idxgidevice1) }; + unsafe { p_idxgidevice1.as_ref() }.context("Null idxgiadapter1") +} + fn d3d11_get_idxgidevice_idxgiadapter( idxgidevice: &dxgi::IDXGIDevice, ) -> Result<&dxgi::IDXGIAdapter> { @@ -601,6 +629,11 @@ pub fn init_d3d11() -> Result<()> { let idxgidevice = d3d11_get_device_idxgidevice(d3d11_device).context("Cannot get idxgidevice")?; + if let Ok(idxgidevice1) = d3d11_get_device_idxgidevice1(d3d11_device) { + let ret = unsafe { idxgidevice1.SetMaximumFrameLatency(1) }; + error!("Set max frame latency: {:x}", ret); + } + let idxgiadapter = d3d11_get_idxgidevice_idxgiadapter(idxgidevice).context("Cannot get idxgiadapter")?;