Skip to content

Commit

Permalink
[host] d12: add wrappers for backend functions
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Jan 30, 2024
1 parent c07b728 commit be82b7e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
31 changes: 27 additions & 4 deletions host/platform/Windows/capture/D12/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand All @@ -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
15 changes: 7 additions & 8 deletions host/platform/Windows/capture/D12/d12.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -278,8 +278,7 @@ static bool d12_init(void * ivshmemBase, unsigned * alignSize)
*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 );
Expand Down Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -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;

Expand Down

0 comments on commit be82b7e

Please sign in to comment.