formatter.h 11 KB

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