[host] d12: add wrappers for backend functions

This commit is contained in:
Geoffrey McRae 2024-01-31 10:18:56 +11:00
parent c07b72883a
commit be82b7e578
2 changed files with 34 additions and 12 deletions

View file

@ -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

View file

@ -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;