Assets/Plugins/Unity.DSPGraph/Runtime/DSPNodeImplementation.cs
/// <summary>
/// Allocate job data for this node, including port buffers, parameters, and sample providers
/// </summary>
/// <remarks>If the needed size is the same as for the last execution, no reallocation is done</remarks>
/// <param name="graph">The graph to which this node belongs</param>
Allocate job data for this node, including port buffers, parameters, and sample providers
Allocate job data for this node including port buffers parameters and sample providers
internal void AllocateJobData(DSPGraph graph)
        {
            var sampleFrameCount = graph.LastReadLength;
            CountPortBuffers(graph, sampleFrameCount, out int inputBufferCount, out int inputSampleCount, out int outputBufferCount, out int outputSampleCount);
            CountParameters(out int parameterCount, out int interpolatedParameterCount);
            CountSampleProviders(out int sampleProviderIndexCount, out int sampleProviderCount);
            int paramInterpolationFloatCount = interpolatedParameterCount * sampleFrameCount;
            int floatCount = paramInterpolationFloatCount + inputSampleCount + outputSampleCount;
            if (inputBufferCount == JobDataBuffer->NativeJobData.InputBufferCount &&
                outputBufferCount == JobDataBuffer->NativeJobData.OutputBufferCount &&
                parameterCount == JobDataBuffer->NativeJobData.ParameterCount &&
                sampleProviderIndexCount == JobDataBuffer->NativeJobData.SampleProviderIndexCount &&
                sampleProviderCount == JobDataBuffer->NativeJobData.SampleProviderCount &&
                floatCount == JobDataBuffer->Count)
                return;
            DeallocateJobData();
            var allocator = new BatchAllocator(Allocator.Persistent);
            allocator.Allocate(floatCount, &JobDataBuffer->Buffer);
            allocator.Allocate(inputBufferCount, &JobDataBuffer->NativeJobData.InputBuffers);
            allocator.Allocate(outputBufferCount, &JobDataBuffer->NativeJobData.OutputBuffers);
            allocator.Allocate(parameterCount, &JobDataBuffer->NativeJobData.Parameters);
            allocator.Allocate(sampleProviderIndexCount, &JobDataBuffer->NativeJobData.SampleProviderIndices);
            allocator.Allocate(sampleProviderCount, &JobDataBuffer->NativeJobData.SampleProviders);
            allocator.Dispose();
            *m_JobDataAllocationRoot = (long)allocator.AllocationRoot;
            JobDataBuffer->NativeJobData.InputBufferCount = (uint)inputBufferCount;
            JobDataBuffer->NativeJobData.OutputBufferCount = (uint)outputBufferCount;
            JobDataBuffer->NativeJobData.ParameterCount = (uint)parameterCount;
            JobDataBuffer->NativeJobData.SampleProviderIndexCount = (uint)sampleProviderIndexCount;
            JobDataBuffer->NativeJobData.SampleProviderCount = (uint)sampleProviderCount;
            JobDataBuffer->Count = floatCount;
        }
internal void AllocateJobData ( DSPGraph graph ) { var sampleFrameCount = graph . LastReadLength ; CountPortBuffers ( graph , sampleFrameCount , out int inputBufferCount , out int inputSampleCount , out int outputBufferCount , out int outputSampleCount ) ; CountParameters ( out int parameterCount , out int interpolatedParameterCount ) ; CountSampleProviders ( out int sampleProviderIndexCount , out int sampleProviderCount ) ; int paramInterpolationFloatCount = interpolatedParameterCount * sampleFrameCount ; int floatCount = paramInterpolationFloatCount + inputSampleCount + outputSampleCount ; if ( inputBufferCount == JobDataBuffer -> NativeJobData . InputBufferCount && outputBufferCount == JobDataBuffer -> NativeJobData . OutputBufferCount && parameterCount == JobDataBuffer -> NativeJobData . ParameterCount && sampleProviderIndexCount == JobDataBuffer -> NativeJobData . SampleProviderIndexCount && sampleProviderCount == JobDataBuffer -> NativeJobData . SampleProviderCount && floatCount == JobDataBuffer -> Count ) return ; DeallocateJobData ( ) ; var allocator = new BatchAllocator ( Allocator . Persistent ) ; allocator . Allocate ( floatCount , & JobDataBuffer -> Buffer ) ; allocator . Allocate ( inputBufferCount , & JobDataBuffer -> NativeJobData . InputBuffers ) ; allocator . Allocate ( outputBufferCount , & JobDataBuffer -> NativeJobData . OutputBuffers ) ; allocator . Allocate ( parameterCount , & JobDataBuffer -> NativeJobData . Parameters ) ; allocator . Allocate ( sampleProviderIndexCount , & JobDataBuffer -> NativeJobData . SampleProviderIndices ) ; allocator . Allocate ( sampleProviderCount , & JobDataBuffer -> NativeJobData . SampleProviders ) ; allocator . Dispose ( ) ; * m_JobDataAllocationRoot = ( long ) allocator . AllocationRoot ; JobDataBuffer -> NativeJobData . InputBufferCount = ( uint ) inputBufferCount ; JobDataBuffer -> NativeJobData . OutputBufferCount = ( uint ) outputBufferCount ; JobDataBuffer -> NativeJobData . ParameterCount = ( uint ) parameterCount ; JobDataBuffer -> NativeJobData . SampleProviderIndexCount = ( uint ) sampleProviderIndexCount ; JobDataBuffer -> NativeJobData . SampleProviderCount = ( uint ) sampleProviderCount ; JobDataBuffer -> Count = floatCount ; }
Allocate job data for this node, including port buffers, parameters, and sample providers
Allocate job data for this node including port buffers parameters and sample providers
// No need to reallocate job data // Burst doesn't support the using statement atm
graph
DSPGraph
The graph to which this node belongs
The graph to which this node belongs
remarks
If the needed size is the same as for the last execution, no reallocation is done
If the needed size is the same as for the last execution no reallocation is done