0.2.0-dev Download ZIP
33 lines ·918 B Raw
| 1 | namespace EvilEngine.GenerativeMotion; |
| 2 | |
| 3 | public enum MotionDevice |
| 4 | { |
| 5 | Cpu, |
| 6 | Gpu |
| 7 | } |
| 8 | |
| 9 | public readonly record struct MotionBackend(MotionDevice Device, int Adapter) |
| 10 | { |
| 11 | public static MotionBackend Cpu => new(MotionDevice.Cpu, 0); |
| 12 | |
| 13 | public static MotionBackend Gpu(int adapter) |
| 14 | { |
| 15 | ArgumentOutOfRangeException.ThrowIfNegative(adapter); |
| 16 | return new MotionBackend(MotionDevice.Gpu, adapter); |
| 17 | } |
| 18 | |
| 19 | public static MotionBackend Parse(string text) |
| 20 | { |
| 21 | if (text == "cpu") |
| 22 | return Cpu; |
| 23 | if (text.StartsWith("gpu:", StringComparison.Ordinal) && int.TryParse(text.AsSpan(4), out var adapter) && |
| 24 | adapter >= 0) |
| 25 | return Gpu(adapter); |
| 26 | throw new FormatException($"'{text}' isn't a backend: 'cpu' or 'gpu:<adapter>'."); |
| 27 | } |
| 28 | |
| 29 | public override string ToString() |
| 30 | { |
| 31 | return Device == MotionDevice.Cpu ? "cpu" : $"gpu:{Adapter}"; |
| 32 | } |
| 33 | } |