| 355 | } |
| 356 | |
| 357 | void RunnableGraph::record() |
| 358 | { |
| 359 | auto block( m_timer.start() ); |
| 360 | m_states.clear(); |
| 361 | RecordContext recordContext{ m_resources }; |
| 362 | |
| 363 | for ( auto & dependency : m_graph.getDependencies() ) |
| 364 | { |
| 365 | recordContext.addStates( dependency->getFinalStates() ); |
| 366 | m_states.try_emplace( dependency |
| 367 | , dependency->getFinalStates().getIndexState() ); |
| 368 | } |
| 369 | |
| 370 | auto itGraph = m_states.try_emplace( &m_graph ).first; |
| 371 | itGraph->second.resize( m_passes.size() ); |
| 372 | |
| 373 | if ( !m_passes.empty() ) |
| 374 | { |
| 375 | auto it = itGraph->second.begin(); |
| 376 | auto currPass = m_passes.begin(); |
| 377 | recordContext.setNextPipelineState( ( *currPass )->getPipelineState() |
| 378 | , ( *currPass )->getImageLayouts() ); |
| 379 | auto nextPass = std::next( currPass ); |
| 380 | m_fence.wait( 0xFFFFFFFFFFFFFFFFULL ); |
| 381 | m_context.vkResetCommandBuffer( m_commandBuffer, 0u ); |
| 382 | VkCommandBufferBeginInfo beginInfo{ VK_STRUCTURE_TYPE_COMMAND_BUFFER_BEGIN_INFO |
| 383 | , nullptr |
| 384 | , VK_COMMAND_BUFFER_USAGE_ONE_TIME_SUBMIT_BIT |
| 385 | , nullptr }; |
| 386 | m_context.vkBeginCommandBuffer( m_commandBuffer, &beginInfo ); |
| 387 | m_timer.beginPass( m_commandBuffer ); |
| 388 | |
| 389 | while ( currPass != m_passes.end() ) |
| 390 | { |
| 391 | auto const & pass = *currPass; |
| 392 | ++currPass; |
| 393 | |
| 394 | if ( nextPass != m_passes.end() ) |
| 395 | { |
| 396 | recordContext.setNextPipelineState( rungrf::getNextState( pass->getPipelineState(), nextPass, m_passes.end() ) |
| 397 | , rungrf::gatherNextImageLayouts( pass->getImageLayouts(), nextPass, m_passes.end() ) ); |
| 398 | ++nextPass; |
| 399 | } |
| 400 | else |
| 401 | { |
| 402 | recordContext.setNextPipelineState( pass->getPipelineState() |
| 403 | , m_graph.getOutputLayoutStates() ); |
| 404 | } |
| 405 | |
| 406 | *it = pass->recordCurrentInto( recordContext, m_commandBuffer ); |
| 407 | ++it; |
| 408 | } |
| 409 | |
| 410 | m_timer.endPass( m_commandBuffer ); |
| 411 | m_context.vkEndCommandBuffer( m_commandBuffer ); |
| 412 | } |
| 413 | |
| 414 | m_graph.registerFinalState( recordContext ); |