surface.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518
  1. // Copyright 2014 Citra Emulator Project
  2. // Licensed under GPLv2 or any later version
  3. // Refer to the license.txt file included.
  4. #include "common/common_types.h"
  5. #include "common/math_util.h"
  6. #include "video_core/surface.h"
  7. namespace VideoCore::Surface {
  8. SurfaceTarget SurfaceTargetFromTextureType(Tegra::Texture::TextureType texture_type) {
  9. switch (texture_type) {
  10. case Tegra::Texture::TextureType::Texture1D:
  11. return SurfaceTarget::Texture1D;
  12. case Tegra::Texture::TextureType::Texture2D:
  13. case Tegra::Texture::TextureType::Texture2DNoMipmap:
  14. return SurfaceTarget::Texture2D;
  15. case Tegra::Texture::TextureType::Texture3D:
  16. return SurfaceTarget::Texture3D;
  17. case Tegra::Texture::TextureType::TextureCubemap:
  18. return SurfaceTarget::TextureCubemap;
  19. case Tegra::Texture::TextureType::TextureCubeArray:
  20. return SurfaceTarget::TextureCubeArray;
  21. case Tegra::Texture::TextureType::Texture1DArray:
  22. return SurfaceTarget::Texture1DArray;
  23. case Tegra::Texture::TextureType::Texture2DArray:
  24. return SurfaceTarget::Texture2DArray;
  25. default:
  26. LOG_CRITICAL(HW_GPU, "Unimplemented texture_type={}", static_cast<u32>(texture_type));
  27. UNREACHABLE();
  28. return SurfaceTarget::Texture2D;
  29. }
  30. }
  31. bool SurfaceTargetIsLayered(SurfaceTarget target) {
  32. switch (target) {
  33. case SurfaceTarget::Texture1D:
  34. case SurfaceTarget::Texture2D:
  35. case SurfaceTarget::Texture3D:
  36. return false;
  37. case SurfaceTarget::Texture1DArray:
  38. case SurfaceTarget::Texture2DArray:
  39. case SurfaceTarget::TextureCubemap:
  40. case SurfaceTarget::TextureCubeArray:
  41. return true;
  42. default:
  43. LOG_CRITICAL(HW_GPU, "Unimplemented surface_target={}", static_cast<u32>(target));
  44. UNREACHABLE();
  45. return false;
  46. }
  47. }
  48. bool SurfaceTargetIsArray(SurfaceTarget target) {
  49. switch (target) {
  50. case SurfaceTarget::Texture1D:
  51. case SurfaceTarget::Texture2D:
  52. case SurfaceTarget::Texture3D:
  53. case SurfaceTarget::TextureCubemap:
  54. return false;
  55. case SurfaceTarget::Texture1DArray:
  56. case SurfaceTarget::Texture2DArray:
  57. case SurfaceTarget::TextureCubeArray:
  58. return true;
  59. default:
  60. LOG_CRITICAL(HW_GPU, "Unimplemented surface_target={}", static_cast<u32>(target));
  61. UNREACHABLE();
  62. return false;
  63. }
  64. }
  65. PixelFormat PixelFormatFromDepthFormat(Tegra::DepthFormat format) {
  66. switch (format) {
  67. case Tegra::DepthFormat::S8_Z24_UNORM:
  68. return PixelFormat::S8Z24;
  69. case Tegra::DepthFormat::Z24_S8_UNORM:
  70. return PixelFormat::Z24S8;
  71. case Tegra::DepthFormat::Z32_FLOAT:
  72. return PixelFormat::Z32F;
  73. case Tegra::DepthFormat::Z16_UNORM:
  74. return PixelFormat::Z16;
  75. case Tegra::DepthFormat::Z32_S8_X24_FLOAT:
  76. return PixelFormat::Z32FS8;
  77. default:
  78. LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
  79. UNREACHABLE();
  80. return PixelFormat::S8Z24;
  81. }
  82. }
  83. PixelFormat PixelFormatFromRenderTargetFormat(Tegra::RenderTargetFormat format) {
  84. switch (format) {
  85. // TODO (Hexagon12): Converting SRGBA to RGBA is a hack and doesn't completely correct the
  86. // gamma.
  87. case Tegra::RenderTargetFormat::RGBA8_SRGB:
  88. return PixelFormat::RGBA8_SRGB;
  89. case Tegra::RenderTargetFormat::RGBA8_UNORM:
  90. return PixelFormat::ABGR8U;
  91. case Tegra::RenderTargetFormat::RGBA8_SNORM:
  92. return PixelFormat::ABGR8S;
  93. case Tegra::RenderTargetFormat::RGBA8_UINT:
  94. return PixelFormat::ABGR8UI;
  95. case Tegra::RenderTargetFormat::BGRA8_SRGB:
  96. return PixelFormat::BGRA8_SRGB;
  97. case Tegra::RenderTargetFormat::BGRA8_UNORM:
  98. return PixelFormat::BGRA8;
  99. case Tegra::RenderTargetFormat::RGB10_A2_UNORM:
  100. return PixelFormat::A2B10G10R10U;
  101. case Tegra::RenderTargetFormat::RGBA16_FLOAT:
  102. return PixelFormat::RGBA16F;
  103. case Tegra::RenderTargetFormat::RGBA16_UNORM:
  104. return PixelFormat::RGBA16U;
  105. case Tegra::RenderTargetFormat::RGBA16_UINT:
  106. return PixelFormat::RGBA16UI;
  107. case Tegra::RenderTargetFormat::RGBA32_FLOAT:
  108. return PixelFormat::RGBA32F;
  109. case Tegra::RenderTargetFormat::RG32_FLOAT:
  110. return PixelFormat::RG32F;
  111. case Tegra::RenderTargetFormat::R11G11B10_FLOAT:
  112. return PixelFormat::R11FG11FB10F;
  113. case Tegra::RenderTargetFormat::B5G6R5_UNORM:
  114. return PixelFormat::B5G6R5U;
  115. case Tegra::RenderTargetFormat::BGR5A1_UNORM:
  116. return PixelFormat::A1B5G5R5U;
  117. case Tegra::RenderTargetFormat::RGBA32_UINT:
  118. return PixelFormat::RGBA32UI;
  119. case Tegra::RenderTargetFormat::R8_UNORM:
  120. return PixelFormat::R8U;
  121. case Tegra::RenderTargetFormat::R8_UINT:
  122. return PixelFormat::R8UI;
  123. case Tegra::RenderTargetFormat::RG16_FLOAT:
  124. return PixelFormat::RG16F;
  125. case Tegra::RenderTargetFormat::RG16_UINT:
  126. return PixelFormat::RG16UI;
  127. case Tegra::RenderTargetFormat::RG16_SINT:
  128. return PixelFormat::RG16I;
  129. case Tegra::RenderTargetFormat::RG16_UNORM:
  130. return PixelFormat::RG16;
  131. case Tegra::RenderTargetFormat::RG16_SNORM:
  132. return PixelFormat::RG16S;
  133. case Tegra::RenderTargetFormat::RG8_UNORM:
  134. return PixelFormat::RG8U;
  135. case Tegra::RenderTargetFormat::RG8_SNORM:
  136. return PixelFormat::RG8S;
  137. case Tegra::RenderTargetFormat::R16_FLOAT:
  138. return PixelFormat::R16F;
  139. case Tegra::RenderTargetFormat::R16_UNORM:
  140. return PixelFormat::R16U;
  141. case Tegra::RenderTargetFormat::R16_SNORM:
  142. return PixelFormat::R16S;
  143. case Tegra::RenderTargetFormat::R16_UINT:
  144. return PixelFormat::R16UI;
  145. case Tegra::RenderTargetFormat::R16_SINT:
  146. return PixelFormat::R16I;
  147. case Tegra::RenderTargetFormat::R32_FLOAT:
  148. return PixelFormat::R32F;
  149. case Tegra::RenderTargetFormat::R32_UINT:
  150. return PixelFormat::R32UI;
  151. case Tegra::RenderTargetFormat::RG32_UINT:
  152. return PixelFormat::RG32UI;
  153. default:
  154. LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
  155. UNREACHABLE();
  156. return PixelFormat::RGBA8_SRGB;
  157. }
  158. }
  159. PixelFormat PixelFormatFromTextureFormat(Tegra::Texture::TextureFormat format,
  160. Tegra::Texture::ComponentType component_type,
  161. bool is_srgb) {
  162. // TODO(Subv): Properly implement this
  163. switch (format) {
  164. case Tegra::Texture::TextureFormat::A8R8G8B8:
  165. if (is_srgb) {
  166. return PixelFormat::RGBA8_SRGB;
  167. }
  168. switch (component_type) {
  169. case Tegra::Texture::ComponentType::UNORM:
  170. return PixelFormat::ABGR8U;
  171. case Tegra::Texture::ComponentType::SNORM:
  172. return PixelFormat::ABGR8S;
  173. case Tegra::Texture::ComponentType::UINT:
  174. return PixelFormat::ABGR8UI;
  175. }
  176. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  177. UNREACHABLE();
  178. case Tegra::Texture::TextureFormat::B5G6R5:
  179. switch (component_type) {
  180. case Tegra::Texture::ComponentType::UNORM:
  181. return PixelFormat::B5G6R5U;
  182. }
  183. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  184. UNREACHABLE();
  185. case Tegra::Texture::TextureFormat::A2B10G10R10:
  186. switch (component_type) {
  187. case Tegra::Texture::ComponentType::UNORM:
  188. return PixelFormat::A2B10G10R10U;
  189. }
  190. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  191. UNREACHABLE();
  192. case Tegra::Texture::TextureFormat::A1B5G5R5:
  193. switch (component_type) {
  194. case Tegra::Texture::ComponentType::UNORM:
  195. return PixelFormat::A1B5G5R5U;
  196. }
  197. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  198. UNREACHABLE();
  199. case Tegra::Texture::TextureFormat::R8:
  200. switch (component_type) {
  201. case Tegra::Texture::ComponentType::UNORM:
  202. return PixelFormat::R8U;
  203. case Tegra::Texture::ComponentType::UINT:
  204. return PixelFormat::R8UI;
  205. }
  206. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  207. UNREACHABLE();
  208. case Tegra::Texture::TextureFormat::G8R8:
  209. // TextureFormat::G8R8 is actually ordered red then green, as such we can use
  210. // PixelFormat::RG8U and PixelFormat::RG8S. This was tested with The Legend of Zelda: Breath
  211. // of the Wild, which uses this format to render the hearts on the UI.
  212. switch (component_type) {
  213. case Tegra::Texture::ComponentType::UNORM:
  214. return PixelFormat::RG8U;
  215. case Tegra::Texture::ComponentType::SNORM:
  216. return PixelFormat::RG8S;
  217. }
  218. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  219. UNREACHABLE();
  220. case Tegra::Texture::TextureFormat::R16_G16_B16_A16:
  221. switch (component_type) {
  222. case Tegra::Texture::ComponentType::UNORM:
  223. return PixelFormat::RGBA16U;
  224. case Tegra::Texture::ComponentType::FLOAT:
  225. return PixelFormat::RGBA16F;
  226. }
  227. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  228. UNREACHABLE();
  229. case Tegra::Texture::TextureFormat::BF10GF11RF11:
  230. switch (component_type) {
  231. case Tegra::Texture::ComponentType::FLOAT:
  232. return PixelFormat::R11FG11FB10F;
  233. }
  234. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  235. UNREACHABLE();
  236. case Tegra::Texture::TextureFormat::R32_G32_B32_A32:
  237. switch (component_type) {
  238. case Tegra::Texture::ComponentType::FLOAT:
  239. return PixelFormat::RGBA32F;
  240. case Tegra::Texture::ComponentType::UINT:
  241. return PixelFormat::RGBA32UI;
  242. }
  243. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  244. UNREACHABLE();
  245. case Tegra::Texture::TextureFormat::R32_G32:
  246. switch (component_type) {
  247. case Tegra::Texture::ComponentType::FLOAT:
  248. return PixelFormat::RG32F;
  249. case Tegra::Texture::ComponentType::UINT:
  250. return PixelFormat::RG32UI;
  251. }
  252. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  253. UNREACHABLE();
  254. case Tegra::Texture::TextureFormat::R32_G32_B32:
  255. switch (component_type) {
  256. case Tegra::Texture::ComponentType::FLOAT:
  257. return PixelFormat::RGB32F;
  258. }
  259. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  260. UNREACHABLE();
  261. case Tegra::Texture::TextureFormat::R16:
  262. switch (component_type) {
  263. case Tegra::Texture::ComponentType::FLOAT:
  264. return PixelFormat::R16F;
  265. case Tegra::Texture::ComponentType::UNORM:
  266. return PixelFormat::R16U;
  267. case Tegra::Texture::ComponentType::SNORM:
  268. return PixelFormat::R16S;
  269. case Tegra::Texture::ComponentType::UINT:
  270. return PixelFormat::R16UI;
  271. case Tegra::Texture::ComponentType::SINT:
  272. return PixelFormat::R16I;
  273. }
  274. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  275. UNREACHABLE();
  276. case Tegra::Texture::TextureFormat::R32:
  277. switch (component_type) {
  278. case Tegra::Texture::ComponentType::FLOAT:
  279. return PixelFormat::R32F;
  280. case Tegra::Texture::ComponentType::UINT:
  281. return PixelFormat::R32UI;
  282. }
  283. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  284. UNREACHABLE();
  285. case Tegra::Texture::TextureFormat::ZF32:
  286. return PixelFormat::Z32F;
  287. case Tegra::Texture::TextureFormat::Z16:
  288. return PixelFormat::Z16;
  289. case Tegra::Texture::TextureFormat::Z24S8:
  290. return PixelFormat::Z24S8;
  291. case Tegra::Texture::TextureFormat::DXT1:
  292. return is_srgb ? PixelFormat::DXT1_SRGB : PixelFormat::DXT1;
  293. case Tegra::Texture::TextureFormat::DXT23:
  294. return is_srgb ? PixelFormat::DXT23_SRGB : PixelFormat::DXT23;
  295. case Tegra::Texture::TextureFormat::DXT45:
  296. return is_srgb ? PixelFormat::DXT45_SRGB : PixelFormat::DXT45;
  297. case Tegra::Texture::TextureFormat::DXN1:
  298. return PixelFormat::DXN1;
  299. case Tegra::Texture::TextureFormat::DXN2:
  300. switch (component_type) {
  301. case Tegra::Texture::ComponentType::UNORM:
  302. return PixelFormat::DXN2UNORM;
  303. case Tegra::Texture::ComponentType::SNORM:
  304. return PixelFormat::DXN2SNORM;
  305. }
  306. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  307. UNREACHABLE();
  308. case Tegra::Texture::TextureFormat::BC7U:
  309. return is_srgb ? PixelFormat::BC7U_SRGB : PixelFormat::BC7U;
  310. case Tegra::Texture::TextureFormat::BC6H_UF16:
  311. return PixelFormat::BC6H_UF16;
  312. case Tegra::Texture::TextureFormat::BC6H_SF16:
  313. return PixelFormat::BC6H_SF16;
  314. case Tegra::Texture::TextureFormat::ASTC_2D_4X4:
  315. return is_srgb ? PixelFormat::ASTC_2D_4X4_SRGB : PixelFormat::ASTC_2D_4X4;
  316. case Tegra::Texture::TextureFormat::ASTC_2D_5X4:
  317. return is_srgb ? PixelFormat::ASTC_2D_5X4_SRGB : PixelFormat::ASTC_2D_5X4;
  318. case Tegra::Texture::TextureFormat::ASTC_2D_5X5:
  319. return is_srgb ? PixelFormat::ASTC_2D_5X5_SRGB : PixelFormat::ASTC_2D_5X5;
  320. case Tegra::Texture::TextureFormat::ASTC_2D_8X8:
  321. return is_srgb ? PixelFormat::ASTC_2D_8X8_SRGB : PixelFormat::ASTC_2D_8X8;
  322. case Tegra::Texture::TextureFormat::ASTC_2D_8X5:
  323. return is_srgb ? PixelFormat::ASTC_2D_8X5_SRGB : PixelFormat::ASTC_2D_8X5;
  324. case Tegra::Texture::TextureFormat::ASTC_2D_10X8:
  325. return is_srgb ? PixelFormat::ASTC_2D_10X8_SRGB : PixelFormat::ASTC_2D_10X8;
  326. case Tegra::Texture::TextureFormat::R16_G16:
  327. switch (component_type) {
  328. case Tegra::Texture::ComponentType::FLOAT:
  329. return PixelFormat::RG16F;
  330. case Tegra::Texture::ComponentType::UNORM:
  331. return PixelFormat::RG16;
  332. case Tegra::Texture::ComponentType::SNORM:
  333. return PixelFormat::RG16S;
  334. case Tegra::Texture::ComponentType::UINT:
  335. return PixelFormat::RG16UI;
  336. case Tegra::Texture::ComponentType::SINT:
  337. return PixelFormat::RG16I;
  338. }
  339. LOG_CRITICAL(HW_GPU, "Unimplemented component_type={}", static_cast<u32>(component_type));
  340. UNREACHABLE();
  341. default:
  342. LOG_CRITICAL(HW_GPU, "Unimplemented format={}, component_type={}", static_cast<u32>(format),
  343. static_cast<u32>(component_type));
  344. UNREACHABLE();
  345. return PixelFormat::ABGR8U;
  346. }
  347. }
  348. ComponentType ComponentTypeFromTexture(Tegra::Texture::ComponentType type) {
  349. // TODO(Subv): Implement more component types
  350. switch (type) {
  351. case Tegra::Texture::ComponentType::UNORM:
  352. return ComponentType::UNorm;
  353. case Tegra::Texture::ComponentType::FLOAT:
  354. return ComponentType::Float;
  355. case Tegra::Texture::ComponentType::SNORM:
  356. return ComponentType::SNorm;
  357. case Tegra::Texture::ComponentType::UINT:
  358. return ComponentType::UInt;
  359. case Tegra::Texture::ComponentType::SINT:
  360. return ComponentType::SInt;
  361. default:
  362. LOG_CRITICAL(HW_GPU, "Unimplemented component type={}", static_cast<u32>(type));
  363. UNREACHABLE();
  364. return ComponentType::UNorm;
  365. }
  366. }
  367. ComponentType ComponentTypeFromRenderTarget(Tegra::RenderTargetFormat format) {
  368. // TODO(Subv): Implement more render targets
  369. switch (format) {
  370. case Tegra::RenderTargetFormat::RGBA8_UNORM:
  371. case Tegra::RenderTargetFormat::RGBA8_SRGB:
  372. case Tegra::RenderTargetFormat::BGRA8_UNORM:
  373. case Tegra::RenderTargetFormat::BGRA8_SRGB:
  374. case Tegra::RenderTargetFormat::RGB10_A2_UNORM:
  375. case Tegra::RenderTargetFormat::R8_UNORM:
  376. case Tegra::RenderTargetFormat::RG16_UNORM:
  377. case Tegra::RenderTargetFormat::R16_UNORM:
  378. case Tegra::RenderTargetFormat::B5G6R5_UNORM:
  379. case Tegra::RenderTargetFormat::BGR5A1_UNORM:
  380. case Tegra::RenderTargetFormat::RG8_UNORM:
  381. case Tegra::RenderTargetFormat::RGBA16_UNORM:
  382. return ComponentType::UNorm;
  383. case Tegra::RenderTargetFormat::RGBA8_SNORM:
  384. case Tegra::RenderTargetFormat::RG16_SNORM:
  385. case Tegra::RenderTargetFormat::R16_SNORM:
  386. case Tegra::RenderTargetFormat::RG8_SNORM:
  387. return ComponentType::SNorm;
  388. case Tegra::RenderTargetFormat::RGBA16_FLOAT:
  389. case Tegra::RenderTargetFormat::R11G11B10_FLOAT:
  390. case Tegra::RenderTargetFormat::RGBA32_FLOAT:
  391. case Tegra::RenderTargetFormat::RG32_FLOAT:
  392. case Tegra::RenderTargetFormat::RG16_FLOAT:
  393. case Tegra::RenderTargetFormat::R16_FLOAT:
  394. case Tegra::RenderTargetFormat::R32_FLOAT:
  395. return ComponentType::Float;
  396. case Tegra::RenderTargetFormat::RGBA32_UINT:
  397. case Tegra::RenderTargetFormat::RGBA16_UINT:
  398. case Tegra::RenderTargetFormat::RG16_UINT:
  399. case Tegra::RenderTargetFormat::R8_UINT:
  400. case Tegra::RenderTargetFormat::R16_UINT:
  401. case Tegra::RenderTargetFormat::RG32_UINT:
  402. case Tegra::RenderTargetFormat::R32_UINT:
  403. case Tegra::RenderTargetFormat::RGBA8_UINT:
  404. return ComponentType::UInt;
  405. case Tegra::RenderTargetFormat::RG16_SINT:
  406. case Tegra::RenderTargetFormat::R16_SINT:
  407. return ComponentType::SInt;
  408. default:
  409. LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
  410. UNREACHABLE();
  411. return ComponentType::UNorm;
  412. }
  413. }
  414. PixelFormat PixelFormatFromGPUPixelFormat(Tegra::FramebufferConfig::PixelFormat format) {
  415. switch (format) {
  416. case Tegra::FramebufferConfig::PixelFormat::ABGR8:
  417. return PixelFormat::ABGR8U;
  418. default:
  419. LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
  420. UNREACHABLE();
  421. return PixelFormat::ABGR8U;
  422. }
  423. }
  424. ComponentType ComponentTypeFromDepthFormat(Tegra::DepthFormat format) {
  425. switch (format) {
  426. case Tegra::DepthFormat::Z16_UNORM:
  427. case Tegra::DepthFormat::S8_Z24_UNORM:
  428. case Tegra::DepthFormat::Z24_S8_UNORM:
  429. return ComponentType::UNorm;
  430. case Tegra::DepthFormat::Z32_FLOAT:
  431. case Tegra::DepthFormat::Z32_S8_X24_FLOAT:
  432. return ComponentType::Float;
  433. default:
  434. LOG_CRITICAL(HW_GPU, "Unimplemented format={}", static_cast<u32>(format));
  435. UNREACHABLE();
  436. return ComponentType::UNorm;
  437. }
  438. }
  439. SurfaceType GetFormatType(PixelFormat pixel_format) {
  440. if (static_cast<std::size_t>(pixel_format) <
  441. static_cast<std::size_t>(PixelFormat::MaxColorFormat)) {
  442. return SurfaceType::ColorTexture;
  443. }
  444. if (static_cast<std::size_t>(pixel_format) <
  445. static_cast<std::size_t>(PixelFormat::MaxDepthFormat)) {
  446. return SurfaceType::Depth;
  447. }
  448. if (static_cast<std::size_t>(pixel_format) <
  449. static_cast<std::size_t>(PixelFormat::MaxDepthStencilFormat)) {
  450. return SurfaceType::DepthStencil;
  451. }
  452. // TODO(Subv): Implement the other formats
  453. ASSERT(false);
  454. return SurfaceType::Invalid;
  455. }
  456. bool IsPixelFormatASTC(PixelFormat format) {
  457. switch (format) {
  458. case PixelFormat::ASTC_2D_4X4:
  459. case PixelFormat::ASTC_2D_5X4:
  460. case PixelFormat::ASTC_2D_5X5:
  461. case PixelFormat::ASTC_2D_8X8:
  462. case PixelFormat::ASTC_2D_8X5:
  463. case PixelFormat::ASTC_2D_4X4_SRGB:
  464. case PixelFormat::ASTC_2D_5X4_SRGB:
  465. case PixelFormat::ASTC_2D_5X5_SRGB:
  466. case PixelFormat::ASTC_2D_8X8_SRGB:
  467. case PixelFormat::ASTC_2D_8X5_SRGB:
  468. case PixelFormat::ASTC_2D_10X8:
  469. case PixelFormat::ASTC_2D_10X8_SRGB:
  470. return true;
  471. default:
  472. return false;
  473. }
  474. }
  475. std::pair<u32, u32> GetASTCBlockSize(PixelFormat format) {
  476. return {GetDefaultBlockWidth(format), GetDefaultBlockHeight(format)};
  477. }
  478. bool IsFormatBCn(PixelFormat format) {
  479. switch (format) {
  480. case PixelFormat::DXT1:
  481. case PixelFormat::DXT23:
  482. case PixelFormat::DXT45:
  483. case PixelFormat::DXN1:
  484. case PixelFormat::DXN2SNORM:
  485. case PixelFormat::DXN2UNORM:
  486. case PixelFormat::BC7U:
  487. case PixelFormat::BC6H_UF16:
  488. case PixelFormat::BC6H_SF16:
  489. case PixelFormat::DXT1_SRGB:
  490. case PixelFormat::DXT23_SRGB:
  491. case PixelFormat::DXT45_SRGB:
  492. case PixelFormat::BC7U_SRGB:
  493. return true;
  494. }
  495. return false;
  496. }
  497. } // namespace VideoCore::Surface