Skip to content

Commit

Permalink
[host] dxgi: d3d12 now writes direclty into ivshmem
Browse files Browse the repository at this point in the history
This is still incomplete as d3d12 doesn't have any proper sync with the
captured frame and as such is still not suggested for general usage. This
change though is monumental for this project as it removes a full memory
copy reducing bandwidth consumption enormously.
  • Loading branch information
gnif committed Jan 27, 2024
1 parent adaf40e commit 34e8a22
Show file tree
Hide file tree
Showing 10 changed files with 22,956 additions and 12,346 deletions.
5 changes: 3 additions & 2 deletions host/include/interface/capture.h
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,18 @@ typedef struct CaptureInterface
void (*initOptions )(void);

bool(*create)(
void * ivshmemBase,
CaptureGetPointerBuffer getPointerBufferFn,
CapturePostPointerBuffer postPointerBufferFn
);

bool (*init )(void);
bool (*init )(unsigned * alignSize);
bool (*start )(void);
void (*stop )(void);
bool (*deinit )(void);
void (*free )(void);

CaptureResult (*capture )(void);
CaptureResult (*capture )(unsigned frameBufferIndex, FrameBuffer * frame);
CaptureResult (*waitFrame )(CaptureFrame * frame, const size_t maxFrameSize);
CaptureResult (*getFrame )(FrameBuffer * frame, int frameIndex);
}
Expand Down
2 changes: 1 addition & 1 deletion host/platform/Windows/capture/DXGI/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ add_library(capture_DXGI STATIC
src/pp/rgb24.c
)

add_definitions("-DCOBJMACROS -DINITGUID")
add_definitions("-DCOBJMACROS -DINITGUID -DWIDL_C_INLINE_WRAPPERS")

target_link_libraries(capture_DXGI
lg_common
Expand Down
14 changes: 12 additions & 2 deletions host/platform/Windows/capture/DXGI/src/backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,11 @@ struct DXGICopyBackend
const char * code;

// create the copy backend
bool (*create)(unsigned textures);
bool (*create)(
void * ivshmemBase,
unsigned * alignSize,
unsigned frameBuffers,
unsigned textures);

// configure the copy backend with the specified format
bool (*configure)(
Expand All @@ -50,7 +54,10 @@ struct DXGICopyBackend
void (*free)(void);

// called just before the copy starts
bool (*preCopy)(ID3D11Texture2D * src, unsigned textureIndex);
bool (*preCopy)(ID3D11Texture2D * src,
unsigned textureIndex,
unsigned frameBufferIndex,
FrameBuffer * frameBuffer);

// called to copy the full frame
bool (*copyFull)(ID3D11Texture2D * src, unsigned textureIndex);
Expand All @@ -65,6 +72,9 @@ struct DXGICopyBackend
// maps the copied frame into memory
CaptureResult (*mapTexture)(unsigned textureIndex, void ** map);

// [optional] backend specific write into the FrameBuffer
CaptureResult (*writeFrame)(int textureIndex, FrameBuffer * frame);

// unmaps the copied frame from memory
void (*unmapTexture)(unsigned textureIndex);

Expand Down
12 changes: 10 additions & 2 deletions host/platform/Windows/capture/DXGI/src/d3d11.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,11 @@ struct D3D11Backend

static struct D3D11Backend * this = NULL;

static bool d3d11_create(unsigned textures)
static bool d3d11_create(
void * ivshmemBase,
unsigned * alignSize,
unsigned frameBuffers,
unsigned textures)
{
DEBUG_ASSERT(!this);
this = calloc(1,
Expand Down Expand Up @@ -128,7 +132,11 @@ static void d3d11_free(void)
this = NULL;
}

static bool d3d11_preCopy(ID3D11Texture2D * src, unsigned textureIndex)
static bool d3d11_preCopy(
ID3D11Texture2D * src,
unsigned textureIndex,
unsigned frameBufferIndex,
FrameBuffer * frameBuffer)
{
dxgi_contextLock();
this->texture[textureIndex].copyTime = microtime();
Expand Down
Loading

0 comments on commit 34e8a22

Please sign in to comment.