static BurstLoader() { if (BurstCompilerOptions.ForceDisableBurstCompilation) { UnityEngine.Debug.LogWarning("[com.unity.burst] Burst is disabled entirely from the command line"); return; } // This can be setup to get more diagnostics var debuggingStr = Environment.GetEnvironmentVariable("UNITY_BURST_DEBUG"); IsDebugging = debuggingStr != null; if (IsDebugging) { UnityEngine.Debug.LogWarning("[com.unity.burst] Extra debugging is turned on."); int debuggingLevel; int.TryParse(debuggingStr, out debuggingLevel); if (debuggingLevel <= 0) { debuggingLevel = 1; } DebuggingLevel = debuggingLevel; } // Try to load the runtime through an environment variable RuntimePath = Environment.GetEnvironmentVariable("UNITY_BURST_RUNTIME_PATH"); // Otherwise try to load it from the package itself if (!Directory.Exists(RuntimePath)) { RuntimePath = Path.GetFullPath("Packages/com.unity.burst/.Runtime"); } if (IsDebugging) { UnityEngine.Debug.LogWarning($"[com.unity.burst] Runtime directory set to {RuntimePath}"); } BurstEditorOptions.EnsureSynchronized(); BurstCompilerService.Initialize(RuntimePath, TryGetOptionsFromMemberDelegate); EditorApplication.quitting += BurstCompiler.Shutdown; CompilationPipeline.assemblyCompilationStarted += OnAssemblyCompilationStarted; CompilationPipeline.assemblyCompilationFinished += OnAssemblyCompilationFinished; EditorApplication.playModeStateChanged += EditorApplicationOnPlayModeStateChanged; VersionUpdateCheck(); // Workaround to update the list of assembly folders as soon as possible // in order for the JitCompilerService to not fail with AssemblyResolveExceptions. try { var assemblyList = BurstReflection.GetAssemblyList(AssembliesType.Editor); var assemblyFolders = new HashSet <string>(); foreach (var assembly in assemblyList) { try { var fullPath = Path.GetFullPath(assembly.Location); var assemblyFolder = Path.GetDirectoryName(fullPath); if (!string.IsNullOrEmpty(assemblyFolder)) { assemblyFolders.Add(assemblyFolder); } } catch { // ignore } } // Notify the compiler var assemblyFolderList = assemblyFolders.ToList(); if (IsDebugging) { UnityEngine.Debug.Log($"Burst - Change of list of assembly folders:\n{string.Join("\n", assemblyFolderList)}"); } BurstCompiler.UpdateAssemblerFolders(assemblyFolderList); } catch { // ignore } // Notify the compiler about a domain reload if (IsDebugging) { UnityEngine.Debug.Log("Burst - Domain Reload"); } // Notify the JitCompilerService about a domain reload BurstCompiler.DomainReload(); // Make sure that the X86 CSR function pointers are compiled Intrinsics.X86.CompileManagedCsrAccessors(); // Make sure BurstRuntime is initialized BurstRuntime.Initialize(); }
static BurstLoader() { if (BurstCompilerOptions.ForceDisableBurstCompilation) { UnityEngine.Debug.LogWarning("[com.unity.burst] Burst is disabled entirely from the command line"); return; } // This can be setup to get more diagnostics var debuggingStr = Environment.GetEnvironmentVariable("UNITY_BURST_DEBUG"); IsDebugging = debuggingStr != null; if (IsDebugging) { UnityEngine.Debug.LogWarning("[com.unity.burst] Extra debugging is turned on."); int debuggingLevel; int.TryParse(debuggingStr, out debuggingLevel); if (debuggingLevel <= 0) { debuggingLevel = 1; } DebuggingLevel = debuggingLevel; } // Try to load the runtime through an environment variable if (!UnityBurstRuntimePathOverwritten(out var path)) { // Otherwise try to load it from the package itself path = Path.GetFullPath("Packages/com.unity.burst/.Runtime"); } RuntimePath = path; if (IsDebugging) { UnityEngine.Debug.LogWarning($"[com.unity.burst] Runtime directory set to {RuntimePath}"); } BurstCompilerService.Initialize(RuntimePath, TryGetOptionsFromMemberDelegate); // It's important that this call comes *after* BurstCompilerService.Initialize, // otherwise any calls from within EnsureSynchronized to BurstCompilerService, // such as BurstCompiler.Disable(), will silently fail. BurstEditorOptions.EnsureSynchronized(); EditorApplication.quitting += OnEditorApplicationQuitting; #if UNITY_2019_1_OR_NEWER CompilationPipeline.compilationStarted += OnCompilationStarted; #endif CompilationPipeline.assemblyCompilationStarted += OnAssemblyCompilationStarted; CompilationPipeline.assemblyCompilationFinished += OnAssemblyCompilationFinished; EditorApplication.playModeStateChanged += EditorApplicationOnPlayModeStateChanged; AppDomain.CurrentDomain.DomainUnload += OnDomainUnload; VersionUpdateCheck(); BurstReflection.EnsureInitialized(); #if !UNITY_2019_3_OR_NEWER // Workaround to update the list of assembly folders as soon as possible // in order for the JitCompilerService to not fail with AssemblyResolveExceptions. // This workaround is only necessary for editors prior to 2019.3 (i.e. 2018.4), // because 2019.3+ include a fix on the Unity side. try { var assemblyList = BurstReflection.AllEditorAssemblies; var assemblyFolders = new HashSet <string>(); foreach (var assembly in assemblyList) { try { var fullPath = Path.GetFullPath(assembly.Location); var assemblyFolder = Path.GetDirectoryName(fullPath); if (!string.IsNullOrEmpty(assemblyFolder)) { assemblyFolders.Add(assemblyFolder); } } catch { // ignore } } // Notify the compiler var assemblyFolderList = assemblyFolders.ToList(); if (IsDebugging) { UnityEngine.Debug.Log($"Burst - Change of list of assembly folders:\n{string.Join("\n", assemblyFolderList)}"); } BurstCompiler.UpdateAssemblerFolders(assemblyFolderList); } catch { // ignore } #endif // Notify the compiler about a domain reload if (IsDebugging) { UnityEngine.Debug.Log("Burst - Domain Reload"); } // Notify the JitCompilerService about a domain reload BurstCompiler.DomainReload(); #if UNITY_2020_1_OR_NEWER BurstCompiler.OnProgress += OnProgress; BurstCompiler.SetProgressCallback(); #endif #if !BURST_INTERNAL && !UNITY_DOTSPLAYER // Make sure that the X86 CSR function pointers are compiled Intrinsics.X86.CompileManagedCsrAccessors(); #endif // Make sure BurstRuntime is initialized BurstRuntime.Initialize(); // Schedule upfront compilation of all methods in all assemblies, // with the goal of having as many methods as possible Burst-compiled // by the time the user enters PlayMode. if (!EditorApplication.isPlayingOrWillChangePlaymode) { MaybeTriggerEagerCompilation(); } #if UNITY_2020_1_OR_NEWER // Can't call Menu.AddMenuItem immediately, presumably because the menu controller isn't initialized yet. EditorApplication.CallDelayed(() => CreateDynamicMenuItems()); #endif }