MCPcopy Create free account
hub / github.com/ValveSoftware/openvr / GetCommandBuffer

Method GetCommandBuffer

samples/hellovr_vulkan/hellovr_vulkan_main.cpp:2780–2809  ·  view source on GitHub ↗

----------------------------------------------------------------------------- Purpose: Get an available command buffer or create a new one if none available. Associate a fence with the command buffer. -----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

2778// none available. Associate a fence with the command buffer.
2779//-----------------------------------------------------------------------------
2780CMainApplication::VulkanCommandBuffer_t CMainApplication::GetCommandBuffer()
2781{
2782 VulkanCommandBuffer_t commandBuffer;
2783 if ( m_commandBuffers.size() > 0 )
2784 {
2785 // If the fence associated with the command buffer has finished, reset it and return it
2786 if ( vkGetFenceStatus( m_pDevice, m_commandBuffers.back().m_pFence ) == VK_SUCCESS )
2787 {
2788 VulkanCommandBuffer_t *pCmdBuffer = &m_commandBuffers.back();
2789 commandBuffer.m_pCommandBuffer = pCmdBuffer->m_pCommandBuffer;
2790 commandBuffer.m_pFence = pCmdBuffer->m_pFence;
2791
2792 vkResetCommandBuffer( commandBuffer.m_pCommandBuffer, VK_COMMAND_BUFFER_RESET_RELEASE_RESOURCES_BIT );
2793 vkResetFences( m_pDevice, 1, &commandBuffer.m_pFence );
2794 m_commandBuffers.pop_back();
2795 return commandBuffer;
2796 }
2797 }
2798
2799 // Create a new command buffer and associated fence
2800 VkCommandBufferAllocateInfo commandBufferAllocateInfo = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_ALLOCATE_INFO };
2801 commandBufferAllocateInfo.commandBufferCount = 1;
2802 commandBufferAllocateInfo.commandPool = m_pCommandPool;
2803 commandBufferAllocateInfo.level = VK_COMMAND_BUFFER_LEVEL_PRIMARY;
2804 vkAllocateCommandBuffers( m_pDevice, &commandBufferAllocateInfo, &commandBuffer.m_pCommandBuffer );
2805
2806 VkFenceCreateInfo fenceCreateInfo = { VK_STRUCTURE_TYPE_FENCE_CREATE_INFO };
2807 vkCreateFence( m_pDevice, &fenceCreateInfo, nullptr, &commandBuffer.m_pFence );
2808 return commandBuffer;
2809}
2810
2811//-----------------------------------------------------------------------------
2812// Purpose:

Callers

nothing calls this directly

Calls 1

sizeMethod · 0.80

Tested by

no test coverage detected