Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

Question Job with a bigger output array

Discussion in 'Burst' started by Piflik, May 19, 2021.

  1. Piflik

    Piflik

    Joined:
    Sep 11, 2011
    Posts:
    289
    I am currently trying to parallelise some work (Bayer Demosaicing). I have the single-threaded algorithm working already, but it would be nice to do that in parallel.

    I tried to do it via am IJobParallelFor, but I get an exception, because I try to write to a different index than what the job is working on, and apparently that is not allowed, for safety.

    Basically, my output array is 3 times as big as the input. For each input value I generate 3 output values (due to how bayer mosaicing encodes RGB), and in the output array I write to index * 3 + 0 | 1 | 2.

    I never write to the same index twice or from diferent threads.

    Is there a way to disable or circumvent that restiction? I would like to avoid creating 3 output arrays for R, G and B and then combine them single-threaded.
     
  2. eizenhorn

    eizenhorn

    Joined:
    Oct 17, 2016
    Posts:
    2,653
    If you are sure of safety.
    If it's regular job - add [NativeDisableParallelForRestriction] attribute to field declaration of your array
    If Entities.ForEach - WithNativeDisableParallelForRestriction(array).
     
    Piflik likes this.
  3. M_R

    M_R

    Joined:
    Apr 15, 2015
    Posts:
    558
    use a
    NativeArray<float3>
    for the output.