public FunctionPointer <TDelegate> Get() { if (!m_IsCompiled) { m_IsCompiled = true; if (!BurstCompiler.Options.IsEnabled || !BurstCompiler.Options.EnableBurstCompilation) { return(new FunctionPointer <TDelegate>(Marshal.GetFunctionPointerForDelegate(Origin))); } try { m_BurstResult = BurstCompiler.CompileFunctionPointer(Origin); WasBurstCompiled = true; } catch { m_BurstResult = default; WasBurstCompiled = false; } } if (WasBurstCompiled) { return(m_BurstResult); } return(new FunctionPointer <TDelegate>(Marshal.GetFunctionPointerForDelegate(Origin))); }
public static FunctionPointer <TDelegate> CompileStaticMemberFunction <TDelegate>(Type type, string methodName) where TDelegate : class { if (type.GetCustomAttribute <BurstCompileAttribute>() == null) { throw new ArgumentException($"Compilation of function {methodName} from {type.Name} failed : class is missing [BurstCompile] attribute."); } MethodInfo method = type.GetMethod(methodName, BindingFlags.Public | BindingFlags.Static); if (method == null) { throw new ArgumentException($"Compilation of function {methodName} from {type.Name} failed : method not found."); } if (method.GetCustomAttribute <BurstCompileAttribute>() == null) { throw new ArgumentException($"Compilation of function {methodName} from {type.Name} failed : method is missing [BurstCompile] attribute."); } TDelegate functionDelegate = (TDelegate)(object)method.CreateDelegate(typeof(TDelegate)); try { FunctionPointer <TDelegate> functionPointer = BurstCompiler.CompileFunctionPointer <TDelegate>(functionDelegate); return(functionPointer); } catch (Exception e) { throw new Exception($"Compilation of function {methodName} from {type.Name} failed : {e}"); } }
private static void CompileFunctions() { _1ByteEffectorFunction = BurstCompiler.CompileFunctionPointer <EffectorDelegate>(Effector1Byte); _2ByteEffectorFunction = BurstCompiler.CompileFunctionPointer <EffectorDelegate>(Effector2Byte); _4ByteEffectorFunction = BurstCompiler.CompileFunctionPointer <EffectorDelegate>(Effector4Byte); _8ByteEffectorFunction = BurstCompiler.CompileFunctionPointer <EffectorDelegate>(Effector8Byte); }
internal static void Initialize() { #if !UNITY_IOS if (Managed._initialized) { return; } Managed._initialized = true; Managed._bfp_AddComponentEntitiesBatch = BurstCompiler.CompileFunctionPointer <Managed._dlg_AddComponentEntitiesBatch>(_mono_to_burst_AddComponentEntitiesBatch).Invoke; Managed._bfp_AddComponentsEntitiesBatch = BurstCompiler.CompileFunctionPointer <Managed._dlg_AddComponentsEntitiesBatch>(_mono_to_burst_AddComponentsEntitiesBatch).Invoke; Managed._bfp_AddComponentEntity = BurstCompiler.CompileFunctionPointer <Managed._dlg_AddComponentEntity>(_mono_to_burst_AddComponentEntity).Invoke; Managed._bfp_AddComponentsEntity = BurstCompiler.CompileFunctionPointer <Managed._dlg_AddComponentsEntity>(_mono_to_burst_AddComponentsEntity).Invoke; Managed._bfp_AddComponentChunks = BurstCompiler.CompileFunctionPointer <Managed._dlg_AddComponentChunks>(_mono_to_burst_AddComponentChunks).Invoke; Managed._bfp_AddComponentsChunks = BurstCompiler.CompileFunctionPointer <Managed._dlg_AddComponentsChunks>(_mono_to_burst_AddComponentsChunks).Invoke; Managed._bfp_RemoveComponentEntity = BurstCompiler.CompileFunctionPointer <Managed._dlg_RemoveComponentEntity>(_mono_to_burst_RemoveComponentEntity).Invoke; Managed._bfp_RemoveComponentsEntity = BurstCompiler.CompileFunctionPointer <Managed._dlg_RemoveComponentsEntity>(_mono_to_burst_RemoveComponentsEntity).Invoke; Managed._bfp_RemoveComponentEntitiesBatch = BurstCompiler.CompileFunctionPointer <Managed._dlg_RemoveComponentEntitiesBatch>(_mono_to_burst_RemoveComponentEntitiesBatch).Invoke; Managed._bfp_RemoveComponentsEntitiesBatch = BurstCompiler.CompileFunctionPointer <Managed._dlg_RemoveComponentsEntitiesBatch>(_mono_to_burst_RemoveComponentsEntitiesBatch).Invoke; Managed._bfp_RemoveComponentChunks = BurstCompiler.CompileFunctionPointer <Managed._dlg_RemoveComponentChunks>(_mono_to_burst_RemoveComponentChunks).Invoke; Managed._bfp_RemoveComponentsChunks = BurstCompiler.CompileFunctionPointer <Managed._dlg_RemoveComponentsChunks>(_mono_to_burst_RemoveComponentsChunks).Invoke; Managed._bfp_AddSharedComponentChunks = BurstCompiler.CompileFunctionPointer <Managed._dlg_AddSharedComponentChunks>(_mono_to_burst_AddSharedComponentChunks).Invoke; Managed._bfp_MoveEntityArchetype = BurstCompiler.CompileFunctionPointer <Managed._dlg_MoveEntityArchetype>(_mono_to_burst_MoveEntityArchetype).Invoke; Managed._bfp_SetChunkComponent = BurstCompiler.CompileFunctionPointer <Managed._dlg_SetChunkComponent>(_mono_to_burst_SetChunkComponent).Invoke; Managed._bfp_CreateEntity = BurstCompiler.CompileFunctionPointer <Managed._dlg_CreateEntity>(_mono_to_burst_CreateEntity).Invoke; Managed._bfp_DestroyEntity = BurstCompiler.CompileFunctionPointer <Managed._dlg_DestroyEntity>(_mono_to_burst_DestroyEntity).Invoke; Managed._bfp_InstantiateEntities = BurstCompiler.CompileFunctionPointer <Managed._dlg_InstantiateEntities>(_mono_to_burst_InstantiateEntities).Invoke; #endif }
private unsafe static void WriteFunctionPointer <TDelegate>(IntPtr ptr, TypeDecomposer.FieldData fieldData, MethodInfo method) where TDelegate : Delegate { var func = (TDelegate)method.CreateDelegate(typeof(TDelegate)); var compiled = BurstCompiler.CompileFunctionPointer <TDelegate>(func); UnsafeUtility.CopyStructureToPtr(ref compiled, (ptr + fieldData.offset).ToPointer()); }
public static BurstAction Compile(Action action) { var functionPointer = BurstCompiler.CompileFunctionPointer(action); DelegateCache <Action> .SetDelegate(functionPointer.Value, action); return(new BurstAction(functionPointer)); }
public PortableFunctionPointer(T executeDelegate) { #if !UNITY_DOTSPLAYER Ptr = BurstCompiler.CompileFunctionPointer(executeDelegate); #else Ptr = executeDelegate; #endif }
public static BurstFunc <TResult> Compile(Func <TResult> func) { var functionPointer = BurstCompiler.CompileFunctionPointer(func); DelegateCache <Func <TResult> > .SetDelegate(functionPointer.Value, func); return(new BurstFunc <TResult>(functionPointer)); }
void Start() { m_Texture = new Texture2D(k_Width, k_Height, TextureFormat.RFloat, true, true); TargetMaterial.mainTexture = m_Texture; m_RenderMandelbrot = BurstCompiler.CompileFunctionPointer <Render>(RenderMandelbrot).Invoke; m_RenderMandelbrotSimd = BurstCompiler.CompileFunctionPointer <Render>(RenderMandelbrotSimd).Invoke; }
public void StressTestFromBurst() { fixed(World.StateAllocator *p = &alloc) fixed(byte *s = systems.Bytes) { BurstCompiler.CompileFunctionPointer <RunBurstTest>(RunStressTest).Invoke((IntPtr)p, (IntPtr)s); } }
public float CheckFunctionPointer() { var functionPointer1 = BurstCompiler.CompileFunctionPointer <Add2NumbersDelegate>(Add2Numbers); var result = functionPointer1.Invoke(1.0f, 2.0f); var functionPointer2 = BurstCompiler.CompileFunctionPointer <Add2NumbersDelegate>(Add2NumbersThrows); return(functionPointer2.Invoke(1.0f, 2.0f)); }
static unsafe xxHash3() { if (_initialized) { return; } _initialized = true; _bfp_Hash64Long = BurstCompiler.CompileFunctionPointer <_dlg_Hash64Long>(_mono_to_burst_Hash64Long).Invoke; _bfp_Hash128Long = BurstCompiler.CompileFunctionPointer <_dlg_Hash128Long>(_mono_to_burst_Hash128Long).Invoke; }
private static void CompileFunctions() { _1ByteDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(Decorator1Byte); _2ByteDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(Decorator2Byte); _4ByteDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(Decorator4Byte); _8ByteDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(Decorator8Byte); _1ByteInvertedDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(InvertedDecorator1Byte); _2ByteInvertedDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(InvertedDecorator2Byte); _4ByteInvertedDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(InvertedDecorator4Byte); _8ByteInvertedDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(InvertedDecorator8Byte); }
internal static void Initialize() { #if !(UNITY_DOTSRUNTIME || (UNITY_2020_1_OR_NEWER && UNITY_IOS)) if (_initialized) { return; } _initialized = true; _bfp_PlaybackChainChunk = BurstCompiler.CompileFunctionPointer <_dlg_PlaybackChainChunk>(_mono_to_burst_PlaybackChainChunk).Invoke; #endif }
void Start() { m_CountSmallNumbers = BurstCompiler.CompileFunctionPointer <F>(CountSmallNumbers).Invoke; m_CountSmallNumbersSimd = BurstCompiler.CompileFunctionPointer <F>(CountSmallNumbersSimd).Invoke; m_Data = new float[1024 * 1024 * 16]; for (int i = 0; i < m_Data.Length; i++) { m_Data[i] = Random.value; } }
internal static void Initialize() { #if !UNITY_IOS if (Managed._initialized) { return; } Managed._initialized = true; Managed._bfp_Hash32 = BurstCompiler.CompileFunctionPointer <Managed._dlg_Hash32>(_mono_to_burst_Hash32).Invoke; #endif }
public static void Initialize() { _stripWhiteSpaceDelegate = BurstCompiler. CompileFunctionPointer <StripWhiteSpaceDelegate>(StripWhiteSpaceBurst).Invoke; _stripCharDelegate = BurstCompiler. CompileFunctionPointer <StripCharDelegate>(StripCharBurst).Invoke; _stripStringDelegate = BurstCompiler. CompileFunctionPointer <StripStringDelegate>(StripStringBurst).Invoke; }
internal static void Initialize() { #if !UNITY_IOS if (Managed._initialized) { return; } Managed._initialized = true; Managed._bfp_PlaybackChainChunk = BurstCompiler.CompileFunctionPointer <Managed._dlg_PlaybackChainChunk>(_mono_to_burst_PlaybackChainChunk).Invoke; #endif }
private static void CompileFunctions() { _1ByteEqualsDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(EqualsDecorator1Byte); _2ByteEqualsDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(EqualsDecorator2Byte); _4ByteEqualsDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(EqualsDecorator4Byte); _8ByteEqualsDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(EqualsDecorator8Byte); _1ByteNotEqualsDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(NotEqualsDecorator1Byte); _2ByteNotEqualsDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(NotEqualsDecorator2Byte); _4ByteNotEqualsDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(NotEqualsDecorator4Byte); _8ByteNotEqualsDecoratorFunction = BurstCompiler.CompileFunctionPointer <DecoratorDelegate>(NotEqualsDecorator8Byte); }
public static void Initialize() { _getCharsDelegate = BurstCompiler. CompileFunctionPointer <GetCharsDelegate>(GetCharsBurst).Invoke; _terminateDelegate = BurstCompiler. CompileFunctionPointer <TerminateDelegate>(TerminateBurst).Invoke; _getBytesDelegate = BurstCompiler. CompileFunctionPointer <GetBytesDelegate>(GetBytesBurst).Invoke; }
public IEnumerator CheckSafetyChecksOffGloballyAndOnInFunctionPointer() { BurstCompiler.Options.EnableBurstSafetyChecks = false; BurstCompiler.Options.ForceEnableBurstSafetyChecks = false; yield return(null); var funcPtr = BurstCompiler.CompileFunctionPointer <FunctionPointers.SafetyChecksDelegate>(FunctionPointers.WithSafetyChecksEnabled); // Safety Checks are off globally and on in job, but the global setting takes precedence. Assert.AreEqual(0, funcPtr.Invoke()); }
public IEnumerator CheckSafetyChecksOnGloballyAndOnInFunctionPointer() { BurstCompiler.Options.EnableBurstSafetyChecks = true; BurstCompiler.Options.ForceEnableBurstSafetyChecks = false; yield return(null); var funcPtr = BurstCompiler.CompileFunctionPointer <FunctionPointers.SafetyChecksDelegate>(FunctionPointers.WithSafetyChecksEnabled); // Safety Checks are on globally and on in the job. Assert.AreEqual(1, funcPtr.Invoke()); }
public IEnumerator CheckFunctionPointerForceSafetyChecksWorks() { BurstCompiler.Options.ForceEnableBurstSafetyChecks = true; yield return(null); var funcPtr = BurstCompiler.CompileFunctionPointer <FunctionPointers.SafetyChecksDelegate>(FunctionPointers.WithSafetyChecksDisabled); // Even though the job has set disabled safety checks, the menu item 'Force On' // has been set which overrides any other requested behaviour. Assert.AreEqual(1, funcPtr.Invoke()); }
public void CallJobFromFunctionPointer() { IJobBurstSchedulableExtensions.JobStruct <DivideByZeroJob> .Initialize(); var funcPtr = BurstCompiler.CompileFunctionPointer <CallJobDelegate>(CallJob); var job = new DivideByZeroJob { I = 0 }; funcPtr.Invoke(ref job); Assert.AreEqual(job.I, 1); }
unsafe static IntPtr CompileFunctionGeneric <T>(MethodInfo executeSelf) where T : struct { var executeDelegate = (ExecuteDelegate <T>) Delegate.CreateDelegate( typeof(ExecuteDelegate <T>), executeSelf); var functionPointer = BurstCompiler.CompileFunctionPointer( executeDelegate); return(*(IntPtr *)UnsafeUtility.AddressOf(ref functionPointer)); }
public static void FilterSmallNumbersWorksWithOddLengths() { var scalar = BurstCompiler.CompileFunctionPointer <FilterSmallNumbers>(SimdMath.FilterSmallNumbers).Invoke; var simd = BurstCompiler.CompileFunctionPointer <FilterSmallNumbers>(SimdMath.FilterSmallNumbersSIMD).Invoke; for (int testCase = 0; testCase < 100; testCase++) { Random.InitState(testCase); int length = Random.Range(5 * 16, 20 * 16); uint seed = 3628273133 * ((uint)testCase + 1); FilterSmallNumbersTestCase(seed, length, scalar, simd); } }
public static void RunningSumWorksWithOddLengths() { var scalar = BurstCompiler.CompileFunctionPointer <RunningSum>(SimdMath.RunningSum).Invoke; var simd = BurstCompiler.CompileFunctionPointer <RunningSum>(SimdMath.RunningSumSIMD).Invoke; for (int testCase = 0; testCase < 100; testCase++) { Random.InitState(testCase); int length = Random.Range(5 * 16, 20 * 16); uint seed = 3628273133 * ((uint)testCase + 1); RunningSumTestCase(seed, length, scalar, simd); } }
public void ManagedDelegateTest() { var funcPtr = BurstCompiler.CompileFunctionPointer <DoThingDelegate>(DoThing); // NOTE: funcPtr.Invoke allocates GC memory, // so in real world use cases we want to cache the managed delegate, not the FunctionPointer DoThingDelegate cachableDelegate = funcPtr.Invoke; int value = 5; cachableDelegate(ref value); Assert.AreEqual(6, value); }
public static void MatrixVectorMultiplyWorksWithOddLengths() { var scalar = BurstCompiler.CompileFunctionPointer <MatrixVectorMultiply>(SimdMath.MatrixVectorMultiply).Invoke; var simd = BurstCompiler.CompileFunctionPointer <MatrixVectorMultiply>(SimdMath.MatrixVectorMultiplySIMD).Invoke; for (int testCase = 0; testCase < 100; testCase++) { Random.InitState(testCase); int length = Random.Range(5 * 16, 20 * 16); uint seed = 3628273133 * ((uint)testCase + 1); MatrixVectorMultiplyTestCase(seed, length, scalar, simd); } }
public void JobFunctionPointerTest() { var funcPtr = BurstCompiler.CompileFunctionPointer <DoThingDelegate>(DoThing); var job = new MyJob(); int value = 5; job.Blah = &value; job.FunctionPointer = funcPtr; job.Schedule().Complete(); Assert.AreEqual(6, value); }