Game.Rendering.BatchUploadSystem
Assembly: Assembly-CSharp
Namespace: Game.Rendering
Type: public class
Base: GameSystemBase
Summary:
BatchUploadSystem is a game system responsible for uploading batched instance data (GPU instance buffers) in parallel using Unity's Job System and Burst. It coordinates with BatchManagerSystem to obtain native and managed batch data, prepares upload state, schedules a Burst-compiled IJobParallelFor (BatchUploadJob) to call UploadInstances on each active group, and registers the produced job handles so the batch manager and other systems can observe the produced/consumed dependencies.
Fields
-
private struct BatchUploadJob : IJobParallelFor
This private nested Burst-compiled job type executes the actual per-group instance upload work in parallel. It holds a ParallelUploadWriter (m_NativeBatchInstances) that is produced by NativeBatchInstances.BeginParallelUpload() and in Execute(int index) calls UploadInstances(index) to perform the upload for the given group index. -
public NativeBatchInstances<CullingData, GroupData, BatchData, InstanceData>.ParallelUploadWriter m_NativeBatchInstances
The writer used by the job to upload instances in parallel. This writer is obtained from NativeBatchInstances.BeginParallelUpload() and must be passed back to EndParallelUpload() after scheduling/completion. -
private BatchManagerSystem m_BatchManagerSystem
Holds a reference to the BatchManagerSystem obtained from the world. BatchUploadSystem uses this to retrieve native batch/sub-batch containers and managed batches, and to register readers/writers (job dependencies) with the batch manager.
Properties
- This class does not expose public properties.
Constructors
public BatchUploadSystem()
Default constructor. The system relies on its OnCreate override to obtain references to required systems. The constructor is parameterless and preserved by attribute usage in the class.
Methods
-
protected override void OnCreate()
: System.Void
Initializes the system by calling base.OnCreate() and retrieving the BatchManagerSystem instance from the World (base.World.GetOrCreateSystemManaged()). This prepares the system to access batch data during updates. -
protected override void OnUpdate()
: System.Void
Main update loop that performs the following steps: - Requests access to native batch instances (read/write) and native sub-batches (read-only) from BatchManagerSystem. The calls return JobHandle dependencies for potential in-flight jobs that produce those native containers.
- Retrieves managed batches via m_BatchManagerSystem.GetManagedBatches().
- Calls dependencies.Complete() and dependencies2.Complete() to ensure the native containers are ready to use on the main thread before starting the upload. (These Complete calls block until the dependent jobs finish.)
- Calls managedBatches.StartUpload(nativeBatchInstances, nativeSubBatches) to prepare managed data for upload.
- Reads the number of active groups via nativeBatchInstances.GetActiveGroupCount().
- Calls nativeBatchInstances.BeginParallelUpload() to obtain a ParallelUploadWriter and places it into a Burst-compiled BatchUploadJob instance.
- Schedules the BatchUploadJob as an IJobParallelFor over activeGroupCount with a batchSize of 1 using Unity.Jobs scheduling helpers.
- Calls nativeBatchInstances.EndParallelUpload(jobData.m_NativeBatchInstances, jobHandle) to obtain a JobHandle that ensures the native batch instance writer/producer work is completed.
- Registers the scheduled job handles with the BatchManagerSystem:
- m_BatchManagerSystem.AddNativeSubBatchesReader(jobHandle) — registers that the sub-batches are being read by jobHandle.
- m_BatchManagerSystem.AddNativeBatchInstancesWriter(jobHandle2) — registers the writer job handle so other systems know about the produced writes.
- Overall, OnUpdate coordinates safe multi-threaded upload of instance data to GPU buffers and propagates job dependencies to the batch manager.
Notes: - The nested BatchUploadJob is marked with [BurstCompile] for optimized execution. - The code uses explicit dependency completions before scheduling the upload; this implies the system expects the native containers to be fully available (synchronously) before starting the parallel upload setup. - The scheduling pattern uses BeginParallelUpload / EndParallelUpload to safely manage parallel writers for native batch instance upload.
Usage Example
[Preserve]
protected override void OnCreate()
{
base.OnCreate();
// Obtain the batch manager system to access batch/native data during updates
m_BatchManagerSystem = base.World.GetOrCreateSystemManaged<BatchManagerSystem>();
}