processing / processing/processing4

`loadPixels` and `PGraphics` dependency batching in WebGPU

Aperta
#1,320 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

webgpu
Lingua principale
Java
Stelle
494
Fork
183
Merge medio
4h 39m
PR unite (30g)
3

Descrizione

The processing API allows performing arbitrary GPU->CPU readback on demand via the loadPixels method. This is generally an extension of the immediate mode philosophy of processing but poses significant friction with modern graphics architectures. In contrast with opengl, which goes to significant lengths to preserve the illusion that GPU data is easily accessible, WebGPU is designed to foreground that GPU operations are asynchronous relative to the CPU timeline. While the API does support blocking on these operations, the expectation of most framework including bevy is that you won't.

Concretely why this matters is because modern graphics libraries really want to batch rendering together for efficiency reasons. For example, in Bevy, all cameras (which could be considered an analog to a PGraphics instance) want to render at the same time every frame. loadPixels introduces an architectural complication in that the current draw state may need to be flushed and made visible to any other graphics context at any arbitrary time.

In other words, beyond any performance concerns, this highlights a potential dependency problem between PGraphics instances:

  • In the event where multiple PGraphics instances aren't dependent on each other, batching works fine and we can delay flushing all their draw state til the end of frame.
  • When a PGraphics is used in another PGraphics, e.g. an off-screen texture used by something in rendering to the screen, we could simply just track a relative order to ensure the Bevy Camera for one runs before the other.
  • If the user calls loadPixels, we need to flush the draw state right now and make the texture visible to potentially any other CPU code.

Approach for WebGPU with Bevy

We should start just by mirroring the immediate mode API. What this means is that we'll mirror the drawStart, flush, drawEnd lifecycle. Set CameraOutputMode::Skipat the beginning of each frame for each surface to render only to the intermediate texture and CameraOutputMode::Write only when calling drawEnd.

We can handle loadPixels in this way just by doing a synchronous readback after a flush. It's fine, and will superficially look like opengl's behavior from the user perspective.

Because this immediate mode approach likely has some undesirable overhead (although tbd, it may be pretty minimal), we can do our own dependency/dirty tracking if necessary down the line. What this would look like is keeping an in-flight dependency graph of PGraphics and how they're being used, and only trigger flushes when they acutally need to be made visible to other graphics contexts. This isn't hard to do but will make the implementation more confusing.

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Direzione di ricerca

Inizia tracciando l’implementazione WebGPU di loadPixels, PGraphics e il ciclo di vita di drawStart, flush e drawEnd descritti nell’issue. Verifica come viene impostato CameraOutputMode per ogni superficie, quindi valida l’approccio in modalità immediata con readback sincrono e l’ordine di rendering e i requisiti di visibilità indicati.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Ambito
computer-graphics
Tipo di issue
Funzionalità
Difficoltà
5/5
Tempo stimato
Più di una settimana
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
25/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.