//----------------------------------------------------------------------------- /// Wait for workers to finish and get their results. /// \param pFrameProfiler Pointer to the frame profiler. //----------------------------------------------------------------------------- void VktTraceAnalyzerLayer::WaitAndFetchResults(VktFrameProfilerLayer* pFrameProfiler) { // Gather all known queues std::vector<VktWrappedQueue*> queues; GetAvailableQueues(queues); if (queues.size() > 0) { std::vector<HANDLE> queueThreads; for (UINT i = 0; i < queues.size(); i++) { for (UINT j = 0; j < queues[i]->WorkerThreadCount(); j++) { VktWorkerInfo* pWorkerInfo = queues[i]->GetWorkerInfo(j); if (pWorkerInfo != nullptr) { queueThreads.push_back(queues[i]->GetThreadHandle(j)); } } } const UINT queueWorkerCount = (UINT)queueThreads.size(); // Gather all worker handles if (queueWorkerCount > 0) { // Wait for other workers DWORD retVal = WaitForMultipleObjects(queueWorkerCount, &queueThreads[0], TRUE, QUEUE_RESULTS_WORKER_TIMEOUT); if (WaitSucceeded(retVal, queueWorkerCount) == false) { Log(logWARNING, "Detected failure condition when waiting for worker threads.\n"); } // Get results from thread for (UINT i = 0; i < queues.size(); i++) { for (UINT j = 0; j < queues[i]->WorkerThreadCount(); j++) { VktWorkerInfo* pWorkerInfo = queues[i]->GetWorkerInfo(j); pFrameProfiler->VerifyAlignAndStoreResults( queues[i], pWorkerInfo->m_outputs.results, &pWorkerInfo->m_inputs.timestampPair, pWorkerInfo->m_threadInfo.workerThreadCountID, mFramestartTime); } } // Close worker handles for (UINT i = 0; i < queues.size(); i++) { queues[i]->EndCollection(); } } } }
//----------------------------------------------------------------------------- /// Wait for workers to finish and get their results. /// \param pFrameProfiler Pointer to the frame profiler. //----------------------------------------------------------------------------- void VktTraceAnalyzerLayer::WaitAndFetchResults(VktFrameProfilerLayer* pFrameProfiler) { // Gather all known queues std::vector<VktWrappedQueue*> queues; GetAvailableQueues(queues); if (queues.size() > 0) { #if AMDT_BUILD_TARGET == AMDT_WINDOWS_OS std::vector<HANDLE> queueThreads; #elif AMDT_BUILD_TARGET == AMDT_LINUX_OS std::vector<std::thread*> queueThreads; #else #error Unknown build target! No valid value for AMDT_BUILD_TARGET. #endif for (UINT i = 0; i < queues.size(); i++) { for (UINT j = 0; j < queues[i]->WorkerThreadCount(); j++) { VktWorkerInfo* pWorkerInfo = queues[i]->GetWorkerInfo(j); if (pWorkerInfo != nullptr) { queueThreads.push_back(queues[i]->GetThreadHandle(j)); } } } const UINT queueWorkerCount = (UINT)queueThreads.size(); // Gather all worker handles if (queueWorkerCount > 0) { // Wait for other workers #ifdef WIN32 DWORD retVal = WaitForMultipleObjects(queueWorkerCount, &queueThreads[0], TRUE, QUEUE_RESULTS_WORKER_TIMEOUT); #else for (size_t it = 0; it < queueWorkerCount; it++) { queueThreads[it]->join(); } DWORD retVal = 0; #endif if (WaitSucceeded(retVal, queueWorkerCount) == false) { Log(logWARNING, "Detected failure condition when waiting for worker threads.\n"); } // Get results from thread for (UINT i = 0; i < queues.size(); i++) { for (UINT j = 0; j < queues[i]->WorkerThreadCount(); j++) { VktWorkerInfo* pWorkerInfo = queues[i]->GetWorkerInfo(j); pFrameProfiler->VerifyAlignAndStoreResults( queues[i], pWorkerInfo->m_outputs.results, &pWorkerInfo->m_inputs.timestampPair, pWorkerInfo->m_threadInfo.workerThreadCountID, pWorkerInfo->m_inputs.frameStartTime); } } // Close worker handles for (UINT i = 0; i < queues.size(); i++) { queues[i]->EndCollection(); } } } }