Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

BurstEditorOptions.cs 5.7KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #if UNITY_EDITOR
  2. using System.Diagnostics;
  3. using UnityEditor;
  4. namespace Unity.Burst.Editor
  5. {
  6. /// <summary>
  7. /// Responsible to synchronize <see cref="BurstCompiler.Options"/> with the menu
  8. /// </summary>
  9. internal static class BurstEditorOptions
  10. {
  11. // Properties stored in SessionState (survive between domain reloads, but stays alive only during the life of the editor)
  12. private const string EnableBurstSafetyChecksText = "BurstSafetyChecks";
  13. // Properties stored in EditorPrefs (survive between editor restart)
  14. private const string EnableBurstCompilationText = "BurstCompilation";
  15. private const string EnableBurstTimingsText = "BurstShowTimings";
  16. private const string EnableBurstCompileSynchronouslyText = "BurstCompileSynchronously";
  17. private const string EnableBurstDebugText = "BurstDebug";
  18. private const string ForceEnableBurstSafetyChecksText = "BurstForceSafetyChecks";
  19. /// <summary>
  20. /// <c>true</c> if the menu options are synchronized with <see cref="BurstCompiler.Options"/>
  21. /// </summary>
  22. private static bool _isSynchronized;
  23. public static void EnsureSynchronized()
  24. {
  25. GetGlobalOptions();
  26. }
  27. public static bool EnableBurstCompilation
  28. {
  29. get => GetGlobalOptions().EnableBurstCompilation;
  30. set
  31. {
  32. var enabled = GetGlobalOptions().EnableBurstCompilation;
  33. GetGlobalOptions().EnableBurstCompilation = value;
  34. if (!enabled && value)
  35. {
  36. // Must be called AFTER we actually enable compilation
  37. BurstCompiler.TriggerUnsafeStaticMethodRecompilation();
  38. }
  39. }
  40. }
  41. public static bool EnableBurstSafetyChecks
  42. {
  43. get => GetGlobalOptions().EnableBurstSafetyChecks;
  44. set => GetGlobalOptions().EnableBurstSafetyChecks = value;
  45. }
  46. public static bool EnableBurstCompileSynchronously
  47. {
  48. get => GetGlobalOptions().EnableBurstCompileSynchronously;
  49. set => GetGlobalOptions().EnableBurstCompileSynchronously = value;
  50. }
  51. public static bool EnableBurstTimings
  52. {
  53. get => GetGlobalOptions().EnableBurstTimings;
  54. set => GetGlobalOptions().EnableBurstTimings = value;
  55. }
  56. public static bool EnableBurstDebug
  57. {
  58. get => GetGlobalOptions().EnableBurstDebug;
  59. set => GetGlobalOptions().EnableBurstDebug = value;
  60. }
  61. public static bool ForceEnableBurstSafetyChecks
  62. {
  63. get => GetGlobalOptions().ForceEnableBurstSafetyChecks;
  64. set => GetGlobalOptions().ForceEnableBurstSafetyChecks = value;
  65. }
  66. private static BurstCompilerOptions GetGlobalOptions()
  67. {
  68. var global = BurstCompiler.Options;
  69. // If options are not synchronize with our global instance, setup the sync
  70. if (!_isSynchronized)
  71. {
  72. global.IsInitializing = true;
  73. try
  74. {
  75. // Setup the synchronization
  76. global.EnableBurstCompilation = EditorPrefs.GetBool(EnableBurstCompilationText, true);
  77. global.EnableBurstCompileSynchronously = EditorPrefs.GetBool(EnableBurstCompileSynchronouslyText, false);
  78. global.EnableBurstTimings = EditorPrefs.GetBool(EnableBurstTimingsText, false);
  79. global.EnableBurstDebug = EditorPrefs.GetBool(EnableBurstDebugText, false);
  80. global.ForceEnableBurstSafetyChecks = EditorPrefs.GetBool(ForceEnableBurstSafetyChecksText, false);
  81. #if UNITY_2019_3_OR_NEWER
  82. // Session only properties
  83. global.EnableBurstSafetyChecks = SessionState.GetBool(EnableBurstSafetyChecksText, true);
  84. #else
  85. // In editors older than 2019.3, it's necessary to restart the Editor when changing safety check options.
  86. // So to make it possible to actually set the safety checks option, we need to persist it.
  87. global.EnableBurstSafetyChecks = EditorPrefs.GetBool(EnableBurstSafetyChecksText, true);
  88. #endif
  89. }
  90. finally
  91. {
  92. global.IsInitializing = false;
  93. }
  94. global.OptionsChanged += GlobalOnOptionsChanged;
  95. _isSynchronized = true;
  96. }
  97. return global;
  98. }
  99. private static void GlobalOnOptionsChanged()
  100. {
  101. var global = BurstCompiler.Options;
  102. // We are not optimizing anything here, so whenever one option is set, we reset all of them
  103. EditorPrefs.SetBool(EnableBurstCompilationText, global.EnableBurstCompilation);
  104. EditorPrefs.SetBool(EnableBurstCompileSynchronouslyText, global.EnableBurstCompileSynchronously);
  105. EditorPrefs.SetBool(EnableBurstTimingsText, global.EnableBurstTimings);
  106. EditorPrefs.SetBool(EnableBurstDebugText, global.EnableBurstDebug);
  107. EditorPrefs.SetBool(ForceEnableBurstSafetyChecksText, global.ForceEnableBurstSafetyChecks);
  108. #if UNITY_2019_3_OR_NEWER
  109. // Session only properties
  110. SessionState.SetBool(EnableBurstSafetyChecksText, global.EnableBurstSafetyChecks);
  111. #else
  112. // In editors older than 2019.3, it's necessary to restart the Editor when changing safety check options.
  113. // So to make it possible to actually set the safety checks option, we need to persist it.
  114. EditorPrefs.SetBool(EnableBurstSafetyChecksText, global.EnableBurstSafetyChecks);
  115. #endif
  116. }
  117. }
  118. }
  119. #endif