dimanche 31 octobre 2021

How to share frame rendering between two proceses

Im designing a game menu for an arcade machine as a personal project and to get more familiar with IPC. The project runs on a raspberry Pi rendering to a LED matrix using Hzeller's led matrix library. The menu would present the user a list of games rendered on the matrix. When the user selects a game, the main process will fork and spawn the game in a new process. The game will start and render to the matrix. At any point the user can exit the game which will return the user back to the game menu. Presumably there will be communication between processes so each aren't simultaneously rendering to the matrix at the same time.

Now where I am uncertain is how to actually share resources that are needed to render to the matrix. The library has a background updater thread that cannot be running in both process. Im not certain how this is typically done but here are the solutions I came up with:

  1. Resources needed for rendering are cleaned up and reinitialized before switching contexts between parent and child processes

  2. The Child will serialize the underlying framebuffer data and send it to the main process for rendering.

The first solution seems a little hacky and requires me to make small changes to the library. I also want to create an interface to decouple the menu/game to the display its actually rendered on. This way I can make a separate implementation of the interface to render to a GUI on a computer screen. Choosing this option would be synonymous of creating an entirely new window for the child process (not sharing the same window).

The second solution would require copying the underlying framebuffer of the child process to shared memory. It would then would be picked up by the parent thread copied again out of shared memory and rendered. I worry about latency and how to manage frame rate in this solution. In addition, I am utilizing the library's vsync capability and am unsure how the child would be utilize this if rendering is done in the parent process

My questions are:

  • Are there any other solutions? If not which of the two are better design wise.
  • If I go option two, how would the child take advantage of the vsync functionality and how would I manage framerate in this scenario?

Aucun commentaire:

Enregistrer un commentaire