3
0

SelectorPass.cpp 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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 <Atom/RPI.Public/Pass/Specific/SelectorPass.h>
  9. namespace AZ
  10. {
  11. namespace RPI
  12. {
  13. Ptr<SelectorPass> SelectorPass::Create(const PassDescriptor& descriptor)
  14. {
  15. Ptr<SelectorPass> pass = aznew SelectorPass(descriptor);
  16. return pass;
  17. }
  18. SelectorPass::SelectorPass(const PassDescriptor& descriptor)
  19. : Pass(descriptor)
  20. {
  21. uint32_t outputSlotCount = 0;
  22. for (const PassSlot& slot : m_template->m_slots)
  23. {
  24. if (slot.m_slotType == PassSlotType::Output)
  25. {
  26. outputSlotCount++;
  27. }
  28. }
  29. m_connections.resize(outputSlotCount);
  30. // Maybe move this default mapping to pass data.
  31. uint32_t inputIndex = 0;
  32. for (auto& connection : m_connections)
  33. {
  34. connection = inputIndex++;
  35. }
  36. }
  37. void SelectorPass::BuildInternal()
  38. {
  39. // Update output connections based on m_connections
  40. // This need to be done after BuildAttachment is finished
  41. for (uint32_t outputSlotIndex = 0; outputSlotIndex < m_connections.size(); outputSlotIndex++)
  42. {
  43. PassAttachmentBinding& outputBinding = GetOutputBinding(outputSlotIndex);
  44. PassAttachmentBinding& inputBinding = GetInputBinding(m_connections[outputSlotIndex]);
  45. outputBinding.SetAttachment(inputBinding.GetAttachment());
  46. }
  47. }
  48. void SelectorPass::Connect(uint32_t inputSlotIndex, uint32_t outputSlotIndex)
  49. {
  50. if (outputSlotIndex >= m_connections.size())
  51. {
  52. AZ_Assert(false, "outputSlotIndex %d doesn't exist", outputSlotIndex);
  53. return;
  54. }
  55. if (inputSlotIndex >= GetInputCount())
  56. {
  57. AZ_Assert(false, "inputSlotIndex %d doesn't exist", inputSlotIndex);
  58. return;
  59. }
  60. m_connections[outputSlotIndex] = inputSlotIndex;
  61. // Queue to rebuild attachment connections
  62. QueueForBuildAndInitialization();
  63. }
  64. void SelectorPass::Connect(const AZ::Name& inputSlot, const AZ::Name& outputSlot)
  65. {
  66. // Check whether both inputSlot or outputSlot are valid
  67. uint32_t outputIdx, inputIdx;
  68. for (outputIdx = 0; outputIdx < GetOutputCount(); ++outputIdx)
  69. {
  70. const PassAttachmentBinding& binding = GetOutputBinding(outputIdx);
  71. if (outputSlot == binding.m_name)
  72. {
  73. break;
  74. }
  75. }
  76. if (outputIdx == GetOutputCount())
  77. {
  78. AZ_Assert(false, "Can't find output slot %s", outputSlot.GetCStr());
  79. return;
  80. }
  81. for (inputIdx = 0; inputIdx < GetInputCount(); ++inputIdx)
  82. {
  83. const PassAttachmentBinding& binding = GetInputBinding(inputIdx);
  84. if (inputSlot == binding.m_name)
  85. {
  86. break;
  87. }
  88. }
  89. if (inputIdx == GetInputCount())
  90. {
  91. AZ_Assert(false, "Can't find input slot %s", inputSlot.GetCStr());
  92. return;
  93. }
  94. // Add connection to the map
  95. m_connections[outputIdx] = inputIdx;
  96. // Queue to rebuild attachment connections
  97. QueueForBuildAndInitialization();
  98. }
  99. } // namespace RPI
  100. } // namespace AZ