From 5c4540ed8bce9157a9769614b04f65a525cd02d2 Mon Sep 17 00:00:00 2001 From: Geoffrey McRae Date: Wed, 28 Feb 2024 07:30:39 +1100 Subject: [PATCH] [host] d12: pass frame information in a description structure --- host/platform/Windows/capture/D12/backend.h | 23 +++++++----- .../platform/Windows/capture/D12/backend/dd.c | 9 ++--- host/platform/Windows/capture/D12/d12.c | 37 ++++++++----------- 3 files changed, 33 insertions(+), 36 deletions(-) diff --git a/host/platform/Windows/capture/D12/backend.h b/host/platform/Windows/capture/D12/backend.h index 5984d4b8..dbbd7025 100644 --- a/host/platform/Windows/capture/D12/backend.h +++ b/host/platform/Windows/capture/D12/backend.h @@ -29,6 +29,8 @@ typedef struct D12Backend D12Backend; +typedef struct D12FetchDesc D12FetchDesc; + struct D12Backend { // friendly name @@ -58,12 +60,15 @@ struct D12Backend CaptureResult (*sync)(D12Backend * instance, ID3D12CommandQueue * commandQueue); - ID3D12Resource * (*fetch)( - D12Backend * instance, - unsigned frameBufferIndex, - RECT ** dirtyRects, - unsigned * nbDirtyRects, - CaptureRotation * rotation); + ID3D12Resource * (*fetch)(D12Backend * instance, unsigned frameBufferIndex, + D12FetchDesc * meta); +}; + +struct D12FetchDesc +{ + CaptureRotation rotation; + RECT * dirtyRects; + unsigned nbDirtyRects; }; static inline bool d12_backendCreate(const D12Backend * backend, @@ -98,10 +103,8 @@ static inline CaptureResult d12_backendSync(D12Backend * instance, { return instance->sync(instance, commandQueue); } static inline ID3D12Resource * d12_backendFetch(D12Backend * instance, - unsigned frameBufferIndex, RECT ** dirtyRects, unsigned * nbDirtyRects, - CaptureRotation * rotation) - { return instance->fetch(instance, frameBufferIndex, dirtyRects, - nbDirtyRects, rotation); } + unsigned frameBufferIndex, D12FetchDesc * desc) + { return instance->fetch(instance, frameBufferIndex, desc); } // Backend defines diff --git a/host/platform/Windows/capture/D12/backend/dd.c b/host/platform/Windows/capture/D12/backend/dd.c index d7bb7026..2041b8f5 100644 --- a/host/platform/Windows/capture/D12/backend/dd.c +++ b/host/platform/Windows/capture/D12/backend/dd.c @@ -441,17 +441,16 @@ static CaptureResult d12_dd_sync(D12Backend * instance, } static ID3D12Resource * d12_dd_fetch(D12Backend * instance, - unsigned frameBufferIndex, RECT * dirtyRects[static D12_MAX_DIRTY_RECTS], - unsigned * nbDirtyRects, CaptureRotation * rotation) + unsigned frameBufferIndex, D12FetchDesc * desc) { DDInstance * this = UPCAST(DDInstance, instance); if (!this->current) return NULL; - *dirtyRects = this->current->dirtyRects; - *nbDirtyRects = this->current->nbDirtyRects; - *rotation = this->rotation; + desc->dirtyRects = this->current->dirtyRects; + desc->nbDirtyRects = this->current->nbDirtyRects; + desc->rotation = this->rotation; ID3D12Resource_AddRef(*this->current->d12Res); return *this->current->d12Res; diff --git a/host/platform/Windows/capture/D12/d12.c b/host/platform/Windows/capture/D12/d12.c index fde17ee5..348f53dd 100644 --- a/host/platform/Windows/capture/D12/d12.c +++ b/host/platform/Windows/capture/D12/d12.c @@ -428,13 +428,10 @@ static CaptureResult d12_waitFrame(unsigned frameBufferIndex, CaptureResult result = CAPTURE_RESULT_ERROR; comRef_scopePush(1); - RECT * dirtyRects; - unsigned nbDirtyRects; - CaptureRotation rotation; + D12FetchDesc desc; comRef_defineLocal(ID3D12Resource, src); - *src = d12_backendFetch(this->backend, frameBufferIndex, - &dirtyRects, &nbDirtyRects, &rotation); + *src = d12_backendFetch(this->backend, frameBufferIndex, &desc); if (!*src) { DEBUG_ERROR("D12 backend failed to produce an expected frame: %u", @@ -504,13 +501,14 @@ static CaptureResult d12_waitFrame(unsigned frameBufferIndex, CAPTURE_FMT_BGR_32 : CAPTURE_FMT_BGRA; frame->hdr = false; frame->hdrPQ = false; - frame->rotation = rotation; + frame->rotation = desc.rotation; { // create a clean list of rects - FrameDamageRect allRects[nbDirtyRects]; + FrameDamageRect allRects[desc.nbDirtyRects]; unsigned count = 0; - for(const RECT * rect = dirtyRects; rect < dirtyRects + nbDirtyRects; ++rect) + for(const RECT * rect = desc.dirtyRects; + rect < desc.dirtyRects + desc.nbDirtyRects; ++rect) allRects[count++] = (FrameDamageRect){ .x = rect->left, .y = rect->top, @@ -544,13 +542,10 @@ static CaptureResult d12_getFrame(unsigned frameBufferIndex, CaptureResult result = CAPTURE_RESULT_ERROR; comRef_scopePush(3); - RECT * dirtyRects; - unsigned nbDirtyRects; - CaptureRotation rotation; + D12FetchDesc desc; comRef_defineLocal(ID3D12Resource, src); - *src = d12_backendFetch(this->backend, frameBufferIndex, - &dirtyRects, &nbDirtyRects, &rotation); + *src = d12_backendFetch(this->backend, frameBufferIndex, &desc); if (!*src) { DEBUG_ERROR("D12 backend failed to produce an expected frame: %u", @@ -575,7 +570,7 @@ static CaptureResult d12_getFrame(unsigned frameBufferIndex, { next = d12_effectRun( this->effectRGB24, *this->device, *this->computeCommand.gfxList, next, - dirtyRects, &nbDirtyRects); + desc.dirtyRects, &desc.nbDirtyRects); } // copy into the framebuffer resource @@ -605,7 +600,7 @@ static CaptureResult d12_getFrame(unsigned frameBufferIndex, }; // if full frame damage - if (nbDirtyRects == 0) + if (desc.nbDirtyRects == 0) { this->nbDirtyRects = 0; ID3D12GraphicsCommandList_CopyTextureRegion( @@ -622,7 +617,7 @@ static CaptureResult d12_getFrame(unsigned frameBufferIndex, } else { - FrameDamageRect allRects[this->nbDirtyRects + nbDirtyRects]; + FrameDamageRect allRects[this->nbDirtyRects + desc.nbDirtyRects]; unsigned count = 0; /* we must update the rects that were dirty in the prior frame also, @@ -638,8 +633,8 @@ static CaptureResult d12_getFrame(unsigned frameBufferIndex, }; /* add the new dirtyRects to the array */ - for(const RECT * rect = dirtyRects; - rect < dirtyRects + nbDirtyRects; ++rect) + for(const RECT * rect = desc.dirtyRects; + rect < desc.dirtyRects + desc.nbDirtyRects; ++rect) allRects[count++] = (FrameDamageRect){ .x = rect->left, .y = rect->top, @@ -670,9 +665,9 @@ static CaptureResult d12_getFrame(unsigned frameBufferIndex, } /* store the dirty rects for the next frame */ - memcpy(this->dirtyRects, dirtyRects, - nbDirtyRects * sizeof(*this->dirtyRects)); - this->nbDirtyRects = nbDirtyRects; + memcpy(this->dirtyRects, desc.dirtyRects, + desc.nbDirtyRects * sizeof(*this->dirtyRects)); + this->nbDirtyRects = desc.nbDirtyRects; } // execute the compute commands