MCPcopy Create free account
hub / github.com/NVIDIA/cuda-samples / drawFrame

Function drawFrame

cpp/5_Domain_Specific/simpleVulkan/main.cpp:455–516  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

453 }
454
455 void drawFrame()
456 {
457 static chrono_tp startTime = std::chrono::high_resolution_clock::now();
458
459 chrono_tp currentTime = std::chrono::high_resolution_clock::now();
460 float time = std::chrono::duration<float, std::chrono::seconds::period>(currentTime - startTime).count();
461
462 if (m_currentFrame == 0) {
463 m_lastTime = startTime;
464 }
465
466 float frame_time = std::chrono::duration<float, std::chrono::seconds::period>(currentTime - m_lastTime).count();
467
468 // Have vulkan draw the current frame...
469 VulkanBaseApp::drawFrame();
470
471#ifdef _VK_TIMELINE_SEMAPHORE
472 static uint64_t waitValue = 1;
473 static uint64_t signalValue = 2;
474
475 cudaExternalSemaphoreWaitParams waitParams = {};
476 waitParams.flags = 0;
477 waitParams.params.fence.value = waitValue;
478
479 cudaExternalSemaphoreSignalParams signalParams = {};
480 signalParams.flags = 0;
481 signalParams.params.fence.value = signalValue;
482 // Wait for vulkan to complete it's work
483 checkCudaErrors(cudaWaitExternalSemaphoresAsync(&m_cudaTimelineSemaphore, &waitParams, 1, m_stream));
484 // Now step the simulation
485 m_sim.stepSimulation(time, m_stream);
486 // Signal vulkan to continue with the updated buffers
487 checkCudaErrors(cudaSignalExternalSemaphoresAsync(&m_cudaTimelineSemaphore, &signalParams, 1, m_stream));
488
489 waitValue += 2;
490 signalValue += 2;
491#else
492 cudaExternalSemaphoreWaitParams waitParams = {};
493 waitParams.flags = 0;
494 waitParams.params.fence.value = 0;
495
496 cudaExternalSemaphoreSignalParams signalParams = {};
497 signalParams.flags = 0;
498 signalParams.params.fence.value = 0;
499
500 // Wait for vulkan to complete it's work
501 checkCudaErrors(cudaWaitExternalSemaphoresAsync(&m_cudaWaitSemaphore, &waitParams, 1, m_stream));
502 // Now step the simulation
503 m_sim.stepSimulation(time, m_stream);
504 // Signal vulkan to continue with the updated buffers
505 checkCudaErrors(cudaSignalExternalSemaphoresAsync(&m_cudaSignalSemaphore, &signalParams, 1, m_stream));
506#endif /* _VK_TIMELINE_SEMAPHORE */
507
508 // Output a naive measurement of the frames per second every five seconds
509 if (frame_time > 5) {
510 std::cout << "Average FPS (over " << std::fixed << std::setprecision(2) << frame_time
511 << " seconds): " << std::fixed << std::setprecision(2)
512 << ((m_currentFrame - m_lastFrame) / frame_time) << std::endl;

Callers 3

mainLoopMethod · 0.85
mainLoopMethod · 0.85
drawFrameMethod · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected