using UnityEngine; using UnityEngine.Rendering; namespace Unity.Barracuda { /// /// GPU compute info /// public class ComputeInfo { /// /// Channel order enum /// public enum ChannelsOrder { /// /// Channels last /// NHWC, /// /// Channels first /// NCHW } /// /// GPU supports shared memory /// public static bool supportsComputeSharedMemory = true; /// /// GPU supports Dense 32x32 kernels /// public static bool supportsDense32x32 = true; /// /// GPU supports Dense 64x64 kernels /// public static bool supportsDense64x64 = true; /// /// GPU supports compute /// public static bool supportsCompute = true; /// /// Max compute work group size supported by GPU /// public static uint maxComputeWorkGroupSize = 1024; /// /// GPU vendor /// public static string graphicsDeviceVendor = ""; /// /// Helper for hardware selection /// public static bool IsMobileGPU() { return (Application.platform == RuntimePlatform.Android) || (Application.platform == RuntimePlatform.IPhonePlayer) || graphicsDeviceVendor.Contains("Intel"); } public static bool IsiPhoneGPU() { return (Application.platform == RuntimePlatform.IPhonePlayer); } public static bool IsQualcommGPU() { return (Application.platform == RuntimePlatform.Android) && graphicsDeviceVendor.Contains("Qualcomm"); } public static bool IsARMGPU() { return (Application.platform == RuntimePlatform.Android) && graphicsDeviceVendor.Contains("ARM"); } /// /// EXPERIMENTAL: Select Channel order of the compute backends. /// Production code should stick to default (NHWC) for now. /// public static ChannelsOrder channelsOrder = ChannelsOrder.NHWC; /// /// Static constructor, initializes and caches data /// static ComputeInfo() { string[] args = System.Environment.GetCommandLineArgs (); for (int i = 0; i < args.Length; i++) { if (args [i] == "-barracuda-compute-use-nchw") { channelsOrder = ChannelsOrder.NCHW; } } supportsCompute = SystemInfo.supportsComputeShaders; graphicsDeviceVendor = SystemInfo.graphicsDeviceVendor; // TODO switch to SystemInfo.maxComputeWorkGroupSize when we bump min spec to 2019.3 if (Application.platform == RuntimePlatform.Android) { maxComputeWorkGroupSize = (SystemInfo.graphicsDeviceType == GraphicsDeviceType.Vulkan) ? 256u : 128u; var gpuName = SystemInfo.graphicsDeviceName ?? ""; var osName = SystemInfo.operatingSystem ?? ""; // Known issue with Adreno Vulkan drivers on Android 8.x if (gpuName.Contains("Adreno") && osName.StartsWith("Android OS 8") && SystemInfo.graphicsDeviceType == GraphicsDeviceType.Vulkan) maxComputeWorkGroupSize = 128u; } else if (Application.platform == RuntimePlatform.IPhonePlayer || Application.platform == RuntimePlatform.tvOS) { var gpuName = SystemInfo.graphicsDeviceName; if (gpuName != null && gpuName.StartsWith("Apple A")) { int gpuNumber = 0, idx = "Apple A".Length; while (idx < gpuName.Length && '0' <= gpuName[idx] && gpuName[idx] <= '9') { gpuNumber = gpuNumber * 10 + gpuName[idx++] - '0'; } // TODO check on lower end iOS devices maxComputeWorkGroupSize = (gpuNumber <= 10) ? 224u : 256u; } else { maxComputeWorkGroupSize = 256u; } } } } }