From be82b7e5783083dd3400cfac21edbaa3ae7bf7af Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 31 Jan 2024 10:18:56 +1100 Subject: [PATCH] [host] d12: add wrappers for backend functions --- host/platform/Windows/capture/D12/backend.h | 31 ++++++++++++++++++--- host/platform/Windows/capture/D12/d12.c | 15 +++++----- 2 files changed, 34 insertions(+), 12 deletions(-) diff --git a/host/platform/Windows/capture/D12/backend.h b/host/platform/Windows/capture/D12/backend.h index 23df0cd2..11859503 100644 --- a/host/platform/Windows/capture/D12/backend.h +++ b/host/platform/Windows/capture/D12/backend.h @@ -57,9 +57,7 @@ struct D12Backend unsigned frameBufferIndex); }; -// helpers for the interface - -static inline bool d12_createBackend( +static inline bool d12_backendCreate( D12Backend * backend, D12Backend ** instance, unsigned frameBuffers) { if (!backend->create(instance, frameBuffers)) @@ -68,10 +66,35 @@ static inline bool d12_createBackend( return true; } -// apis for the backend +static inline bool d12_backendInit(D12Backend * instance, bool debug, + ID3D12Device3 * device, IDXGIAdapter1 * adapter, IDXGIOutput * output) + { return instance->init(instance, debug, device, adapter, output); } + +static inline bool d12_backendDeinit(D12Backend * instance) + { return instance->deinit(instance); } + +static inline void d12_backendFree(D12Backend ** instance) + { (*instance)->free(instance); } + +static inline CaptureResult d12_backendCapture(D12Backend * instance, + unsigned frameBufferIndex) + { return instance->capture(instance, frameBufferIndex); } + +static inline CaptureResult d12_backendSync(D12Backend * instance, + ID3D12CommandQueue * commandQueue) + { return instance->sync(instance, commandQueue); } + +static inline ID3D12Resource * d12_backendFetch(D12Backend * instance, + unsigned frameBufferIndex) + { return instance->fetch(instance, frameBufferIndex); } + +// APIs for the backend to call + void d12_updatePointer( CapturePointer * pointer, void * shape, size_t shapeSize); +// Backend defines + extern D12Backend D12Backend_DD; #endif diff --git a/host/platform/Windows/capture/D12/d12.c b/host/platform/Windows/capture/D12/d12.c index 36af179b..acbb51e9 100644 --- a/host/platform/Windows/capture/D12/d12.c +++ b/host/platform/Windows/capture/D12/d12.c @@ -166,7 +166,7 @@ static bool d12_create( this->getPointerBufferFn = getPointerBufferFn; this->postPointerBufferFn = postPointerBufferFn; - if (!d12_createBackend(&D12Backend_DD, &this->backend, frameBuffers)) + if (!d12_backendCreate(&D12Backend_DD, &this->backend, frameBuffers)) { DEBUG_ERROR("backend \"%s\" failed to create", this->backend->codeName); CloseHandle(this->d3d12); @@ -278,8 +278,7 @@ retryCreateCommandQueue: *alignSize = heapDesc.Alignment; // initialize the backend - if (!this->backend->init(this->backend, - this->debug, *device, *adapter, *output)) + if (!d12_backendInit(this->backend, this->debug, *device, *adapter, *output)) goto exit; comRef_toGlobal(this->factory , factory ); @@ -314,7 +313,7 @@ static bool d12_deinit(void) static void d12_free(void) { - this->backend->free(&this->backend); + d12_backendFree(&this->backend); FreeLibrary(this->d3d12); free(this); this = NULL; @@ -323,7 +322,7 @@ static void d12_free(void) static CaptureResult d12_capture( unsigned frameBufferIndex, FrameBuffer * frameBuffer) { - return this->backend->capture(this->backend, frameBufferIndex); + return d12_backendCapture(this->backend, frameBufferIndex); } static CaptureResult d12_waitFrame(unsigned frameBufferIndex, @@ -333,7 +332,7 @@ static CaptureResult d12_waitFrame(unsigned frameBufferIndex, comRef_scopePush(1); comRef_defineLocal(ID3D12Resource, src); - *src = this->backend->fetch(this->backend, frameBufferIndex); + *src = d12_backendFetch(this->backend, frameBufferIndex); if (!*src) { DEBUG_ERROR("D12 backend failed to produce an expected frame: %u", @@ -383,7 +382,7 @@ static CaptureResult d12_getFrame(unsigned frameBufferIndex, comRef_scopePush(2); comRef_defineLocal(ID3D12Resource, src); - *src = this->backend->fetch(this->backend, frameBufferIndex); + *src = d12_backendFetch(this->backend, frameBufferIndex); if (!*src) { DEBUG_ERROR("D12 backend failed to produce an expected frame: %u", @@ -427,7 +426,7 @@ static CaptureResult d12_getFrame(unsigned frameBufferIndex, *this->copyCommand.gfxList, &dstLoc, 0, 0, 0, &srcLoc, NULL); // allow the backend to insert a fence into the command queue if it needs it - result = this->backend->sync(this->backend, *this->commandQueue); + result = d12_backendSync(this->backend, *this->commandQueue); if (result != CAPTURE_RESULT_OK) goto exit;