Skip to content

Commit

Permalink
win-capture: shared texture data includes system timestamp when the t…
Browse files Browse the repository at this point in the history
…exture was captured
  • Loading branch information
lostmsu committed Apr 24, 2023
1 parent 2db38e1 commit a4bfe03
Show file tree
Hide file tree
Showing 8 changed files with 42 additions and 4 deletions.
2 changes: 2 additions & 0 deletions plugins/win-capture/graphics-hook-info.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,12 @@ struct shmem_data {
volatile int last_tex;
uint32_t tex1_offset;
uint32_t tex2_offset;
uint64_t timestamp;
};

struct shtex_data {
uint32_t tex_handle;
uint64_t timestamp;
};

enum capture_type {
Expand Down
1 change: 1 addition & 0 deletions plugins/win-capture/graphics-hook/d3d8-capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,7 @@ static void d3d8_capture(IDirect3DDevice8 *device,
}
if (capture_ready()) {
d3d8_shmem_capture(device, backbuffer);
shmem_update_timestamp();
signal_frame_ready();
}
}
Expand Down
7 changes: 5 additions & 2 deletions plugins/win-capture/graphics-hook/d3d9-capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -585,10 +585,13 @@ static void d3d9_capture(IDirect3DDevice9 *device,
return;
}

if (data.using_shtex)
if (data.using_shtex) {
d3d9_shtex_capture(backbuffer);
else
shtex_update_timestamp();
} else {
d3d9_shmem_capture(backbuffer);
shmem_update_timestamp();
}

signal_frame_ready();
}
Expand Down
4 changes: 4 additions & 0 deletions plugins/win-capture/graphics-hook/dxgi-capture.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,7 @@ static HRESULT STDMETHODCALLTYPE hook_present(IDXGISwapChain *swap,

if (backbuffer) {
data.capture(swap, backbuffer);
shtex_update_timestamp();
signal_frame_ready();
backbuffer->Release();
}
Expand All @@ -251,6 +252,7 @@ static HRESULT STDMETHODCALLTYPE hook_present(IDXGISwapChain *swap,

if (backbuffer) {
data.capture(swap, backbuffer);
shtex_update_timestamp();
signal_frame_ready();
backbuffer->Release();
}
Expand Down Expand Up @@ -293,6 +295,7 @@ hook_present1(IDXGISwapChain1 *swap, UINT sync_interval, UINT flags,

if (backbuffer) {
data.capture(swap, backbuffer);
shtex_update_timestamp();
signal_frame_ready();
backbuffer->Release();
}
Expand All @@ -311,6 +314,7 @@ hook_present1(IDXGISwapChain1 *swap, UINT sync_interval, UINT flags,

if (backbuffer) {
data.capture(swap, backbuffer);
shtex_update_timestamp();
signal_frame_ready();
backbuffer->Release();
}
Expand Down
3 changes: 2 additions & 1 deletion plugins/win-capture/graphics-hook/gl-capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -628,6 +628,7 @@ static void gl_shtex_capture(void)

jimglDXUnlockObjectsNV(data.gl_device, 1, &data.gl_dxobj);

shtex_update_timestamp();
signal_frame_ready();

IDXGISwapChain_Present(data.dxgi_swap, 0, 0);
Expand All @@ -650,7 +651,7 @@ static void gl_shmem_capture_copy(int i)
if (buffer) {
data.texture_mapped[i] = true;
shmem_copy_data(i, buffer);

shmem_update_timestamp();
signal_frame_ready();
}
}
Expand Down
6 changes: 5 additions & 1 deletion plugins/win-capture/graphics-hook/graphics-hook.c
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ wchar_t keepalive_name[64] = {0};
HWND dummy_window = NULL;

static unsigned int shmem_id_counter = 0;
static void *shmem_info = NULL;
void *shmem_info = NULL;
static HANDLE shmem_file_handle = 0;

static struct thread_data thread_data = {0};
Expand Down Expand Up @@ -570,6 +570,7 @@ bool capture_init_shtex(struct shtex_data **data, HWND window, uint32_t cx,

*data = shmem_info;
(*data)->tex_handle = (uint32_t)handle;
(*data)->timestamp = 0;

global_hook_info->hook_ver_major = HOOK_VER_MAJOR;
global_hook_info->hook_ver_minor = HOOK_VER_MINOR;
Expand Down Expand Up @@ -640,6 +641,8 @@ static DWORD CALLBACK copy_thread(LPVOID unused)
((struct shmem_data *)shmem_info)->last_tex =
lock_id;

shmem_update_timestamp();

shmem_id = lock_id == 0 ? 1 : 0;
}

Expand Down Expand Up @@ -765,6 +768,7 @@ bool capture_init_shmem(struct shmem_data **data, HWND window, uint32_t cx,
(*data)->last_tex = -1;
(*data)->tex1_offset = (uint32_t)align_pos;
(*data)->tex2_offset = (*data)->tex1_offset + aligned_tex;
(*data)->timestamp = 0;

global_hook_info->hook_ver_major = HOOK_VER_MAJOR;
global_hook_info->hook_ver_minor = HOOK_VER_MINOR;
Expand Down
22 changes: 22 additions & 0 deletions plugins/win-capture/graphics-hook/graphics-hook.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ extern char system_path[MAX_PATH];
extern char process_name[MAX_PATH];
extern wchar_t keepalive_name[64];
extern HWND dummy_window;
extern void *shmem_info;
extern volatile bool active;

static inline const char *get_process_name(void)
Expand Down Expand Up @@ -164,6 +165,27 @@ static inline bool capture_active(void)
return active;
}

static inline void update_timestamp(uint64_t *ts)
{
InterlockedExchange64((LONG64 *)ts, os_gettime_ns());
}

static inline void shtex_update_timestamp()
{
if (!shmem_info)
return;

update_timestamp(&((struct shtex_data *)shmem_info)->timestamp);
}

static inline void shmem_update_timestamp()
{
if (!shmem_info)
return;

update_timestamp(&((struct shmem_data *)shmem_info)->timestamp);
}

static inline void signal_frame_ready()
{
if (!SetEvent(signal_frame)) {
Expand Down
1 change: 1 addition & 0 deletions plugins/win-capture/graphics-hook/vulkan-capture.c
Original file line number Diff line number Diff line change
Expand Up @@ -1168,6 +1168,7 @@ static void vk_shtex_capture(struct vk_data *data,

if (res == VK_SUCCESS) {
frame_data->cmd_buffer_busy = true;
shtex_update_timestamp();
signal_frame_ready();
}
}
Expand Down

0 comments on commit a4bfe03

Please sign in to comment.