RibirX / Ribir

Non-intrusive GUI framework for Rust

Home Page:https://ribir.org

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Implementing a Dedicated Thread for the Painter Backend

M-Adoo opened this issue · comments

commented

In our current painter architecture, the painter generates path commands and the backend renders them. These two processes are completely independent, with only a PainterResult passed from the Painter to its backend.

This separation allows us to easily parallelize the painter and its backend by using a Mutex to synchronize them with every frame.

For the GPU backend, we can leverage the GPU's parallelism in two ways:

  1. Tessellating the path into triangles, which can be a heavy task.
  2. Interacting with the GPU and awaiting its response, can be time-consuming, especially in the browser where we have to go from wasm to JS to WebGL (sometimes taking milliseconds).

By introducing a dedicated render thread, we can reduce the load on the main thread:

We use ULP to represent the tasks of the main thread, such as user interaction, layout, painting, etc.
We use SS to represent the tasks of tessellation and submission to the GPU.

main thread: ----|ULP|--|ULP|--....->
render thread: --------|SS|---|SS| --...-->

The subsequent ULP doesn't need to wait for the previous SS to finish.