MCPcopy Create free account
hub / github.com/defold/defold / VulkanFlip

Function VulkanFlip

engine/graphics/src/vulkan/graphics_vulkan.cpp:1840–1940  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1838
1839
1840 static void VulkanFlip(HContext _context)
1841 {
1842 DM_PROFILE(__FUNCTION__);
1843 VulkanContext* context = (VulkanContext*) _context;
1844
1845 if (!context->m_FrameBegun)
1846 {
1847 return;
1848 }
1849
1850 uint32_t frameInFlight = context->m_CurrentFrameInFlight;
1851 FrameResource& currentFrame = context->m_FrameResources[frameInFlight];
1852
1853 // Determine the swapchain image we rendered to
1854 uint32_t swapchainImageIndex = context->m_SwapChain->m_ImageIndex;
1855 VkSemaphore renderFinishedSemaphore = context->m_SwapChain->m_RenderFinishedSemaphores[swapchainImageIndex];
1856
1857 FlushPendingRenderTargetClear(context, context->m_CurrentRenderTarget);
1858
1859 // End the current render pass
1860 EndRenderPass(context);
1861
1862 // Present still requires a valid swapchain image layout even on frames that never
1863 // materialized the main render pass.
1864 if (!context->m_MainRTBegunThisFrame)
1865 {
1866 DM_MUTEX_SCOPED_LOCK(context->m_BaseContext.m_AssetHandleContainerMutex);
1867 VulkanTexture* tex_sc = GetAssetFromContainer<VulkanTexture>(context->m_BaseContext.m_AssetHandleContainer, context->m_CurrentSwapchainTexture);
1868 TransitionImageLayoutWithCmdBuffer(
1869 context->m_MainCommandBuffers[frameInFlight],
1870 tex_sc,
1871 VK_IMAGE_ASPECT_COLOR_BIT,
1872 VK_IMAGE_LAYOUT_PRESENT_SRC_KHR,
1873 0,
1874 1);
1875 }
1876
1877 // Finish recording the command buffer for this frame-in-flight
1878 VkCommandBuffer cmd = context->m_MainCommandBuffers[frameInFlight];
1879 VkResult res = vkEndCommandBuffer(cmd);
1880 CHECK_VK_ERROR(res);
1881
1882 // Submit the command buffer
1883 VkPipelineStageFlags waitStages = VK_PIPELINE_STAGE_COLOR_ATTACHMENT_OUTPUT_BIT;
1884 VkSubmitInfo submitInfo = {};
1885 submitInfo.sType = VK_STRUCTURE_TYPE_SUBMIT_INFO;
1886 submitInfo.waitSemaphoreCount = 1;
1887 submitInfo.pWaitSemaphores = &currentFrame.m_ImageAvailable;
1888 submitInfo.pWaitDstStageMask = &waitStages;
1889 submitInfo.commandBufferCount = 1;
1890 submitInfo.pCommandBuffers = &cmd;
1891 submitInfo.signalSemaphoreCount = 1;
1892 submitInfo.pSignalSemaphores = &renderFinishedSemaphore;
1893
1894 res = vkQueueSubmit(context->m_LogicalDevice.m_GraphicsQueue, 1, &submitInfo, currentFrame.m_SubmitFence);
1895 CHECK_VK_ERROR(res);
1896
1897 // Present the swapchain image

Callers

nothing calls this directly

Calls 4

EndRenderPassFunction · 0.70
SwapBuffersFunction · 0.50

Tested by

no test coverage detected