From 36f97f08ad15fd215d5138f9cef9f3e138cec49a Mon Sep 17 00:00:00 2001 From: vmfortress Date: Sat, 5 Mar 2022 23:26:56 -0500 Subject: [PATCH] [host] dxgi: add nanosecond-scale sleep capability to d3d12 The nsleep() call lets d3d12 sleep for a more precise amount of time while maintaining the current millisecond-scale sleep interface in the configuration file. --- host/platform/Windows/capture/DXGI/src/d3d12.c | 9 +++++---- host/platform/Windows/capture/DXGI/src/dxgi.c | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/host/platform/Windows/capture/DXGI/src/d3d12.c b/host/platform/Windows/capture/DXGI/src/d3d12.c index a9096131..83adcb0e 100644 --- a/host/platform/Windows/capture/DXGI/src/d3d12.c +++ b/host/platform/Windows/capture/DXGI/src/d3d12.c @@ -23,6 +23,7 @@ #include #include #include +#include "common/time.h" #include "common/debug.h" #include "common/option.h" #include "common/windebug.h" @@ -44,7 +45,7 @@ struct D3D12Texture struct D3D12Backend { - int copySleep; + float copySleep; ID3D12Device * device; ID3D12InfoQueue1 * debugInfoQueue; ID3D12CommandQueue * commandQueue; @@ -120,8 +121,8 @@ static bool d3d12_create(struct DXGIInterface * intf) return false; } - this->copySleep = option_get_int("dxgi", "d3d12CopySleep"); - DEBUG_INFO("Sleep before copy : %d ms", this->copySleep); + this->copySleep = option_get_float("dxgi", "d3d12CopySleep"); + DEBUG_INFO("Sleep before copy : %f ms", this->copySleep); status = D3D12CreateDevice((IUnknown *) dxgi->adapter, D3D_FEATURE_LEVEL_11_0, &IID_ID3D12Device, (void **)&this->device); @@ -346,7 +347,7 @@ static bool d3d12_copyFrame(Texture * parent, ID3D11Texture2D * src) HRESULT status; if (this->copySleep > 0) - Sleep(this->copySleep); + nsleep((uint64_t)(this->copySleep * 1000000)); HANDLE handle = INVALID_HANDLE_VALUE; diff --git a/host/platform/Windows/capture/DXGI/src/dxgi.c b/host/platform/Windows/capture/DXGI/src/dxgi.c index 9202d340..8c11316a 100644 --- a/host/platform/Windows/capture/DXGI/src/dxgi.c +++ b/host/platform/Windows/capture/DXGI/src/dxgi.c @@ -130,7 +130,7 @@ static void dxgi_initOptions(void) .module = "dxgi", .name = "d3d12CopySleep", .description = "Milliseconds to sleep before copying frame with d3d12", - .type = OPTION_TYPE_INT, + .type = OPTION_TYPE_FLOAT, .value.x_int = 5 }, {