Pass.cpp 73 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873
  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 <AzCore/RTTI/RTTI.h>
  9. #include <AzCore/std/string/conversions.h>
  10. #include <AtomCore/Instance/InstanceDatabase.h>
  11. #include <AtomCore/std/containers/vector_set.h>
  12. #include <Atom/RHI/FrameGraphAttachmentInterface.h>
  13. #include <Atom/RHI/FrameGraphBuilder.h>
  14. #include <Atom/RHI/RHIUtils.h>
  15. #include <Atom/RHI.Reflect/Base.h>
  16. #include <Atom/RPI.Public/Buffer/Buffer.h>
  17. #include <Atom/RPI.Public/Image/AttachmentImage.h>
  18. #include <Atom/RPI.Reflect/Image/Image.h>
  19. #include <Atom/RPI.Public/Pass/AttachmentReadback.h>
  20. #include <Atom/RPI.Public/Pass/ParentPass.h>
  21. #include <Atom/RPI.Public/Pass/Pass.h>
  22. #include <Atom/RPI.Public/Pass/PassLibrary.h>
  23. #include <Atom/RPI.Public/Pass/PassDefines.h>
  24. #include <Atom/RPI.Public/Pass/PassSystemInterface.h>
  25. #include <Atom/RPI.Public/Pass/PassUtils.h>
  26. #include <Atom/RPI.Public/Pass/Specific/ImageAttachmentPreviewPass.h>
  27. #include <Atom/RPI.Public/RenderPipeline.h>
  28. #include <Atom/RPI.Public/Image/ImageSystemInterface.h>
  29. #include <Atom/RPI.Public/Image/AttachmentImagePool.h>
  30. #include <Atom/RPI.Reflect/Image/AttachmentImageAsset.h>
  31. #include <Atom/RPI.Reflect/Pass/PassRequest.h>
  32. #include <Atom/RPI.Reflect/Pass/PassTemplate.h>
  33. #include <Atom/RPI.Reflect/Pass/PassName.h>
  34. #include <Atom/RPI.Reflect/Asset/AssetUtils.h>
  35. namespace AZ
  36. {
  37. namespace RPI
  38. {
  39. // --- Constructors ---
  40. Pass::Pass(const PassDescriptor& descriptor)
  41. : m_name(descriptor.m_passName)
  42. , m_path(descriptor.m_passName)
  43. {
  44. AZ_RPI_PASS_ASSERT((descriptor.m_passRequest == nullptr) || (descriptor.m_passTemplate != nullptr),
  45. "Pass::Pass - request is valid but template is nullptr. This is not allowed. Passing a valid passRequest also requires a valid passTemplate.");
  46. m_passData = PassUtils::GetPassDataPtr(descriptor);
  47. if (m_passData)
  48. {
  49. PassUtils::ExtractPipelineGlobalConnections(m_passData, m_pipelineGlobalConnections);
  50. m_viewTag = m_passData->m_pipelineViewTag;
  51. }
  52. m_flags.m_enabled = true;
  53. m_flags.m_timestampQueryEnabled = false;
  54. m_flags.m_pipelineStatisticsQueryEnabled = false;
  55. m_template = descriptor.m_passTemplate;
  56. if (descriptor.m_passRequest != nullptr)
  57. {
  58. // Assert m_template is the same as the one in the pass request
  59. if (PassValidation::IsEnabled())
  60. {
  61. const AZStd::shared_ptr<const PassTemplate> passTemplate = PassSystemInterface::Get()->GetPassTemplate(descriptor.m_passRequest->m_templateName);
  62. AZ_RPI_PASS_ASSERT(m_template == passTemplate, "Error: template in PassDescriptor doesn't match template from PassRequest!");
  63. }
  64. m_request = *descriptor.m_passRequest;
  65. m_flags.m_createdByPassRequest = true;
  66. m_flags.m_enabled = m_request.m_passEnabled;
  67. }
  68. PassSystemInterface::Get()->RegisterPass(this);
  69. QueueForBuildAndInitialization();
  70. // Skip reset since the pass just got created
  71. m_state = PassState::Reset;
  72. }
  73. Pass::~Pass()
  74. {
  75. AZ_RPI_BREAK_ON_TARGET_PASS;
  76. PassSystemInterface::Get()->UnregisterPass(this);
  77. }
  78. PassDescriptor Pass::GetPassDescriptor() const
  79. {
  80. PassDescriptor desc;
  81. desc.m_passName = m_name;
  82. desc.m_passTemplate = m_template ? PassSystemInterface::Get()->GetPassTemplate(m_template->m_name) : nullptr;
  83. if (m_flags.m_createdByPassRequest)
  84. {
  85. desc.m_passRequest = AZStd::make_shared<PassRequest>(m_request);
  86. }
  87. else
  88. {
  89. desc.m_passRequest.reset();
  90. }
  91. desc.m_passData = m_passData;
  92. return desc;
  93. }
  94. void Pass::SetEnabled(bool enabled)
  95. {
  96. m_flags.m_enabled = enabled;
  97. OnHierarchyChange();
  98. }
  99. // --- Error Logging ---
  100. void Pass::LogError(AZStd::string&& message)
  101. {
  102. #if AZ_RPI_ENABLE_PASS_DEBUGGING
  103. AZ::Debug::Trace::Instance().Break();
  104. #endif
  105. if (PassValidation::IsEnabled())
  106. {
  107. ++m_errors;
  108. if (m_errorMessages.size() < MessageLogLimit)
  109. {
  110. m_errorMessages.push_back(AZStd::move(message));
  111. }
  112. }
  113. }
  114. void Pass::LogWarning(AZStd::string&& message)
  115. {
  116. if (PassValidation::IsEnabled())
  117. {
  118. ++m_warnings;
  119. if (m_warningMessages.size() < MessageLogLimit)
  120. {
  121. m_warningMessages.push_back(AZStd::move(message));
  122. }
  123. }
  124. }
  125. // --- Hierarchy functions ---
  126. void Pass::OnHierarchyChange()
  127. {
  128. if (m_parent != nullptr)
  129. {
  130. // Set new tree depth and path
  131. m_flags.m_parentEnabled = m_parent->m_flags.m_enabled && (m_parent->m_flags.m_parentEnabled || m_parent->m_parent == nullptr);
  132. m_treeDepth = m_parent->m_treeDepth + 1;
  133. m_path = ConcatPassName(m_parent->m_path, m_name);
  134. m_flags.m_partOfHierarchy = m_parent->m_flags.m_partOfHierarchy;
  135. if (m_state == PassState::Orphaned)
  136. {
  137. QueueForBuildAndInitialization();
  138. }
  139. }
  140. AZ_RPI_BREAK_ON_TARGET_PASS;
  141. }
  142. void Pass::RemoveFromParent()
  143. {
  144. AZ_RPI_BREAK_ON_TARGET_PASS;
  145. AZ_RPI_PASS_ASSERT(m_parent != nullptr, "Trying to remove pass from parent but pointer to the parent pass is null.");
  146. m_parent->RemoveChild(Ptr<Pass>(this));
  147. m_queueState = PassQueueState::NoQueue;
  148. m_state = PassState::Orphaned;
  149. }
  150. void Pass::OnOrphan()
  151. {
  152. AZ_RPI_BREAK_ON_TARGET_PASS;
  153. if (m_flags.m_containsGlobalReference && m_pipeline != nullptr)
  154. {
  155. m_pipeline->RemovePipelineGlobalConnectionsFromPass(this);
  156. }
  157. m_parent = nullptr;
  158. m_flags.m_partOfHierarchy = false;
  159. m_treeDepth = 0;
  160. m_parentChildIndex = 0;
  161. m_queueState = PassQueueState::NoQueue;
  162. m_state = PassState::Orphaned;
  163. }
  164. ParentPass* Pass::AsParent()
  165. {
  166. return azrtti_cast<ParentPass*>(this);
  167. }
  168. const ParentPass* Pass::AsParent() const
  169. {
  170. return azrtti_cast<const ParentPass*>(this);
  171. }
  172. // --- Bindings ---
  173. PassAttachmentBinding& Pass::GetInputBinding(uint32_t index)
  174. {
  175. uint32_t bindingIndex = m_inputBindingIndices[index];
  176. return m_attachmentBindings[bindingIndex];
  177. }
  178. PassAttachmentBinding& Pass::GetInputOutputBinding(uint32_t index)
  179. {
  180. uint32_t bindingIndex = m_inputOutputBindingIndices[index];
  181. return m_attachmentBindings[bindingIndex];
  182. }
  183. PassAttachmentBinding& Pass::GetOutputBinding(uint32_t index)
  184. {
  185. uint32_t bindingIndex = m_outputBindingIndices[index];
  186. return m_attachmentBindings[bindingIndex];
  187. }
  188. void Pass::AddAttachmentBinding(PassAttachmentBinding attachmentBinding)
  189. {
  190. auto index = static_cast<uint8_t>(m_attachmentBindings.size());
  191. // Add the binding. This will assert if the fixed size array is full.
  192. m_attachmentBindings.push_back(attachmentBinding);
  193. // Add the index of the binding to the input, output or input/output list based on the slot type
  194. switch (attachmentBinding.m_slotType)
  195. {
  196. case PassSlotType::Input:
  197. m_inputBindingIndices.push_back(index);
  198. break;
  199. case PassSlotType::InputOutput:
  200. m_inputOutputBindingIndices.push_back(index);
  201. break;
  202. case PassSlotType::Output:
  203. m_outputBindingIndices.push_back(index);
  204. break;
  205. default:
  206. break;
  207. }
  208. }
  209. // --- Finders ---
  210. Ptr<Pass> Pass::FindAdjacentPass(const Name& passName)
  211. {
  212. // 1. Check This
  213. if (passName == PassNameThis)
  214. {
  215. return Ptr<Pass>(this);
  216. }
  217. // 2. Check Parent
  218. if (m_parent == nullptr)
  219. {
  220. return nullptr;
  221. }
  222. if (passName == PassNameParent || passName == m_parent->GetName())
  223. {
  224. return Ptr<Pass>(m_parent);
  225. }
  226. // 3. Check Siblings
  227. Ptr<Pass> foundPass = m_parent->FindChildPass(passName);
  228. // 4. Check Children
  229. if (!foundPass && AsParent())
  230. {
  231. foundPass = AsParent()->FindChildPass(passName);
  232. }
  233. // Finished search, return
  234. return foundPass;
  235. }
  236. PassAttachmentBinding* Pass::FindAttachmentBinding(const Name& slotName)
  237. {
  238. for (PassAttachmentBinding& binding : m_attachmentBindings)
  239. {
  240. if (slotName == binding.m_name)
  241. {
  242. return &binding;
  243. }
  244. }
  245. return nullptr;
  246. }
  247. const PassAttachmentBinding* Pass::FindAttachmentBinding(const Name& slotName) const
  248. {
  249. for (const PassAttachmentBinding& binding : m_attachmentBindings)
  250. {
  251. if (slotName == binding.m_name)
  252. {
  253. return &binding;
  254. }
  255. }
  256. return nullptr;
  257. }
  258. Ptr<PassAttachment> Pass::FindOwnedAttachment(const Name& attachmentName) const
  259. {
  260. for (const Ptr<PassAttachment>& attachment : m_ownedAttachments)
  261. {
  262. if (attachment->m_name == attachmentName)
  263. {
  264. return attachment;
  265. }
  266. }
  267. return nullptr;
  268. }
  269. Ptr<PassAttachment> Pass::FindAttachment(const Name& slotName) const
  270. {
  271. if (const PassAttachmentBinding* binding = FindAttachmentBinding(slotName))
  272. {
  273. return binding->GetAttachment();
  274. }
  275. return FindOwnedAttachment(slotName);
  276. }
  277. const PassAttachmentBinding* Pass::FindAdjacentBinding(const PassAttachmentRef& attachmentRef, [[maybe_unused]] const char* attachmentSourceTypeDebugName)
  278. {
  279. const PassAttachmentBinding* result = nullptr;
  280. if (attachmentRef.m_pass.IsEmpty() && attachmentRef.m_attachment.IsEmpty())
  281. {
  282. // The data isn't actually referencing anything, so this is not an error, just return null.
  283. return result;
  284. }
  285. if (attachmentRef.m_pass.IsEmpty() != attachmentRef.m_attachment.IsEmpty())
  286. {
  287. AZ_Error("Pass", false,
  288. "Invalid attachment reference (Pass [%s], Attachment [%s]). Both Pass and Attachment must be set.",
  289. attachmentRef.m_pass.GetCStr(), attachmentRef.m_attachment.GetCStr());
  290. return result;
  291. }
  292. // Find pass
  293. if (Ptr<Pass> pass = FindAdjacentPass(attachmentRef.m_pass))
  294. {
  295. // Find attachment within pass
  296. result = pass->FindAttachmentBinding(attachmentRef.m_attachment);
  297. }
  298. AZ_Error("Pass", result, "Pass [%s] could not find %s (Pass [%s], Attachment [%s])",
  299. m_path.GetCStr(), attachmentSourceTypeDebugName, attachmentRef.m_pass.GetCStr(), attachmentRef.m_attachment.GetCStr());
  300. return result;
  301. }
  302. // --- PassTemplate related functions ---
  303. void Pass::CreateBindingsFromTemplate()
  304. {
  305. if (m_template)
  306. {
  307. for (const PassSlot& slot : m_template->m_slots)
  308. {
  309. PassAttachmentBinding binding(slot);
  310. AddAttachmentBinding(binding);
  311. }
  312. }
  313. }
  314. void Pass::AttachBufferToSlot(AZStd::string_view slot, Data::Instance<Buffer> buffer)
  315. {
  316. AttachBufferToSlot(Name(slot), buffer);
  317. }
  318. void Pass::AttachBufferToSlot(const Name& slot, Data::Instance<Buffer> buffer)
  319. {
  320. if (!buffer)
  321. {
  322. return;
  323. }
  324. PassAttachmentBinding* localBinding = FindAttachmentBinding(slot);
  325. if (!localBinding)
  326. {
  327. AZ_RPI_PASS_ERROR(false, "Pass::AttachBufferToSlot - Pass [%s] failed to find slot [%s].",
  328. m_path.GetCStr(), slot.GetCStr());
  329. return;
  330. }
  331. // We can't handle the case that there is already an attachment attached yet.
  332. // We could consider to add it later if there are needs. It may require remove from the owned attachment list and
  333. // handle the connected bindings
  334. if (localBinding->GetAttachment())
  335. {
  336. AZ_RPI_PASS_ERROR(false, "Pass::AttachBufferToSlot - Slot [%s] already has attachment [%s].",
  337. slot.GetCStr(), localBinding->GetAttachment()->m_name.GetCStr());
  338. return;
  339. }
  340. PassBufferAttachmentDesc desc;
  341. desc.m_bufferDescriptor = buffer->GetRHIBuffer()->GetDescriptor();
  342. desc.m_lifetime = RHI::AttachmentLifetimeType::Imported;
  343. desc.m_name = buffer->GetAttachmentId();
  344. Ptr<PassAttachment> attachment = CreateAttachmentFromDesc(desc);
  345. attachment->m_importedResource = buffer;
  346. m_ownedAttachments.push_back(attachment);
  347. localBinding->SetOriginalAttachment(attachment);
  348. }
  349. void Pass::AttachImageToSlot(const Name& slot, Data::Instance<AttachmentImage> image)
  350. {
  351. PassAttachmentBinding* localBinding = FindAttachmentBinding(slot);
  352. if (!localBinding)
  353. {
  354. AZ_RPI_PASS_ERROR(false, "Pass::AttachImageToSlot - Pass [%s] failed to find slot [%s].",
  355. m_path.GetCStr(), slot.GetCStr());
  356. return;
  357. }
  358. // We can't handle the case that there is already an attachment attached yet.
  359. // We could consider to add it later if there are needs. It may require remove from the owned attachment list and
  360. // handle the connected bindings
  361. if (localBinding->GetAttachment())
  362. {
  363. AZ_RPI_PASS_ERROR(false, "Pass::AttachImageToSlot - Slot [%s] already has attachment [%s].",
  364. slot.GetCStr(), localBinding->GetAttachment()->m_name.GetCStr());
  365. return;
  366. }
  367. PassImageAttachmentDesc desc;
  368. desc.m_imageDescriptor = image->GetRHIImage()->GetDescriptor();
  369. desc.m_lifetime = RHI::AttachmentLifetimeType::Imported;
  370. desc.m_name = image->GetAttachmentId();
  371. Ptr<PassAttachment> attachment = CreateAttachmentFromDesc(desc);
  372. attachment->m_importedResource = image;
  373. m_ownedAttachments.push_back(attachment);
  374. localBinding->SetOriginalAttachment(attachment);
  375. }
  376. void Pass::ProcessConnection(const PassConnection& connection, uint32_t slotTypeMask)
  377. {
  378. [[maybe_unused]] auto prefix = [&]() -> AZStd::string
  379. {
  380. return AZStd::string::format(
  381. "Pass::ProcessConnection %s:%s -> %s:%s",
  382. m_path.GetCStr(),
  383. connection.m_localSlot.GetCStr(),
  384. connection.m_attachmentRef.m_pass.GetCStr(),
  385. connection.m_attachmentRef.m_attachment.GetCStr());
  386. };
  387. // -- Find Local Binding --
  388. // Get the input from this pass that forms one end of the connection
  389. PassAttachmentBinding* localBinding = FindAttachmentBinding(connection.m_localSlot);
  390. if (!localBinding)
  391. {
  392. AZ_RPI_PASS_ERROR(false, "%s: failed to find Local Slot.", prefix().c_str());
  393. return;
  394. }
  395. // Slot type mask used to skip connections at various stages of initialization
  396. uint32_t bindingMask = (1 << uint32_t(localBinding->m_slotType));
  397. if (!(bindingMask & slotTypeMask))
  398. {
  399. return;
  400. }
  401. // -- Local Variables --
  402. Name connectedPassName = connection.m_attachmentRef.m_pass;
  403. Name connectedSlotName = connection.m_attachmentRef.m_attachment;
  404. Ptr<PassAttachment> attachment = nullptr;
  405. PassAttachmentBinding* connectedBinding = nullptr;
  406. bool foundPass = false;
  407. bool slotTypeMismatch = false;
  408. // -- Search This Pass --
  409. if (connectedPassName == PassNameThis)
  410. {
  411. foundPass = true;
  412. attachment = FindOwnedAttachment(connectedSlotName);
  413. AZ_RPI_PASS_ERROR(
  414. attachment, "%s: Current Pass doesn't own an attachment named [%s].", prefix().c_str(), connectedSlotName.GetCStr());
  415. }
  416. // -- Search Pipeline --
  417. else if (connectedPassName == PipelineGlobalKeyword)
  418. {
  419. AZ_RPI_PASS_ERROR(m_pipeline != nullptr, "%s: Pass doesn't have a valid pipeline pointer.", prefix().c_str());
  420. foundPass = true; // Using the "Pipeline" keyword, no need to continue searching for passes
  421. if (m_pipeline)
  422. {
  423. const PipelineGlobalBinding* globalBinding = m_pipeline->GetPipelineGlobalConnection(connectedSlotName);
  424. if (globalBinding)
  425. {
  426. connectedBinding = globalBinding->m_binding;
  427. }
  428. AZ_RPI_PASS_ERROR(connectedBinding, "%s: Cannot find pipeline global connection.", prefix().c_str());
  429. }
  430. }
  431. // -- Search Parent & Siblings --
  432. // The (connectedPassName != m_name) avoids edge case where parent pass has child pass of same name.
  433. // In this case, parent pass would ask it's parent pass for a sibling with the given name and get a pointer to itself.
  434. // It would then try to connect to itself, which is obviously not the intention of the user
  435. if (!foundPass && m_parent && connectedPassName != m_name)
  436. {
  437. if (connectedPassName == PassNameParent)
  438. {
  439. foundPass = true;
  440. connectedBinding = m_parent->FindAttachmentBinding(connectedSlotName);
  441. if (!connectedBinding)
  442. {
  443. attachment = m_parent->FindOwnedAttachment(connectedSlotName);
  444. }
  445. else
  446. {
  447. slotTypeMismatch = connectedBinding->m_slotType != localBinding->m_slotType &&
  448. connectedBinding->m_slotType != PassSlotType::InputOutput &&
  449. localBinding->m_slotType != PassSlotType::InputOutput;
  450. }
  451. }
  452. else
  453. {
  454. // Use the connection Name to find a sibling pass
  455. Ptr<Pass> siblingPass = m_parent->FindChildPass(connectedPassName);
  456. if (siblingPass)
  457. {
  458. foundPass = true;
  459. connectedBinding = siblingPass->FindAttachmentBinding(connectedSlotName);
  460. slotTypeMismatch = connectedBinding != nullptr &&
  461. connectedBinding->m_slotType == localBinding->m_slotType &&
  462. connectedBinding->m_slotType != PassSlotType::InputOutput;
  463. }
  464. }
  465. }
  466. // -- Search Children --
  467. ParentPass* asParent = AsParent();
  468. if (!foundPass && asParent)
  469. {
  470. Ptr<Pass> childPass = asParent->FindChildPass(connectedPassName);
  471. if (childPass)
  472. {
  473. foundPass = true;
  474. connectedBinding = childPass->FindAttachmentBinding(connectedSlotName);
  475. slotTypeMismatch = connectedBinding != nullptr &&
  476. connectedBinding->m_slotType != localBinding->m_slotType &&
  477. connectedBinding->m_slotType != PassSlotType::InputOutput &&
  478. localBinding->m_slotType != PassSlotType::InputOutput;
  479. }
  480. }
  481. // -- Finalize & Report Errors --
  482. if (slotTypeMismatch)
  483. {
  484. AZ_RPI_PASS_ERROR(
  485. false,
  486. "%s: Slot Type Mismatch - When connecting to a child slot, both slots must be of the same type, or one must be "
  487. "InputOutput.",
  488. prefix().c_str());
  489. connectedBinding = nullptr;
  490. }
  491. if (connectedBinding)
  492. {
  493. localBinding->m_connectedBinding = connectedBinding;
  494. UpdateConnectedBinding(*localBinding);
  495. }
  496. else if (attachment)
  497. {
  498. localBinding->SetOriginalAttachment(attachment);
  499. }
  500. else
  501. {
  502. if (!m_flags.m_partOfHierarchy)
  503. {
  504. // [GFX TODO][ATOM-13693]: REMOVE POST R1 - passes not in hierarchy should no longer have this function called
  505. // When view is changing, removal of the passes can occur (cascade shadow passes for example)
  506. // resulting in temporary orphan passes that will be removed over the next frame.
  507. AZ_RPI_PASS_WARNING(false, "%s: Pass is no longer part of the hierarchy and about to be removed.", prefix().c_str());
  508. }
  509. else if (foundPass)
  510. {
  511. AZ_RPI_PASS_ERROR(false, "%s: Could not find binding on target.", prefix().c_str());
  512. }
  513. else
  514. {
  515. AZ_RPI_PASS_ERROR(false, "%s: Could not find target pass.", prefix().c_str());
  516. }
  517. }
  518. }
  519. void Pass::ProcessFallbackConnection(const PassFallbackConnection& connection)
  520. {
  521. PassAttachmentBinding* inputBinding = FindAttachmentBinding(connection.m_inputSlotName);
  522. PassAttachmentBinding* outputBinding = FindAttachmentBinding(connection.m_outputSlotName);
  523. [[maybe_unused]] auto prefix = [&]() -> AZStd::string
  524. {
  525. return AZStd::string::format(
  526. "Pass::ProcessFallbackConnection: %s, %s -> %s",
  527. m_path.GetCStr(),
  528. connection.m_inputSlotName.GetCStr(),
  529. connection.m_outputSlotName.GetCStr());
  530. };
  531. if (!outputBinding || !inputBinding)
  532. {
  533. AZ_RPI_PASS_ERROR(inputBinding, "%s: failed to find input slot.", prefix().c_str());
  534. AZ_RPI_PASS_ERROR(outputBinding, "%s: failed to find output slot.", prefix().c_str());
  535. return;
  536. }
  537. bool typesAreValid = inputBinding->m_slotType == PassSlotType::Input && outputBinding->m_slotType == PassSlotType::Output;
  538. if (!typesAreValid)
  539. {
  540. AZ_RPI_PASS_ERROR(
  541. inputBinding->m_slotType == PassSlotType::Input, "%s: Input doesn't have SlotType::Input.", prefix().c_str());
  542. AZ_RPI_PASS_ERROR(
  543. outputBinding->m_slotType == PassSlotType::Output, "%s: Output doesn't have SlotType::Output.", prefix().c_str());
  544. return;
  545. }
  546. outputBinding->m_fallbackBinding = inputBinding;
  547. UpdateConnectedBinding(*outputBinding);
  548. }
  549. template<typename AttachmentDescType>
  550. Ptr<PassAttachment> Pass::CreateAttachmentFromDesc(const AttachmentDescType& desc)
  551. {
  552. Ptr<PassAttachment> attachment = aznew PassAttachment(desc);
  553. // If the attachment is imported, we will create the resource (buffer or image) of this attachment
  554. // from asset referenced in m_assetRef
  555. // The resource instance will be saved in m_importedResource and the attachment id is acquired from resource instance
  556. if (desc.m_lifetime == RHI::AttachmentLifetimeType::Imported)
  557. {
  558. attachment->m_path = desc.m_name;
  559. if (attachment->m_descriptor.m_type == RHI::AttachmentType::Buffer)
  560. {
  561. Data::Asset<BufferAsset> bufferAsset = AssetUtils::LoadAssetById<BufferAsset>(desc.m_assetRef.m_assetId, AssetUtils::TraceLevel::None);
  562. if (bufferAsset.IsReady())
  563. {
  564. Data::Instance<Buffer> buffer = Buffer::FindOrCreate(bufferAsset);
  565. if (buffer)
  566. {
  567. attachment->m_path = buffer->GetAttachmentId();
  568. attachment->m_importedResource = buffer;
  569. attachment->m_descriptor = buffer->GetRHIBuffer()->GetDescriptor();
  570. }
  571. }
  572. }
  573. else if (attachment->m_descriptor.m_type == RHI::AttachmentType::Image)
  574. {
  575. Data::Asset<AttachmentImageAsset> imageAsset = AssetUtils::LoadAssetById<AttachmentImageAsset>(desc.m_assetRef.m_assetId, AssetUtils::TraceLevel::None);
  576. if (imageAsset.IsReady())
  577. {
  578. Data::Instance<AttachmentImage> image = AttachmentImage::FindOrCreate(imageAsset);
  579. if (image)
  580. {
  581. attachment->m_path = image->GetAttachmentId();
  582. attachment->m_importedResource = image;
  583. attachment->m_descriptor = image->GetDescriptor();
  584. }
  585. }
  586. }
  587. else
  588. {
  589. AZ_RPI_PASS_ASSERT(false, "Unsupported imported attachment type");
  590. }
  591. }
  592. else
  593. {
  594. // Only apply path name to transient attachment. Keep the original name for imported attachment
  595. attachment->ComputePathName(m_path);
  596. }
  597. // Setup attachment sources...
  598. if (desc.m_sizeSource.m_source.m_pass == PipelineKeyword) // if source is pipeline
  599. {
  600. attachment->m_renderPipelineSource = m_pipeline;
  601. attachment->m_getSizeFromPipeline = true;
  602. attachment->m_sizeMultipliers = desc.m_sizeSource.m_multipliers;
  603. }
  604. else if (const PassAttachmentBinding* source = FindAdjacentBinding(desc.m_sizeSource.m_source, "SizeSource"))
  605. {
  606. attachment->m_sizeSource = source;
  607. attachment->m_sizeMultipliers = desc.m_sizeSource.m_multipliers;
  608. }
  609. if (desc.m_formatSource.m_pass == PipelineKeyword) // if source is pipeline
  610. {
  611. attachment->m_renderPipelineSource = m_pipeline;
  612. attachment->m_getFormatFromPipeline = true;
  613. }
  614. else if (const PassAttachmentBinding* source = FindAdjacentBinding(desc.m_formatSource, "FormatSource"))
  615. {
  616. attachment->m_formatSource = source;
  617. }
  618. if (desc.m_multisampleSource.m_pass == PipelineKeyword) // if source is pipeline
  619. {
  620. attachment->m_renderPipelineSource = m_pipeline;
  621. attachment->m_getMultisampleStateFromPipeline = true;
  622. }
  623. else if (const PassAttachmentBinding* source = FindAdjacentBinding(desc.m_multisampleSource, "MultisampleSource"))
  624. {
  625. attachment->m_multisampleSource = source;
  626. }
  627. if (const PassAttachmentBinding* source = FindAdjacentBinding(desc.m_arraySizeSource, "ArraySizeSource"))
  628. {
  629. attachment->m_arraySizeSource = source;
  630. }
  631. attachment->m_ownerPass = this;
  632. return attachment;
  633. }
  634. template<typename AttachmentDescType>
  635. void Pass::OverrideOrAddAttachment(const AttachmentDescType& desc)
  636. {
  637. bool overrideAttachment = false;
  638. // Search existing attachments
  639. for (size_t i = 0; i < m_ownedAttachments.size(); ++i)
  640. {
  641. // If we find one with the same name
  642. if (m_ownedAttachments[i]->m_name == desc.m_name)
  643. {
  644. // Override it
  645. m_ownedAttachments[i] = CreateAttachmentFromDesc(desc);
  646. overrideAttachment = true;
  647. break;
  648. }
  649. }
  650. // If we didn't override any attachments
  651. if (!overrideAttachment)
  652. {
  653. // Create a new one
  654. m_ownedAttachments.emplace_back(CreateAttachmentFromDesc(desc));
  655. }
  656. }
  657. void Pass::SetupInputsFromRequest()
  658. {
  659. if (m_flags.m_createdByPassRequest)
  660. {
  661. const uint32_t slotTypeMask = (1 << uint32_t(PassSlotType::Input)) | (1 << uint32_t(PassSlotType::InputOutput));
  662. for (const PassConnection& connection : m_request.m_connections)
  663. {
  664. ProcessConnection(connection, slotTypeMask);
  665. }
  666. }
  667. }
  668. void Pass::SetupOutputsFromRequest()
  669. {
  670. if (m_flags.m_createdByPassRequest)
  671. {
  672. const uint32_t slotTypeMask = (1 << uint32_t(PassSlotType::Output));
  673. for (const PassConnection& connection : m_request.m_connections)
  674. {
  675. ProcessConnection(connection, slotTypeMask);
  676. }
  677. }
  678. }
  679. void Pass::SetupPassDependencies()
  680. {
  681. // Get dependencies declared in the PassRequest
  682. if (m_flags.m_createdByPassRequest)
  683. {
  684. for (const Name& passName : m_request.m_executeAfterPasses)
  685. {
  686. Ptr<Pass> executeAfterPass = FindAdjacentPass(passName);
  687. if (executeAfterPass != nullptr)
  688. {
  689. m_executeAfterPasses.push_back(executeAfterPass.get());
  690. }
  691. }
  692. for (const Name& passName : m_request.m_executeBeforePasses)
  693. {
  694. Ptr<Pass> executeBeforePass = FindAdjacentPass(passName);
  695. if (executeBeforePass != nullptr)
  696. {
  697. m_executeBeforePasses.push_back(executeBeforePass.get());
  698. }
  699. }
  700. }
  701. // Inherit dependencies from ParentPass
  702. if (m_parent)
  703. {
  704. for (Pass* pass : m_parent->m_executeAfterPasses)
  705. {
  706. m_executeAfterPasses.push_back(pass);
  707. }
  708. for (Pass* pass : m_parent->m_executeBeforePasses)
  709. {
  710. m_executeBeforePasses.push_back(pass);
  711. }
  712. }
  713. }
  714. void Pass::DeclareAttachmentsToFrameGraph(RHI::FrameGraphInterface frameGraph, PassSlotType slotType) const
  715. {
  716. for (const PassAttachmentBinding& attachmentBinding : m_attachmentBindings)
  717. {
  718. if(slotType == PassSlotType::Uninitialized || slotType == attachmentBinding.m_slotType)
  719. {
  720. if (attachmentBinding.GetAttachment() != nullptr &&
  721. frameGraph.GetAttachmentDatabase().IsAttachmentValid(attachmentBinding.GetAttachment()->GetAttachmentId()))
  722. {
  723. switch (attachmentBinding.m_unifiedScopeDesc.GetType())
  724. {
  725. case RHI::AttachmentType::Image:
  726. {
  727. frameGraph.UseAttachment(attachmentBinding.m_unifiedScopeDesc.GetAsImage(), attachmentBinding.GetAttachmentAccess(), attachmentBinding.m_scopeAttachmentUsage);
  728. break;
  729. }
  730. case RHI::AttachmentType::Buffer:
  731. {
  732. frameGraph.UseAttachment(attachmentBinding.m_unifiedScopeDesc.GetAsBuffer(), attachmentBinding.GetAttachmentAccess(), attachmentBinding.m_scopeAttachmentUsage);
  733. break;
  734. }
  735. default:
  736. AZ_Assert(false, "Error, trying to bind an attachment that is neither an image nor a buffer!");
  737. break;
  738. }
  739. }
  740. }
  741. }
  742. }
  743. void Pass::SetupInputsFromTemplate()
  744. {
  745. if (m_template)
  746. {
  747. const uint32_t slotTypeMask = (1 << uint32_t(PassSlotType::Input)) | (1 << uint32_t(PassSlotType::InputOutput));
  748. for (const PassConnection& outputConnection : m_template->m_connections)
  749. {
  750. ProcessConnection(outputConnection, slotTypeMask);
  751. }
  752. }
  753. }
  754. void Pass::SetupOutputsFromTemplate()
  755. {
  756. if (m_template)
  757. {
  758. const uint32_t slotTypeMask = (1 << uint32_t(PassSlotType::Output));
  759. for (const PassConnection& outputConnection : m_template->m_connections)
  760. {
  761. ProcessConnection(outputConnection, slotTypeMask);
  762. }
  763. for (const PassFallbackConnection& fallbackConnection : m_template->m_fallbackConnections)
  764. {
  765. ProcessFallbackConnection(fallbackConnection);
  766. }
  767. }
  768. }
  769. void Pass::CreateAttachmentsFromTemplate()
  770. {
  771. if (m_template)
  772. {
  773. // Create image attachments
  774. for (const PassImageAttachmentDesc& desc : m_template->m_imageAttachments)
  775. {
  776. m_ownedAttachments.emplace_back(CreateAttachmentFromDesc(desc));
  777. }
  778. // Create buffer attachments
  779. for (const PassBufferAttachmentDesc& desc : m_template->m_bufferAttachments)
  780. {
  781. m_ownedAttachments.emplace_back(CreateAttachmentFromDesc(desc));
  782. }
  783. }
  784. }
  785. void Pass::CreateAttachmentsFromRequest()
  786. {
  787. if (m_flags.m_createdByPassRequest)
  788. {
  789. // Create image attachments
  790. for (const PassImageAttachmentDesc& desc : m_request.m_imageAttachmentOverrides)
  791. {
  792. OverrideOrAddAttachment(desc);
  793. }
  794. // Create buffer attachments
  795. for (const PassBufferAttachmentDesc& desc : m_request.m_bufferAttachmentOverrides)
  796. {
  797. OverrideOrAddAttachment(desc);
  798. }
  799. }
  800. }
  801. // --- Attachment and Binding related functions ---
  802. void Pass::StoreImportedAttachmentReferences()
  803. {
  804. m_importedAttachmentStore.clear();
  805. for (const Ptr<PassAttachment>& attachment : m_ownedAttachments)
  806. {
  807. if (attachment->m_lifetime == RHI::AttachmentLifetimeType::Imported)
  808. {
  809. m_importedAttachmentStore.push_back(attachment);
  810. }
  811. }
  812. }
  813. void Pass::CreateTransientAttachments(RHI::FrameGraphAttachmentInterface attachmentDatabase)
  814. {
  815. for (const Ptr<PassAttachment>& attachment : m_ownedAttachments)
  816. {
  817. if (attachment->m_lifetime == RHI::AttachmentLifetimeType::Transient)
  818. {
  819. switch (attachment->m_descriptor.m_type)
  820. {
  821. case RHI::AttachmentType::Image:
  822. attachmentDatabase.CreateTransientImage(attachment->GetTransientImageDescriptor());
  823. break;
  824. case RHI::AttachmentType::Buffer:
  825. attachmentDatabase.CreateTransientBuffer(attachment->GetTransientBufferDescriptor());
  826. break;
  827. default:
  828. AZ_RPI_PASS_ASSERT(false, "Error, transient attachment is neither an image nor a buffer!");
  829. break;
  830. }
  831. }
  832. }
  833. }
  834. void Pass::ImportAttachments(RHI::FrameGraphAttachmentInterface attachmentDatabase)
  835. {
  836. for (const Ptr<PassAttachment>& attachment : m_ownedAttachments)
  837. {
  838. if (attachment->m_lifetime == RHI::AttachmentLifetimeType::Imported)
  839. {
  840. // make sure to only import the resource one time
  841. RHI::AttachmentId attachmentId = attachment->GetAttachmentId();
  842. const RHI::FrameAttachment* currentAttachment = attachmentDatabase.FindAttachment(attachmentId);
  843. if (azrtti_istypeof<Image>(attachment->m_importedResource.get()))
  844. {
  845. Image* image = static_cast<Image*>(attachment->m_importedResource.get());
  846. if (currentAttachment == nullptr)
  847. {
  848. attachmentDatabase.ImportImage(attachmentId, image->GetRHIImage());
  849. }
  850. else
  851. {
  852. AZ_Assert(currentAttachment->GetResource() == image->GetRHIImage(),
  853. "Importing image attachment named \"%s\" but a different attachment with the "
  854. "same name already exists in the database.\n", attachmentId.GetCStr());
  855. }
  856. }
  857. else if (azrtti_istypeof<Buffer>(attachment->m_importedResource.get()))
  858. {
  859. Buffer* buffer = static_cast<Buffer*>(attachment->m_importedResource.get());
  860. if (currentAttachment == nullptr)
  861. {
  862. attachmentDatabase.ImportBuffer(attachmentId, buffer->GetRHIBuffer());
  863. }
  864. else
  865. {
  866. AZ_Assert(currentAttachment->GetResource() == buffer->GetRHIBuffer(),
  867. "Importing buffer attachment named \"%s\" but a different attachment with the "
  868. "same name already exists in the database.\n", attachmentId.GetCStr());
  869. }
  870. }
  871. else
  872. {
  873. AZ_RPI_PASS_ERROR(false, "Can't import unknown resource type");
  874. }
  875. }
  876. }
  877. }
  878. void Pass::UpdateAttachmentUsageIndices()
  879. {
  880. // We want to find attachments that are used more than once by the same pass
  881. // An example of this could be reading from and writing to different mips of the same texture
  882. // Loop over all attachments bound to this pass
  883. size_t size = m_attachmentBindings.size();
  884. for (size_t i = 0; i < size; ++i)
  885. {
  886. PassAttachmentBinding& binding01 = m_attachmentBindings[i];
  887. // For the outer loop, only consider bindings which are the
  888. // first occurrence of their given attachment in the pass
  889. if (binding01.m_attachmentUsageIndex != 0)
  890. {
  891. continue;
  892. }
  893. // Loop over all subsequent bindings in the pass
  894. uint8_t duplicateCount = 0;
  895. for (size_t j = i + 1; j < size; ++j)
  896. {
  897. PassAttachmentBinding& binding02 = m_attachmentBindings[j];
  898. // Bindings are considered having the same attachment if they are connected to the same binding...
  899. bool haveSameConnection = binding01.m_connectedBinding == binding02.m_connectedBinding;
  900. haveSameConnection = haveSameConnection && binding01.m_connectedBinding != nullptr;
  901. // ... Or if they point to the same attachment
  902. bool isSameAttachment = binding01.GetAttachment() == binding02.GetAttachment();
  903. isSameAttachment = isSameAttachment && binding01.GetAttachment() != nullptr;
  904. // If binding 01 and binding 02 have the same attachment, update the attachment usage index on binding 02
  905. if (haveSameConnection || isSameAttachment)
  906. {
  907. binding02.m_attachmentUsageIndex = ++duplicateCount;
  908. }
  909. }
  910. }
  911. }
  912. void Pass::UpdateOwnedAttachments()
  913. {
  914. // Update the output attachments to coincide with their source attachments (if specified)
  915. // This involves getting the format and calculating the size from the source attachment
  916. for (Ptr<PassAttachment>& attachment: m_ownedAttachments)
  917. {
  918. attachment->Update();
  919. }
  920. }
  921. void Pass::UpdateConnectedBinding(PassAttachmentBinding& binding)
  922. {
  923. bool useFallback = (m_state != PassState::Building && !IsEnabled());
  924. binding.UpdateConnection(useFallback);
  925. }
  926. void Pass::UpdateConnectedBindings()
  927. {
  928. // Depending on whether a pass is enabled or not, it may switch it's bindings to become a pass-through
  929. // For this reason we update connecting bindings on a per-frame basis
  930. for (PassAttachmentBinding& binding : m_attachmentBindings)
  931. {
  932. UpdateConnectedBinding(binding);
  933. }
  934. }
  935. void Pass::UpdateConnectedInputBindings()
  936. {
  937. for (uint8_t idx : m_inputBindingIndices)
  938. {
  939. UpdateConnectedBinding(m_attachmentBindings[idx]);
  940. }
  941. for (uint8_t idx : m_inputOutputBindingIndices)
  942. {
  943. UpdateConnectedBinding(m_attachmentBindings[idx]);
  944. }
  945. }
  946. void Pass::UpdateConnectedOutputBindings()
  947. {
  948. for (uint8_t idx : m_outputBindingIndices)
  949. {
  950. UpdateConnectedBinding(m_attachmentBindings[idx]);
  951. }
  952. }
  953. void Pass::RegisterPipelineGlobalConnections()
  954. {
  955. if (!m_pipeline)
  956. {
  957. AZ_RPI_PASS_ERROR(m_pipelineGlobalConnections.size() == 0,
  958. "Pass::RegisterPipelineGlobalConnections() - PipelineGlobal connections specified but no pipeline set on pass [%s]",
  959. m_path.GetCStr());
  960. }
  961. for (const PipelineGlobalConnection& connection : m_pipelineGlobalConnections)
  962. {
  963. PassAttachmentBinding* binding = FindAttachmentBinding(connection.m_localBinding);
  964. AZ_RPI_PASS_ERROR(binding != nullptr, "Pass::RegisterPipelineGlobalConnections() - Could not find local binding [%s]",
  965. connection.m_localBinding.GetCStr());
  966. if (binding)
  967. {
  968. m_pipeline->AddPipelineGlobalConnection(connection.m_globalName, binding, this);
  969. }
  970. }
  971. m_flags.m_containsGlobalReference = (m_pipelineGlobalConnections.size() > 0);
  972. }
  973. // --- Queuing functions with PassSystem ---
  974. void Pass::QueueForBuildAndInitialization()
  975. {
  976. // Don't queue if we're currently building. Don't queue if we're already queued for Build or Removal
  977. if (m_state != PassState::Building &&
  978. m_queueState != PassQueueState::QueuedForBuildAndInitialization &&
  979. m_queueState != PassQueueState::QueuedForRemoval)
  980. {
  981. // NOTE: We only queue for Build here, the queue for Initialization happens at the end of Pass::Build
  982. // (doing it this way is an optimization to minimize the number of passes queued for initialization,
  983. // as many passes will be initialized by their parent passes and thus don't need to be queued)
  984. PassSystemInterface::Get()->QueueForBuild(this);
  985. m_queueState = PassQueueState::QueuedForBuildAndInitialization;
  986. // Transition state
  987. // If we are Rendering, the state will transition [Rendering -> Queued] in Pass::FrameEnd
  988. // TODO: the PassState::Reset check is a quick fix until the pass concurrency with multiple scenes issue is fixed
  989. if (m_state != PassState::Rendering && m_state != PassState::Reset)
  990. {
  991. m_state = PassState::Queued;
  992. }
  993. }
  994. }
  995. void Pass::QueueForInitialization()
  996. {
  997. // Only queue if the pass is not in any queue. Don't queue if we're currently initializing.
  998. if (m_queueState == PassQueueState::NoQueue && m_state != PassState::Initializing)
  999. {
  1000. PassSystemInterface::Get()->QueueForInitialization(this);
  1001. m_queueState = PassQueueState::QueuedForInitialization;
  1002. // Transition state
  1003. // If we are Rendering, the state will transition [Rendering -> Queued] in Pass::FrameEnd
  1004. // If the state is Built, preserve the state since [Built -> Initializing] is a valid transition
  1005. // Preserving PassState::Built lets the pass ignore subsequent build calls in the same frame
  1006. if (m_state != PassState::Rendering && m_state != PassState::Built)
  1007. {
  1008. m_state = PassState::Queued;
  1009. }
  1010. }
  1011. }
  1012. void Pass::QueueForRemoval()
  1013. {
  1014. // Skip only if we're already queued for removal, otherwise proceed.
  1015. // QueuedForRemoval overrides QueuedForBuildAndInitialization and QueuedForInitialization.
  1016. if (m_queueState != PassQueueState::QueuedForRemoval)
  1017. {
  1018. PassSystemInterface::Get()->QueueForRemoval(this);
  1019. m_queueState = PassQueueState::QueuedForRemoval;
  1020. // Transition state
  1021. // If we are Rendering, the state will transition [Rendering -> Queued] in Pass::FrameEnd
  1022. if (m_state != PassState::Rendering)
  1023. {
  1024. m_state = PassState::Queued;
  1025. }
  1026. }
  1027. }
  1028. // --- Pass behavior functions ---
  1029. void Pass::Reset()
  1030. {
  1031. AZ_RPI_BREAK_ON_TARGET_PASS;
  1032. // Ensure we're in a valid state to reset. This ensures the pass won't be reset multiple times in the same frame.
  1033. bool execute = (m_state == PassState::Idle);
  1034. execute = execute || (m_state == PassState::Queued && m_queueState == PassQueueState::QueuedForBuildAndInitialization);
  1035. execute = execute || (m_state == PassState::Queued && m_queueState == PassQueueState::QueuedForInitialization);
  1036. if (!execute)
  1037. {
  1038. return;
  1039. }
  1040. m_state = PassState::Resetting;
  1041. if (m_flags.m_isPipelineRoot)
  1042. {
  1043. m_pipeline->ClearGlobalBindings();
  1044. }
  1045. // Store references to imported attachments to underlying images and buffers aren't deleted during attachment building
  1046. StoreImportedAttachmentReferences();
  1047. // Clear lists
  1048. m_inputBindingIndices.clear();
  1049. m_inputOutputBindingIndices.clear();
  1050. m_outputBindingIndices.clear();
  1051. m_attachmentBindings.clear();
  1052. m_ownedAttachments.clear();
  1053. m_executeAfterPasses.clear();
  1054. m_executeBeforePasses.clear();
  1055. ResetInternal();
  1056. m_state = PassState::Reset;
  1057. }
  1058. void Pass::Build(bool calledFromPassSystem)
  1059. {
  1060. AZ_RPI_BREAK_ON_TARGET_PASS;
  1061. // Ensure we're in a valid state to build. This ensures the pass won't be built multiple times in the same frame.
  1062. bool execute = (m_state == PassState::Reset);
  1063. if (!execute)
  1064. {
  1065. return;
  1066. }
  1067. m_state = PassState::Building;
  1068. // Bindings, inputs and attachments
  1069. CreateBindingsFromTemplate();
  1070. RegisterPipelineGlobalConnections();
  1071. SetupPassDependencies();
  1072. CreateAttachmentsFromTemplate();
  1073. CreateAttachmentsFromRequest();
  1074. SetupInputsFromTemplate();
  1075. SetupInputsFromRequest();
  1076. // Custom pass behavior
  1077. BuildInternal();
  1078. // Outputs
  1079. SetupOutputsFromTemplate();
  1080. SetupOutputsFromRequest();
  1081. // Update
  1082. UpdateConnectedBindings();
  1083. UpdateOwnedAttachments();
  1084. UpdateAttachmentUsageIndices();
  1085. m_state = PassState::Built;
  1086. m_queueState = PassQueueState::NoQueue;
  1087. // If this pass's Build() wasn't called from the Pass System, then it was called by it's parent pass
  1088. // In which case we don't need to queue for initialization because the parent will already be queued
  1089. if (calledFromPassSystem)
  1090. {
  1091. // Queue for Initialization
  1092. QueueForInitialization();
  1093. }
  1094. }
  1095. void Pass::Initialize()
  1096. {
  1097. AZ_RPI_BREAK_ON_TARGET_PASS;
  1098. // Ensure we're in a valid state to initialize. This ensures the pass won't be initialized multiple times in the same frame.
  1099. bool execute = (m_state == PassState::Idle || m_state == PassState::Built);
  1100. execute = execute || (m_state == PassState::Queued && m_queueState == PassQueueState::QueuedForInitialization);
  1101. if (!execute)
  1102. {
  1103. return;
  1104. }
  1105. m_state = PassState::Initializing;
  1106. m_queueState = PassQueueState::NoQueue;
  1107. InitializeInternal();
  1108. // Need to recreate the dest attachment because the source attachment might be changed
  1109. if (!m_attachmentCopy.expired())
  1110. {
  1111. m_attachmentCopy.lock()->InvalidateDestImage();
  1112. }
  1113. m_state = PassState::Initialized;
  1114. }
  1115. void Pass::OnInitializationFinished()
  1116. {
  1117. m_flags.m_alreadyCreatedChildren = false;
  1118. m_importedAttachmentStore.clear();
  1119. OnInitializationFinishedInternal();
  1120. m_state = PassState::Idle;
  1121. }
  1122. void Pass::Validate(PassValidationResults& validationResults)
  1123. {
  1124. if (PassValidation::IsEnabled())
  1125. {
  1126. // Log passes with missing input
  1127. for (uint8_t idx : m_inputBindingIndices)
  1128. {
  1129. if (!m_attachmentBindings[idx].GetAttachment())
  1130. {
  1131. validationResults.m_passesWithMissingInputs.push_back(this);
  1132. break;
  1133. }
  1134. }
  1135. // Log passes with missing input/output
  1136. for (uint8_t idx : m_inputOutputBindingIndices)
  1137. {
  1138. if (!m_attachmentBindings[idx].GetAttachment())
  1139. {
  1140. validationResults.m_passesWithMissingInputOutputs.push_back(this);
  1141. break;
  1142. }
  1143. }
  1144. // Log passes with missing output (note that missing output connections are not considered an error)
  1145. for (uint8_t idx : m_outputBindingIndices)
  1146. {
  1147. if (!m_attachmentBindings[idx].GetAttachment())
  1148. {
  1149. validationResults.m_passesWithMissingOutputs.push_back(this);
  1150. break;
  1151. }
  1152. }
  1153. if (m_errorMessages.size() > 0)
  1154. {
  1155. validationResults.m_passesWithErrors.push_back(this);
  1156. }
  1157. if (m_warningMessages.size() > 0)
  1158. {
  1159. validationResults.m_passesWithWarnings.push_back(this);
  1160. }
  1161. }
  1162. }
  1163. void Pass::FrameBegin(FramePrepareParams params)
  1164. {
  1165. AZ_RPI_BREAK_ON_TARGET_PASS;
  1166. bool earlyOut = !IsEnabled();
  1167. // Skip if this pass is the root of the pipeline and the pipeline is set to not render
  1168. if (m_flags.m_isPipelineRoot)
  1169. {
  1170. AZ_RPI_PASS_ASSERT(m_pipeline != nullptr, "Pass is flagged as a pipeline root but it's pipeline pointer is invalid while trying to render");
  1171. earlyOut = earlyOut || m_pipeline == nullptr || m_pipeline->GetRenderMode() == RenderPipeline::RenderMode::NoRender;
  1172. }
  1173. if (earlyOut)
  1174. {
  1175. return;
  1176. }
  1177. AZ_Error("PassSystem", m_state == PassState::Idle,
  1178. "Pass::FrameBegin - Pass [%s] is attempting to render, and should be in the 'Idle' or 'Queued' state, but is in the '%s' state.",
  1179. m_path.GetCStr(), ToString(m_state).data());
  1180. m_state = PassState::Rendering;
  1181. UpdateOwnedAttachments();
  1182. CreateTransientAttachments(params.m_frameGraphBuilder->GetAttachmentDatabase());
  1183. ImportAttachments(params.m_frameGraphBuilder->GetAttachmentDatabase());
  1184. // readback attachment with input state
  1185. UpdateReadbackAttachment(params, true);
  1186. // FrameBeginInternal needs to be the last function be called in FrameBegin because its implementation expects
  1187. // all the attachments are imported to database (for example, ImageAttachmentPreview)
  1188. FrameBeginInternal(params);
  1189. // readback attachment with output state
  1190. UpdateReadbackAttachment(params, false);
  1191. // update attachment copy for preview
  1192. UpdateAttachmentCopy(params);
  1193. }
  1194. void Pass::FrameEnd()
  1195. {
  1196. if (m_state == PassState::Rendering)
  1197. {
  1198. FrameEndInternal();
  1199. m_state = (m_queueState == PassQueueState::NoQueue) ? PassState::Idle : PassState::Queued;
  1200. }
  1201. }
  1202. // --- RenderPipeline, PipelineViewTag and DrawListTag ---
  1203. RHI::DrawListTag Pass::GetDrawListTag() const
  1204. {
  1205. static RHI::DrawListTag invalidTag;
  1206. return invalidTag;
  1207. }
  1208. const PipelineViewTag& Pass::GetPipelineViewTag() const
  1209. {
  1210. if (m_viewTag.IsEmpty())
  1211. {
  1212. if (m_flags.m_isPipelineRoot && m_pipeline)
  1213. {
  1214. return m_pipeline->GetMainViewTag();
  1215. }
  1216. else if (m_parent)
  1217. {
  1218. return m_parent->GetPipelineViewTag();
  1219. }
  1220. }
  1221. return m_viewTag;
  1222. }
  1223. void Pass::SetRenderPipeline(RenderPipeline* pipeline)
  1224. {
  1225. AZ_Assert(!m_pipeline || !pipeline || m_pipeline == pipeline,
  1226. "Switching passes between pipelines is not supported and may result in undefined behavior");
  1227. if (m_pipeline != pipeline)
  1228. {
  1229. m_pipeline = pipeline;
  1230. // Re-queue for new pipeline.
  1231. if (m_pipeline != nullptr)
  1232. {
  1233. PassState currentState = m_state;
  1234. m_queueState = PassQueueState::NoQueue;
  1235. QueueForBuildAndInitialization();
  1236. if (currentState == PassState::Reset)
  1237. {
  1238. m_state = PassState::Reset;
  1239. }
  1240. }
  1241. }
  1242. }
  1243. void Pass::ManualPipelineBuildAndInitialize()
  1244. {
  1245. Build();
  1246. Initialize();
  1247. OnInitializationFinished();
  1248. }
  1249. Scene* Pass::GetScene() const
  1250. {
  1251. if (m_pipeline)
  1252. {
  1253. return m_pipeline->GetScene();
  1254. }
  1255. return nullptr;
  1256. }
  1257. PassTree* Pass::GetPassTree() const
  1258. {
  1259. return m_pipeline ? &(m_pipeline->m_passTree) : nullptr;
  1260. }
  1261. void Pass::GetViewDrawListInfo(RHI::DrawListMask& outDrawListMask, PassesByDrawList& outPassesByDrawList, const PipelineViewTag& viewTag) const
  1262. {
  1263. // NOTE: we always collect the draw list mask regardless if the pass enabled or not. The reason is we want to keep the view information
  1264. // even when pass is disabled so it can continue work correctly when re-enable it.
  1265. // Only get the DrawListTag if this pass has a DrawListTag and it's PipelineViewId matches
  1266. if (BindViewSrg() && HasDrawListTag() && GetPipelineViewTag() == viewTag)
  1267. {
  1268. RHI::DrawListTag drawListTag = GetDrawListTag();
  1269. if (drawListTag.IsValid() && outPassesByDrawList.find(drawListTag) == outPassesByDrawList.end())
  1270. {
  1271. outPassesByDrawList[drawListTag] = this;
  1272. outDrawListMask.set(drawListTag.GetIndex());
  1273. }
  1274. }
  1275. }
  1276. void Pass::GetPipelineViewTags(PipelineViewTags& outTags) const
  1277. {
  1278. if (BindViewSrg())
  1279. {
  1280. outTags.insert(GetPipelineViewTag());
  1281. }
  1282. }
  1283. void Pass::SortDrawList(RHI::DrawList& drawList) const
  1284. {
  1285. if (!drawList.empty())
  1286. {
  1287. RHI::SortDrawList(drawList, m_drawListSortType);
  1288. }
  1289. }
  1290. // --- Debug & Validation functions ---
  1291. bool PassValidationResults::IsValid()
  1292. {
  1293. if (PassValidation::IsEnabled())
  1294. {
  1295. // Pass validation fail if there are any passes with build errors or missing inputs (or input/outputs)
  1296. return (m_passesWithErrors.size() == 0) && (m_passesWithMissingInputs.size() == 0) && (m_passesWithMissingInputOutputs.size() == 0);
  1297. }
  1298. else
  1299. {
  1300. return true;
  1301. }
  1302. }
  1303. TimestampResult Pass::GetLatestTimestampResult() const
  1304. {
  1305. return GetTimestampResultInternal();
  1306. }
  1307. PipelineStatisticsResult Pass::GetLatestPipelineStatisticsResult() const
  1308. {
  1309. return GetPipelineStatisticsResultInternal();
  1310. }
  1311. bool Pass::ReadbackAttachment(AZStd::shared_ptr<AttachmentReadback> readback, uint32_t readbackIndex, const Name& slotName
  1312. , PassAttachmentReadbackOption option, const RHI::ImageSubresourceRange* mipsRange)
  1313. {
  1314. // Return false if it's already readback
  1315. if (m_attachmentReadback)
  1316. {
  1317. AZ_Warning("Pass", false, "ReadbackAttachment: skip readback pass [%s] slot [%s] because there is an another active readback", m_path.GetCStr(), slotName.GetCStr());
  1318. return false;
  1319. }
  1320. uint32_t bindingIndex = 0;
  1321. for (auto& binding : m_attachmentBindings)
  1322. {
  1323. if (slotName == binding.m_name)
  1324. {
  1325. RHI::AttachmentType type = binding.GetAttachment()->GetAttachmentType();
  1326. if (type == RHI::AttachmentType::Buffer || type == RHI::AttachmentType::Image)
  1327. {
  1328. RHI::AttachmentId attachmentId = binding.GetAttachment()->GetAttachmentId();
  1329. // Append slot index and pass name so the read back's name won't be same as the attachment used in other passes.
  1330. AZStd::string readbackName = AZStd::string::format("%s_%d_%d_%s", attachmentId.GetCStr(),
  1331. readbackIndex, bindingIndex, GetName().GetCStr());
  1332. if (readback->ReadPassAttachment(binding.GetAttachment().get(), AZ::Name(readbackName), mipsRange))
  1333. {
  1334. m_readbackOption = PassAttachmentReadbackOption::Output;
  1335. // The m_readbackOption is only meaningful if the attachment is used for InputOutput.
  1336. if (binding.m_slotType == PassSlotType::InputOutput)
  1337. {
  1338. m_readbackOption = option;
  1339. }
  1340. m_attachmentReadback = readback;
  1341. return true;
  1342. }
  1343. return false;
  1344. }
  1345. }
  1346. bindingIndex++;
  1347. }
  1348. AZ_Warning("Pass", false, "ReadbackAttachment: failed to find slot [%s] from pass [%s]", slotName.GetCStr(), m_path.GetCStr());
  1349. return false;
  1350. }
  1351. void Pass::UpdateReadbackAttachment(FramePrepareParams params, bool beforeAddScopes)
  1352. {
  1353. if (beforeAddScopes == (m_readbackOption == PassAttachmentReadbackOption::Input) && m_attachmentReadback)
  1354. {
  1355. // Read the attachment for one frame. The reference can be released afterwards
  1356. m_attachmentReadback->FrameBegin(params);
  1357. m_attachmentReadback = nullptr;
  1358. }
  1359. }
  1360. void Pass::UpdateAttachmentCopy(FramePrepareParams params)
  1361. {
  1362. if (!m_attachmentCopy.expired())
  1363. {
  1364. m_attachmentCopy.lock()->FrameBegin(params);
  1365. }
  1366. }
  1367. bool Pass::UpdateImportedAttachmentImage(Ptr<PassAttachment>& attachment, RHI::ImageBindFlags bindFlags, RHI::ImageAspectFlags aspectFlags)
  1368. {
  1369. if (!attachment)
  1370. {
  1371. return false;
  1372. }
  1373. // update the image attachment descriptor to sync up size and format
  1374. attachment->Update(true);
  1375. RHI::ImageDescriptor& imageDesc = attachment->m_descriptor.m_image;
  1376. // The Format Source had no valid attachment
  1377. if (imageDesc.m_format == RHI::Format::Unknown)
  1378. {
  1379. return false;
  1380. }
  1381. RPI::AttachmentImage* currentImage = azrtti_cast<RPI::AttachmentImage*>(attachment->m_importedResource.get());
  1382. if (attachment->m_importedResource && imageDesc.m_size == currentImage->GetDescriptor().m_size)
  1383. {
  1384. // If there's a resource already and the size didn't change, just keep using the old AttachmentImage.
  1385. return true;
  1386. }
  1387. Data::Instance<RPI::AttachmentImagePool> pool = RPI::ImageSystemInterface::Get()->GetSystemAttachmentPool();
  1388. // set the bind flags
  1389. imageDesc.m_bindFlags |= bindFlags;
  1390. // The ImageViewDescriptor must be specified to make sure the frame graph compiler doesn't treat this as a transient image.
  1391. RHI::ImageViewDescriptor viewDesc = RHI::ImageViewDescriptor::Create(imageDesc.m_format, 0, 0);
  1392. viewDesc.m_aspectFlags = aspectFlags;
  1393. // The full path name is needed for the attachment image so it's not deduplicated from accumulation images in different pipelines.
  1394. AZStd::string imageName = RPI::ConcatPassString(GetPathName(), attachment->m_path);
  1395. auto attachmentImage = RPI::AttachmentImage::Create(*pool.get(), imageDesc, Name(imageName), nullptr, &viewDesc);
  1396. if (attachmentImage)
  1397. {
  1398. attachment->m_path = attachmentImage->GetAttachmentId();
  1399. attachment->m_importedResource = attachmentImage;
  1400. return true;
  1401. }else
  1402. {
  1403. AZ_Error("Pass", false, "UpdateImportedAttachmentImage failed because it is unable to create an attachment image.");
  1404. }
  1405. return false;
  1406. }
  1407. void Pass::PrintIndent(AZStd::string& stringOutput, uint32_t indent) const
  1408. {
  1409. if (PassValidation::IsEnabled())
  1410. {
  1411. for (uint32_t i = 0; i < indent; ++i)
  1412. {
  1413. stringOutput += " ";
  1414. }
  1415. }
  1416. }
  1417. void Pass::PrintPassName(AZStd::string& stringOutput, uint32_t indent) const
  1418. {
  1419. if (PassValidation::IsEnabled())
  1420. {
  1421. stringOutput += "\n";
  1422. PrintIndent(stringOutput, indent);
  1423. stringOutput += "- ";
  1424. //stringOutput += m_name.GetStringView();
  1425. //stringOutput += "- ";
  1426. stringOutput += m_path.GetStringView();
  1427. stringOutput += "\n";
  1428. }
  1429. }
  1430. void Pass::PrintErrors() const
  1431. {
  1432. if (PassValidation::IsEnabled())
  1433. {
  1434. PrintMessages(m_errorMessages);
  1435. }
  1436. }
  1437. void Pass::PrintWarnings() const
  1438. {
  1439. if (PassValidation::IsEnabled())
  1440. {
  1441. PrintMessages(m_warningMessages);
  1442. }
  1443. }
  1444. void Pass::PrintMessages(const AZStd::vector<AZStd::string>& messages) const
  1445. {
  1446. if (PassValidation::IsEnabled())
  1447. {
  1448. AZStd::string stringOutput;
  1449. PrintPassName(stringOutput);
  1450. for (const AZStd::string& message : messages)
  1451. {
  1452. PrintIndent(stringOutput, 1);
  1453. stringOutput += message;
  1454. stringOutput += "\n";
  1455. }
  1456. AZ_Printf("PassSystem", stringOutput.c_str());
  1457. }
  1458. }
  1459. void Pass::PrintBindingsWithoutAttachments(uint32_t slotTypeMask) const
  1460. {
  1461. if (PassValidation::IsEnabled())
  1462. {
  1463. AZStd::string stringOutput;
  1464. PrintPassName(stringOutput);
  1465. for (const PassAttachmentBinding& binding : m_attachmentBindings)
  1466. {
  1467. uint32_t bindingMask = (1 << uint32_t(binding.m_slotType));
  1468. if ((bindingMask & slotTypeMask) && (binding.GetAttachment() == nullptr))
  1469. {
  1470. // Print the name of the slot
  1471. PrintIndent(stringOutput, 1);
  1472. stringOutput += binding.m_name.GetStringView();
  1473. stringOutput += " has no valid attachment\n";
  1474. }
  1475. }
  1476. AZ_Printf("PassSystem", stringOutput.c_str());
  1477. }
  1478. }
  1479. void Pass::DebugPrintBinding(AZStd::string& stringOutput, const PassAttachmentBinding& binding) const
  1480. {
  1481. if (PassValidation::IsEnabled())
  1482. {
  1483. // Print the name of the slot
  1484. stringOutput += binding.m_name.GetStringView();
  1485. // Print the attachment type and size, for example:
  1486. // (Image, 1920, 1080) or (Buffer, 4096 bytes)
  1487. if (binding.GetAttachment() != nullptr)
  1488. {
  1489. stringOutput += " (";
  1490. // Images will have the format: AttachmentName (Image, 1920, 1080)
  1491. if (binding.GetAttachment()->m_descriptor.m_type == RHI::AttachmentType::Image)
  1492. {
  1493. stringOutput += "Image";
  1494. RHI::ImageDescriptor& desc = binding.GetAttachment()->m_descriptor.m_image;
  1495. uint32_t dimensions = static_cast<uint32_t>(desc.m_dimension);
  1496. for (uint32_t i = 0; i < dimensions; ++i)
  1497. {
  1498. stringOutput += ", ";
  1499. stringOutput += AZStd::to_string(desc.m_size[i]);
  1500. }
  1501. if (desc.m_multisampleState.m_samples > 1)
  1502. {
  1503. if (desc.m_multisampleState.m_customPositionsCount > 0)
  1504. {
  1505. stringOutput += ", Custom_MSAA_";
  1506. }
  1507. else
  1508. {
  1509. stringOutput += ", MSAA_";
  1510. }
  1511. stringOutput += AZStd::to_string(desc.m_multisampleState.m_samples);
  1512. stringOutput += "x";
  1513. }
  1514. }
  1515. // Buffers will have the format: AttachmentName (Buffer, 4092 bytes)
  1516. else if (binding.GetAttachment()->m_descriptor.m_type == RHI::AttachmentType::Buffer)
  1517. {
  1518. stringOutput += "Buffer, ";
  1519. stringOutput += AZStd::to_string(binding.GetAttachment()->m_descriptor.m_buffer.m_byteCount);
  1520. stringOutput += " bytes";
  1521. }
  1522. stringOutput += ")";
  1523. }
  1524. }
  1525. }
  1526. void Pass::DebugPrintBindingAndConnection(AZStd::string& stringOutput, uint8_t bindingIndex) const
  1527. {
  1528. if (PassValidation::IsEnabled())
  1529. {
  1530. PrintIndent(stringOutput, m_treeDepth + 2);
  1531. // Print the Attachment
  1532. const PassAttachmentBinding& binding = m_attachmentBindings[bindingIndex];
  1533. DebugPrintBinding(stringOutput, binding);
  1534. // Print the Attachment it's connected to
  1535. if (binding.m_connectedBinding != nullptr)
  1536. {
  1537. stringOutput += " connected to ";
  1538. DebugPrintBinding(stringOutput, *binding.m_connectedBinding);
  1539. }
  1540. stringOutput += "\n";
  1541. }
  1542. }
  1543. void Pass::DebugPrint() const
  1544. {
  1545. if (PassValidation::IsEnabled())
  1546. {
  1547. AZStd::string stringOutput;
  1548. PrintPassName(stringOutput, m_treeDepth);
  1549. // Print inputs
  1550. if (m_inputBindingIndices.size() > 0)
  1551. {
  1552. PrintIndent(stringOutput, m_treeDepth + 1);
  1553. stringOutput += "Inputs:\n";
  1554. for (uint8_t inputIndex : m_inputBindingIndices)
  1555. {
  1556. DebugPrintBindingAndConnection(stringOutput, inputIndex);
  1557. }
  1558. }
  1559. // Print input/outputs
  1560. if (m_inputOutputBindingIndices.size() > 0)
  1561. {
  1562. PrintIndent(stringOutput, m_treeDepth + 1);
  1563. stringOutput += "Input/Outputs:\n";
  1564. for (uint8_t inputIndex : m_inputOutputBindingIndices)
  1565. {
  1566. DebugPrintBindingAndConnection(stringOutput, inputIndex);
  1567. }
  1568. }
  1569. // Print outputs
  1570. if (m_outputBindingIndices.size() > 0)
  1571. {
  1572. PrintIndent(stringOutput, m_treeDepth + 1);
  1573. stringOutput += "Outputs:\n";
  1574. for (uint8_t inputIndex : m_outputBindingIndices)
  1575. {
  1576. DebugPrintBindingAndConnection(stringOutput, inputIndex);
  1577. }
  1578. }
  1579. AZ_Printf("PassSystem", stringOutput.c_str());
  1580. }
  1581. }
  1582. void PassValidationResults::PrintValidationIfError()
  1583. {
  1584. if (PassValidation::IsEnabled())
  1585. {
  1586. if (!IsValid())
  1587. {
  1588. AZ_Printf("PassSystem", "\n--- PASS VALIDATION FAILURE ---"
  1589. "\n--Critical Errors--\n");
  1590. AZ_Printf("PassSystem", "\nThere are %d passes with errors:\n", m_passesWithErrors.size());
  1591. for (Pass* pass : m_passesWithErrors)
  1592. {
  1593. pass->PrintErrors();
  1594. }
  1595. AZ_Printf("PassSystem", "\nThere are %d passes with missing Inputs:\n", m_passesWithMissingInputs.size());
  1596. for (Pass* pass : m_passesWithMissingInputs)
  1597. {
  1598. pass->PrintBindingsWithoutAttachments(uint32_t(PassSlotMask::Input));
  1599. }
  1600. AZ_Printf("PassSystem", "\nThere are %d passes with missing Inputs/Outputs:\n", m_passesWithMissingInputOutputs.size());
  1601. for (Pass* pass : m_passesWithMissingInputOutputs)
  1602. {
  1603. pass->PrintBindingsWithoutAttachments(uint32_t(PassSlotMask::InputOutput));
  1604. }
  1605. AZ_Printf("PassSystem", "\n--Non-Critical Errors/Warnings--\n");
  1606. AZ_Printf("PassSystem", "\nThere are %d passes with warnings:\n", m_passesWithWarnings.size());
  1607. for (Pass* pass : m_passesWithWarnings)
  1608. {
  1609. pass->PrintWarnings();
  1610. }
  1611. }
  1612. }
  1613. }
  1614. } // namespace RPI
  1615. } // namespace AZ