Bevy 0.22 Render Graph パイプライン破壊的変更対応完全ガイド|既存プロジェクト段階的マイグレーション【2026年7月最新】
Bevy 0.22の破壊的なRender Graph変更に対応する完全ガイド。RenderGraphApp廃止、Node構造変更、既存プロジェクトの段階的マイグレーション手順を実装例付きで解説
約10分で読めますBevy 0.22(2026年7月リリース予定)では、Render Graphシステムに大規模な破壊的変更が加えられます。この変更により、既存のカスタムレンダーパスを持つプロジェクトは動作しなくなります。本記事では、Bevy開発チームが2026年6月に公開したRFC(Request for Comments)#15とプルリクエスト#14892の内容を基に、破壊的変更の詳細と段階的なマイグレーション戦略を解説します。
Bevy 0.22 Render Graph破壊的変更の全容
Bevy 0.22では、レンダリングパイプラインの基盤となるRender Graphシステムが完全に再設計されました。この変更は2026年6月15日にマージされたPR #14892で導入され、既存のすべてのカスタムレンダーノードに影響を与えます。
主要な破壊的変更3点
1. RenderGraphApp traitの廃止
Bevy 0.21までの実装:
use bevy::render::render_graph::RenderGraphApp;
app.add_render_graph_node::<MyCustomNode>(
core_3d::graph::Core3d,
MyCustomNode::NAME
);
Bevy 0.22での新実装:
use bevy::render::render_graph::{RenderGraph, RenderLabel};
let mut render_app = app.sub_app_mut(RenderApp);
let mut graph = render_app.world.resource_mut::<RenderGraph>();
graph.add_node(MyLabel, MyCustomNode::new(&mut render_app.world));
この変更により、add_render_graph_nodeやadd_render_graph_edgeといった便利メソッドが完全に削除されました。開発者は直接RenderGraphリソースを操作する必要があります。
2. Node構造体のライフタイム変更
Bevy 0.21の署名:
fn run<'w>(
&self,
graph: &mut RenderGraphContext,
render_context: &mut RenderContext<'w>,
world: &'w World,
) -> Result<(), NodeRunError>;
Bevy 0.22の新署名:
fn run(
&self,
input: &RenderGraphInput,
render_context: &mut RenderContext,
world: &World,
) -> Result<(), NodeRunError>;
RenderGraphContextが廃止され、新しいRenderGraphInput構造体に置き換えられました。スロット入力へのアクセス方法も変更されています。
3. エッジ追加APIの変更
Bevy 0.21:
graph.add_node_edge(node_a, node_b);
graph.add_slot_edge(
node_a,
"texture_output",
node_b,
"texture_input"
);
Bevy 0.22:
graph.add_edge(NodeALabel, NodeBLabel);
graph.add_slot_edge(
NodeALabel,
"texture_output",
NodeBLabel,
"texture_input"
);
メソッド名が統一され、文字列ベースのノード識別子からラベルベースの識別子に変更されました。
以下のダイアグラムは、Bevy 0.21と0.22のRender Graph APIの構造的な違いを示しています。
graph TD
A["アプリケーション初期化"] --> B["Bevy 0.21方式"]
A --> C["Bevy 0.22方式"]
B --> B1["RenderGraphApp trait"]
B1 --> B2["add_render_graph_node"]
B1 --> B3["add_render_graph_edge"]
B2 --> B4["自動的にRenderGraphへ登録"]
C --> C1["RenderAppから直接アクセス"]
C1 --> C2["RenderGraph resource取得"]
C2 --> C3["graph.add_node"]
C2 --> C4["graph.add_edge"]
C3 --> C5["手動でWorldを渡す"]
style B fill:#ffcccc
style C fill:#ccffcc
この図は、0.21では抽象化されたtraitメソッドで隠蔽されていたRenderGraph操作が、0.22では開発者に直接公開されることを示しています。
既存プロジェクトの影響範囲分析
Bevy 0.22への移行には、プロジェクトの規模に応じて異なる労力が必要です。2026年6月のBevy開発者調査によると、カスタムレンダーパスを持つプロジェクトの約78%が何らかの変更を必要とします。
影響を受けるコンポーネント
カスタムポストプロセスエフェクト
ブルームやカラーグレーディングなどのポストプロセスエフェクトは、ほぼ確実に変更が必要です。特にテクスチャスロット入出力を持つノードは、入力アクセスAPIが完全に変更されています。
// Bevy 0.21
fn run(&self, graph: &mut RenderGraphContext, ...) {
let input_texture = graph.get_input_texture("view").unwrap();
}
// Bevy 0.22
fn run(&self, input: &RenderGraphInput, ...) {
let input_texture = input.get_view_entity()
.and_then(|entity| world.get::<ViewTarget>(entity))
.map(|target| &target.main_texture);
}
遅延レンダリングパイプライン
G-Bufferパスやライティングパスなど、複数のレンダーターゲットを扱うシステムは、スロットエッジの追加方法が変更されているため修正が必要です。
カスタムシャドウマップ実装
シャドウマップ生成ノードは、ビューエンティティへのアクセス方法が変更されているため、カメラ情報の取得ロジックを書き直す必要があります。
以下のシーケンス図は、Bevy 0.21と0.22でのレンダーノード実行フローの違いを示しています。
sequenceDiagram
participant App as Application
participant RG as RenderGraph
participant Node as CustomNode
participant World as World
Note over App,World: Bevy 0.21
App->>RG: add_render_graph_node
RG->>Node: 自動的にノード登録
RG->>Node: run(graph, render_ctx, world)
Node->>RG: graph.get_input_texture("view")
RG-->>Node: テクスチャ参照
Note over App,World: Bevy 0.22
App->>RG: resource_mut::<RenderGraph>()
App->>RG: graph.add_node(label, node)
RG->>Node: run(input, render_ctx, world)
Node->>World: input.get_view_entity()
World-->>Node: ViewTargetエンティティ
Node->>World: world.get::<ViewTarget>(entity)
World-->>Node: テクスチャコンポーネント
この図から、0.22ではノードがWorldに直接クエリを発行する責任を持つことがわかります。
段階的マイグレーション戦略
大規模プロジェクトでは、一度にすべてを移行するのは現実的ではありません。以下の4段階アプローチを推奨します。
フェーズ1: 依存関係の更新とコンパイルエラーの確認
まず、Cargo.tomlを更新してBevy 0.22に依存させます。
[dependencies]
bevy = "0.22"
この時点で発生する主なコンパイルエラー:
RenderGraphApptraitが存在しないadd_render_graph_nodeメソッドが存在しないNode::runの引数の型が一致しない
これらのエラーをすべてリストアップし、影響を受けるファイルの数をカウントします。
フェーズ2: RenderGraph登録コードの書き換え
RenderGraphAppを使用していた箇所を、RenderGraphリソースへの直接アクセスに変更します。
use bevy::render::{
RenderApp,
render_graph::{RenderGraph, RenderLabel},
};
#[derive(Debug, Hash, PartialEq, Eq, Clone, RenderLabel)]
struct MyCustomPass;
impl Plugin for MyRenderPlugin {
fn build(&self, app: &mut App) {
// 0.21: app.add_render_graph_node...は削除
// 0.22: RenderAppから直接操作
let render_app = app.sub_app_mut(RenderApp);
{
let mut graph = render_app
.world
.resource_mut::<RenderGraph>();
let node = MyCustomNode::new(&mut render_app.world);
graph.add_node(MyCustomPass, node);
// core_3d graphに接続
use bevy::core_pipeline::core_3d::graph::Core3d;
graph.add_edge(Core3d::Tonemapping, MyCustomPass);
graph.add_edge(MyCustomPass, Core3d::EndMainPassPostProcessing);
}
}
}
ポイント:
RenderLabelderiveマクロで型安全なラベルを定義sub_app_mut(RenderApp)でレンダーサブアプリケーションを取得- スコープブロック
{}でresource_mutの借用を明示的に終了
フェーズ3: Node実装の書き換え
Node::runメソッドのシグネチャと内部実装を変更します。
use bevy::render::render_graph::{Node, RenderGraphInput, NodeRunError};
struct MyCustomNode {
// フィールドは変更不要
}
impl Node for MyCustomNode {
// 0.22の新しいシグネチャ
fn run(
&self,
input: &RenderGraphInput,
render_context: &mut RenderContext,
world: &World,
) -> Result<(), NodeRunError> {
// ビューエンティティの取得
let view_entity = input.get_view_entity()
.ok_or(NodeRunError::MissingInput("view"))?;
// Worldから直接コンポーネント取得
let view_target = world
.get::<ViewTarget>(view_entity)
.ok_or(NodeRunError::MissingComponent("ViewTarget"))?;
let post_process = world
.get::<MyPostProcessSettings>(view_entity)
.ok_or(NodeRunError::MissingComponent("MyPostProcessSettings"))?;
// レンダーパス実行
let mut render_pass = render_context.begin_tracked_render_pass(
RenderPassDescriptor {
label: Some("my_custom_pass"),
color_attachments: &[Some(RenderPassColorAttachment {
view: &view_target.main_texture.default_view,
resolve_target: None,
ops: Operations {
load: LoadOp::Load,
store: StoreOp::Store,
},
})],
depth_stencil_attachment: None,
timestamp_writes: None,
occlusion_query_set: None,
}
);
// シェーダー実行...
Ok(())
}
}
変更のポイント:
graph: &mut RenderGraphContext→input: &RenderGraphInputrender_context: &mut RenderContext<'w>→render_context: &mut RenderContext(ライフタイム削除)graph.get_input_texture()→input.get_view_entity()+world.get()- エラーハンドリングで
ok_orを使用してOption→Result変換
フェーズ4: スロットエッジの移行
テクスチャやバッファをノード間で渡す実装を修正します。
// 0.21
graph.add_slot_edge(
upstream_node,
"color_output",
downstream_node,
"color_input"
);
// 0.22
graph.add_slot_edge(
UpstreamLabel,
"color_output",
DownstreamLabel,
"color_input"
);
スロット名は文字列のままですが、ノード識別子がラベルに変更されています。この変更により、タイポによる実行時エラーがコンパイル時に検出可能になりました。
以下のフローチャートは、段階的マイグレーションの意思決定プロセスを示しています。
flowchart TD
Start["移行開始"] --> Check["カスタムレンダーノードの有無確認"]
Check -->|無し| Easy["標準パイプラインのみ使用<br/>移行作業不要"]
Check -->|有り| Count["影響を受けるノード数カウント"]
Count --> Phase1["フェーズ1: Cargo.toml更新"]
Phase1 --> Compile1["コンパイルエラー確認"]
Compile1 --> Phase2["フェーズ2: RenderGraph登録修正"]
Phase2 --> Test1["ビルド成功?"]
Test1 -->|No| Debug1["エラーメッセージ確認<br/>RenderLabel追加忘れをチェック"]
Debug1 --> Phase2
Test1 -->|Yes| Phase3["フェーズ3: Node::run書き換え"]
Phase3 --> Test2["実行時エラー確認"]
Test2 -->|有り| Debug2["ViewEntity取得失敗?<br/>Component取得失敗?"]
Debug2 --> Phase3
Test2 -->|無し| Phase4["フェーズ4: スロットエッジ修正"]
Phase4 --> Final["テクスチャ入出力テスト"]
Final --> Done["移行完了"]
style Easy fill:#90EE90
style Done fill:#90EE90
style Debug1 fill:#FFB6C1
style Debug2 fill:#FFB6C1
この図は、各フェーズでの検証ポイントと、問題が発生した場合の対処フローを示しています。
よくある移行エラーと解決策
Bevy公式Discordでの2026年6月の報告を基に、頻出する3つのエラーパターンとその解決策を示します。
エラー1: ViewEntity取得の失敗
症状:
thread 'main' panicked at 'called `Option::unwrap()` on a `None` value'
原因:
input.get_view_entity()がNoneを返している。これは、ノードがビューコンテキスト外で実行されている場合に発生します。
解決策:
fn run(&self, input: &RenderGraphInput, ...) -> Result<(), NodeRunError> {
let view_entity = input.get_view_entity()
.ok_or_else(|| {
NodeRunError::RunSubGraphError(
"This node requires a view context".into()
)
})?;
// 以降の処理...
}
エラーを適切に伝播させ、unwrapを避けることが重要です。
エラー2: RenderLabelの重複
症状:
thread 'main' panicked at 'RenderLabel already registered: MyLabel'
原因:
同じRenderLabelを複数回登録しようとしている。プラグインの二重初期化や、誤って同じラベルを複数のノードに使用している場合に発生します。
解決策:
// 各ノードに一意のラベルを定義
#[derive(Debug, Hash, PartialEq, Eq, Clone, RenderLabel)]
struct BloomNode;
#[derive(Debug, Hash, PartialEq, Eq, Clone, RenderLabel)]
struct ColorGradingNode;
// プラグインの二重初期化チェック
impl Plugin for MyRenderPlugin {
fn build(&self, app: &mut App) {
if app.is_plugin_added::<Self>() {
return;
}
// 初期化処理...
}
}
エラー3: Component取得の型不一致
症状:
thread 'main' panicked at 'Component not found: MySettings'
原因:
world.get::<T>(entity)で指定した型が、実際にエンティティに付与されているコンポーネントと一致していない。
解決策:
// コンポーネントの存在確認とフォールバック
let settings = world
.get::<MySettings>(view_entity)
.or_else(|| {
// デフォルト値を使用
Some(&MySettings::default())
})
.ok_or(NodeRunError::MissingComponent("MySettings"))?;
または、コンポーネントがオプショナルな場合:
if let Some(settings) = world.get::<MySettings>(view_entity) {
// 設定が有効な場合の処理
apply_effect(settings);
}
// 設定がない場合はスキップ
パフォーマンスへの影響と最適化
Bevy 0.22のRender Graph変更は、実行時パフォーマンスにも影響を与えます。2026年6月のベンチマーク結果によると、適切に移行されたプロジェクトでは平均12%のフレームレート向上が見られました。
最適化ポイント1: Worldクエリのキャッシング
Bevy 0.22では、ノードがWorldに直接クエリを発行します。このクエリコストを削減するため、フレームごとに変化しないデータはノード初期化時にキャッシュします。
struct MyCustomNode {
pipeline: CachedRenderPipelineId,
bind_group_layout: BindGroupLayout,
}
impl MyCustomNode {
fn new(world: &mut World) -> Self {
let pipeline_cache = world.resource::<PipelineCache>();
let render_device = world.resource::<RenderDevice>();
let bind_group_layout = render_device.create_bind_group_layout(
"my_layout",
&BindGroupLayoutEntries::sequential(
ShaderStages::FRAGMENT,
(
texture_2d(TextureSampleType::Float { filterable: true }),
sampler(SamplerBindingType::Filtering),
),
),
);
let pipeline = pipeline_cache.queue_render_pipeline(
RenderPipelineDescriptor {
// パイプライン定義...
layout: vec![bind_group_layout.clone()],
// ...
}
);
Self {
pipeline,
bind_group_layout,
}
}
}
この変更により、毎フレームのパイプライン検索が不要になり、約8%のCPU時間削減が報告されています。
最適化ポイント2: 不要なComponent取得の削減
// 非効率: 毎フレーム複数のコンポーネント取得
fn run(&self, input: &RenderGraphInput, ...) {
let entity = input.get_view_entity().unwrap();
let target = world.get::<ViewTarget>(entity).unwrap();
let camera = world.get::<Camera>(entity).unwrap();
let transform = world.get::<GlobalTransform>(entity).unwrap();
// ...
}
// 効率的: 必要なコンポーネントのみ取得
fn run(&self, input: &RenderGraphInput, ...) {
let entity = input.get_view_entity().unwrap();
let target = world.get::<ViewTarget>(entity).unwrap();
// このノードではカメラとトランスフォームは不要なので取得しない
}
以下のガントチャートは、移行プロジェクトの典型的なタイムラインを示しています。
gantt
title Bevy 0.22 マイグレーションタイムライン
dateFormat YYYY-MM-DD
section 準備
依存関係調査 :done, prep1, 2026-07-01, 1d
影響範囲分析 :done, prep2, 2026-07-02, 1d
section 実装
フェーズ1実装 :active, phase1, 2026-07-03, 2d
フェーズ2実装 :phase2, 2026-07-05, 3d
フェーズ3実装 :phase3, 2026-07-08, 4d
フェーズ4実装 :phase4, 2026-07-12, 2d
section 検証
統合テスト :test, 2026-07-14, 2d
パフォーマンス計測 :perf, 2026-07-16, 1d
section リリース
本番デプロイ :deploy, 2026-07-17, 1d
中規模プロジェクト(カスタムノード5〜10個)の場合、約2週間の移行期間が標準的です。
まとめ
Bevy 0.22のRender Graph破壊的変更への対応には、以下の重要ポイントを押さえることが成功の鍵です。
- RenderGraphApp traitは完全に廃止 —
RenderGraphリソースへの直接アクセスに変更 - Node::runのシグネチャ変更 —
RenderGraphContextからRenderGraphInputへの移行が必須 - 段階的移行が推奨 — 4つのフェーズに分割して、各段階で動作確認を行う
- エラーハンドリングの強化 —
unwrapを避け、Result型で適切にエラーを伝播 - パフォーマンス最適化の機会 — Worldクエリのキャッシングで平均12%の性能向上
- ラベルベース識別子 — 型安全な
RenderLabelでコンパイル時エラー検出が可能に
Bevy 0.22の変更は、短期的には移行コストが発生しますが、長期的にはより柔軟で保守性の高いレンダリングパイプラインを実現します。公式ドキュメントとマイグレーションガイドを参照しながら、計画的に移行を進めることを推奨します。