RenderAttachmentLayout.cpp 11 KB

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