Beispiel #1
0
        public void Submit(VkSemaphore waitSemaphore, VkPipelineStageFlags waitDstStageMask,
                           VkCommandBuffer commandBuffer, VkSemaphore signalSemaphore, VkFence fence = default)
        {
            VkCommandBuffer commandBufferHandle = commandBuffer;

            var nativeSubmit = new VkSubmitInfo
            {
                sType = VkStructureType.SubmitInfo
            };

            if (waitSemaphore != default)
            {
                nativeSubmit.waitSemaphoreCount = 1;
                nativeSubmit.pWaitSemaphores    = &waitSemaphore;
                nativeSubmit.pWaitDstStageMask  = &waitDstStageMask;
            }

            if (commandBuffer != null)
            {
                nativeSubmit.commandBufferCount = 1;
                nativeSubmit.pCommandBuffers    = &commandBufferHandle;
            }

            if (signalSemaphore != default)
            {
                nativeSubmit.signalSemaphoreCount = 1;
                nativeSubmit.pSignalSemaphores    = &signalSemaphore;
            }

            VulkanUtil.CheckResult(vkQueueSubmit(this, 1, &nativeSubmit, fence));
        }
Beispiel #2
0
 public static VkResult vkQueueSubmit(VkQueue queue, VkSubmitInfo submit, VkFence fence)
 {
     return(vkQueueSubmit(queue, 1, &submit, fence));
 }
Beispiel #3
0
 public void Submit(VkSubmitInfo submit, VkFence fence = default)
 {
     VulkanUtil.CheckResult(vkQueueSubmit(this, 1, &submit, fence));
 }
Beispiel #4
0
        public void RenderFrame(Action <VkCommandBuffer, VkFramebuffer, VkExtent2D> draw, [CallerMemberName] string?frameName = null)
        {
            VkResult result = AcquireNextImage(out uint swapchainIndex);

            // Handle outdated error in acquire.
            if (result == VkResult.SuboptimalKHR || result == VkResult.ErrorOutOfDateKHR)
            {
                //Resize(context.swapchain_dimensions.width, context.swapchain_dimensions.height);
                result = AcquireNextImage(out swapchainIndex);
            }

            if (result != VkResult.Success)
            {
                vkDeviceWaitIdle(VkDevice);
                return;
            }

            // Begin command recording
            VkCommandBuffer cmd = _perFrame[swapchainIndex].PrimaryCommandBuffer;

            VkCommandBufferBeginInfo beginInfo = new VkCommandBufferBeginInfo
            {
                sType = VkStructureType.CommandBufferBeginInfo,
                flags = VkCommandBufferUsageFlags.OneTimeSubmit
            };

            vkBeginCommandBuffer(cmd, &beginInfo).CheckResult();

            draw(cmd, Swapchain.Framebuffers[swapchainIndex], Swapchain.Extent);

            // Complete the command buffer.
            vkEndCommandBuffer(cmd).CheckResult();

            if (_perFrame[swapchainIndex].SwapchainReleaseSemaphore == VkSemaphore.Null)
            {
                vkCreateSemaphore(VkDevice, out _perFrame[swapchainIndex].SwapchainReleaseSemaphore).CheckResult();
            }

            VkPipelineStageFlags wait_stage      = VkPipelineStageFlags.ColorAttachmentOutput;
            VkSemaphore          waitSemaphore   = _perFrame[swapchainIndex].SwapchainAcquireSemaphore;
            VkSemaphore          signalSemaphore = _perFrame[swapchainIndex].SwapchainReleaseSemaphore;

            VkSubmitInfo submitInfo = new VkSubmitInfo
            {
                sType = VkStructureType.SubmitInfo,
                commandBufferCount   = 1u,
                pCommandBuffers      = &cmd,
                waitSemaphoreCount   = 1u,
                pWaitSemaphores      = &waitSemaphore,
                pWaitDstStageMask    = &wait_stage,
                signalSemaphoreCount = 1u,
                pSignalSemaphores    = &signalSemaphore
            };

            // Submit command buffer to graphics queue
            vkQueueSubmit(GraphicsQueue, submitInfo, _perFrame[swapchainIndex].QueueSubmitFence);

            result = PresentImage(swapchainIndex);

            // Handle Outdated error in present.
            if (result == VkResult.SuboptimalKHR || result == VkResult.ErrorOutOfDateKHR)
            {
                //Resize(context.swapchain_dimensions.width, context.swapchain_dimensions.height);
            }
            else if (result != VkResult.Success)
            {
                Log.Error("Failed to present swapchain image.");
            }
        }