Skip to content

Commit

Permalink
Enable vsync on multiple pipes on top of v1.0.0
Browse files Browse the repository at this point in the history
Signed-off-by: Eshe N Pickett <[email protected]>
  • Loading branch information
eshenayo committed Dec 21, 2023
1 parent c1a76cc commit c849178
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 11 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
*.swp
*.so
*.o
*.exe
*.lib
*.dll
*~
release/
30 changes: 24 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,34 @@
This program allows a system to alter their vertical sync firing times.
This is sample code only and is only supported on 11th Gen Core.

Building steps:
1) sudo apt install libdrm-dev libpciaccess-dev
1) Type 'make release' from the main directory. It compiles everything and creates a
# Prerequisites
The build system assumes the following, prior to executing the build steps:
1) The system has an [Ubuntu OS](https://ubuntu.com/tutorials/install-ubuntu-desktop#1-overview)
1) Libraries installed: `sudo apt install -y git build-essential make`

# Building steps:
1) Git clone this repository
1) `sudo apt install libdrm-dev libpciaccess-dev`
1) If the directory /usr/include/drm does not exist, you may need to also add `sudo apt install -y linux-libc-dev`
1) Type `make release` from the main directory. It compiles everything and creates a
release folder which can then be copied to the target systems.

Building of this program has been succesfully tested on both Ubuntu 20 and Fedora 30.

Installing and running the programs:
# Installing and running the programs:
1) On the system, go to the directory where these files exist and set environment variable:
export LD_LIBRARY_PATH=.
```console
export LD_LIBRARY_PATH=`pwd`
``````
2) On the primary system, run it as follows:
./synctest
```console
./synctest
```

(Note by default this is set to move vsync by 1.0 ms.)

# Helpful libraries to have installed
If you are doing debug, it helps to have the following libraries installed:
```
apt install -y intel-gpu-tools edid-decode
```
2 changes: 1 addition & 1 deletion cmn/vsyncalter.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
int vsync_lib_init();
void vsync_lib_uninit();
void synchronize_vsync(double time_diff);
int get_vsync(long *vsync_array, int size);
int get_vsync(long *vsync_array, int size, int pipe = 0);
int find_enabled_combo_phys();

#endif
42 changes: 39 additions & 3 deletions lib/vsyncalter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ typedef struct _vbl_info {
long *vsync_array;
int size;
int counter;
int pipe;
} vbl_info;


Expand Down Expand Up @@ -354,6 +355,9 @@ static int make_timer(long expire_ms, void *user_ptr, timer_t *t)
return -1;
}

/* Ensure that alarm struct is zeroed out prior to use */
memset(&te, 0, sizeof te);

/* Set and enable alarm */
te.sigev_notify = SIGEV_SIGNAL;
te.sigev_signo = sig_no;
Expand Down Expand Up @@ -768,6 +772,33 @@ static void vblank_handler(int fd, unsigned int frame, unsigned int sec,
drmWaitVBlank(g_dev_fd, &vbl);
}

/*******************************************************************************
* Description
* pipe_to_wait_for - This function determines the type of vblank synchronization to
* use for the output.
*Parameters
* int pipe - Indicates which CRTC to get vblank for. Knowing this, we
* can determine which vblank sequence type to use for it. Traditional
* cards had only two CRTCs, with CRTC 0 using no special flags, and
* CRTC 1 using DRM_VBLANK_SECONDARY. The first bit of the pipe
* Bits 1-5 of the pipe parameter are 5 bit wide pipe number between
* 0-31. If this is non-zero it indicates we're dealing with a
* multi-gpu situation and we need to calculate the vblank sync
* using DRM_BLANK_HIGH_CRTC_MASK.
* Return val
* int - The flag to OR in for drmWaitVBlank API
******************************************************************************/
unsigned int pipe_to_wait_for(int pipe)
{
int ret = 0;
if (pipe > 1) {
ret = (pipe << DRM_VBLANK_HIGH_CRTC_SHIFT) & DRM_VBLANK_HIGH_CRTC_MASK;
} else if (pipe > 0) {
ret = DRM_VBLANK_SECONDARY;
}
return ret;
}

/*******************************************************************************
* Description
* get_vsync - This function gets a list of vsyncs for the number of times
Expand All @@ -776,10 +807,12 @@ static void vblank_handler(int fd, unsigned int frame, unsigned int sec,
* long *vsync_array - The array in which vsync timestamps need to be given
* int size - The size of this array. This is also the number of times that we
* need to get the next few vsync timestamps.
* int pipe - This is the pipe whose vblank is needed. Defaults to 0 if not
* provided.
* Return val
* int - 0 == SUCCESS, -1 = ERROR
******************************************************************************/
int get_vsync(long *vsync_array, int size)
int get_vsync(long *vsync_array, int size, int pipe)
{
drmVBlank vbl;
int ret;
Expand All @@ -797,9 +830,12 @@ int get_vsync(long *vsync_array, int size)
handler_info.vsync_array = vsync_array;
handler_info.size = size;
handler_info.counter = 0;
handler_info.pipe = pipe;

/* Queue an event for frame + 1 */
vbl.request.type = (drmVBlankSeqType) (DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT);
vbl.request.type = (drmVBlankSeqType)
(DRM_VBLANK_RELATIVE | DRM_VBLANK_EVENT | pipe_to_wait_for(pipe));
DBG("vbl.request.type = 0x%X\n", vbl.request.type);
vbl.request.sequence = 1;
vbl.request.signal = (unsigned long)&handler_info;
ret = drmWaitVBlank(g_dev_fd, &vbl);
Expand Down Expand Up @@ -840,4 +876,4 @@ int get_vsync(long *vsync_array, int size)

close_device();
return 0;
}
}
2 changes: 1 addition & 1 deletion synctest/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ BINNAME=$(notdir $(PWD))
MAKE += --no-print-directory
export CC=g++
export DBG_FLAGS?=-Ofast
export LIBS=-L. -L../lib -L/home/ssingh/workspace/tools/vsync/lib -lvsyncalter
export LIBS=-L. -L../lib -lvsyncalter
export INCLUDES=-I. -I../cmn
export CFLAGS=-c -Wall
export HEADERS=$(wildcard *.h)
Expand Down

0 comments on commit c849178

Please sign in to comment.