RenderAttachmentLayout.cpp 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229
  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/RHI.Reflect/RenderAttachmentLayout.h>
  9. #include <AzCore/Serialization/SerializeContext.h>
  10. #include <AzCore/Utils/TypeHash.h>
  11. namespace AZ::RHI
  12. {
  13. void RenderAttachmentDescriptor::Reflect(ReflectContext* context)
  14. {
  15. if (SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context))
  16. {
  17. serializeContext->Class<RenderAttachmentDescriptor>()
  18. ->Version(0)
  19. ->Field("AttachmentIndex", &RenderAttachmentDescriptor::m_attachmentIndex)
  20. ->Field("ResolveAttachmentIndex", &RenderAttachmentDescriptor::m_resolveAttachmentIndex)
  21. ->Field("AttachmentLoadStore", &RenderAttachmentDescriptor::m_loadStoreAction);
  22. }
  23. }
  24. bool RenderAttachmentDescriptor::IsValid() const
  25. {
  26. return m_attachmentIndex != InvalidRenderAttachmentIndex;
  27. }
  28. bool RenderAttachmentDescriptor::operator==(const RenderAttachmentDescriptor& other) const
  29. {
  30. return (m_attachmentIndex == other.m_attachmentIndex)
  31. && (m_resolveAttachmentIndex == other.m_resolveAttachmentIndex)
  32. && (m_loadStoreAction == other.m_loadStoreAction);
  33. }
  34. bool RenderAttachmentDescriptor::operator!=(const RenderAttachmentDescriptor& other) const
  35. {
  36. return !(*this == other);
  37. }
  38. void SubpassRenderAttachmentLayout::Reflect(ReflectContext* context)
  39. {
  40. SubpassInputDescriptor::Reflect(context);
  41. if (SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context))
  42. {
  43. serializeContext->Class<SubpassRenderAttachmentLayout>()
  44. ->Version(0)
  45. ->Field("RenderTargetCount", &SubpassRenderAttachmentLayout::m_rendertargetCount)
  46. ->Field("SubpassInputCount", &SubpassRenderAttachmentLayout::m_subpassInputCount)
  47. ->Field("RenderTargetDescriptors", &SubpassRenderAttachmentLayout::m_rendertargetDescriptors)
  48. ->Field("SubpasInputAttachmentDescriptors", &SubpassRenderAttachmentLayout::m_subpassInputDescriptors)
  49. ->Field("DepthStencilDescriptor", &SubpassRenderAttachmentLayout::m_depthStencilDescriptor);
  50. }
  51. RenderAttachmentDescriptor::Reflect(context);
  52. }
  53. bool SubpassRenderAttachmentLayout::operator==(const SubpassRenderAttachmentLayout& other) const
  54. {
  55. if ((m_rendertargetCount != other.m_rendertargetCount)
  56. || (m_subpassInputCount != other.m_subpassInputCount)
  57. || (m_depthStencilDescriptor != other.m_depthStencilDescriptor))
  58. {
  59. return false;
  60. }
  61. for (uint32_t i = 0; i < m_rendertargetCount; ++i)
  62. {
  63. if (m_rendertargetDescriptors[i] != other.m_rendertargetDescriptors[i])
  64. {
  65. return false;
  66. }
  67. }
  68. for (uint32_t i = 0; i < m_subpassInputCount; ++i)
  69. {
  70. if (m_subpassInputDescriptors[i] != other.m_subpassInputDescriptors[i])
  71. {
  72. return false;
  73. }
  74. }
  75. return true;
  76. }
  77. bool SubpassRenderAttachmentLayout::operator!=(const SubpassRenderAttachmentLayout& other) const
  78. {
  79. return !(*this == other);
  80. }
  81. void RenderAttachmentLayout::Reflect(ReflectContext* context)
  82. {
  83. if (SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context))
  84. {
  85. serializeContext->Class<RenderAttachmentLayout>()
  86. ->Version(0)
  87. ->Field("AttachmentCount", &RenderAttachmentLayout::m_attachmentCount)
  88. ->Field("SubpassCount", &RenderAttachmentLayout::m_subpassCount)
  89. ->Field("AttachmentFormats", &RenderAttachmentLayout::m_attachmentFormats)
  90. ->Field("SubpassLayouts", &RenderAttachmentLayout::m_subpassLayouts);
  91. }
  92. SubpassRenderAttachmentLayout::Reflect(context);
  93. }
  94. HashValue64 RenderAttachmentLayout::GetHash() const
  95. {
  96. return TypeHash64(*this);
  97. }
  98. bool RenderAttachmentLayout::operator==(const RenderAttachmentLayout& other) const
  99. {
  100. if ((m_attachmentCount != other.m_attachmentCount)
  101. || (m_subpassCount != other.m_subpassCount))
  102. {
  103. return false;
  104. }
  105. for (uint32_t i = 0; i < m_attachmentCount; ++i)
  106. {
  107. if (m_attachmentFormats[i] != other.m_attachmentFormats[i])
  108. {
  109. return false;
  110. }
  111. }
  112. for (uint32_t i = 0; i < m_subpassCount; ++i)
  113. {
  114. if(m_subpassLayouts[i] != other.m_subpassLayouts[i])
  115. {
  116. return false;
  117. }
  118. }
  119. return true;
  120. }
  121. void RenderAttachmentConfiguration::Reflect(ReflectContext* context)
  122. {
  123. RenderAttachmentLayout::Reflect(context);
  124. if (SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context))
  125. {
  126. serializeContext->Class<RenderAttachmentConfiguration>()
  127. ->Version(0)
  128. ->Field("RenderAttachmentLayout", &RenderAttachmentConfiguration::m_renderAttachmentLayout)
  129. ->Field("SubpassIndex", &RenderAttachmentConfiguration::m_subpassIndex);
  130. }
  131. }
  132. HashValue64 RenderAttachmentConfiguration::GetHash() const
  133. {
  134. HashValue64 hash = m_renderAttachmentLayout.GetHash();
  135. hash = TypeHash64(m_subpassIndex, hash);
  136. return hash;
  137. }
  138. Format RenderAttachmentConfiguration::GetRenderTargetFormat(uint32_t index) const
  139. {
  140. const auto& subpassAttachmentLayout = m_renderAttachmentLayout.m_subpassLayouts[m_subpassIndex];
  141. return m_renderAttachmentLayout.m_attachmentFormats[subpassAttachmentLayout.m_rendertargetDescriptors[index].m_attachmentIndex];
  142. }
  143. Format RenderAttachmentConfiguration::GetSubpassInputFormat(uint32_t index) const
  144. {
  145. const auto& subpassAttachmentLayout = m_renderAttachmentLayout.m_subpassLayouts[m_subpassIndex];
  146. return m_renderAttachmentLayout.m_attachmentFormats[subpassAttachmentLayout.m_subpassInputDescriptors[index].m_attachmentIndex];
  147. }
  148. Format RenderAttachmentConfiguration::GetRenderTargetResolveFormat(uint32_t index) const
  149. {
  150. const auto& subpassAttachmentLayout = m_renderAttachmentLayout.m_subpassLayouts[m_subpassIndex];
  151. if (subpassAttachmentLayout.m_rendertargetDescriptors[index].m_resolveAttachmentIndex != InvalidRenderAttachmentIndex)
  152. {
  153. return m_renderAttachmentLayout.m_attachmentFormats[subpassAttachmentLayout.m_rendertargetDescriptors[index].m_resolveAttachmentIndex];
  154. }
  155. return Format::Unknown;
  156. }
  157. Format RenderAttachmentConfiguration::GetDepthStencilFormat() const
  158. {
  159. const auto& subpassAttachmentLayout = m_renderAttachmentLayout.m_subpassLayouts[m_subpassIndex];
  160. return subpassAttachmentLayout.m_depthStencilDescriptor.IsValid() ?
  161. m_renderAttachmentLayout.m_attachmentFormats[subpassAttachmentLayout.m_depthStencilDescriptor.m_attachmentIndex] :
  162. RHI::Format::Unknown;
  163. }
  164. uint32_t RenderAttachmentConfiguration::GetRenderTargetCount() const
  165. {
  166. return m_renderAttachmentLayout.m_subpassLayouts[m_subpassIndex].m_rendertargetCount;
  167. }
  168. uint32_t RenderAttachmentConfiguration::GetSubpassInputCount() const
  169. {
  170. return m_renderAttachmentLayout.m_subpassLayouts[m_subpassIndex].m_subpassInputCount;
  171. }
  172. bool RenderAttachmentConfiguration::DoesRenderTargetResolve(uint32_t index) const
  173. {
  174. return m_renderAttachmentLayout.m_subpassLayouts[m_subpassIndex].m_rendertargetDescriptors[index].m_resolveAttachmentIndex != InvalidRenderAttachmentIndex;
  175. }
  176. bool RenderAttachmentConfiguration::operator==(const RenderAttachmentConfiguration& other) const
  177. {
  178. return (m_renderAttachmentLayout == other.m_renderAttachmentLayout) && (m_subpassIndex == other.m_subpassIndex);
  179. }
  180. void SubpassInputDescriptor::Reflect(ReflectContext* context)
  181. {
  182. if (SerializeContext* serializeContext = azrtti_cast<SerializeContext*>(context))
  183. {
  184. serializeContext->Class<SubpassInputDescriptor>()
  185. ->Version(0)
  186. ->Field("RenderAttachmentIndex", &SubpassInputDescriptor::m_attachmentIndex)
  187. ->Field("AspectFlags", &SubpassInputDescriptor::m_aspectFlags);
  188. }
  189. }
  190. bool SubpassInputDescriptor::operator==(const SubpassInputDescriptor& other) const
  191. {
  192. return (m_attachmentIndex == other.m_attachmentIndex) && (m_aspectFlags == other.m_aspectFlags);
  193. }
  194. bool SubpassInputDescriptor::operator!=(const SubpassInputDescriptor& other) const
  195. {
  196. return !(*this == other);
  197. }
  198. }