private void DrawFrame()
        {
            // Acquiring and image from the swap chain
            uint imageIndex;

            Helpers.CheckErrors(VulkanNative.vkAcquireNextImageKHR(this.device, this.swapChain, ulong.MaxValue, this.imageAvailableSemaphore, 0, &imageIndex));

            // Submitting the command buffer
            VkSemaphore *         waitSemaphores    = stackalloc VkSemaphore[] { this.imageAvailableSemaphore };
            VkPipelineStageFlags *waitStages        = stackalloc VkPipelineStageFlags[] { VkPipelineStageFlags.VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
            VkSemaphore *         signalSemaphores  = stackalloc VkSemaphore[] { this.renderFinishedSemaphore };
            VkCommandBuffer *     commandBuffersPtr = stackalloc VkCommandBuffer[] { commandBuffers[imageIndex] };

            VkSubmitInfo submitInfo = new VkSubmitInfo()
            {
                sType = VkStructureType.VK_STRUCTURE_TYPE_SUBMIT_INFO,
                waitSemaphoreCount   = 1,
                pWaitSemaphores      = waitSemaphores,
                pWaitDstStageMask    = waitStages,
                commandBufferCount   = 1,
                pCommandBuffers      = commandBuffersPtr,
                signalSemaphoreCount = 1,
                pSignalSemaphores    = signalSemaphores,
            };

            Helpers.CheckErrors(VulkanNative.vkQueueSubmit(this.graphicsQueue, 1, &submitInfo, 0));

            // Presentation
            VkSwapchainKHR * swapChains  = stackalloc VkSwapchainKHR[] { this.swapChain };
            VkPresentInfoKHR presentInfo = new VkPresentInfoKHR()
            {
                sType = VkStructureType.VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
                waitSemaphoreCount = 1,
                pWaitSemaphores    = signalSemaphores,
                swapchainCount     = 1,
                pSwapchains        = swapChains,
                pImageIndices      = &imageIndex,
                pResults           = null, // Optional
            };

            Helpers.CheckErrors(VulkanNative.vkQueuePresentKHR(this.presentQueue, &presentInfo));

            Helpers.CheckErrors(VulkanNative.vkQueueWaitIdle(this.presentQueue));
        }
    }
}
Esempio n. 2
0
        public void DrawFrame()
        {
            var result = VulkanNative.vkQueueWaitIdle(vkPresentQueue);

            Helpers.CheckErrors(result);

            uint imageIndex;

            result = VulkanNative.vkAcquireNextImageKHR(vkDevice, vkSwapChain, ulong.MaxValue, vkImageAvailableSemaphore, 0, &imageIndex);
            Helpers.CheckErrors(result);

            VkSemaphore *            waitSemaphores   = stackalloc VkSemaphore[] { vkImageAvailableSemaphore };
            VkPipelineStageFlagBits *waitStages       = stackalloc VkPipelineStageFlagBits[] { VkPipelineStageFlagBits.VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT };
            VkSemaphore *            signalSemaphores = stackalloc VkSemaphore[] { vkRenderFinishedSemaphore };
            VkCommandBuffer *        commandBuffers   = stackalloc VkCommandBuffer[] { vkCommandBuffers[imageIndex] };
            var submitInfo = new VkSubmitInfo()
            {
                sType                = VkStructureType.VK_STRUCTURE_TYPE_SUBMIT_INFO,
                pWaitSemaphores      = waitSemaphores,
                waitSemaphoreCount   = 1,
                pWaitDstStageMask    = waitStages,
                commandBufferCount   = 1,
                pCommandBuffers      = commandBuffers,
                signalSemaphoreCount = 1,
                pSignalSemaphores    = signalSemaphores,
            };

            result = VulkanNative.vkQueueSubmit(vkGraphicsQueue, 1, &submitInfo, 0);
            Helpers.CheckErrors(result);

            VkSwapchainKHR *swapChains  = stackalloc VkSwapchainKHR[] { vkSwapChain };
            var             presentInfo = new VkPresentInfoKHR()
            {
                sType = VkStructureType.VK_STRUCTURE_TYPE_PRESENT_INFO_KHR,
                waitSemaphoreCount = 1,
                pWaitSemaphores    = signalSemaphores,
                swapchainCount     = 1,
                pSwapchains        = swapChains,
                pImageIndices      = &imageIndex,
            };

            result = VulkanNative.vkQueuePresentKHR(vkPresentQueue, &presentInfo);
            Helpers.CheckErrors(result);
        }
Esempio n. 3
0
        /// <summary>
        /// acquire's swapchain image index
        /// </summary>
        /// <returns>image index</returns>
        public async Task <uint> AcquireSwapchainImage()
        {
            _fence.Reset();
            uint imageIndex = 0;

            unsafe
            {
                VulkanNative.vkAcquireNextImageKHR(
                    _graphicsModule.GraphicsService.PrimaryDevice.Handle,
                    _swapchain.Handle,
                    ulong.MaxValue,
                    VkSemaphore.Null,
                    _fence.Handle,
                    &imageIndex
                    );
            }
            await _fence.WaitAsync();

            return(imageIndex);
        }