Similar to IJobProcessComponentData.ScheduleSingle, can we also get a schedule function which runs single-threaded for IJobChunk?
4 Likes
IJobChunk is run single threaded. If you pass down the job handle, you can tell other IJobChunk to wait for the previous one.
for(i = 0; i > length; i++){
var job = new IJobChunk(); // Create Job
inputdeps = job.schedule(this, inputdeps); // Tell this job to wait for previous job in previous loop
}
I’m not tested yet but I think relatively job handle should work like that.
IJobChunk runs as a parallel-for job. If you look into the source (IJobChunk.cs) you’ll see this line
return JobsUtility.ScheduleParallelFor(ref scheduleParams, totalChunks, 1);
A ScheduleSingle extension method would call JobsUtility.Schedule instead of ScheduleParallelFor.
Yeah that’s not true. Chunks are spread across threads.
Well my bad. That is badly written and I do not have that deep understand of ECS.
1 Like
Sorry didn’t mean to come off so blunt.
From memory, every job except IJob is parallel by default.
1 Like
bump
Since it might be a while for us to get this, I wrote a quick’n’dirty work-around
public static JobHandle ScheduleSingle<T>(this T job, EntityQuery query, JobHandle dependsOn)
where T : struct, IJobChunk {
var chunks = query.CreateArchetypeChunkArray(Allocator.TempJob, out JobHandle chunksHandle);
dependsOn = JobHandle.CombineDependencies(dependsOn, chunksHandle);
return new JobChunkSingleRunner<T> {
RealJob = job,
Chunks = chunks,
}.Schedule(dependsOn);
}
[BurstCompile]
struct JobChunkSingleRunner<T> : IJob where T : IJobChunk {
public T RealJob;
[DeallocateOnJobCompletion]
public NativeArray<ArchetypeChunk> Chunks;
public void Execute() {
int firstEntityIndex = 0;
for (int i = 0; i < Chunks.Length; ++i) {
RealJob.Execute(Chunks[i], i, firstEntityIndex);
firstEntityIndex += Chunks[i].Count;
}
}
}
1 Like
please add this.