/// <summary> /// Initialize the graphic library. /// </summary> public override void Initialize() { base.Initialize(); // - Create a Vulkan instance, this instance must be alive during all the game execution Library.Initialize(TargetSurface); // - Makes a new device manager PhysicalDevice.Initialize(TargetSurface); // - Initialize the physical device on this drawing area GraphicDevice.Initialize(); // - Initialize index and vert manager VertexManager.Setup(); IndexManager.Setup(); // - Makes syncronization semaphores and fances CPU<->GPU for (int i = 0; i < MaxFrameInFlight; ++i) { CommandBuffers.Add(null); Commands.Add(GraphicDevice.Handle.CreateCommandPool(GraphicDevice.GraphicQueueIndex, CommandPoolCreateFlags.ResetCommandBuffer)); ImageAvailableSemaphores.Add(GraphicDevice.Handle.CreateSemaphore()); RenderFinishedSemaphores.Add(GraphicDevice.Handle.CreateSemaphore()); InFlightFences.Add(GraphicDevice.Handle.CreateFence(FenceCreateFlags.Signaled)); } }
/// <summary> /// Implement IDisposable. /// </summary> protected override void Dispose(bool disposing) { base.Dispose(disposing); GraphicDevice.Handle.WaitForFences(InFlightFences.ToArray(), true, UInt64.MaxValue); // - Wait the GPU (we must operate only when GPU is idle) GraphicDevice.Handle.WaitIdle(); // - Dispose render pass DefaultRenderPass.Dispose(); // - Dispose the pipeline Pipeline.Dispose(); // - Dipose current swapchain Swapchain.Dispose(); // - Dispose vertex and index managers VertexManager.Dispose(); IndexManager.Dispose(); // - Release all VK shaders ShaderManager.Dispose(); for (int i = 0; i < MaxFrameInFlight; ++i) { if (CommandBuffers[i] != null) { foreach (var buffer in CommandBuffers[i]) { buffer.Reset(); } } } foreach (CommandPool pool in Commands) { pool?.Destroy(); } foreach (Fence fence in InFlightFences) { fence?.Destroy(); } foreach (Semaphore sem in ImageAvailableSemaphores) { sem?.Destroy(); } foreach (Semaphore sem in RenderFinishedSemaphores) { sem?.Destroy(); } // - Dispose device GraphicDevice.Dispose(); // - Dispose vulkan Library.Dispose(); }