formatter.h 9.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264
  1. // Copyright 2020 yuzu Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #pragma once
  5. #include <string>
  6. #include <fmt/format.h>
  7. #include "video_core/surface.h"
  8. #include "video_core/texture_cache/types.h"
  9. template <>
  10. struct fmt::formatter<VideoCore::Surface::PixelFormat> : fmt::formatter<fmt::string_view> {
  11. template <typename FormatContext>
  12. auto format(VideoCore::Surface::PixelFormat format, FormatContext& ctx) {
  13. using VideoCore::Surface::PixelFormat;
  14. const string_view name = [format] {
  15. switch (format) {
  16. case PixelFormat::A8B8G8R8_UNORM:
  17. return "A8B8G8R8_UNORM";
  18. case PixelFormat::A8B8G8R8_SNORM:
  19. return "A8B8G8R8_SNORM";
  20. case PixelFormat::A8B8G8R8_SINT:
  21. return "A8B8G8R8_SINT";
  22. case PixelFormat::A8B8G8R8_UINT:
  23. return "A8B8G8R8_UINT";
  24. case PixelFormat::R5G6B5_UNORM:
  25. return "R5G6B5_UNORM";
  26. case PixelFormat::B5G6R5_UNORM:
  27. return "B5G6R5_UNORM";
  28. case PixelFormat::A1R5G5B5_UNORM:
  29. return "A1R5G5B5_UNORM";
  30. case PixelFormat::A2B10G10R10_UNORM:
  31. return "A2B10G10R10_UNORM";
  32. case PixelFormat::A2B10G10R10_UINT:
  33. return "A2B10G10R10_UINT";
  34. case PixelFormat::A1B5G5R5_UNORM:
  35. return "A1B5G5R5_UNORM";
  36. case PixelFormat::R8_UNORM:
  37. return "R8_UNORM";
  38. case PixelFormat::R8_SNORM:
  39. return "R8_SNORM";
  40. case PixelFormat::R8_SINT:
  41. return "R8_SINT";
  42. case PixelFormat::R8_UINT:
  43. return "R8_UINT";
  44. case PixelFormat::R16G16B16A16_FLOAT:
  45. return "R16G16B16A16_FLOAT";
  46. case PixelFormat::R16G16B16A16_UNORM:
  47. return "R16G16B16A16_UNORM";
  48. case PixelFormat::R16G16B16A16_SNORM:
  49. return "R16G16B16A16_SNORM";
  50. case PixelFormat::R16G16B16A16_SINT:
  51. return "R16G16B16A16_SINT";
  52. case PixelFormat::R16G16B16A16_UINT:
  53. return "R16G16B16A16_UINT";
  54. case PixelFormat::B10G11R11_FLOAT:
  55. return "B10G11R11_FLOAT";
  56. case PixelFormat::R32G32B32A32_UINT:
  57. return "R32G32B32A32_UINT";
  58. case PixelFormat::BC1_RGBA_UNORM:
  59. return "BC1_RGBA_UNORM";
  60. case PixelFormat::BC2_UNORM:
  61. return "BC2_UNORM";
  62. case PixelFormat::BC3_UNORM:
  63. return "BC3_UNORM";
  64. case PixelFormat::BC4_UNORM:
  65. return "BC4_UNORM";
  66. case PixelFormat::BC4_SNORM:
  67. return "BC4_SNORM";
  68. case PixelFormat::BC5_UNORM:
  69. return "BC5_UNORM";
  70. case PixelFormat::BC5_SNORM:
  71. return "BC5_SNORM";
  72. case PixelFormat::BC7_UNORM:
  73. return "BC7_UNORM";
  74. case PixelFormat::BC6H_UFLOAT:
  75. return "BC6H_UFLOAT";
  76. case PixelFormat::BC6H_SFLOAT:
  77. return "BC6H_SFLOAT";
  78. case PixelFormat::ASTC_2D_4X4_UNORM:
  79. return "ASTC_2D_4X4_UNORM";
  80. case PixelFormat::B8G8R8A8_UNORM:
  81. return "B8G8R8A8_UNORM";
  82. case PixelFormat::R32G32B32A32_FLOAT:
  83. return "R32G32B32A32_FLOAT";
  84. case PixelFormat::R32G32B32A32_SINT:
  85. return "R32G32B32A32_SINT";
  86. case PixelFormat::R32G32_FLOAT:
  87. return "R32G32_FLOAT";
  88. case PixelFormat::R32G32_SINT:
  89. return "R32G32_SINT";
  90. case PixelFormat::R32_FLOAT:
  91. return "R32_FLOAT";
  92. case PixelFormat::R16_FLOAT:
  93. return "R16_FLOAT";
  94. case PixelFormat::R16_UNORM:
  95. return "R16_UNORM";
  96. case PixelFormat::R16_SNORM:
  97. return "R16_SNORM";
  98. case PixelFormat::R16_UINT:
  99. return "R16_UINT";
  100. case PixelFormat::R16_SINT:
  101. return "R16_SINT";
  102. case PixelFormat::R16G16_UNORM:
  103. return "R16G16_UNORM";
  104. case PixelFormat::R16G16_FLOAT:
  105. return "R16G16_FLOAT";
  106. case PixelFormat::R16G16_UINT:
  107. return "R16G16_UINT";
  108. case PixelFormat::R16G16_SINT:
  109. return "R16G16_SINT";
  110. case PixelFormat::R16G16_SNORM:
  111. return "R16G16_SNORM";
  112. case PixelFormat::R32G32B32_FLOAT:
  113. return "R32G32B32_FLOAT";
  114. case PixelFormat::A8B8G8R8_SRGB:
  115. return "A8B8G8R8_SRGB";
  116. case PixelFormat::R8G8_UNORM:
  117. return "R8G8_UNORM";
  118. case PixelFormat::R8G8_SNORM:
  119. return "R8G8_SNORM";
  120. case PixelFormat::R8G8_SINT:
  121. return "R8G8_SINT";
  122. case PixelFormat::R8G8_UINT:
  123. return "R8G8_UINT";
  124. case PixelFormat::R32G32_UINT:
  125. return "R32G32_UINT";
  126. case PixelFormat::R16G16B16X16_FLOAT:
  127. return "R16G16B16X16_FLOAT";
  128. case PixelFormat::R32_UINT:
  129. return "R32_UINT";
  130. case PixelFormat::R32_SINT:
  131. return "R32_SINT";
  132. case PixelFormat::ASTC_2D_8X8_UNORM:
  133. return "ASTC_2D_8X8_UNORM";
  134. case PixelFormat::ASTC_2D_8X5_UNORM:
  135. return "ASTC_2D_8X5_UNORM";
  136. case PixelFormat::ASTC_2D_5X4_UNORM:
  137. return "ASTC_2D_5X4_UNORM";
  138. case PixelFormat::B8G8R8A8_SRGB:
  139. return "B8G8R8A8_SRGB";
  140. case PixelFormat::BC1_RGBA_SRGB:
  141. return "BC1_RGBA_SRGB";
  142. case PixelFormat::BC2_SRGB:
  143. return "BC2_SRGB";
  144. case PixelFormat::BC3_SRGB:
  145. return "BC3_SRGB";
  146. case PixelFormat::BC7_SRGB:
  147. return "BC7_SRGB";
  148. case PixelFormat::A4B4G4R4_UNORM:
  149. return "A4B4G4R4_UNORM";
  150. case PixelFormat::ASTC_2D_4X4_SRGB:
  151. return "ASTC_2D_4X4_SRGB";
  152. case PixelFormat::ASTC_2D_8X8_SRGB:
  153. return "ASTC_2D_8X8_SRGB";
  154. case PixelFormat::ASTC_2D_8X5_SRGB:
  155. return "ASTC_2D_8X5_SRGB";
  156. case PixelFormat::ASTC_2D_5X4_SRGB:
  157. return "ASTC_2D_5X4_SRGB";
  158. case PixelFormat::ASTC_2D_5X5_UNORM:
  159. return "ASTC_2D_5X5_UNORM";
  160. case PixelFormat::ASTC_2D_5X5_SRGB:
  161. return "ASTC_2D_5X5_SRGB";
  162. case PixelFormat::ASTC_2D_10X8_UNORM:
  163. return "ASTC_2D_10X8_UNORM";
  164. case PixelFormat::ASTC_2D_10X8_SRGB:
  165. return "ASTC_2D_10X8_SRGB";
  166. case PixelFormat::ASTC_2D_6X6_UNORM:
  167. return "ASTC_2D_6X6_UNORM";
  168. case PixelFormat::ASTC_2D_6X6_SRGB:
  169. return "ASTC_2D_6X6_SRGB";
  170. case PixelFormat::ASTC_2D_10X10_UNORM:
  171. return "ASTC_2D_10X10_UNORM";
  172. case PixelFormat::ASTC_2D_10X10_SRGB:
  173. return "ASTC_2D_10X10_SRGB";
  174. case PixelFormat::ASTC_2D_12X12_UNORM:
  175. return "ASTC_2D_12X12_UNORM";
  176. case PixelFormat::ASTC_2D_12X12_SRGB:
  177. return "ASTC_2D_12X12_SRGB";
  178. case PixelFormat::ASTC_2D_8X6_UNORM:
  179. return "ASTC_2D_8X6_UNORM";
  180. case PixelFormat::ASTC_2D_8X6_SRGB:
  181. return "ASTC_2D_8X6_SRGB";
  182. case PixelFormat::ASTC_2D_6X5_UNORM:
  183. return "ASTC_2D_6X5_UNORM";
  184. case PixelFormat::ASTC_2D_6X5_SRGB:
  185. return "ASTC_2D_6X5_SRGB";
  186. case PixelFormat::E5B9G9R9_FLOAT:
  187. return "E5B9G9R9_FLOAT";
  188. case PixelFormat::D32_FLOAT:
  189. return "D32_FLOAT";
  190. case PixelFormat::D16_UNORM:
  191. return "D16_UNORM";
  192. case PixelFormat::S8_UINT:
  193. return "S8_UINT";
  194. case PixelFormat::D24_UNORM_S8_UINT:
  195. return "D24_UNORM_S8_UINT";
  196. case PixelFormat::S8_UINT_D24_UNORM:
  197. return "S8_UINT_D24_UNORM";
  198. case PixelFormat::D32_FLOAT_S8_UINT:
  199. return "D32_FLOAT_S8_UINT";
  200. case PixelFormat::MaxDepthStencilFormat:
  201. case PixelFormat::Invalid:
  202. return "Invalid";
  203. }
  204. return "Invalid";
  205. }();
  206. return formatter<string_view>::format(name, ctx);
  207. }
  208. };
  209. template <>
  210. struct fmt::formatter<VideoCommon::ImageType> : fmt::formatter<fmt::string_view> {
  211. template <typename FormatContext>
  212. auto format(VideoCommon::ImageType type, FormatContext& ctx) {
  213. const string_view name = [type] {
  214. using VideoCommon::ImageType;
  215. switch (type) {
  216. case ImageType::e1D:
  217. return "1D";
  218. case ImageType::e2D:
  219. return "2D";
  220. case ImageType::e3D:
  221. return "3D";
  222. case ImageType::Linear:
  223. return "Linear";
  224. case ImageType::Buffer:
  225. return "Buffer";
  226. }
  227. return "Invalid";
  228. }();
  229. return formatter<string_view>::format(name, ctx);
  230. }
  231. };
  232. template <>
  233. struct fmt::formatter<VideoCommon::Extent3D> {
  234. constexpr auto parse(fmt::format_parse_context& ctx) {
  235. return ctx.begin();
  236. }
  237. template <typename FormatContext>
  238. auto format(const VideoCommon::Extent3D& extent, FormatContext& ctx) {
  239. return fmt::format_to(ctx.out(), "{{{}, {}, {}}}", extent.width, extent.height,
  240. extent.depth);
  241. }
  242. };
  243. namespace VideoCommon {
  244. struct ImageBase;
  245. struct ImageViewBase;
  246. struct RenderTargets;
  247. [[nodiscard]] std::string Name(const ImageBase& image);
  248. [[nodiscard]] std::string Name(const ImageViewBase& image_view);
  249. [[nodiscard]] std::string Name(const RenderTargets& render_targets);
  250. } // namespace VideoCommon