Skip to content

Commit

Permalink
Fix network stalling at swap buffers sync, use MIN
Browse files Browse the repository at this point in the history
  • Loading branch information
dmaivel committed Jul 29, 2024
1 parent c1cd5a0 commit 9a02088
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
8 changes: 8 additions & 0 deletions inc/sharedgl.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,14 @@
#define UNPACK_A(packed) (((packed) >> 16) & 0xFFFF)
#define UNPACK_B(packed) ((packed) & 0xFFFF)

#ifndef MIN
#define MIN( A, B ) ( (A)<(B) ? (A) : (B) )
#endif

#ifndef MAX
#define MAX( A, B ) ( (A)>(B) ? (A) : (B) )
#endif

#ifdef _WIN32
# define FORCEINLINE __forceinline
#else
Expand Down
7 changes: 5 additions & 2 deletions src/client/glimpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -318,6 +318,7 @@ static const char glimpl_extensions_list[NUM_EXTENSIONS][48] = {
static struct net_context *net_ctx = NULL;
static int *fake_register_space = NULL;
static int *fake_framebuffer = NULL;
static int fake_swap_buffers_sync = 0;

static int glimpl_major = SGL_DEFAULT_MAJOR;
static int glimpl_minor = SGL_DEFAULT_MINOR;
Expand Down Expand Up @@ -356,6 +357,8 @@ static void *pb_ptr_hook(size_t offset)
return &fake_register_space[0];
case SGL_OFFSET_REGISTER_RETVAL_V:
return &fake_register_space[2];
case SGL_OFFSET_REGISTER_SWAP_BUFFERS_SYNC:
return &fake_swap_buffers_sync;
default:
fprintf(stderr, "pb_ptr_hook: defaulted to pb_iptr, possible undefined behavior\n");
return pb_iptr(offset);
Expand Down Expand Up @@ -435,7 +438,7 @@ static inline void submit_net()
* packet
*/
for (int i = 0; i < blocks; i++) {
size_t packet_count = count > SGL_FIFO_UPLOAD_COMMAND_BLOCK_COUNT ? SGL_FIFO_UPLOAD_COMMAND_BLOCK_COUNT : count;
size_t packet_count = MIN(count, SGL_FIFO_UPLOAD_COMMAND_BLOCK_COUNT);

struct sgl_packet_fifo_upload packet = {
/* client_id = */ client_id,
Expand Down Expand Up @@ -763,7 +766,7 @@ static inline void glimpl_download_buffer(void *dst, size_t size)
void *retval_v = pb_ptr(SGL_OFFSET_REGISTER_RETVAL_V);

for (int i = 0; i < blocks; i++) {
size_t true_count = count > SGL_VP_DOWNLOAD_BLOCK_SIZE_IN_BYTES ? SGL_VP_DOWNLOAD_BLOCK_SIZE_IN_BYTES : count;
size_t true_count = MIN(count, SGL_VP_DOWNLOAD_BLOCK_SIZE_IN_BYTES);

pb_push(SGL_CMD_VP_DOWNLOAD);
pb_push(true_count);
Expand Down
5 changes: 1 addition & 4 deletions src/client/platform/windrv.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,6 @@ static void *swap_sync_lock;
ICD_SET_MAX_DIMENSIONS_DEFINITION(max_width, max_height, real_width, real_height);
ICD_RESIZE_DEFINITION(real_width, real_height);

#define MIN_INTERNAL( A, B ) ( (A)<(B) ? (A) : (B) )
#define MAX_INTERNAL( A, B ) ( (A)>(B) ? (A) : (B) )

typedef HGLRC(WINAPI * wglCreateContext_t )(HDC);
typedef BOOL(WINAPI * wglDeleteContext_t )(HGLRC);

Expand Down Expand Up @@ -284,7 +281,7 @@ PROC APIENTRY DrvGetProcAddress(LPCSTR lpszProc)

void APIENTRY DrvSetCallbackProcs(INT nProcs, PROC *pProcs)
{
size_t size = MIN_INTERNAL(nProcs * sizeof(*pProcs), sizeof(callbacks));
size_t size = MIN(nProcs * sizeof(*pProcs), sizeof(callbacks));
memcpy(&callbacks, pProcs, size);

return;
Expand Down

0 comments on commit 9a02088

Please sign in to comment.