From cf7d501bc457427387e4d3729a0c21ce93bcbf84 Mon Sep 17 00:00:00 2001 From: Quantum Date: Sun, 9 Jan 2022 22:23:59 -0500 Subject: [PATCH] [host] dxgi: allow copy backend selection --- .../platform/Windows/capture/DXGI/src/d3d11.c | 1 + .../platform/Windows/capture/DXGI/src/d3d12.c | 1 + host/platform/Windows/capture/DXGI/src/dxgi.c | 22 +++++++++++++++---- .../Windows/capture/DXGI/src/dxgi_capture.h | 1 + 4 files changed, 21 insertions(+), 4 deletions(-) diff --git a/host/platform/Windows/capture/DXGI/src/d3d11.c b/host/platform/Windows/capture/DXGI/src/d3d11.c index eec0bf51..292d53b9 100644 --- a/host/platform/Windows/capture/DXGI/src/d3d11.c +++ b/host/platform/Windows/capture/DXGI/src/d3d11.c @@ -195,6 +195,7 @@ static void d3d11_preRelease(void) struct DXGICopyBackend copyBackendD3D11 = { .name = "Direct3D 11", + .code = "d3d11", .create = d3d11_create, .free = d3d11_free, .copyFrame = d3d11_copyFrame, diff --git a/host/platform/Windows/capture/DXGI/src/d3d12.c b/host/platform/Windows/capture/DXGI/src/d3d12.c index cca2d90f..4968cda0 100644 --- a/host/platform/Windows/capture/DXGI/src/d3d12.c +++ b/host/platform/Windows/capture/DXGI/src/d3d12.c @@ -446,6 +446,7 @@ static void d3d12_preRelease(void) struct DXGICopyBackend copyBackendD3D12 = { .name = "Direct3D 12", + .code = "d3d12", .create = d3d12_create, .free = d3d12_free, .copyFrame = d3d12_copyFrame, diff --git a/host/platform/Windows/capture/DXGI/src/dxgi.c b/host/platform/Windows/capture/DXGI/src/dxgi.c index 625a1220..340acee2 100644 --- a/host/platform/Windows/capture/DXGI/src/dxgi.c +++ b/host/platform/Windows/capture/DXGI/src/dxgi.c @@ -106,6 +106,13 @@ static void dxgi_initOptions(void) .type = OPTION_TYPE_BOOL, .value.x_bool = false }, + { + .module = "dxgi", + .name = "copyBackend", + .description = "The copy backend to use, i.e. d3d11 or d3d12", + .type = OPTION_TYPE_STRING, + .value.x_string = "d3d11", + }, {0} }; @@ -487,10 +494,17 @@ static bool dxgi_init(void) goto fail; } + const char * copyBackend = option_get_string("dxgi", "copyBackend"); for (int i = 0; i < ARRAY_LENGTH(backends); ++i) { - if (backends[i]->create(this)) + if (!strcasecmp(copyBackend, backends[i]->code)) { + if (!backends[i]->create(this)) + { + DEBUG_ERROR("Failed to initialize selected capture backend: %s", backends[i]->name); + goto fail; + } + this->backend = backends[i]; break; } @@ -498,12 +512,12 @@ static bool dxgi_init(void) if (!this->backend) { - DEBUG_ERROR("Could not find a usable copy backend"); + DEBUG_ERROR("Could not find copy backend: %s", copyBackend); goto fail; } - DEBUG_INFO("Copy backend : %s", this->backend->name); - DEBUG_INFO("AcquireLock : %s", this->useAcquireLock ? "enabled" : "disabled"); + DEBUG_INFO("Copy backend : %s", this->backend->name); + DEBUG_INFO("AcquireLock : %s", this->useAcquireLock ? "enabled" : "disabled"); for (int i = 0; i < this->maxTextures; ++i) this->texture[i].texDamageCount = -1; diff --git a/host/platform/Windows/capture/DXGI/src/dxgi_capture.h b/host/platform/Windows/capture/DXGI/src/dxgi_capture.h index 65e25456..72055acd 100644 --- a/host/platform/Windows/capture/DXGI/src/dxgi_capture.h +++ b/host/platform/Windows/capture/DXGI/src/dxgi_capture.h @@ -108,6 +108,7 @@ struct DXGIInterface struct DXGICopyBackend { const char * name; + const char * code; bool (*create)(struct DXGIInterface * intf); void (*free)(void); bool (*copyFrame)(Texture * tex, ID3D11Texture2D * src);