Skip to content

Commit

Permalink
[host] d12: implement initial RGB24 support
Browse files Browse the repository at this point in the history
  • Loading branch information
gnif committed Feb 4, 2024
1 parent 4076377 commit 60b0156
Show file tree
Hide file tree
Showing 10 changed files with 704 additions and 89 deletions.
5 changes: 5 additions & 0 deletions common/include/common/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
#ifndef _H_LG_COMMON_UTIL_
#define _H_LG_COMMON_UTIL_

#include <stddef.h>

#ifndef min
#define min(a,b) ({ __typeof__ (a) _a = (a); __typeof__ (b) _b = (b); \
_a < _b ? _a : _b; })
Expand All @@ -43,4 +45,7 @@
#define unlikely(expr) __builtin_expect(!!(expr), 0)
#define likely(expr) __builtin_expect(!!(expr), 1)

#define _STR(x) #x
#define STR(x) _STR(x)

#endif
1 change: 1 addition & 0 deletions host/platform/Windows/capture/D12/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ add_library(capture_D12 STATIC
d12.c
command_group.c
backend/dd.c
effect/rgb24.c
)

target_link_libraries(capture_D12
Expand Down
6 changes: 3 additions & 3 deletions host/platform/Windows/capture/D12/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ struct D12Backend
unsigned frameBufferIndex);
};

static inline bool d12_backendCreate(
D12Backend * backend, D12Backend ** instance, unsigned frameBuffers)
static inline bool d12_backendCreate(const D12Backend * backend,
D12Backend ** instance, unsigned frameBuffers)
{
if (!backend->create(instance, frameBuffers))
return false;
Expand Down Expand Up @@ -90,6 +90,6 @@ static inline ID3D12Resource * d12_backendFetch(D12Backend * instance,

// Backend defines

extern D12Backend D12Backend_DD;
extern const D12Backend D12Backend_DD;

#endif
17 changes: 12 additions & 5 deletions host/platform/Windows/capture/D12/backend/dd.c
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,11 @@
typedef struct DDCacheInfo
{
D3D11_TEXTURE2D_DESC format;
ID3D11Texture2D ** srcTex;

/* this value is likely released, only used to check if the texture supplied
by DD is different, do not rely on it pointing to valid memory! */
ID3D11Texture2D * srcTex;

ID3D12Resource ** d12Res;
ID3D11Fence ** fence;
ID3D12Fence ** d12Fence;
Expand Down Expand Up @@ -386,7 +390,10 @@ static CaptureResult d12_dd_capture(D12Backend * instance,

// if this was not a frame update, go back and try again
if (frameInfo.LastPresentTime.QuadPart == 0)
{
comRef_release(res);
goto retry;
}

exit:
comRef_scopePop();
Expand Down Expand Up @@ -605,7 +612,7 @@ static bool d12_dd_getCache(DDInstance * this,
}

// check for a resource match
if (*cache->srcTex != srcTex)
if (cache->srcTex != srcTex)
continue;

// check if the match is not valid
Expand Down Expand Up @@ -715,8 +722,8 @@ static bool d12_dd_convertResource(DDInstance * this,
CloseHandle(sharedHandle);

// store the details
ID3D11Texture2D_AddRef(srcTex);
comRef_toGlobal(cache->srcTex , &srcTex );
cache->srcTex = srcTex;

comRef_toGlobal(cache->d12Res , dst );
comRef_toGlobal(cache->fence , fence );
comRef_toGlobal(cache->d12Fence, d12Fence);
Expand All @@ -730,7 +737,7 @@ static bool d12_dd_convertResource(DDInstance * this,
return result;
}

D12Backend D12Backend_DD =
const D12Backend D12Backend_DD =
{
.name = "Desktop Duplication",
.codeName = "DD",
Expand Down
20 changes: 14 additions & 6 deletions host/platform/Windows/capture/D12/command_group.c
Original file line number Diff line number Diff line change
Expand Up @@ -129,13 +129,21 @@ bool d12_commandGroupExecute(ID3D12CommandQueue * queue, D12CommandGroup * grp)
return false;
}

if (ID3D12Fence_GetCompletedValue(*grp->fence) < grp->fenceValue)
{
ID3D12Fence_SetEventOnCompletion(*grp->fence, grp->fenceValue, grp->event);
WaitForSingleObject(grp->event, INFINITE);
}
return true;
}

hr = ID3D12CommandAllocator_Reset(*grp->allocator);
void d12_commandGroupWait(D12CommandGroup * grp)
{
if (ID3D12Fence_GetCompletedValue(*grp->fence) >= grp->fenceValue)
return;

ID3D12Fence_SetEventOnCompletion(*grp->fence, grp->fenceValue, grp->event);
WaitForSingleObject(grp->event, INFINITE);
}

bool d12_commandGroupReset(D12CommandGroup * grp)
{
HRESULT hr = ID3D12CommandAllocator_Reset(*grp->allocator);
if (FAILED(hr))
{
DEBUG_WINERROR("Failed to reset the command allocator", hr);
Expand Down
4 changes: 4 additions & 0 deletions host/platform/Windows/capture/D12/command_group.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,8 @@ void d12_commandGroupFree(D12CommandGroup * grp);

bool d12_commandGroupExecute(ID3D12CommandQueue * queue, D12CommandGroup * grp);

void d12_commandGroupWait(D12CommandGroup * grp);

bool d12_commandGroupReset(D12CommandGroup * grp);

#endif
Loading

0 comments on commit 60b0156

Please sign in to comment.