Exemplo n.º 1
0
        /// <summary>
        /// This call configure the graphic library for the new device instance.
        /// </summary>
        public override void InvalidateDevice()
        {
            base.InvalidateDevice();

            // - 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 current VK surface
            DrawingSurface.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();
                    }
                    Commands[i].FreeCommandBuffers(CommandBuffers[i]);
                }
            }

            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();

            // - Initialize device
            Initialize();

            // - Reconfigure the renderer
            ConfigureRendering();
        }
Exemplo n.º 2
0
        /// <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();
        }