rccontroller.cpp 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621
  1. /*
  2. * Copyright (c) Contributors to the Open 3D Engine Project.
  3. * For complete copyright and license terms please see the LICENSE at the root of this distribution.
  4. *
  5. * SPDX-License-Identifier: Apache-2.0 OR MIT
  6. *
  7. */
  8. #include "rccontroller.h"
  9. #include <AzCore/Settings/SettingsRegistry.h>
  10. #include <AzCore/std/parallel/thread.h>
  11. #include <native/resourcecompiler/RCCommon.h>
  12. #include <QMetaObject>
  13. #include <QThreadPool>
  14. #include <QTimer>
  15. namespace AssetProcessor
  16. {
  17. RCController::RCController(QObject* parent)
  18. : QObject(parent)
  19. , m_dispatchingJobs(false)
  20. , m_shuttingDown(false)
  21. {
  22. AssetProcessorPlatformBus::Handler::BusConnect();
  23. UpdateAndComputeJobSlots();
  24. m_RCQueueSortModel.AttachToModel(&m_RCJobListModel);
  25. QObject::connect(this, &RCController::EscalateJobs, &m_RCQueueSortModel, &AssetProcessor::RCQueueSortModel::OnEscalateJobs);
  26. }
  27. void RCController::UpdateAndComputeJobSlots()
  28. {
  29. if (auto settingsRegistry = AZ::SettingsRegistry::Get())
  30. {
  31. auto settingsRoot = AZ::SettingsRegistryInterface::FixedValueString(AssetProcessorSettingsKey);
  32. AZ::s64 valueFromRegistry = 0;
  33. if (settingsRegistry->Get(valueFromRegistry, settingsRoot + "/Jobs/maxJobs"))
  34. {
  35. m_maxJobs = aznumeric_cast<int>(valueFromRegistry);
  36. }
  37. settingsRegistry->Get(m_alwaysUseMaxJobs, settingsRoot + "/Jobs/AlwaysUseMaxJobs");
  38. }
  39. bool isDefaultJobCount = m_maxJobs <= 1;
  40. if (isDefaultJobCount)
  41. {
  42. // Determine a good starting value for max jobs, we want to use hand tuned numbers for 2, 4, 8, 12, 16, etc
  43. unsigned int cpuConcurrency = AZStd::thread::hardware_concurrency();
  44. if (cpuConcurrency <= 1)
  45. {
  46. AZ_Printf(
  47. ConsoleChannel,
  48. "Unable to determine the number of hardware threads supported on this platform, assuming 4.\n",
  49. cpuConcurrency);
  50. cpuConcurrency = 4; // we can't query it on this platform, set a reasonable default that gets some work done
  51. }
  52. AZ_Printf(ConsoleChannel, "Auto (0) selected for maxJobs - auto-configuring based on %u available CPU cores.\n", cpuConcurrency)
  53. // for very low numbers of cores, hand-tune the values, these might be logical cores (hyperthread) and not real ones.
  54. // we will reserve about half of this for "backround processing" and then the other half will be reserved for on-demand
  55. // (critical or escalated) processing when we actually dispatch jobs.
  56. if (cpuConcurrency <= 4)
  57. {
  58. m_maxJobs = 3;
  59. }
  60. else if (cpuConcurrency <= 6)
  61. {
  62. m_maxJobs = 5;
  63. }
  64. else
  65. {
  66. // for larger number of cores, 8, 16, 24, we want a few extra cores free
  67. m_maxJobs = (cpuConcurrency - 2);
  68. }
  69. }
  70. // final fail-safe
  71. if (m_maxJobs < 2)
  72. {
  73. m_maxJobs = 2;
  74. }
  75. AZ_Printf(ConsoleChannel, "Asset Processor CPU Usage: (settings registry 'Jobs' section):\n");
  76. AZ_Printf(ConsoleChannel, " - Process up to %u jobs in parallel\n", m_maxJobs);
  77. if (m_alwaysUseMaxJobs)
  78. {
  79. AZ_Printf(ConsoleChannel, " - use all %u jobs whenever possible\n", m_maxJobs);
  80. }
  81. else
  82. {
  83. AZ_Printf(
  84. ConsoleChannel,
  85. " - only use %u jobs when critical work is waiting, %u otherwise.\n",
  86. m_maxJobs,
  87. AZStd::GetMax(m_maxJobs / 2u, 1u));
  88. }
  89. // make sure that the global thread pool has enough slots to accomidate your request though, since
  90. // by default, the global thread pool has idealThreadCount() slots only.
  91. // leave an extra slot for non-job work.
  92. int currentMaxThreadCount = QThreadPool::globalInstance()->maxThreadCount();
  93. int newMaxThreadCount = qMax<int>(currentMaxThreadCount, m_maxJobs + 1);
  94. QThreadPool::globalInstance()->setMaxThreadCount(newMaxThreadCount);
  95. }
  96. RCController::~RCController()
  97. {
  98. AssetProcessorPlatformBus::Handler::BusDisconnect();
  99. m_RCQueueSortModel.AttachToModel(nullptr);
  100. }
  101. RCJobListModel* RCController::GetQueueModel()
  102. {
  103. return &m_RCJobListModel;
  104. }
  105. void RCController::StartJob(RCJob* rcJob)
  106. {
  107. AZ_Assert(rcJob, "StartJob(nullptr) invoked, programmer error.");
  108. if (!rcJob)
  109. {
  110. return;
  111. }
  112. // request to be notified when job is done
  113. QObject::connect(rcJob, &RCJob::Finished, this, [this, rcJob]()
  114. {
  115. FinishJob(rcJob);
  116. }, Qt::QueuedConnection);
  117. // Mark as "being processed" by moving to Processing list
  118. m_RCJobListModel.markAsProcessing(rcJob);
  119. m_RCJobListModel.markAsStarted(rcJob);
  120. Q_EMIT JobStatusChanged(rcJob->GetJobEntry(), AzToolsFramework::AssetSystem::JobStatus::InProgress);
  121. rcJob->Start();
  122. Q_EMIT JobStarted(rcJob->GetJobEntry().m_sourceAssetReference.RelativePath().c_str(), QString::fromUtf8(rcJob->GetPlatformInfo().m_identifier.c_str()));
  123. }
  124. void RCController::QuitRequested()
  125. {
  126. m_shuttingDown = true;
  127. // cancel all jobs:
  128. AssetBuilderSDK::JobCommandBus::Broadcast(&AssetBuilderSDK::JobCommandBus::Events::Cancel);
  129. if (m_RCJobListModel.jobsInFlight() == 0)
  130. {
  131. Q_EMIT ReadyToQuit(this);
  132. return;
  133. }
  134. QTimer::singleShot(10, this, SLOT(QuitRequested()));
  135. }
  136. int RCController::NumberOfPendingCriticalJobsPerPlatform(QString platform)
  137. {
  138. return m_pendingCriticalJobsPerPlatform[platform.toLower()];
  139. }
  140. int RCController::NumberOfPendingJobsPerPlatform(QString platform)
  141. {
  142. return m_jobsCountPerPlatform[platform.toLower()];
  143. }
  144. void RCController::FinishJob(RCJob* rcJob)
  145. {
  146. m_RCQueueSortModel.RemoveJobIdEntry(rcJob);
  147. QString platform = rcJob->GetPlatformInfo().m_identifier.c_str();
  148. auto found = m_jobsCountPerPlatform.find(platform);
  149. if (found != m_jobsCountPerPlatform.end())
  150. {
  151. int prevCount = found.value();
  152. if (prevCount > 0)
  153. {
  154. int newCount = prevCount - 1;
  155. m_jobsCountPerPlatform[platform] = newCount;
  156. Q_EMIT JobsInQueuePerPlatform(platform, newCount);
  157. }
  158. }
  159. if (rcJob->IsCritical())
  160. {
  161. int criticalJobsCount = m_pendingCriticalJobsPerPlatform[platform.toLower()] - 1;
  162. m_pendingCriticalJobsPerPlatform[platform.toLower()] = criticalJobsCount;
  163. }
  164. if (rcJob->GetState() == RCJob::cancelled)
  165. {
  166. Q_EMIT FileCancelled(rcJob->GetJobEntry());
  167. }
  168. else if (rcJob->GetState() != RCJob::completed)
  169. {
  170. Q_EMIT FileFailed(rcJob->GetJobEntry());
  171. Q_EMIT JobStatusChanged(rcJob->GetJobEntry(), AzToolsFramework::AssetSystem::JobStatus::Failed);
  172. }
  173. else
  174. {
  175. Q_EMIT FileCompiled(rcJob->GetJobEntry(), AZStd::move(rcJob->GetProcessJobResponse()));
  176. Q_EMIT JobStatusChanged(rcJob->GetJobEntry(), AzToolsFramework::AssetSystem::JobStatus::Completed);
  177. }
  178. // Move to Completed list which will mark as "completed"
  179. // unless a different state has been set.
  180. m_RCJobListModel.markAsCompleted(rcJob);
  181. if (!m_dispatchingPaused)
  182. {
  183. Q_EMIT ActiveJobsCountChanged(aznumeric_cast<unsigned int>(m_RCJobListModel.itemCount()));
  184. }
  185. if (!m_shuttingDown)
  186. {
  187. // Start next job only if we are not shutting down
  188. DispatchJobs();
  189. // if there is no next job, and nothing is in flight, we are done.
  190. if (IsIdle())
  191. {
  192. Q_EMIT BecameIdle();
  193. }
  194. }
  195. }
  196. bool RCController::IsIdle()
  197. {
  198. bool queueIsEmpty = m_RCQueueSortModel.rowCount() == 0;
  199. return (queueIsEmpty && (m_RCJobListModel.jobsInFlight() == 0));
  200. }
  201. void RCController::JobSubmitted(JobDetails details)
  202. {
  203. AssetProcessor::QueueElementID checkFile(details.m_jobEntry.m_sourceAssetReference,
  204. details.m_jobEntry.m_platformInfo.m_identifier.c_str(),
  205. details.m_jobEntry.m_jobKey);
  206. bool hasMissingDependency = details.HasMissingSourceDependency();
  207. bool cancelJob = false;
  208. bool markCancelledJobAsFinished = false;
  209. RCJob* existingJob = nullptr;
  210. int existingJobIndex = -1;
  211. int existingJobEscalation = AssetProcessor::DefaultEscalation;
  212. int existingJobPriority = 0;
  213. bool existingJobIsCritical = false;
  214. if (m_RCJobListModel.isInQueue(checkFile))
  215. {
  216. existingJobIndex = m_RCJobListModel.GetIndexOfJobByState(checkFile, RCJob::pending);
  217. if (existingJobIndex != -1)
  218. {
  219. existingJob = m_RCJobListModel.getItem(existingJobIndex);
  220. existingJobEscalation = existingJob->JobEscalation();
  221. existingJobPriority = existingJob->GetPriority();
  222. existingJobIsCritical = existingJob->IsCritical();
  223. // The job status has changed
  224. if (existingJob->HasMissingSourceDependency() != hasMissingDependency)
  225. {
  226. AZ_TracePrintf(
  227. AssetProcessor::DebugChannel,
  228. "Cancelling Job [%s, %s, %s] missing source dependency status has changed.\n",
  229. checkFile.GetSourceAssetReference().AbsolutePath().c_str(),
  230. checkFile.GetPlatform().toUtf8().data(),
  231. checkFile.GetJobDescriptor().toUtf8().data());
  232. cancelJob = true;
  233. markCancelledJobAsFinished = existingJob->GetState() == RCJob::JobState::pending;
  234. }
  235. }
  236. if (!cancelJob)
  237. {
  238. AZ_TracePrintf(
  239. AssetProcessor::DebugChannel,
  240. "Job is already in queue and has not started yet - ignored [%s, %s, %s]\n",
  241. checkFile.GetSourceAssetReference().AbsolutePath().c_str(),
  242. checkFile.GetPlatform().toUtf8().data(),
  243. checkFile.GetJobDescriptor().toUtf8().data());
  244. // Don't just discard the job, we need to let APM know so it can keep track of the number of jobs that are pending/finished
  245. AssetBuilderSDK::JobCommandBus::Event(details.m_jobEntry.m_jobRunKey, &AssetBuilderSDK::JobCommandBus::Events::Cancel);
  246. Q_EMIT FileCancelled(details.m_jobEntry);
  247. return;
  248. }
  249. }
  250. if (m_RCJobListModel.isInFlight(checkFile))
  251. {
  252. // if the computed fingerprint is the same as the fingerprint of the in-flight job, this is okay.
  253. existingJobIndex = m_RCJobListModel.GetIndexOfJobByState(checkFile, RCJob::processing);
  254. if (existingJobIndex != -1)
  255. {
  256. existingJob = m_RCJobListModel.getItem(existingJobIndex);
  257. existingJobEscalation = existingJob->JobEscalation();
  258. existingJobPriority = existingJob->GetPriority();
  259. existingJobIsCritical = existingJob->IsCritical();
  260. // This does not set markCanceledJobAsFinished to true in either case the job is cancelled, because the job will
  261. // have FinishJob called once through the callback in RCController::StartJob. FinishJob should not be called more than once.
  262. if (existingJob->GetJobEntry().m_computedFingerprint != details.m_jobEntry.m_computedFingerprint)
  263. {
  264. AZ_TracePrintf(
  265. AssetProcessor::DebugChannel,
  266. "Cancelling Job [%s, %s, %s] with old FP %u, replacing with new FP %u \n",
  267. checkFile.GetSourceAssetReference().AbsolutePath().c_str(),
  268. checkFile.GetPlatform().toUtf8().data(),
  269. checkFile.GetJobDescriptor().toUtf8().data(),
  270. existingJob->GetJobEntry().m_computedFingerprint,
  271. details.m_jobEntry.m_computedFingerprint);
  272. cancelJob = true;
  273. }
  274. else if (!existingJob->GetJobDependencies().empty())
  275. {
  276. // If a job has dependencies, it's very likely it was re-queued as a result of a dependency being changed
  277. // The in-flight job is probably going to fail at best, or use old data at worst, so cancel the in-flight job
  278. AZ_TracePrintf(AssetProcessor::DebugChannel, "Cancelling Job with dependencies [%s, %s, %s], replacing with re-queued job\n",
  279. checkFile.GetSourceAssetReference().AbsolutePath().c_str(), checkFile.GetPlatform().toUtf8().data(), checkFile.GetJobDescriptor().toUtf8().data());
  280. cancelJob = true;
  281. }
  282. else
  283. {
  284. AZ_TracePrintf(
  285. AssetProcessor::DebugChannel,
  286. "Job is already in progress but has the same computed fingerprint (%u) - ignored [%s, %s, %s]\n",
  287. details.m_jobEntry.m_computedFingerprint,
  288. checkFile.GetSourceAssetReference().AbsolutePath().c_str(),
  289. checkFile.GetPlatform().toUtf8().data(),
  290. checkFile.GetJobDescriptor().toUtf8().data());
  291. // Don't just discard the job, we need to let APM know so it can keep track of the number of jobs that are
  292. // pending/finished
  293. AssetBuilderSDK::JobCommandBus::Event(details.m_jobEntry.m_jobRunKey, &AssetBuilderSDK::JobCommandBus::Events::Cancel);
  294. Q_EMIT FileCancelled(details.m_jobEntry);
  295. return;
  296. }
  297. }
  298. }
  299. if (cancelJob && existingJob && existingJobIndex != -1)
  300. {
  301. existingJob->SetState(RCJob::JobState::cancelled);
  302. // If the job was pending, mark it as finished, so asset processor can clean up the interface for this job and update tracking info.
  303. if (markCancelledJobAsFinished)
  304. {
  305. FinishJob(existingJob);
  306. }
  307. AssetBuilderSDK::JobCommandBus::Event(existingJob->GetJobEntry().m_jobRunKey, &AssetBuilderSDK::JobCommandBus::Events::Cancel);
  308. m_RCJobListModel.UpdateRow(existingJobIndex);
  309. }
  310. // create the new job, and make sure that if it replaces an escalated or proritized job, it inherits those.
  311. RCJob* rcJob = new RCJob(&m_RCJobListModel);
  312. details.m_priority = AZStd::GetMax(details.m_priority, existingJobPriority);
  313. details.m_critical = existingJobIsCritical || details.m_critical;
  314. rcJob->Init(details); // note - move operation. From this point on you must use the job details to refer to it.
  315. rcJob->SetJobEscalation(existingJobEscalation);
  316. m_RCQueueSortModel.AddJobIdEntry(rcJob);
  317. m_RCJobListModel.addNewJob(rcJob);
  318. QString platformName = rcJob->GetPlatformInfo().m_identifier.c_str();// we need to get the actual platform from the rcJob
  319. if (rcJob->IsCritical())
  320. {
  321. int criticalJobsCount = m_pendingCriticalJobsPerPlatform[platformName.toLower()] + 1;
  322. m_pendingCriticalJobsPerPlatform[platformName.toLower()] = criticalJobsCount;
  323. }
  324. auto found = m_jobsCountPerPlatform.find(platformName);
  325. if (found != m_jobsCountPerPlatform.end())
  326. {
  327. int newCount = found.value() + 1;
  328. m_jobsCountPerPlatform[platformName] = newCount;
  329. }
  330. else
  331. {
  332. m_jobsCountPerPlatform[platformName] = 1;
  333. }
  334. Q_EMIT JobsInQueuePerPlatform(platformName, m_jobsCountPerPlatform[platformName]);
  335. Q_EMIT JobStatusChanged(rcJob->GetJobEntry(), AzToolsFramework::AssetSystem::JobStatus::Queued);
  336. if (!m_dispatchingPaused)
  337. {
  338. Q_EMIT ActiveJobsCountChanged(aznumeric_cast<unsigned int>(m_RCJobListModel.itemCount()));
  339. }
  340. // Start the job we just received if no job currently running
  341. if ((!m_shuttingDown) && (!m_dispatchingJobs))
  342. {
  343. DispatchJobs();
  344. }
  345. }
  346. void RCController::SetDispatchPaused(bool pause)
  347. {
  348. if (m_dispatchingPaused != pause)
  349. {
  350. m_dispatchingPaused = pause;
  351. if (!pause)
  352. {
  353. if ((!m_shuttingDown) && (!m_dispatchingJobs))
  354. {
  355. DispatchJobs();
  356. Q_EMIT ActiveJobsCountChanged(aznumeric_cast<unsigned int>(m_RCJobListModel.itemCount()));
  357. }
  358. }
  359. }
  360. }
  361. void RCController::DispatchJobsImpl()
  362. {
  363. m_dispatchJobsQueued = false;
  364. if (m_dispatchingJobs)
  365. {
  366. return;
  367. }
  368. m_dispatchingJobs = true;
  369. do
  370. {
  371. RCJob* rcJob = m_RCQueueSortModel.GetNextPendingJob();
  372. if (!rcJob)
  373. {
  374. // there aren't any jobs remaining to dispatch.
  375. break;
  376. }
  377. // note that critical jobs and escalated jobs will always be at the top of the list
  378. const bool criticalOrEscalated = rcJob->IsCritical() || (rcJob->JobEscalation() > AssetProcessor::DefaultEscalation);
  379. // do we have an open slot for this job?
  380. const unsigned int numJobsInFlight = m_RCJobListModel.jobsInFlight();
  381. const unsigned int regularJobLimit = m_alwaysUseMaxJobs ? m_maxJobs : AZStd::GetMax(m_maxJobs / 2, 1u);
  382. const unsigned int maxJobsToStart = criticalOrEscalated ? m_maxJobs : regularJobLimit;
  383. // note that "auto fail jobs" oimmediately return as failed without doing any processing
  384. // so they get to skip the line (they don't use up a thread
  385. const bool isAutoJob = rcJob->IsAutoFail();
  386. const bool tooManyJobs = numJobsInFlight >= maxJobsToStart;
  387. if (!isAutoJob)
  388. {
  389. if ((tooManyJobs) || (m_dispatchingPaused))
  390. {
  391. // already using too much slots.
  392. break;
  393. }
  394. }
  395. StartJob(rcJob);
  396. } while (true);
  397. m_dispatchingJobs = false;
  398. }
  399. void RCController::DispatchJobs()
  400. {
  401. if ((!m_dispatchJobsQueued) && (!m_dispatchingPaused))
  402. {
  403. m_dispatchJobsQueued = true;
  404. QMetaObject::invokeMethod(this, "DispatchJobsImpl", Qt::QueuedConnection);
  405. }
  406. }
  407. void RCController::OnRequestCompileGroup(AssetProcessor::NetworkRequestID groupID, QString platform, QString searchTerm, AZ::Data::AssetId assetId, bool isStatusRequest, int searchType)
  408. {
  409. // someone has asked for a compile group to be created that conforms to that search term.
  410. // the goal here is to use a heuristic to find any assets that match the search term and place them in a new group
  411. // then respond with the appropriate response.
  412. // lets do some minimal processing on the search term
  413. AssetProcessor::JobIdEscalationList escalationList;
  414. QSet<AssetProcessor::QueueElementID> results;
  415. if (assetId.IsValid())
  416. {
  417. m_RCJobListModel.PerformUUIDSearch(assetId.m_guid, platform, results, escalationList, isStatusRequest);
  418. }
  419. else
  420. {
  421. m_RCJobListModel.PerformHeuristicSearch(AssetUtilities::NormalizeAndRemoveAlias(searchTerm), platform, results, escalationList, isStatusRequest, searchType);
  422. }
  423. if (results.isEmpty())
  424. {
  425. // nothing found
  426. AZ_Info(
  427. AssetProcessor::DebugChannel,
  428. "OnRequestCompileGroup: %s - %s requested, but no matching source assets found.\n",
  429. searchTerm.toUtf8().constData(),
  430. assetId.ToString<AZStd::string>().c_str());
  431. Q_EMIT CompileGroupCreated(groupID, AzFramework::AssetSystem::AssetStatus_Unknown);
  432. }
  433. else
  434. {
  435. AZ_Info(
  436. AssetProcessor::DebugChannel,
  437. "GetAssetStatus: OnRequestCompileGroup: %s - %s requested and queued, found %d results.\n",
  438. searchTerm.toUtf8().constData(),
  439. assetId.ToFixedString().c_str(), results.size());
  440. // it is not necessary to denote the search terms or list of results here because
  441. // PerformHeursticSearch already prints out the results.
  442. m_RCQueueSortModel.OnEscalateJobs(escalationList);
  443. m_activeCompileGroups.push_back(AssetCompileGroup());
  444. m_activeCompileGroups.back().m_groupMembers.swap(results);
  445. m_activeCompileGroups.back().m_requestID = groupID;
  446. Q_EMIT CompileGroupCreated(groupID, AzFramework::AssetSystem::AssetStatus_Queued);
  447. // escalating a job could free up an idle cpu thats dedicated to critical or escalated jobs.
  448. DispatchJobs();
  449. }
  450. }
  451. void RCController::OnEscalateJobsBySearchTerm(QString platform, QString searchTerm)
  452. {
  453. AssetProcessor::JobIdEscalationList escalationList;
  454. QSet<AssetProcessor::QueueElementID> results;
  455. m_RCJobListModel.PerformHeuristicSearch(AssetUtilities::NormalizeAndRemoveAlias(searchTerm), platform, results, escalationList, true);
  456. if (!results.isEmpty())
  457. {
  458. // it is not necessary to denote the search terms or list of results here because
  459. // PerformHeursticSearch already prints out the results.
  460. m_RCQueueSortModel.OnEscalateJobs(escalationList);
  461. }
  462. // escalating a job could free up an idle cpu thats dedicated to critical or escalated jobs.
  463. DispatchJobs();
  464. }
  465. void RCController::OnEscalateJobsBySourceUUID(QString platform, AZ::Uuid sourceUuid)
  466. {
  467. AssetProcessor::JobIdEscalationList escalationList;
  468. QSet<AssetProcessor::QueueElementID> results;
  469. m_RCJobListModel.PerformUUIDSearch(sourceUuid, platform, results, escalationList, true);
  470. if (!results.isEmpty())
  471. {
  472. #if defined(AZ_ENABLE_TRACING)
  473. for (const AssetProcessor::QueueElementID& result : results)
  474. {
  475. AZ_TracePrintf(AssetProcessor::DebugChannel, "OnEscalateJobsBySourceUUID: %s --> %s\n", sourceUuid.ToString<AZStd::string>().c_str(), result.GetSourceAssetReference().AbsolutePath().c_str());
  476. }
  477. #endif
  478. m_RCQueueSortModel.OnEscalateJobs(escalationList);
  479. }
  480. // do not print a warning out when this fails, its fine for things to escalate jobs as a matter of course just to "make sure" they are escalated
  481. // and its fine if none are in the build queue.
  482. // escalating a job could free up an idle cpu thats dedicated to critical or escalated jobs.
  483. DispatchJobs();
  484. }
  485. void RCController::OnIntermediateSourceAppeared(QString sourceRef)
  486. {
  487. if (m_RCJobListModel.UpdateMissingSourceDependencies(sourceRef))
  488. {
  489. // if we're waiting, then we could unblock and go.
  490. DispatchJobs();
  491. }
  492. }
  493. void RCController::OnJobComplete(JobEntry completeEntry, AzToolsFramework::AssetSystem::JobStatus state)
  494. {
  495. if (m_activeCompileGroups.empty())
  496. {
  497. return;
  498. }
  499. QueueElementID jobQueueId(completeEntry.m_sourceAssetReference, completeEntry.m_platformInfo.m_identifier.c_str(), completeEntry.m_jobKey);
  500. // only the 'completed' status means success:
  501. bool statusSucceeded = (state == AzToolsFramework::AssetSystem::JobStatus::Completed);
  502. // start at the end so that we can actually erase the compile groups and not skip any:
  503. for (int groupIdx = m_activeCompileGroups.size() - 1; groupIdx >= 0; --groupIdx)
  504. {
  505. AssetCompileGroup& compileGroup = m_activeCompileGroups[groupIdx];
  506. auto it = compileGroup.m_groupMembers.find(jobQueueId);
  507. if (it != compileGroup.m_groupMembers.end())
  508. {
  509. compileGroup.m_groupMembers.erase(it);
  510. if ((compileGroup.m_groupMembers.isEmpty()) || (!statusSucceeded))
  511. {
  512. // if we get here, we're either empty (and succeeded) or we failed one and have now failed
  513. Q_EMIT CompileGroupFinished(compileGroup.m_requestID, statusSucceeded ? AzFramework::AssetSystem::AssetStatus_Compiled: AzFramework::AssetSystem::AssetStatus_Failed);
  514. m_activeCompileGroups.removeAt(groupIdx);
  515. }
  516. }
  517. }
  518. }
  519. void RCController::RemoveJobsBySource(const SourceAssetReference& sourceAsset)
  520. {
  521. // some jobs may have not been started yet, these need to be removed manually
  522. AZStd::vector<RCJob*> pendingJobs;
  523. m_RCJobListModel.EraseJobs(sourceAsset, pendingJobs);
  524. // force finish all pending jobs
  525. for (auto* rcJob : pendingJobs)
  526. {
  527. FinishJob(rcJob);
  528. }
  529. }
  530. void RCController::OnAddedToCatalog(JobEntry jobEntry)
  531. {
  532. AssetProcessor::QueueElementID checkFile(jobEntry.m_sourceAssetReference, jobEntry.m_platformInfo.m_identifier.c_str(), jobEntry.m_jobKey);
  533. m_RCJobListModel.markAsCataloged(checkFile);
  534. DispatchJobs();
  535. }
  536. } // Namespace AssetProcessor