using System;
using System.Runtime.CompilerServices;
// Make internals visible for BurstGlobalCompilerOptions
[assembly: InternalsVisibleTo("Unity.Burst.CodeGen")]
[assembly: InternalsVisibleTo("Unity.Burst.Editor")]
// Make internals visible to Unity burst tests
[assembly: InternalsVisibleTo("Unity.Burst.Tests.UnitTests")]
[assembly: InternalsVisibleTo("Unity.Burst.Editor.Tests")]
[assembly: InternalsVisibleTo("Unity.Burst.Benchmarks")]
namespace Unity.Burst
{
///
/// How the code should be optimized.
///
public enum OptimizeFor
{
///
/// The default optimization mode - uses .
///
Default = 0,
///
/// Optimize for performance - the compiler should make the most optimal binary possible.
///
Performance = 1,
///
/// Optimize for size - the compiler should make the smallest binary possible.
///
Size = 2,
///
/// Optimize for fast compilation - the compiler should perform some optimization, but take as little time as possible to do it.
///
FastCompilation = 3,
///
/// Optimize for balanced compilation - ensuring that good performance is obtained while keeping compile time as low as possible.
///
Balanced = 4,
}
#if !BURST_COMPILER_SHARED
// FloatMode and FloatPrecision must be kept in sync with burst.h / Burst.Backend
///
/// Represents the floating point optimization mode for compilation.
///
public enum FloatMode
{
///
/// Use the default target floating point mode - .
///
Default = 0,
///
/// No floating point optimizations are performed.
///
Strict = 1,
///
/// Reserved for future.
///
Deterministic = 2,
///
/// Allows algebraically equivalent optimizations (which can alter the results of calculations), it implies :
/// optimizations can assume results and arguments contain no NaNs or +/- Infinity and treat sign of zero as insignificant.
/// optimizations can use reciprocals - 1/x * y , instead of y/x.
/// optimizations can use fused instructions, e.g. madd.
///
Fast = 3,
}
///
/// Represents the floating point precision used for certain builtin operations e.g. sin/cos.
///
public enum FloatPrecision
{
///
/// Use the default target floating point precision - .
///
Standard = 0,
///
/// Compute with an accuracy of 1 ULP - highly accurate, but increased runtime as a result, should not be required for most purposes.
///
High = 1,
///
/// Compute with an accuracy of 3.5 ULP - considered acceptable accuracy for most tasks.
///
Medium = 2,
///
/// Compute with an accuracy lower than or equal to , with some range restrictions (defined per function).
///
Low = 3,
}
///
/// This attribute is used to tag jobs or function-pointers as being Burst compiled, and optionally set compilation parameters.
///
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Assembly)]
public class BurstCompileAttribute : System.Attribute
{
///
/// Gets or sets the float mode of operation for this Burst compilation.
///
///
/// The default is .
///
public FloatMode FloatMode { get; set; }
///
/// Gets or sets the floating point precision to use for this Burst compilation.
/// Allows you to trade accuracy for speed of computation, useful when you don't require much precision.
///
///
/// The default is .
///
public FloatPrecision FloatPrecision { get; set; }
internal bool? _compileSynchronously;
///
/// Gets or sets whether or not to Burst compile the code immediately on first use, or in the background over time.
///
/// The default is false, true will force this code to be compiled synchronously on first invocation.
public bool CompileSynchronously
{
get => _compileSynchronously.HasValue ? _compileSynchronously.Value : false;
set => _compileSynchronously = value;
}
internal bool? _debug;
///
/// Gets or sets whether to compile the code in a way that allows it to be debugged.
/// If this is set to true, the current implementation disables optimisations on this method
/// allowing it to be debugged using a Native debugger.
///
///
/// The default is false.
///
public bool Debug
{
get => _debug.HasValue ? _debug.Value : false;
set => _debug = value;
}
internal bool? _disableSafetyChecks;
///
/// Gets or sets whether to disable safety checks for the current job or function pointer.
/// If this is set to true, the current job or function pointer will be compiled
/// with safety checks disabled unless the global 'Safety Checks/Force On' option is active.
///
///
/// The default is false.
///
public bool DisableSafetyChecks
{
get => _disableSafetyChecks.HasValue ? _disableSafetyChecks.Value : false;
set => _disableSafetyChecks = value;
}
#if UNITY_2019_3_OR_NEWER
internal bool? _disableDirectCall;
///
/// Gets or sets a boolean to disable the translation of a static method call as direct call to
/// the generated native method. By default, when compiling static methods with Burst and calling
/// them from C#, they will be translated to a direct call to the Burst generated method.
/// code.
///
///
/// The default is false.
///
public bool DisableDirectCall
{
get => _disableDirectCall.HasValue ? _disableDirectCall.Value : false;
set => _disableDirectCall = value;
}
#endif
///
/// How should this entry-point be optimized.
///
///
/// The default is .
///
public OptimizeFor OptimizeFor { get; set; }
internal string[] Options { get; set; }
///
/// Tags a struct/method/class as being Burst compiled, with the default , and .
///
///
///
/// [BurstCompile]
/// struct MyMethodsAreCompiledByBurstUsingTheDefaultSettings
/// {
/// //....
/// }
///
///
public BurstCompileAttribute()
{
}
///
/// Tags a struct/method/class as being Burst compiled, with the specified and .
///
///
///
/// [BurstCompile(FloatPrecision.Low, FloatMode.Fast)]
/// struct MyMethodsAreCompiledByBurstWithLowPrecisionAndFastFloatingPointMode
/// {
/// //....
/// }
///
///
/// Specify the required floating point precision.
/// Specify the required floating point mode.
public BurstCompileAttribute(FloatPrecision floatPrecision, FloatMode floatMode)
{
FloatMode = floatMode;
FloatPrecision = floatPrecision;
}
internal BurstCompileAttribute(string[] options)
{
Options = options;
}
}
#endif
}