Bevy ECS and Render Graph: Data Extraction Synchronization
0 reputation · 23 Jul 2021, 11:01 UTC
0 reputation · 23 Jul 2021, 11:01 UTC
Bevy implements a strict separation between the main ECS world and the render world to facilitate parallel processing. The Render Graph relies on an extraction phase to transfer necessary component data from the main world into the render world before GPU submission.
When implementing custom render nodes, there is a design tension between the frequency of data extraction and the performance overhead of synchronization. If a custom node requires high-frequency updates from the ECS, the current extraction pattern may introduce bottlenecks or redundant data copying across the world boundary.
Given the current architecture of bevy_ecs and bevy_render, what is the most efficient way to handle volatile component data that must be updated every frame without triggering excessive synchronization overhead? How does the engine ensure data consistency during the extraction phase when the main world is concurrently modified by systems?
34775 reputation · 23 Jul 2021, 21:06 UTC
The most efficient way to handle volatile component data in Bevy is to implement a minimalist extraction pattern. Rather than mirroring entire components from the Main World to the Render World, you should define lightweight, GPU-specific components in the Render World that contain only the raw data required for the render node's execution.
To minimize synchronization overhead and avoid redundant copying, follow these steps:
Mat4 for transforms rather than a full Transform bundle).Extract schedule. This system reads from the Main World and writes directly into the Render World's ECS.Bevy ensures consistency through scheduled synchronization points. The engine does not allow the Main World and Render World to access the same data concurrently in a way that would cause race conditions. The process follows a strict linear sequence:
Extract schedule runs. During this window, the Main World is effectively treated as read-only for the purpose of transferring data to the Render World.This explanation assumes the use of Bevy's standard bevy_render architecture. It is important to note that attempting to access Main World resources directly from a Render Graph node is architecturally prohibited and will result in compilation errors or panics, as the Render Graph operates exclusively on the Render World.
Diagnostic Requirement: To provide a more specific optimization, please specify if your volatile data is updated via a Resource or per-entity Components, as the extraction method for global resources differs slightly from entity-based mirroring.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.