ImageViewDescriptor.cpp 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  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/ImageViewDescriptor.h>
  9. #include <Atom/RHI.Reflect/Interval.h>
  10. #include <AzCore/Serialization/SerializeContext.h>
  11. #include <AzCore/Utils/TypeHash.h>
  12. namespace AZ::RHI
  13. {
  14. ImageViewDescriptor::ImageViewDescriptor(
  15. Format overrideFormat)
  16. : m_overrideFormat{ overrideFormat }
  17. {}
  18. void ImageViewDescriptor::Reflect(AZ::ReflectContext* context)
  19. {
  20. if (auto* serializeContext = azrtti_cast<SerializeContext*>(context))
  21. {
  22. serializeContext->Class<ImageViewDescriptor>()
  23. ->Version(1)
  24. ->Field("MipSliceMin", &ImageViewDescriptor::m_mipSliceMin)
  25. ->Field("MipSliceMax", &ImageViewDescriptor::m_mipSliceMax)
  26. ->Field("ArraySliceMin", &ImageViewDescriptor::m_arraySliceMin)
  27. ->Field("ArraySliceMax", &ImageViewDescriptor::m_arraySliceMax)
  28. ->Field("OverrideFormat", &ImageViewDescriptor::m_overrideFormat)
  29. ->Field("OverrideBindFlags", &ImageViewDescriptor::m_overrideBindFlags)
  30. ->Field("IsCubemap", &ImageViewDescriptor::m_isCubemap)
  31. ->Field("AspectFlags", &ImageViewDescriptor::m_aspectFlags)
  32. ->Field("IsArray", &ImageViewDescriptor::m_isArray)
  33. ;
  34. }
  35. }
  36. ImageViewDescriptor ImageViewDescriptor::Create(
  37. Format format,
  38. uint16_t mipSliceMin,
  39. uint16_t mipSliceMax)
  40. {
  41. ImageViewDescriptor descriptor;
  42. descriptor.m_overrideFormat = format;
  43. descriptor.m_mipSliceMin = mipSliceMin;
  44. descriptor.m_mipSliceMax = mipSliceMax;
  45. return descriptor;
  46. }
  47. ImageViewDescriptor ImageViewDescriptor::Create(
  48. Format format,
  49. uint16_t mipSliceMin,
  50. uint16_t mipSliceMax,
  51. uint16_t arraySliceMin,
  52. uint16_t arraySliceMax)
  53. {
  54. ImageViewDescriptor descriptor;
  55. descriptor.m_overrideFormat = format;
  56. descriptor.m_mipSliceMin = mipSliceMin;
  57. descriptor.m_mipSliceMax = mipSliceMax;
  58. descriptor.m_arraySliceMin = arraySliceMin;
  59. descriptor.m_arraySliceMax = arraySliceMax;
  60. return descriptor;
  61. }
  62. ImageViewDescriptor ImageViewDescriptor::CreateCubemap()
  63. {
  64. ImageViewDescriptor descriptor;
  65. descriptor.m_isCubemap = true;
  66. return descriptor;
  67. }
  68. ImageViewDescriptor ImageViewDescriptor::CreateCubemap(
  69. Format format,
  70. uint16_t mipSliceMin,
  71. uint16_t mipSliceMax)
  72. {
  73. ImageViewDescriptor descriptor = Create(format, mipSliceMin, mipSliceMax);
  74. descriptor.m_isCubemap = true;
  75. return descriptor;
  76. }
  77. ImageViewDescriptor ImageViewDescriptor::CreateCubemap(
  78. Format format,
  79. uint16_t mipSliceMin,
  80. uint16_t mipSliceMax,
  81. uint16_t cubeSliceMin,
  82. uint16_t cubeSliceMax)
  83. {
  84. const uint16_t CubeFaceCount = 6;
  85. const uint16_t arraySliceMin = cubeSliceMin * CubeFaceCount;
  86. const uint16_t arraySliceMax = cubeSliceMax * CubeFaceCount;
  87. ImageViewDescriptor descriptor;
  88. descriptor.m_overrideFormat = format;
  89. descriptor.m_mipSliceMin = mipSliceMin;
  90. descriptor.m_mipSliceMax = mipSliceMax;
  91. descriptor.m_arraySliceMin = arraySliceMin;
  92. descriptor.m_arraySliceMax = arraySliceMax;
  93. descriptor.m_isCubemap = true;
  94. return descriptor;
  95. }
  96. ImageViewDescriptor ImageViewDescriptor::CreateCubemapFace(
  97. Format format,
  98. uint16_t mipSliceMin,
  99. uint16_t mipSliceMax,
  100. uint16_t faceSlice)
  101. {
  102. ImageViewDescriptor descriptor;
  103. descriptor.m_overrideFormat = format;
  104. descriptor.m_mipSliceMin = mipSliceMin;
  105. descriptor.m_mipSliceMax = mipSliceMax;
  106. descriptor.m_arraySliceMin = faceSlice;
  107. descriptor.m_arraySliceMax = faceSlice;
  108. descriptor.m_isCubemap = true;
  109. return descriptor;
  110. }
  111. ImageViewDescriptor ImageViewDescriptor::Create3D(
  112. Format overrideFormat,
  113. uint16_t mipSliceMin,
  114. uint16_t mipSliceMax,
  115. uint16_t depthSliceMin,
  116. uint16_t depthSliceMax)
  117. {
  118. ImageViewDescriptor descriptor;
  119. descriptor.m_overrideFormat = overrideFormat;
  120. descriptor.m_mipSliceMin = mipSliceMin;
  121. descriptor.m_mipSliceMax = mipSliceMax;
  122. descriptor.m_depthSliceMin = depthSliceMin;
  123. descriptor.m_depthSliceMax = depthSliceMax;
  124. return descriptor;
  125. }
  126. HashValue64 ImageViewDescriptor::GetHash(HashValue64 seed) const
  127. {
  128. return TypeHash64(*this, seed);
  129. }
  130. bool ImageViewDescriptor::IsSameSubResource(const ImageViewDescriptor& other) const
  131. {
  132. return
  133. m_mipSliceMin == other.m_mipSliceMin &&
  134. m_mipSliceMax == other.m_mipSliceMax &&
  135. m_arraySliceMin == other.m_arraySliceMin &&
  136. m_arraySliceMax == other.m_arraySliceMax &&
  137. m_depthSliceMin == other.m_depthSliceMin &&
  138. m_depthSliceMax == other.m_depthSliceMax &&
  139. m_aspectFlags == other.m_aspectFlags;
  140. }
  141. bool ImageViewDescriptor::OverlapsSubResource(const ImageViewDescriptor& other) const
  142. {
  143. return CheckBitsAny(m_aspectFlags, other.m_aspectFlags) &&
  144. Interval(m_arraySliceMin, m_arraySliceMax).Overlaps(Interval(other.m_arraySliceMin, other.m_arraySliceMax)) &&
  145. Interval(m_mipSliceMin, m_mipSliceMax).Overlaps(Interval(other.m_mipSliceMin, other.m_mipSliceMax));
  146. ;
  147. }
  148. bool ImageViewDescriptor::operator==(const ImageViewDescriptor& other) const
  149. {
  150. return
  151. IsSameSubResource(other) &&
  152. m_overrideFormat == other.m_overrideFormat &&
  153. m_overrideBindFlags == other.m_overrideBindFlags &&
  154. m_isCubemap == other.m_isCubemap &&
  155. m_isArray == other.m_isArray;
  156. }
  157. bool ImageViewDescriptor::operator!=(const ImageViewDescriptor& other) const
  158. {
  159. return !operator==(other);
  160. }
  161. }