Skip to content

Instantly share code, notes, and snippets.

@Jakz
Forked from mthuurne/rotating_framebuffers.md
Last active December 20, 2019 14:45
Show Gist options
  • Save Jakz/0c4f83ae947b11a9715b4fdee13f60d3 to your computer and use it in GitHub Desktop.
Save Jakz/0c4f83ae947b11a9715b4fdee13f60d3 to your computer and use it in GitHub Desktop.
Rotating framebuffers

Goals:

  • support vsynced double and triple buffering
  • zero buffer copies

User space execution flow:

  1. block on free_queue.size() > 0
  2. lock free_queue, remove top element, unlock
  3. acquire buffer handle
  4. map buffer into virtual memory region
  5. draw into buffer
  6. unmap buffer
  7. lock ready_queue, enqueue buffer, unlock
  8. goto 1

Kernel execution flow:

  1. scanout current foreground buffer
  2. at vsync
    1. if ready_queue.size() > 0, lock the queue, get first frame, render it, then lock free_queue and add current frame to it
    2. else go back rendering current frame

Notes on buffer mapping:

  • the buffer can be mapped into user space virtual memory with any cache setting
  • cache flush happens on unmap
  • mapping could use a huge page, so it needs fewer TLB entries
  • the buffer doesn't need to be mapped while it's owned by the kernel, since we only DMA from it
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment