private static bool GetIsSupported() { bool result = false; try { if (RuntimeInformation.IsOSPlatform(OSPlatform.OSX)) { if (RuntimeInformation.OSDescription.Contains("Darwin")) { NSArray allDevices = MTLDevice.MTLCopyAllDevices(); result |= (ulong)allDevices.count > 0; ObjectiveCRuntime.release(allDevices.NativePtr); } else { MTLDevice defaultDevice = MTLDevice.MTLCreateSystemDefaultDevice(); if (defaultDevice.NativePtr != IntPtr.Zero) { result = true; ObjectiveCRuntime.release(defaultDevice.NativePtr); } } } } catch { result = false; } return(result); }
public void GetAllDevicesTestOutObserver() { var devices = MTLDevice.GetAllDevices((IMTLDevice device, NSString notifyName) => { }, out var observer); // It's possible to run on a system that does not support metal, // in which case we'll get an empty array of devices. Assert.IsNotNull(devices, "MTLDevices.GetAllDevices not null"); MTLDevice.RemoveObserver(observer); }
public void GetAllDevicesTest() { NSObject refObj = new NSObject(); var devices = MTLDevice.GetAllDevices(ref refObj, (IMTLDevice device, NSString notifyName) => { }); Assert.That(devices, Is.Not.Empty, "MTLDevice.GetAllDevices"); Assert.DoesNotThrow(() => { MTLDevice.RemoveObserver(refObj); }); }
public void GetAllDevicesTest() { #if __MACCATALYST__ TestRuntime.AssertXcodeVersion(13, 0); #endif NSObject refObj = new NSObject(); var devices = MTLDevice.GetAllDevices(); // It's possible to run on a system that does not support metal, // in which case we'll get an empty array of devices. Assert.IsNotNull(devices, "MTLDevices.GetAllDevices not null"); }
public void GetAllDevicesTest() { NSObject refObj = new NSObject(); var devices = MTLDevice.GetAllDevices(ref refObj, (IMTLDevice device, NSString notifyName) => { }); // It's possible to run on a system that does not support metal, // in which case we'll get an empty array of devices. Assert.IsNotNull(devices, "MTLDevices.GetAllDevices not null"); Assert.DoesNotThrow(() => { MTLDevice.RemoveObserver(refObj); }); }
public MTLFeatureSupport(MTLDevice device) { foreach (MTLFeatureSet set in Enum.GetValues(typeof(MTLFeatureSet))) { if (device.supportsFeatureSet(set)) { _supportedFeatureSets.Add(set); } } IsMacOS = IsSupported(MTLFeatureSet.macOS_GPUFamily1_v1) || IsSupported(MTLFeatureSet.macOS_GPUFamily1_v2) || IsSupported(MTLFeatureSet.macOS_GPUFamily1_v3); }
public MTLGraphicsDevice( GraphicsDeviceOptions options, SwapchainDescription?swapchainDesc) { _device = MTLDevice.MTLCreateSystemDefaultDevice(); MetalFeatures = new MTLFeatureSupport(_device); Features = new GraphicsDeviceFeatures( computeShader: true, geometryShader: false, tessellationShaders: false, multipleViewports: MetalFeatures.IsSupported(MTLFeatureSet.macOS_GPUFamily1_v3), samplerLodBias: false, drawBaseVertex: true, drawBaseInstance: true, drawIndirect: true, drawIndirectBaseInstance: true, fillModeWireframe: true, samplerAnisotropy: true, depthClipDisable: true, texture1D: true, // TODO: Should be macOS 10.11+ and iOS 11.0+. independentBlend: true, structuredBuffer: true, subsetTextureView: true, commandListDebugMarkers: true, bufferRangeBinding: true); ResourceBindingModel = options.ResourceBindingModel; _libSystem = new NativeLibrary("libSystem.dylib"); _concreteGlobalBlock = _libSystem.LoadFunction <IntPtr>("_NSConcreteGlobalBlock"); if (MetalFeatures.IsMacOS) { _completionHandler = OnCommandBufferCompleted; } else { _completionHandler = OnCommandBufferCompleted_Static; } _completionHandlerFuncPtr = Marshal.GetFunctionPointerForDelegate <MTLCommandBufferHandler>(_completionHandler); _completionBlockDescriptor = Marshal.AllocHGlobal(Unsafe.SizeOf <BlockDescriptor>()); BlockDescriptor *descriptorPtr = (BlockDescriptor *)_completionBlockDescriptor; descriptorPtr->reserved = 0; descriptorPtr->Block_size = (ulong)Unsafe.SizeOf <BlockDescriptor>(); _completionBlockLiteral = Marshal.AllocHGlobal(Unsafe.SizeOf <BlockLiteral>()); BlockLiteral *blockPtr = (BlockLiteral *)_completionBlockLiteral; blockPtr->isa = _concreteGlobalBlock; blockPtr->flags = 1 << 28 | 1 << 29; blockPtr->invoke = _completionHandlerFuncPtr; blockPtr->descriptor = descriptorPtr; if (!MetalFeatures.IsMacOS) { lock (s_aotRegisteredBlocks) { s_aotRegisteredBlocks.Add(_completionBlockLiteral, this); } } ResourceFactory = new MTLResourceFactory(this); _commandQueue = _device.newCommandQueue(); TextureSampleCount[] allSampleCounts = (TextureSampleCount[])Enum.GetValues(typeof(TextureSampleCount)); _supportedSampleCounts = new bool[allSampleCounts.Length]; for (int i = 0; i < allSampleCounts.Length; i++) { TextureSampleCount count = allSampleCounts[i]; uint uintValue = FormatHelpers.GetSampleCountUInt32(count); if (_device.supportsTextureSampleCount((UIntPtr)uintValue)) { _supportedSampleCounts[i] = true; } } if (swapchainDesc != null) { SwapchainDescription desc = swapchainDesc.Value; _mainSwapchain = new MTLSwapchain(this, ref desc); } PostDeviceCreated(); }