Ejemplo n.º 1
0
        public void Set(params VkCommandBuffer[] value)
        {
            IntPtr ptr = (IntPtr)this.pointer;

            value.Set(ref ptr, ref this.count);
            this.pointer = (VkCommandBuffer *)ptr;
        }
Ejemplo n.º 2
0
 public VkCommandBufferGroup(params VkCommandBuffer[] value)
 {
     this.count   = 0;
     this.pointer = null;
     if (value != null)
     {
         IntPtr ptr = IntPtr.Zero;
         value.Set(ref ptr, ref this.count);
         this.pointer = (VkCommandBuffer *)ptr;
     }
 }
        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));
        }
    }
}
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
 public static void FreeCommandBuffers(VkCommandPool cmdPool, uint count, VkCommandBuffer *cmdBuffers)
 {
     vkFreeCommandBuffers(device, cmdPool, count, cmdBuffers);
 }
Ejemplo n.º 6
0
        public static void AllocateCommandBuffers(VkCommandPool cmdPool, VkCommandBufferLevel level, uint count, VkCommandBuffer *cmdBuffers)
        {
            VkCommandBufferAllocateInfo cmdBufAllocateInfo = new VkCommandBufferAllocateInfo
            {
                sType = VkStructureType.CommandBufferAllocateInfo
            };

            cmdBufAllocateInfo.commandPool        = cmdPool;
            cmdBufAllocateInfo.level              = level;
            cmdBufAllocateInfo.commandBufferCount = count;

            VulkanUtil.CheckResult(vkAllocateCommandBuffers(device, &cmdBufAllocateInfo, cmdBuffers));
        }