//----------------------------------------------------------------------------- /// Kill all info retained by this thread. //----------------------------------------------------------------------------- void VktWrappedQueue::EndCollection() { ScopeLock lock(&m_workerThreadInfoMutex); for (UINT i = 0; i < m_workerThreadInfo.size(); i++) { // Delete profiler memory for (UINT j = 0; j < m_workerThreadInfo[i]->m_inputs.cmdBufs.size(); j++) { VktWrappedCmdBuf* pCmdBuf = m_workerThreadInfo[i]->m_inputs.cmdBufs[j]; if (pCmdBuf != nullptr) { pCmdBuf->DestroyDynamicProfilers(); } } // Free the fence we created earlier if (m_workerThreadInfo[i]->m_inputs.internalFence) { device_dispatch_table(m_createInfo.device)->DestroyFence(m_createInfo.device, m_workerThreadInfo[i]->m_inputs.fenceToWaitOn, nullptr); } m_workerThreadInfo[i]->m_outputs.results.clear(); CloseHandle(m_workerThreadInfo[i]->m_threadInfo.threadHandle); SAFE_DELETE(m_workerThreadInfo[i]); } m_workerThreadInfo.clear(); }
//----------------------------------------------------------------------------- /// Profiler results collection worker function. /// \param lpParam A void pointer to the incoming VktWorkerInfo argument. /// \returns Always 0. //----------------------------------------------------------------------------- DWORD WINAPI ThreadFunc(LPVOID lpParam) { VktWorkerInfo* pWorkerInfo = (VktWorkerInfo*)lpParam; pWorkerInfo->m_threadInfo.workerThreadID = osGetCurrentThreadId(); VkResult waitResult = VK_TIMEOUT; #if GPU_FENCES_FOR_PROFILER_WAIT VkDevice device = pWorkerInfo->m_inputs.pQueue->ParentDevice(); do { waitResult = device_dispatch_table(device)->WaitForFences(device, 1, &pWorkerInfo->m_inputs.fenceToWaitOn, VK_TRUE, GPU_FENCE_TIMEOUT_TIME); } while (waitResult == VK_TIMEOUT); #else VkQueue queue = pWorkerInfo->m_inputs.pQueue->AppHandle(); waitResult = device_dispatch_table(queue)->QueueWaitIdle(queue); #endif if (pWorkerInfo->m_inputs.timestampPair.mQueueCanBeTimestamped) { for (UINT i = 0; i < pWorkerInfo->m_inputs.cmdBufs.size(); i++) { VktWrappedCmdBuf* pWrappedCmdBuf = pWorkerInfo->m_inputs.cmdBufs[i]; ProfilerResultCode profResult = pWrappedCmdBuf->GetCmdBufResultsMT(pWorkerInfo->m_inputs.executionID, pWorkerInfo->m_outputs.results); if (profResult != PROFILER_SUCCESS) { const char* profilerErrorCode = VktCmdBufProfiler::PrintProfilerResult(profResult); // Report that a problem occurred in retrieving full profiler results. Log(logERROR, "Failed to retrieve full profiler results: CmdBuf 0x%p, Queue 0x%p, ErrorCode %s\n", pWorkerInfo->m_inputs.cmdBufs[i], pWorkerInfo->m_inputs.pQueue, profilerErrorCode); } } } // This will only be set to true if the GPU results have come back in time. pWorkerInfo->m_outputs.bResultsGathered = true; return 0; }
//----------------------------------------------------------------------------- /// Profiler results collection worker function. /// \param lpParam A void pointer to the incoming VktWorkerInfo argument. /// \returns Always 0. //----------------------------------------------------------------------------- DWORD WINAPI ThreadFunc(LPVOID lpParam) { VktWorkerInfo* pWorkerInfo = (VktWorkerInfo*)lpParam; pWorkerInfo->m_threadInfo.workerThreadID = osGetCurrentThreadId(); VkResult waitResult = VK_TIMEOUT; #if GPU_FENCES_FOR_PROFILER_WAIT VkDevice device = pWorkerInfo->m_inputs.pQueue->ParentDevice(); do { waitResult = device_dispatch_table(device)->WaitForFences(device, 1, &pWorkerInfo->m_inputs.fenceToWaitOn, VK_TRUE, GPU_FENCE_TIMEOUT_TIME); } while (waitResult == VK_TIMEOUT); #else VkQueue queue = pWorkerInfo->m_inputs.pQueue->AppHandle(); waitResult = device_dispatch_table(queue)->QueueWaitIdle(queue); #endif for (UINT i = 0; i < pWorkerInfo->m_inputs.cmdBufData.size(); i++) { VktWrappedCmdBuf* pWrappedCmdBuf = pWorkerInfo->m_inputs.cmdBufData[i].pCmdBuf; UINT64 targetFillId = pWorkerInfo->m_inputs.cmdBufData[i].targetFillID; UINT profiledCallCount = pWorkerInfo->m_inputs.cmdBufData[i].profiledCallCount; ProfilerResultCode profResult = pWrappedCmdBuf->GetCmdBufResultsMT(targetFillId, profiledCallCount, pWorkerInfo->m_outputs.results); if (profResult != PROFILER_SUCCESS) { const char* profilerErrorCode = VktCmdBufProfiler::PrintProfilerResult(profResult); // Report that a problem occurred in retrieving full profiler results. Log(logERROR, "Failed to retrieve full profiler results: CmdBuf 0x%p, Queue 0x%p, ErrorCode %s\n", pWorkerInfo->m_inputs.cmdBufData[i].pCmdBuf, pWorkerInfo->m_inputs.pQueue, profilerErrorCode); } } return 0; }