rccontroller.cpp 24 KB

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