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