Esempio n. 1
0
        public void DrawFrame()
        {
            this.Device.WaitForFence(this.vkInFlightFences[this.currentFrame], true, UInt64.MaxValue);

            uint imageIndex = 0;

            try {
                imageIndex = this.Device.AcquireNextImageKHR(this.Pipeline.Swapchain,
                                                             UInt64.MaxValue, this.vkImageAvailableSemaphores[this.currentFrame]);
            } catch (Vk.ResultException result) {
                if (result.Result == Vk.Result.ErrorOutOfDateKhr)
                {
                    this.createPipelineWrapper();
                    return;
                }
                else
                {
                    throw new VkException("An error occurred while acquiring a swapchain image.", result);
                }
            }

            this.Device.ResetFence(this.vkInFlightFences[this.currentFrame]);

            var waitSemaphores   = new Vk.Semaphore[] { this.vkImageAvailableSemaphores[this.currentFrame] };
            var signalSemaphores = new Vk.Semaphore[] { this.vkRenderFinishedSemaphores[this.currentFrame] };

            this.updateUniformBuffer(imageIndex);

            var submitInfo = new Vk.SubmitInfo();

            submitInfo.CommandBufferCount   = 1;
            submitInfo.WaitSemaphoreCount   = 1;
            submitInfo.SignalSemaphoreCount = 1;

            submitInfo.CommandBuffers = new Vk.CommandBuffer[] {
                this.Pipeline.CommandBuffers[imageIndex]
            };

            submitInfo.WaitSemaphores   = waitSemaphores;
            submitInfo.WaitDstStageMask = new Vk.PipelineStageFlags[] {
                Vk.PipelineStageFlags.ColorAttachmentOutput
            };
            submitInfo.SignalSemaphores = signalSemaphores;

            try {
                this.GraphicsQueue.Submit(new Vk.SubmitInfo[] { submitInfo },
                                          this.vkInFlightFences[this.currentFrame]);
            } catch (Vk.ResultException result) {
                throw new VkException("An error has occurred while submitting a command buffer.", result);
            }

            var presentInfo = new Vk.PresentInfoKhr();

            presentInfo.WaitSemaphoreCount = 1;
            presentInfo.WaitSemaphores     = signalSemaphores;
            presentInfo.SwapchainCount     = 1;
            presentInfo.Swapchains         = new Vk.SwapchainKhr[] {
                this.Pipeline.Swapchain
            };

            presentInfo.ImageIndices = new uint[] {
                imageIndex
            };

            try {
                this.PresentQueue.PresentKHR(presentInfo);
            } catch (Vk.ResultException result) {
                if (result.Result == Vk.Result.ErrorOutOfDateKhr ||
                    result.Result == Vk.Result.SuboptimalKhr ||
                    this.Window.HasBeenResized)
                {
                    this.createPipelineWrapper();
                    this.Window.HasBeenResized = false;
                }
                else
                {
                    throw new VkException("An error occurred while presenting an image.", result);
                }
            }
        }