----------------------------------------------------------------------------- Purpose: Initialize Vulkan. Returns true if Vulkan has been successfully initialized, false if shaders could not be created. If failure occurred in a module other than shaders, the function may return true or throw an error. -----------------------------------------------------------------------------
| 1407 | // may return true or throw an error. |
| 1408 | //----------------------------------------------------------------------------- |
| 1409 | bool CMainApplication::BInitVulkan() |
| 1410 | { |
| 1411 | if ( !BInitVulkanInstance() ) |
| 1412 | return false; |
| 1413 | |
| 1414 | if ( !BInitVulkanDevice() ) |
| 1415 | return false; |
| 1416 | |
| 1417 | if ( !BInitVulkanSwapchain() ) |
| 1418 | return false; |
| 1419 | |
| 1420 | VkResult nResult; |
| 1421 | |
| 1422 | // Create the command pool |
| 1423 | { |
| 1424 | VkCommandPoolCreateInfo commandPoolCreateInfo = { VK_STRUCTURE_TYPE_COMMAND_POOL_CREATE_INFO }; |
| 1425 | commandPoolCreateInfo.queueFamilyIndex = m_nQueueFamilyIndex; |
| 1426 | commandPoolCreateInfo.flags = VK_COMMAND_POOL_CREATE_RESET_COMMAND_BUFFER_BIT; |
| 1427 | nResult = vkCreateCommandPool( m_pDevice, &commandPoolCreateInfo, nullptr, &m_pCommandPool ); |
| 1428 | if ( nResult != VK_SUCCESS ) |
| 1429 | { |
| 1430 | dprintf( "vkCreateCommandPool returned error %d.", nResult ); |
| 1431 | return false; |
| 1432 | } |
| 1433 | } |
| 1434 | |
| 1435 | // Command buffer used during resource loading |
| 1436 | m_currentCommandBuffer = GetCommandBuffer(); |
| 1437 | VkCommandBufferBeginInfo commandBufferBeginInfo = { VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO }; |
| 1438 | commandBufferBeginInfo.flags = VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT; |
| 1439 | vkBeginCommandBuffer( m_currentCommandBuffer.m_pCommandBuffer, &commandBufferBeginInfo ); |
| 1440 | |
| 1441 | SetupTexturemaps(); |
| 1442 | SetupScene(); |
| 1443 | SetupCameras(); |
| 1444 | SetupStereoRenderTargets(); |
| 1445 | SetupCompanionWindow(); |
| 1446 | |
| 1447 | if( !CreateAllShaders() ) |
| 1448 | return false; |
| 1449 | |
| 1450 | CreateAllDescriptorSets(); |
| 1451 | SetupRenderModels(); |
| 1452 | |
| 1453 | // Submit the command buffer used during loading |
| 1454 | vkEndCommandBuffer( m_currentCommandBuffer.m_pCommandBuffer ); |
| 1455 | VkSubmitInfo submitInfo = { VK_STRUCTURE_TYPE_SUBMIT_INFO }; |
| 1456 | submitInfo.commandBufferCount = 1; |
| 1457 | submitInfo.pCommandBuffers = &m_currentCommandBuffer.m_pCommandBuffer; |
| 1458 | vkQueueSubmit( m_pQueue, 1, &submitInfo, m_currentCommandBuffer.m_pFence ); |
| 1459 | m_commandBuffers.push_front( m_currentCommandBuffer ); |
| 1460 | |
| 1461 | m_currentCommandBuffer.m_pCommandBuffer = VK_NULL_HANDLE; |
| 1462 | m_currentCommandBuffer.m_pFence = VK_NULL_HANDLE; |
| 1463 | |
| 1464 | // Wait for the GPU before proceeding |
| 1465 | vkQueueWaitIdle( m_pQueue ); |
| 1466 |