Beispiel #1
0
 public BurstOutputCombination(string outputPath, MinMaxTargetCpu minMaxTargetCpu, string libraryName = DefaultLibraryName)
 {
     MinMaxTargetCpu = minMaxTargetCpu;
     OutputPath      = outputPath;
     LibraryName     = libraryName;
 }
Beispiel #2
0
        private static TargetPlatform GetTargetPlatformAndDefaultCpu(BuildTarget target, out MinMaxTargetCpu targetCpu)
        {
            var platform = TryGetTargetPlatform(target, out targetCpu);

            if (!platform.HasValue)
            {
                throw new NotSupportedException("The target platform " + target + " is not supported by the burst compiler");
            }
            return(platform.Value);
        }
Beispiel #3
0
        private static TargetPlatform?TryGetTargetPlatform(BuildTarget target, out MinMaxTargetCpu targetCpu)
        {
            var aotSettingsForTarget = BurstPlatformAotSettings.GetOrCreateSettings(target);

            // TODO: Add support for multi-CPU switch
            targetCpu.min = TargetCpu.Auto;
            targetCpu.max = TargetCpu.Auto;
            switch (target)
            {
            case BuildTarget.StandaloneWindows:
                targetCpu = aotSettingsForTarget.GetDesktopCpu32Bit();
                return(TargetPlatform.Windows);

            case BuildTarget.StandaloneWindows64:
                targetCpu = aotSettingsForTarget.GetDesktopCpu64Bit();
                return(TargetPlatform.Windows);

            case BuildTarget.StandaloneOSX:
                targetCpu = aotSettingsForTarget.GetDesktopCpu64Bit();
                return(TargetPlatform.macOS);

#if !UNITY_2019_2_OR_NEWER
            //32 bit linux support was deprecated
            case BuildTarget.StandaloneLinux:
                targetCpu = aotSettingsForTarget.GetDesktopCpu32Bit();
                return(TargetPlatform.Linux);
#endif
            case BuildTarget.StandaloneLinux64:
                targetCpu = aotSettingsForTarget.GetDesktopCpu64Bit();
                return(TargetPlatform.Linux);

            case BuildTarget.WSAPlayer:
                targetCpu = new MinMaxTargetCpu(TargetCpu.X64_SSE4);
                return(TargetPlatform.UWP);

            case BuildTarget.XboxOne:
                targetCpu = new MinMaxTargetCpu(TargetCpu.X64_SSE4);
                return(TargetPlatform.XboxOne);

            case BuildTarget.PS4:
                targetCpu = new MinMaxTargetCpu(TargetCpu.X64_SSE4);
                return(TargetPlatform.PS4);

            case BuildTarget.Android:
                targetCpu = new MinMaxTargetCpu(TargetCpu.ARMV7A_NEON32);
                return(TargetPlatform.Android);

            case BuildTarget.iOS:
                targetCpu = new MinMaxTargetCpu(TargetCpu.ARMV7A_NEON32);
                return(TargetPlatform.iOS);

            case BuildTarget.Lumin:
                targetCpu = new MinMaxTargetCpu(TargetCpu.ARMV8A_AARCH64);
                return(TargetPlatform.Lumin);

            case BuildTarget.Switch:
                targetCpu = new MinMaxTargetCpu(TargetCpu.ARMV8A_AARCH64);
                return(TargetPlatform.Switch);

#if UNITY_2019_3_OR_NEWER
            case BuildTarget.Stadia:
                targetCpu = new MinMaxTargetCpu(TargetCpu.AVX2);
                return(TargetPlatform.Stadia);
#endif
            }
            return(null);
        }
Beispiel #4
0
        /// <summary>
        /// Collect CPU combinations for the specified TargetPlatform and TargetCPU
        /// </summary>
        /// <param name="targetPlatform">The target platform (e.g Windows)</param>
        /// <param name="targetCpu">The target CPU (e.g X64_SSE4)</param>
        /// <param name="report">Error reporting</param>
        /// <returns>The list of CPU combinations</returns>
        private static List <BurstOutputCombination> CollectCombinations(TargetPlatform targetPlatform, MinMaxTargetCpu targetCpu, BuildReport report)
        {
            var combinations = new List <BurstOutputCombination>();

            if (targetPlatform == TargetPlatform.macOS)
            {
                // NOTE: OSX has a special folder for the plugin
                // Declared in GetStagingAreaPluginsFolder
                // PlatformDependent\OSXPlayer\Extensions\Managed\OSXDesktopStandalonePostProcessor.cs
#if UNITY_2019_3_OR_NEWER
                combinations.Add(new BurstOutputCombination(Path.Combine(Path.GetFileName(report.summary.outputPath), "Contents", "Plugins"), targetCpu));
#else
                combinations.Add(new BurstOutputCombination("UnityPlayer.app/Contents/Plugins", targetCpu));
#endif
            }
            else if (targetPlatform == TargetPlatform.iOS)
            {
                if (Application.platform != RuntimePlatform.OSXEditor)
                {
                    Debug.LogWarning("Burst Cross Compilation to iOS for standalone player, is only supported on OSX Editor at this time, burst is disabled for this build.");
                }
                else
                {
                    var targetArchitecture = (IOSArchitecture)UnityEditor.PlayerSettings.GetArchitecture(report.summary.platformGroup);
                    if (targetArchitecture == IOSArchitecture.ARMv7 || targetArchitecture == IOSArchitecture.Universal)
                    {
                        // PlatformDependent\iPhonePlayer\Extensions\Common\BuildPostProcessor.cs
                        combinations.Add(new BurstOutputCombination("StaticLibraries", new MinMaxTargetCpu(TargetCpu.ARMV7A_NEON32), DefaultLibraryName + "32"));
                    }

                    if (targetArchitecture == IOSArchitecture.ARM64 || targetArchitecture == IOSArchitecture.Universal)
                    {
                        // PlatformDependent\iPhonePlayer\Extensions\Common\BuildPostProcessor.cs
                        combinations.Add(new BurstOutputCombination("StaticLibraries", new MinMaxTargetCpu(TargetCpu.ARMV8A_AARCH64), DefaultLibraryName + "64"));
                    }
                }
            }
            else if (targetPlatform == TargetPlatform.Android)
            {
                // TODO: would be better to query AndroidNdkRoot (but thats not exposed from unity)
                string ndkRoot        = null;
                var    targetAPILevel = PlayerSettings.Android.GetMinTargetAPILevel();
#if UNITY_2019_3_OR_NEWER && UNITY_ANDROID
                ndkRoot = UnityEditor.Android.AndroidExternalToolsSettings.ndkRootPath;
#elif UNITY_2019_1_OR_NEWER
                // 2019.1 now has an embedded ndk
                if (EditorPrefs.HasKey("NdkUseEmbedded"))
                {
                    if (EditorPrefs.GetBool("NdkUseEmbedded"))
                    {
                        ndkRoot = Path.Combine(BuildPipeline.GetPlaybackEngineDirectory(BuildTarget.Android, BuildOptions.None), "NDK");
                    }
                    else
                    {
                        ndkRoot = EditorPrefs.GetString("AndroidNdkRootR16b");
                    }
                }
#elif UNITY_2018_3_OR_NEWER
                // Unity 2018.3 is using NDK r16b
                ndkRoot = EditorPrefs.GetString("AndroidNdkRootR16b");
#endif

                // If we still don't have a valid root, try the old key
                if (string.IsNullOrEmpty(ndkRoot))
                {
                    ndkRoot = EditorPrefs.GetString("AndroidNdkRoot");
                }

                // Verify the directory at least exists, if not we fall back to ANDROID_NDK_ROOT current setting
                if (!string.IsNullOrEmpty(ndkRoot) && !Directory.Exists(ndkRoot))
                {
                    ndkRoot = null;
                }

                // Always set the ANDROID_NDK_ROOT (if we got a valid result from above), so BCL knows where to find the Android toolchain and its the one the user expects
                if (!string.IsNullOrEmpty(ndkRoot))
                {
                    Environment.SetEnvironmentVariable("ANDROID_NDK_ROOT", ndkRoot);
                }

                Environment.SetEnvironmentVariable("BURST_ANDROID_MIN_API_LEVEL", $"{targetAPILevel}");

                var androidTargetArch = UnityEditor.PlayerSettings.Android.targetArchitectures;
                if ((androidTargetArch & AndroidArchitecture.ARMv7) != 0)
                {
                    combinations.Add(new BurstOutputCombination("libs/armeabi-v7a", new MinMaxTargetCpu(TargetCpu.ARMV7A_NEON32)));
                }

                if ((androidTargetArch & AndroidArchitecture.ARM64) != 0)
                {
                    combinations.Add(new BurstOutputCombination("libs/arm64-v8a", new MinMaxTargetCpu(TargetCpu.ARMV8A_AARCH64)));
                }
#if !UNITY_2019_2_OR_NEWER
                if ((androidTargetArch & AndroidArchitecture.X86) != 0)
                {
                    combinations.Add(new BurstOutputCombination("libs/x86", new MinMaxTargetCpu(TargetCpu.X86_SSE2)));
                }
#endif
            }
            else if (targetPlatform == TargetPlatform.UWP)
            {
                // TODO: Make it configurable for x86 (sse2, sse4)
                combinations.Add(new BurstOutputCombination("Plugins/x64", new MinMaxTargetCpu(TargetCpu.X64_SSE4)));
                combinations.Add(new BurstOutputCombination("Plugins/x86", new MinMaxTargetCpu(TargetCpu.X86_SSE2)));
                combinations.Add(new BurstOutputCombination("Plugins/ARM", new MinMaxTargetCpu(TargetCpu.THUMB2_NEON32)));
                combinations.Add(new BurstOutputCombination("Plugins/ARM64", new MinMaxTargetCpu(TargetCpu.ARMV8A_AARCH64)));
            }
            else if (targetPlatform == TargetPlatform.Lumin)
            {
                // Set the LUMINSDK_UNITY so bcl.exe will be able to find the SDK
                if (string.IsNullOrEmpty(Environment.GetEnvironmentVariable("LUMINSDK_UNITY")))
                {
                    var sdkRoot = EditorPrefs.GetString("LuminSDKRoot");
                    if (!string.IsNullOrEmpty(sdkRoot))
                    {
                        Environment.SetEnvironmentVariable("LUMINSDK_UNITY", sdkRoot);
                    }
                }
                combinations.Add(new BurstOutputCombination("Data/Plugins/", targetCpu));
            }
            else if (targetPlatform == TargetPlatform.Switch)
            {
                combinations.Add(new BurstOutputCombination("NativePlugins/", targetCpu));
            }
#if UNITY_2019_3_OR_NEWER
            else if (targetPlatform == TargetPlatform.Stadia)
            {
                combinations.Add(new BurstOutputCombination("NativePlugins", targetCpu));
            }
#endif
            else
            {
#if UNITY_2020_1_OR_NEWER
                if (targetPlatform == TargetPlatform.Windows)
                {
                    // This is what is expected by PlatformDependent\Win\Plugins.cpp
                    switch (targetCpu.max)
                    {
                    case TargetCpu.X86_SSE2:
                    case TargetCpu.X86_SSE4:
                        combinations.Add(new BurstOutputCombination("Data/Plugins/x86", targetCpu));
                        break;

                    case TargetCpu.X64_SSE2:
                    case TargetCpu.X64_SSE4:
                    case TargetCpu.AVX:
                    case TargetCpu.AVX2:
                        combinations.Add(new BurstOutputCombination("Data/Plugins/x86_64", targetCpu));
                        break;

                    default:
                        // Safeguard
                        combinations.Add(new BurstOutputCombination("Data/Plugins", targetCpu));
                        break;
                    }
                }
                else
#endif
                {
                    // Safeguard
                    combinations.Add(new BurstOutputCombination("Data/Plugins/", targetCpu));
                }
            }

            return(combinations);
        }