Game.EndFrameBarrier
Assembly:
Inferred from project layout / namespace (Game)
Namespace: Game
Type: class (EndFrameBarrier is expected to be a system-type class used to synchronize GPU work at frame end)
Base: (not present in the provided file) — typically a barrier/system base (e.g., an Entity/Frame barrier or a custom system that integrates with the job system and CommandBuffer submission)
Summary: EndFrameBarrier is a synchronization/system helper that coordinates GPU work at the end of a frame. It typically tracks the producer JobHandle for GPU work, measures timings (for profiling or throttling), and exposes a JobHandle property that other systems can wait on. The provided source file (IGPUSystem.cs) defines the IGPUSystem interface which GPU-capable systems implement to perform their GPU-side simulation with a UnityEngine.Rendering.CommandBuffer. That interface is directly relevant to EndFrameBarrier because EndFrameBarrier will usually collect or invoke IGPUSystem implementations' OnSimulateGPU(...) during end-of-frame processing.
Key responsibilities (inferred): - Hold and expose a producer JobHandle representing GPU/producer work to be waited upon. - Optionally measure elapsed time for GPU submission/latency using a Stopwatch. - Coordinate submission of CommandBuffers (via IGPUSystem implementers) and integration with the Unity job system. - Provide a single point where GPU simulation for multiple systems can be chained or synchronized before the frame is presented.
Fields
-
private System.Diagnostics.Stopwatch m_Stopwatch
This field is commonly used to measure durations related to GPU submission or to profile time spent between frame end and GPU completion. The Stopwatch is not present in the provided IGPUSystem.cs interface (that file only contains an interface), but EndFrameBarrier implementations often include a private Stopwatch to gather timing metrics or to implement time-based throttling/sliding windows. -
private Unity.Jobs.JobHandle <producerHandle>k__BackingField
This is the compiler-generated backing field for a property named producerHandle. It stores the Unity.Jobs.JobHandle that represents the "producer" or GPU-related job chain that other systems may need to wait for. The backing field itself is private and managed via the producerHandle property.
Properties
public Unity.Jobs.JobHandle producerHandle { get; private set }
A JobHandle that represents the producer work (typically GPU/CommandBuffer submission or dependent jobs). Other systems can read this handle to add dependencies or wait for completion. The setter is private — the barrier manages updates to this handle internally. This property is essential for integrating end-of-frame GPU work into the Unity job dependency graph.
Constructors
public EndFrameBarrier()
Typical behavior for an EndFrameBarrier constructor:- Initialize internal fields (e.g., create or reset the Stopwatch).
- Prepare any internal state for tracking the producer handle.
- Possibly register the system with a scheduler or set initial JobHandle to default.
Note: The concrete constructor implementation is not present in the provided IGPUSystem.cs file; the above describes the expected responsibilities of EndFrameBarrier's constructor.
Methods
protected virtual OnCreate() : System.Void
OnCreate is typically overridden to perform system initialization (for example, instantiate the Stopwatch, initialize job handles, and set up any required resources). The template usage below shows a common pattern where OnCreate calls base.OnCreate() and initializes the Stopwatch.
Additional relevant method from the provided source (IGPUSystem.cs):
-
bool Enabled { get; }
(interface property) Indicates whether the implementing GPU system is currently enabled. EndFrameBarrier will commonly check this before invoking a system's OnSimulateGPU method. -
bool IsAsync { get; set; }
(interface property) Indicates whether the GPU system can run asynchronously (i.e., may submit work that does not block the main thread). EndFrameBarrier may use this to decide how to schedule or wait for submitted work. -
void OnSimulateGPU(CommandBuffer cmd)
(interface method) IGPUSystem implementers provide this method to record GPU commands into the provided CommandBuffer. EndFrameBarrier is responsible for invoking these implementations at the appropriate time (typically at end-of-frame) and for managing submission of the resulting CommandBuffer to the GPU or render pipeline.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
m_Stopwatch = new Stopwatch();
}
Notes and integration tips: - Implementers of IGPUSystem should implement Enabled, IsAsync, and OnSimulateGPU(CommandBuffer) so EndFrameBarrier (or a similar end-of-frame system) can discover and invoke them. - EndFrameBarrier should collect JobHandles from producer work and expose them via producerHandle so other systems can chain dependencies correctly. - Use CommandBuffer instances carefully: record commands during OnSimulateGPU, then submit them in a single, well-defined place (EndFrameBarrier) to ensure ordering and correct synchronization with the CPU job graph.