private bool InitialiseMg() { try { // SINGLETONS HERE var localDevice = MTLDevice.SystemDefault; if (localDevice == null) { Console.WriteLine("Metal is not supported on this device"); return(false); } // APPLICATION HERE mContainer.Register <SpinningCube>(Lifestyle.Singleton); RegisterMagnesiumSingletons(localDevice); RegisterMagnesiumMappings(); // RESOLVE HERE mDriver = mContainer.GetInstance <MgDriverContext>(); var err = mDriver.Initialize( new Magnesium.MgApplicationInfo { ApplicationName = "MetalSample", EngineName = "Magnesium", ApplicationVersion = 1, EngineVersion = 1, ApiVersion = Magnesium.MgApplicationInfo.GenerateApiVersion(1, 0, 17), }, Magnesium.MgInstanceExtensionOptions.ALL ); if (err != Result.SUCCESS) { throw new InvalidOperationException("Metal is not supported on this device : " + err); } mGraphicsConfiguration = mContainer.GetInstance <IMgGraphicsConfiguration>(); mApplication = mContainer.GetInstance <SpinningCube>(); // BIND TO VIEW mApplicationView.Delegate = this; mApplicationView.Device = localDevice; return(true); } catch (Exception ex) { Console.WriteLine(ex.Message); throw ex; } }
public static void Main(string[] args) { try { var entrypoint = new VkEntrypoint(); using (var driver = new MgDriverContext(entrypoint)) { driver.Initialize(new MgApplicationInfo { ApiVersion = MgApplicationInfo.GenerateApiVersion(1, 0, 17), ApplicationName = "InstanceDemo", ApplicationVersion = 1, EngineName = "Magnesium.Vulkan", EngineVersion = 1, }, MgInstanceExtensionOptions.ALL); using (var device = driver.CreateLogicalDevice(null, MgDeviceExtensionOptions.SWAPCHAIN_ONLY, MgQueueAllocation.One, MgQueueFlagBits.GRAPHICS_BIT | MgQueueFlagBits.COMPUTE_BIT)) { if (device.Queues.Length > 0) { Console.WriteLine(nameof(device.Queues.Length) + " : " + device.Queues.Length); using (var partition = device.Queues[0].CreatePartition(0)) { IMgBuffer buffer; var result = partition.Device.CreateBuffer(new MgBufferCreateInfo { SharingMode = MgSharingMode.EXCLUSIVE, Size = 1024, Usage = MgBufferUsageFlagBits.VERTEX_BUFFER_BIT }, null, out buffer); buffer.DestroyBuffer(partition.Device, null); } } } Console.WriteLine("NO ERRORS!"); } } catch (Exception ex) { Console.WriteLine(ex); throw ex; } }
public VulkanPresentationSurface(MgDriverContext context, INativeWindow window) { mDriverContext = context; mWindow = window; }