processing / processing/processing4
`loadPixels` and `PGraphics` dependency batching in WebGPU
まだ誰も着手していません。
- 主要言語
- Java
- スター
- 494
- フォーク
- 183
- 平均マージ
- 4時間 39分
- マージ済み PR(30日)
- 3
説明
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
PGraphicsinstances 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
PGraphicsis used in anotherPGraphics, 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 BevyCamerafor 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.
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、issue に記載されている loadPixels、PGraphics、および drawStart、flush、drawEnd のライフサイクルに関する WebGPU 実装を追跡します。各 surface に対して CameraOutputMode がどのように設定されるかを確認し、その後、同期 readback を使用する immediate-mode アプローチと、記載されたレンダリング順序および可視性要件を検証します。
索引モデルが issue の本文から書いたものです。
評価
- 領域
- computer-graphics
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 25/100