0

I'm programming some routines on a Linux NASM x86-64 asm code.

How can I obtain the pulse of the display refresh, VSync?

I guess maybe via syscall I can reach the pulse, but I accept other suggestions, don't ask me why, i really need the pulse to avoid Flicker on display.

I know how to do it for windows as shown in code below, but Linux doesn't support D3D.

;;;;; WINDOWS VERSION EXAMPLE!
;ENABLE VSYNC
Therraszeta3:
CMP BYTE [RY_X+0x1003],255
jnz .L1232321
mov rcx,0
mov rax, [GetDC__]
mov [D3DKMT_OPENADAPTERFROMHDC_hDc], rax
lea rcx, [D3DKMT_OPENADAPTERFROMHDC]
call [GetProcAddress_LoadLibrary_Gdi32_dll_D3DKMTOpenAdapterFromHdc_]
mov [D3DKMTOpenAdapterFromHdc__], rax
;;
mov eax, dword [D3DKMT_OPENADAPTERFROMHDC_hAdapter]
mov dword [D3DKMT_WAITFORVERTICALBLANKEVENT_hAdapter], eax
mov dword [D3DKMT_WAITFORVERTICALBLANKEVENT_hDevice],0
mov eax, dword [D3DKMT_OPENADAPTERFROMHDC_VidPnSourceId]
mov dword [D3DKMT_WAITFORVERTICALBLANKEVENT_VidPnSourceId], eax
lea rcx, [D3DKMT_WAITFORVERTICALBLANKEVENT]
call [GetProcAddress_LoadLibrary_Gdi32_dll_D3DKMTWaitForVerticalBlankEvent_]
mov [D3DKMTWaitForVerticalBlankEvent__], rax
.L1232321
;;;;;

I expect to obtain the pulse in an infinite loop, indicating the beginning of every frame.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • Which library do you use to do graphics on Linux? – fuz Jun 12 '19 at 19:14
  • What graphics stack is your Linux machine running? traditional X11? Wayland? Console terminal in text mode or a framebuffer? There's no one magic way; find a way in C and compile that to asm with an optimizing compiler. And yes it will involve a system call because you're running in user-space; using `iopl` for `in`/`out` instructions isn't going to be helpful because you can't assume legacy VGA or set up your own interrupt handlers. – Peter Cordes Jun 12 '19 at 19:15
  • 1
    This is not really an asm question. Anyway, see [this answer](https://stackoverflow.com/a/36888778/547981) – Jester Jun 12 '19 at 19:15
  • I'd recommend looking at the source of a video player, e.g. `mpv` attempts to be a high-quality as possible for frame-timing (and color rendering). https://github.com/mpv-player/mpv/blob/199aabddcc0105b504cc8e0cb240bc3c89288c1a/video/out/opengl/context_glx.c#L229 has a block of comments about how it uses GLX to get the time since last vsync. It has other video-out drivers for other graphics stacks.... If you just want to sleep until right after a vsync, that's probably easier. – Peter Cordes Jun 12 '19 at 19:25
  • @PeterCordes, both purposes libX11 and terminal in syscall sys_write. – Phillip Krüger Jun 12 '19 at 19:29
  • @Jester, thks for the tip. – Phillip Krüger Jun 12 '19 at 19:29
  • @PhillipKrüger How do you do graphics in a terminal with just `write` calls? Do you open a framebuffer device or something? – fuz Jun 12 '19 at 23:29
  • On terminal i don't do that, only create a thread to write to the buffer on a infinite loop, then i get the actual realtime size of the buffer, row and col, and , wow the code is big, there's a lot of features, but the purpose is that it is refreshed with an secondary thread whose performs a BIT_BLK of a secondary buffer to the main one, relative to the screen display refresh, so when i clear the terminal it flickers, and, if i don't clear, the image get's unstable. – Phillip Krüger Jun 13 '19 at 02:18

0 Answers0