Без опису
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239
  1. using System;
  2. using System.Runtime.CompilerServices;
  3. // Make internals visible for BurstGlobalCompilerOptions
  4. [assembly: InternalsVisibleTo("Unity.Burst.CodeGen")]
  5. [assembly: InternalsVisibleTo("Unity.Burst.Editor")]
  6. // Make internals visible to Unity burst tests
  7. [assembly: InternalsVisibleTo("Unity.Burst.Tests.UnitTests")]
  8. [assembly: InternalsVisibleTo("Unity.Burst.Editor.Tests")]
  9. [assembly: InternalsVisibleTo("Unity.Burst.Benchmarks")]
  10. namespace Unity.Burst
  11. {
  12. /// <summary>
  13. /// How the code should be optimized.
  14. /// </summary>
  15. public enum OptimizeFor
  16. {
  17. /// <summary>
  18. /// The default optimization mode - uses <see cref="OptimizeFor.Balanced"/>.
  19. /// </summary>
  20. Default = 0,
  21. /// <summary>
  22. /// Optimize for performance - the compiler should make the most optimal binary possible.
  23. /// </summary>
  24. Performance = 1,
  25. /// <summary>
  26. /// Optimize for size - the compiler should make the smallest binary possible.
  27. /// </summary>
  28. Size = 2,
  29. /// <summary>
  30. /// Optimize for fast compilation - the compiler should perform some optimization, but take as little time as possible to do it.
  31. /// </summary>
  32. FastCompilation = 3,
  33. /// <summary>
  34. /// Optimize for balanced compilation - ensuring that good performance is obtained while keeping compile time as low as possible.
  35. /// </summary>
  36. Balanced = 4,
  37. }
  38. #if !BURST_COMPILER_SHARED
  39. // FloatMode and FloatPrecision must be kept in sync with burst.h / Burst.Backend
  40. /// <summary>
  41. /// Represents the floating point optimization mode for compilation.
  42. /// </summary>
  43. public enum FloatMode
  44. {
  45. /// <summary>
  46. /// Use the default target floating point mode - <see cref="FloatMode.Strict"/>.
  47. /// </summary>
  48. Default = 0,
  49. /// <summary>
  50. /// No floating point optimizations are performed.
  51. /// </summary>
  52. Strict = 1,
  53. /// <summary>
  54. /// Reserved for future.
  55. /// </summary>
  56. Deterministic = 2,
  57. /// <summary>
  58. /// Allows algebraically equivalent optimizations (which can alter the results of calculations), it implies :
  59. /// <para/> optimizations can assume results and arguments contain no NaNs or +/- Infinity and treat sign of zero as insignificant.
  60. /// <para/> optimizations can use reciprocals - 1/x * y , instead of y/x.
  61. /// <para/> optimizations can use fused instructions, e.g. madd.
  62. /// </summary>
  63. Fast = 3,
  64. }
  65. /// <summary>
  66. /// Represents the floating point precision used for certain builtin operations e.g. sin/cos.
  67. /// </summary>
  68. public enum FloatPrecision
  69. {
  70. /// <summary>
  71. /// Use the default target floating point precision - <see cref="FloatPrecision.Medium"/>.
  72. /// </summary>
  73. Standard = 0,
  74. /// <summary>
  75. /// Compute with an accuracy of 1 ULP - highly accurate, but increased runtime as a result, should not be required for most purposes.
  76. /// </summary>
  77. High = 1,
  78. /// <summary>
  79. /// Compute with an accuracy of 3.5 ULP - considered acceptable accuracy for most tasks.
  80. /// </summary>
  81. Medium = 2,
  82. /// <summary>
  83. /// Compute with an accuracy lower than or equal to <see cref="FloatPrecision.Medium"/>, with some range restrictions (defined per function).
  84. /// </summary>
  85. Low = 3,
  86. }
  87. /// <summary>
  88. /// This attribute is used to tag jobs or function-pointers as being Burst compiled, and optionally set compilation parameters.
  89. /// </summary>
  90. [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Assembly)]
  91. public class BurstCompileAttribute : System.Attribute
  92. {
  93. /// <summary>
  94. /// Gets or sets the float mode of operation for this Burst compilation.
  95. /// </summary>
  96. /// <value>
  97. /// The default is <see cref="FloatMode.Default"/>.
  98. /// </value>
  99. public FloatMode FloatMode { get; set; }
  100. /// <summary>
  101. /// Gets or sets the floating point precision to use for this Burst compilation.
  102. /// Allows you to trade accuracy for speed of computation, useful when you don't require much precision.
  103. /// </summary>
  104. /// <value>
  105. /// The default is <see cref="FloatPrecision.Standard"/>.
  106. /// </value>
  107. public FloatPrecision FloatPrecision { get; set; }
  108. internal bool? _compileSynchronously;
  109. /// <summary>
  110. /// Gets or sets whether or not to Burst compile the code immediately on first use, or in the background over time.
  111. /// </summary>
  112. /// <value>The default is <c>false</c>, <c>true</c> will force this code to be compiled synchronously on first invocation.</value>
  113. public bool CompileSynchronously
  114. {
  115. get => _compileSynchronously.HasValue ? _compileSynchronously.Value : false;
  116. set => _compileSynchronously = value;
  117. }
  118. internal bool? _debug;
  119. /// <summary>
  120. /// Gets or sets whether to compile the code in a way that allows it to be debugged.
  121. /// If this is set to <c>true</c>, the current implementation disables optimisations on this method
  122. /// allowing it to be debugged using a Native debugger.
  123. /// </summary>
  124. /// <value>
  125. /// The default is <c>false</c>.
  126. /// </value>
  127. public bool Debug
  128. {
  129. get => _debug.HasValue ? _debug.Value : false;
  130. set => _debug = value;
  131. }
  132. internal bool? _disableSafetyChecks;
  133. /// <summary>
  134. /// Gets or sets whether to disable safety checks for the current job or function pointer.
  135. /// If this is set to <c>true</c>, the current job or function pointer will be compiled
  136. /// with safety checks disabled unless the global 'Safety Checks/Force On' option is active.
  137. /// </summary>
  138. /// <value>
  139. /// The default is <c>false</c>.
  140. /// </value>
  141. public bool DisableSafetyChecks
  142. {
  143. get => _disableSafetyChecks.HasValue ? _disableSafetyChecks.Value : false;
  144. set => _disableSafetyChecks = value;
  145. }
  146. internal bool? _disableDirectCall;
  147. /// <summary>
  148. /// Gets or sets a boolean to disable the translation of a static method call as direct call to
  149. /// the generated native method. By default, when compiling static methods with Burst and calling
  150. /// them from C#, they will be translated to a direct call to the Burst generated method.
  151. /// code.
  152. /// </summary>
  153. /// <value>
  154. /// The default is <c>false</c>.
  155. /// </value>
  156. public bool DisableDirectCall
  157. {
  158. get => _disableDirectCall.HasValue ? _disableDirectCall.Value : false;
  159. set => _disableDirectCall = value;
  160. }
  161. /// <summary>
  162. /// How should this entry-point be optimized.
  163. /// </summary>
  164. /// <value>
  165. /// The default is <see cref="OptimizeFor.Default"/>.
  166. /// </value>
  167. public OptimizeFor OptimizeFor { get; set; }
  168. internal string[] Options { get; set; }
  169. /// <summary>
  170. /// Tags a struct/method/class as being Burst compiled, with the default <see cref="FloatPrecision"/>, <see cref="FloatMode"/> and <see cref="CompileSynchronously"/>.
  171. /// </summary>
  172. /// <example>
  173. /// <code>
  174. /// [BurstCompile]
  175. /// struct MyMethodsAreCompiledByBurstUsingTheDefaultSettings
  176. /// {
  177. /// //....
  178. /// }
  179. ///</code>
  180. /// </example>
  181. public BurstCompileAttribute()
  182. {
  183. }
  184. /// <summary>
  185. /// Tags a struct/method/class as being Burst compiled, with the specified <see cref="FloatPrecision"/> and <see cref="FloatMode"/>.
  186. /// </summary>
  187. /// <example>
  188. /// <code>
  189. /// [BurstCompile(FloatPrecision.Low, FloatMode.Fast)]
  190. /// struct MyMethodsAreCompiledByBurstWithLowPrecisionAndFastFloatingPointMode
  191. /// {
  192. /// //....
  193. /// }
  194. ///</code>
  195. ///</example>
  196. /// <param name="floatPrecision">Specify the required floating point precision.</param>
  197. /// <param name="floatMode">Specify the required floating point mode.</param>
  198. public BurstCompileAttribute(FloatPrecision floatPrecision, FloatMode floatMode)
  199. {
  200. FloatMode = floatMode;
  201. FloatPrecision = floatPrecision;
  202. }
  203. internal BurstCompileAttribute(string[] options)
  204. {
  205. Options = options;
  206. }
  207. }
  208. #endif
  209. }